add more templates

This commit is contained in:
Roy Qu 2022-01-10 10:53:16 +08:00
parent 4c57a7beda
commit c56b6c5414
15 changed files with 315 additions and 105 deletions

View File

@ -1,6 +1,7 @@
Red Panda C++ Version 0.13.2 Red Panda C++ Version 0.13.2
- fix: "delete and exit" button in the environtment / page option page doesn't work correctly - fix: "delete and exit" button in the environtment / page option page doesn't work correctly
- fix: crash when closing the options dialog under Ubuntu 20.04 LTS ( no memory leak now) - fix: crash when closing the options dialog under Ubuntu 20.04 LTS ( no memory leak now)
- enhancement: can add non-code file in templates
Red Panda C++ Version 0.13.1 Red Panda C++ Version 0.13.1
- enhancement: suppoort localization info in project templates - enhancement: suppoort localization info in project templates

View File

@ -172,6 +172,12 @@ CompileIssueType Compiler::getIssueTypeFromOutputLine(QString &line)
Settings::PCompilerSet Compiler::compilerSet() Settings::PCompilerSet Compiler::compilerSet()
{ {
if (mProject) {
int index = mProject->options().compilerSet;
Settings::PCompilerSet set = pSettings->compilerSets().getSet(index);
if (set)
return set;
}
return pSettings->compilerSets().defaultSet(); return pSettings->compilerSets().defaultSet();
} }

View File

@ -1346,6 +1346,7 @@ void MainWindow::checkSyntaxInBack(Editor *e)
mCompilerManager->checkSyntax(e->filename(),e->text(), mCompilerManager->checkSyntax(e->filename(),e->text(),
e->fileEncoding() == ENCODING_ASCII, mProject); e->fileEncoding() == ENCODING_ASCII, mProject);
} else { } else {
qDebug()<<"compile file";
mCompilerManager->checkSyntax(e->filename(),e->text(), mCompilerManager->checkSyntax(e->filename(),e->text(),
e->fileEncoding() == ENCODING_ASCII, nullptr); e->fileEncoding() == ENCODING_ASCII, nullptr);
} }

View File

@ -648,38 +648,49 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, b
for (int i=0;i<aTemplate->unitCount();i++) { for (int i=0;i<aTemplate->unitCount();i++) {
// Pick file contents // Pick file contents
PTemplateUnit templateUnit = aTemplate->unit(i); PTemplateUnit templateUnit = aTemplate->unit(i);
QString s; if (!templateUnit->Source.isEmpty()) {
PProjectUnit unit; QString target = templateUnit->Source;
if (mOptions.useGPP) { PProjectUnit unit;
s = templateUnit->CppText; if (!templateUnit->Target.isEmpty())
unit = newUnit(mNode, templateUnit->CppName); target = templateUnit->Target;
QFile::copy(
QDir(pSettings->dirs().templateDir()).absoluteFilePath(templateUnit->Source),
includeTrailingPathDelimiter(this->directory())+target);
unit = newUnit(mNode, target);
} else { } else {
s = templateUnit->CText; QString s;
unit = newUnit(mNode,templateUnit->CName); PProjectUnit unit;
} if (mOptions.useGPP) {
s = templateUnit->CppText;
Editor * editor = pMainWindow->editorList()->newEditor( unit = newUnit(mNode, templateUnit->CppName);
QDir(directory()).absoluteFilePath(unit->fileName()), } else {
unit->encoding(), s = templateUnit->CText;
true, unit = newUnit(mNode,templateUnit->CName);
true);
QString s2 = QDir(pSettings->dirs().templateDir()).absoluteFilePath(s);
if (fileExists(s2) && !s.isEmpty()) {
try {
editor->loadFile(s2);
} catch(FileError& e) {
QMessageBox::critical(pMainWindow,
tr("Error Load File"),
e.reason());
} }
} else {
s.replace("#13#10","\r\n"); Editor * editor = pMainWindow->editorList()->newEditor(
editor->insertString(s,false); QDir(directory()).absoluteFilePath(unit->fileName()),
unit->encoding(),
true,
true);
QString s2 = QDir(pSettings->dirs().templateDir()).absoluteFilePath(s);
if (fileExists(s2) && !s.isEmpty()) {
try {
editor->loadFile(s2);
} catch(FileError& e) {
QMessageBox::critical(pMainWindow,
tr("Error Load File"),
e.reason());
}
} else {
s.replace("#13#10","\r\n");
editor->insertString(s,false);
}
unit->setEditor(editor);
editor->save(true,false);
editor->activate();
} }
unit->setEditor(editor);
editor->save(true,false);
editor->activate();
} }
} }
return true; return true;

View File

@ -38,6 +38,8 @@ PTemplateUnit ProjectTemplate::unit(int index)
return PTemplateUnit(); return PTemplateUnit();
QString section = QString("Unit%1").arg(index); QString section = QString("Unit%1").arg(index);
PTemplateUnit unit = std::make_shared<TemplateUnit>(); PTemplateUnit unit = std::make_shared<TemplateUnit>();
unit->Source = fromByteArray(mIni->GetValue(toByteArray(section), "Source", ""));
unit->Target = fromByteArray(mIni->GetValue(toByteArray(section), "Target", ""));
unit->CText = fromByteArray(mIni->GetValue(toByteArray(section), "C", "")); unit->CText = fromByteArray(mIni->GetValue(toByteArray(section), "C", ""));
unit->CppText = fromByteArray(mIni->GetValue(toByteArray(section), "Cpp", "")); unit->CppText = fromByteArray(mIni->GetValue(toByteArray(section), "Cpp", ""));
if (unit->CppText.isEmpty()) if (unit->CppText.isEmpty())
@ -59,6 +61,8 @@ void ProjectTemplate::setUnit(int index, PTemplateUnit newUnit)
mIni->SetValue(section,"Cpp", toByteArray(newUnit->CppText)); mIni->SetValue(section,"Cpp", toByteArray(newUnit->CppText));
mIni->SetValue(section,"CName", toByteArray(newUnit->CName)); mIni->SetValue(section,"CName", toByteArray(newUnit->CName));
mIni->SetValue(section,"CppName", toByteArray(newUnit->CppName)); mIni->SetValue(section,"CppName", toByteArray(newUnit->CppName));
mIni->SetValue(section,"Source", toByteArray(newUnit->Source));
mIni->SetValue(section,"Target", toByteArray(newUnit->Target));
} }
int ProjectTemplate::addUnit() int ProjectTemplate::addUnit()

View File

@ -26,6 +26,8 @@ struct TemplateUnit {
QString CppName; QString CppName;
QString CText; QString CText;
QString CppText; QString CppText;
QString Source;
QString Target;
}; };
using PTemplateUnit = std::shared_ptr<TemplateUnit>; using PTemplateUnit = std::shared_ptr<TemplateUnit>;

View File

@ -5,7 +5,7 @@ Icon=CL_GLUT.ico
Description=A simple GLUT program Description=A simple GLUT program
Description[zh_CN]=一个简单的GLUT程序 Description[zh_CN]=一个简单的GLUT程序
Category=Multimedia Category=Multimedia
Category[zh_CN]=多媒体 Category[zh_CN]=3D
[Unit0] [Unit0]
CppName=main.cpp CppName=main.cpp

View File

@ -5,7 +5,7 @@ Description=A simple GLFW program
Description[zh_CN]=一个简单的GLFW程序 Description[zh_CN]=一个简单的GLFW程序
Icon=GLFW.ico Icon=GLFW.ico
Category=Multimedia Category=Multimedia
Category[zh_CN]=多媒体 Category[zh_CN]=3D
[Unit0] [Unit0]
CppName=main.cpp CppName=main.cpp

View File

@ -5,7 +5,7 @@ Icon=Pizza.ico
Description=A basic OpenGL program Description=A basic OpenGL program
Description[zh_CN]=一个基本的OpenGL程序 Description[zh_CN]=一个基本的OpenGL程序
Category=Multimedia Category=Multimedia
Category[zh_CN]=多媒体 Category[zh_CN]=3D
[Unit0] [Unit0]
CName=main.c CName=main.c

View File

@ -4,7 +4,7 @@ Name=raylib
Name[zh_CN]=raylib Name[zh_CN]=raylib
Icon=raylib.ico Icon=raylib.ico
Description=A simple program using raylib ( https://raylib.com ) Description=A simple program using raylib ( https://raylib.com )
Description[zh_CN]=简单的raylib程序 ( https://raylib.com ) Description[zh_CN]=简单的raylib绘图程序 ( https://raylib.com )
Category=Multimedia Category=Multimedia
Category[zh_CN]=多媒体 Category[zh_CN]=多媒体
@ -12,8 +12,16 @@ Category[zh_CN]=多媒体
CName=main.c CName=main.c
C=raylib_c.txt C=raylib_c.txt
[Unit1]
Source=raylib_boom.wav
Target=boom.wav
[Unit2]
Source=raylib_explosion.png
Target=explosion.png
[Project] [Project]
UnitCount=1 UnitCount=3
Type=0 Type=0
IsCpp=0 IsCpp=0
linker=-lraylib -lopengl32 -lgdi32 -lwinmm_@@__@@_ linker=-lraylib -lopengl32 -lgdi32 -lwinmm_@@__@@_

View File

@ -0,0 +1,20 @@
[Template]
ver=2
Name=raylib 3D
Name[zh_CN]=raylib 3D
Icon=raylib.ico
Description=A simple 3D program using raylib ( https://raylib.com )
Description[zh_CN]=简单的raylib 3D程序 ( https://raylib.com )
Category=Multimedia
Category[zh_CN]=3D
[Unit0]
CName=main.c
C=raylib_3d_c.txt
[Project]
UnitCount=1
Type=0
IsCpp=0
linker=-lraylib -lopengl32 -lgdi32 -lwinmm_@@__@@_

112
templates/raylib_3d_c.txt Normal file
View File

@ -0,0 +1,112 @@
/*******************************************************************************************
*
* raylib [models] example - Waving cubes
*
* This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Example contributed by Codecat (@codecat) and reviewed by Ramon Santamaria (@raysan5)
*
* Copyright (c) 2019 Codecat (@codecat) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include <raylib.h>
#include <math.h>
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [models] example - waving cubes");
// Initialize the camera
Camera3D camera = { 0 };
camera.position = (Vector3){ 30.0f, 20.0f, 30.0f };
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.fovy = 70.0f;
camera.projection = CAMERA_PERSPECTIVE;
// Specify the amount of blocks in each direction
const int numBlocks = 15;
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
double time = GetTime();
// Calculate time scale for cube position and size
float scale = (2.0f + (float)sin(time))*0.7f;
// Move camera around the scene
double cameraTime = time*0.3;
camera.position.x = (float)cos(cameraTime)*40.0f;
camera.position.z = (float)sin(cameraTime)*40.0f;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
DrawGrid(10, 5.0f);
for (int x = 0; x < numBlocks; x++)
{
for (int y = 0; y < numBlocks; y++)
{
for (int z = 0; z < numBlocks; z++)
{
// Scale of the blocks depends on x/y/z positions
float blockScale = (x + y + z)/30.0f;
// Scatter makes the waving effect by adding blockScale over time
float scatter = sinf(blockScale*20.0f + (float)(time*4.0f));
// Calculate the cube position
Vector3 cubePos = {
(float)(x - numBlocks/2)*(scale*3.0f) + scatter,
(float)(y - numBlocks/2)*(scale*2.0f) + scatter,
(float)(z - numBlocks/2)*(scale*3.0f) + scatter
};
// Pick a color with a hue depending on cube position for the rainbow color effect
Color cubeColor = ColorFromHSV((float)(((x + y + z)*18)%360), 0.75f, 0.9f);
// Calculate cube size
float cubeSize = (2.4f - scale)*blockScale;
// And finally, draw the cube!
DrawCube(cubePos, cubeSize, cubeSize, cubeSize, cubeColor);
}
}
}
EndMode3D();
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

BIN
templates/raylib_boom.wav Normal file

Binary file not shown.

View File

@ -1,78 +1,123 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib [shapes] example - Draw basic shapes 2d (rectangle, circle, line...) * raylib [textures] example - sprite explosion
* *
* This example has been created using raylib 1.0 (www.raylib.com) * This example has been created using raylib 2.5 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
* *
* Copyright (c) 2014 Ramon Santamaria (@raysan5) * Copyright (c) 2019 Anata and Ramon Santamaria (@raysan5)
* * Copyright (c) 2022 Roy Qu (royqh1979@gmail.com)
********************************************************************************************/ *
********************************************************************************************/
#include <raylib.h> #include <raylib.h>
#define NUM_FRAMES_PER_LINE 5
#define NUM_LINES 5
int main(void) int main(void)
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
const int screenWidth = 800; const int screenWidth = 800;
const int screenHeight = 450; const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing"); InitWindow(screenWidth, screenHeight, "raylib [textures] example - sprite explosion");
SetTargetFPS(60); // Set our game to run at 60 frames-per-second InitAudioDevice();
//--------------------------------------------------------------------------------------
// Load explosion sound
// Main game loop Sound fxBoom = LoadSound("boom.wav");
while (!WindowShouldClose()) // Detect window close button or ESC key
{ // Load explosion texture
// Update Texture2D explosion = LoadTexture("explosion.png");
//----------------------------------------------------------------------------------
// TODO: Update your variables here // Init variables for animation
//---------------------------------------------------------------------------------- float frameWidth = (float)(explosion.width/NUM_FRAMES_PER_LINE); // Sprite one frame rectangle width
float frameHeight = (float)(explosion.height/NUM_LINES); // Sprite one frame rectangle height
// Draw int currentFrame = 0;
//---------------------------------------------------------------------------------- int currentLine = 0;
BeginDrawing();
Rectangle frameRec = { 0, 0, frameWidth, frameHeight };
ClearBackground(RAYWHITE); Vector2 position = { 0.0f, 0.0f };
DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY); bool active = false;
int framesCounter = 0;
// Circle shapes and lines
DrawCircle(screenWidth/5, 120, 35, DARKBLUE); SetTargetFPS(120);
DrawCircleGradient(screenWidth/5, 220, 60, GREEN, SKYBLUE); //--------------------------------------------------------------------------------------
DrawCircleLines(screenWidth/5, 340, 80, DARKBLUE);
// Main game loop
// Rectangle shapes and ines while (!WindowShouldClose()) // Detect window close button or ESC key
DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED); {
DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD); // Update
DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); // NOTE: Uses QUADS internally, not lines //----------------------------------------------------------------------------------
// Triangle shapes and lines // Check for mouse button pressed and activate explosion (if not active)
DrawTriangle((Vector2){screenWidth/4.0f *3.0f, 80.0f}, if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) )
(Vector2){screenWidth/4.0f *3.0f - 60.0f, 150.0f}, {
(Vector2){screenWidth/4.0f *3.0f + 60.0f, 150.0f}, VIOLET); position = GetMousePosition();
active = true;
DrawTriangleLines((Vector2){screenWidth/4.0f*3.0f, 160.0f},
(Vector2){screenWidth/4.0f*3.0f - 20.0f, 230.0f}, position.x -= frameWidth/2.0f;
(Vector2){screenWidth/4.0f*3.0f + 20.0f, 230.0f}, DARKBLUE); position.y -= frameHeight/2.0f;
// Polygon shapes and lines PlaySound(fxBoom);
DrawPoly((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, BROWN); }
DrawPolyLinesEx((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, 6, BEIGE);
// Compute explosion animation frames
// NOTE: We draw all LINES based shapes together to optimize internal drawing, if (active)
// this way, all LINES are rendered in a single draw pass {
DrawLine(18, 42, screenWidth - 18, 42, BLACK); framesCounter++;
EndDrawing();
//---------------------------------------------------------------------------------- if (framesCounter > 2)
} {
currentFrame++;
// De-Initialization
//-------------------------------------------------------------------------------------- if (currentFrame >= NUM_FRAMES_PER_LINE)
CloseWindow(); // Close window and OpenGL context {
//-------------------------------------------------------------------------------------- currentFrame = 0;
currentLine++;
return 0;
if (currentLine >= NUM_LINES)
{
currentLine = 0;
active = false;
}
}
framesCounter = 0;
}
}
frameRec.x = frameWidth*currentFrame;
frameRec.y = frameHeight*currentLine;
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw explosion required frame rectangle
if (active) DrawTextureRec(explosion, frameRec, position, WHITE);
DrawText("Click to explode!", 440, 400, 40, DARKGRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(explosion); // Unload texture
UnloadSound(fxBoom); // Unload sound
CloseAudioDevice();
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 811 KiB