add more templates
This commit is contained in:
parent
4c57a7beda
commit
c56b6c5414
1
NEWS.md
1
NEWS.md
|
@ -1,6 +1,7 @@
|
|||
Red Panda C++ Version 0.13.2
|
||||
- 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)
|
||||
- enhancement: can add non-code file in templates
|
||||
|
||||
Red Panda C++ Version 0.13.1
|
||||
- enhancement: suppoort localization info in project templates
|
||||
|
|
|
@ -172,6 +172,12 @@ CompileIssueType Compiler::getIssueTypeFromOutputLine(QString &line)
|
|||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -1346,6 +1346,7 @@ void MainWindow::checkSyntaxInBack(Editor *e)
|
|||
mCompilerManager->checkSyntax(e->filename(),e->text(),
|
||||
e->fileEncoding() == ENCODING_ASCII, mProject);
|
||||
} else {
|
||||
qDebug()<<"compile file";
|
||||
mCompilerManager->checkSyntax(e->filename(),e->text(),
|
||||
e->fileEncoding() == ENCODING_ASCII, nullptr);
|
||||
}
|
||||
|
|
|
@ -648,6 +648,16 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, b
|
|||
for (int i=0;i<aTemplate->unitCount();i++) {
|
||||
// Pick file contents
|
||||
PTemplateUnit templateUnit = aTemplate->unit(i);
|
||||
if (!templateUnit->Source.isEmpty()) {
|
||||
QString target = templateUnit->Source;
|
||||
PProjectUnit unit;
|
||||
if (!templateUnit->Target.isEmpty())
|
||||
target = templateUnit->Target;
|
||||
QFile::copy(
|
||||
QDir(pSettings->dirs().templateDir()).absoluteFilePath(templateUnit->Source),
|
||||
includeTrailingPathDelimiter(this->directory())+target);
|
||||
unit = newUnit(mNode, target);
|
||||
} else {
|
||||
QString s;
|
||||
PProjectUnit unit;
|
||||
if (mOptions.useGPP) {
|
||||
|
@ -682,6 +692,7 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate, b
|
|||
editor->activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ PTemplateUnit ProjectTemplate::unit(int index)
|
|||
return PTemplateUnit();
|
||||
QString section = QString("Unit%1").arg(index);
|
||||
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->CppText = fromByteArray(mIni->GetValue(toByteArray(section), "Cpp", ""));
|
||||
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,"CName", toByteArray(newUnit->CName));
|
||||
mIni->SetValue(section,"CppName", toByteArray(newUnit->CppName));
|
||||
mIni->SetValue(section,"Source", toByteArray(newUnit->Source));
|
||||
mIni->SetValue(section,"Target", toByteArray(newUnit->Target));
|
||||
}
|
||||
|
||||
int ProjectTemplate::addUnit()
|
||||
|
|
|
@ -26,6 +26,8 @@ struct TemplateUnit {
|
|||
QString CppName;
|
||||
QString CText;
|
||||
QString CppText;
|
||||
QString Source;
|
||||
QString Target;
|
||||
};
|
||||
|
||||
using PTemplateUnit = std::shared_ptr<TemplateUnit>;
|
||||
|
|
|
@ -5,7 +5,7 @@ Icon=CL_GLUT.ico
|
|||
Description=A simple GLUT program
|
||||
Description[zh_CN]=一个简单的GLUT程序
|
||||
Category=Multimedia
|
||||
Category[zh_CN]=多媒体
|
||||
Category[zh_CN]=3D
|
||||
|
||||
[Unit0]
|
||||
CppName=main.cpp
|
||||
|
|
|
@ -5,7 +5,7 @@ Description=A simple GLFW program
|
|||
Description[zh_CN]=一个简单的GLFW程序
|
||||
Icon=GLFW.ico
|
||||
Category=Multimedia
|
||||
Category[zh_CN]=多媒体
|
||||
Category[zh_CN]=3D
|
||||
|
||||
[Unit0]
|
||||
CppName=main.cpp
|
||||
|
|
|
@ -5,7 +5,7 @@ Icon=Pizza.ico
|
|||
Description=A basic OpenGL program
|
||||
Description[zh_CN]=一个基本的OpenGL程序
|
||||
Category=Multimedia
|
||||
Category[zh_CN]=多媒体
|
||||
Category[zh_CN]=3D
|
||||
|
||||
[Unit0]
|
||||
CName=main.c
|
||||
|
|
|
@ -4,7 +4,7 @@ Name=raylib
|
|||
Name[zh_CN]=raylib
|
||||
Icon=raylib.ico
|
||||
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[zh_CN]=多媒体
|
||||
|
||||
|
@ -12,8 +12,16 @@ Category[zh_CN]=多媒体
|
|||
CName=main.c
|
||||
C=raylib_c.txt
|
||||
|
||||
[Unit1]
|
||||
Source=raylib_boom.wav
|
||||
Target=boom.wav
|
||||
|
||||
[Unit2]
|
||||
Source=raylib_explosion.png
|
||||
Target=explosion.png
|
||||
|
||||
[Project]
|
||||
UnitCount=1
|
||||
UnitCount=3
|
||||
Type=0
|
||||
IsCpp=0
|
||||
linker=-lraylib -lopengl32 -lgdi32 -lwinmm_@@__@@_
|
||||
|
|
|
@ -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_@@__@@_
|
||||
|
|
@ -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;
|
||||
}
|
Binary file not shown.
|
@ -1,16 +1,20 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* 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)
|
||||
*
|
||||
* 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>
|
||||
|
||||
#define NUM_FRAMES_PER_LINE 5
|
||||
#define NUM_LINES 5
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
|
@ -18,9 +22,29 @@ int main(void)
|
|||
const int screenWidth = 800;
|
||||
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
|
||||
Sound fxBoom = LoadSound("boom.wav");
|
||||
|
||||
// Load explosion texture
|
||||
Texture2D explosion = LoadTexture("explosion.png");
|
||||
|
||||
// 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
|
||||
int currentFrame = 0;
|
||||
int currentLine = 0;
|
||||
|
||||
Rectangle frameRec = { 0, 0, frameWidth, frameHeight };
|
||||
Vector2 position = { 0.0f, 0.0f };
|
||||
|
||||
bool active = false;
|
||||
int framesCounter = 0;
|
||||
|
||||
SetTargetFPS(120);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
|
@ -28,7 +52,46 @@ int main(void)
|
|||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
|
||||
// Check for mouse button pressed and activate explosion (if not active)
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT) )
|
||||
{
|
||||
position = GetMousePosition();
|
||||
active = true;
|
||||
|
||||
position.x -= frameWidth/2.0f;
|
||||
position.y -= frameHeight/2.0f;
|
||||
|
||||
PlaySound(fxBoom);
|
||||
}
|
||||
|
||||
// Compute explosion animation frames
|
||||
if (active)
|
||||
{
|
||||
framesCounter++;
|
||||
|
||||
if (framesCounter > 2)
|
||||
{
|
||||
currentFrame++;
|
||||
|
||||
if (currentFrame >= NUM_FRAMES_PER_LINE)
|
||||
{
|
||||
currentFrame = 0;
|
||||
currentLine++;
|
||||
|
||||
if (currentLine >= NUM_LINES)
|
||||
{
|
||||
currentLine = 0;
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
|
||||
framesCounter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
frameRec.x = frameWidth*currentFrame;
|
||||
frameRec.y = frameHeight*currentLine;
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
|
@ -37,40 +100,22 @@ int main(void)
|
|||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
DrawText("some basic shapes available on raylib", 20, 20, 20, DARKGRAY);
|
||||
// Draw explosion required frame rectangle
|
||||
if (active) DrawTextureRec(explosion, frameRec, position, WHITE);
|
||||
|
||||
// Circle shapes and lines
|
||||
DrawCircle(screenWidth/5, 120, 35, DARKBLUE);
|
||||
DrawCircleGradient(screenWidth/5, 220, 60, GREEN, SKYBLUE);
|
||||
DrawCircleLines(screenWidth/5, 340, 80, DARKBLUE);
|
||||
DrawText("Click to explode!", 440, 400, 40, DARKGRAY);
|
||||
|
||||
// Rectangle shapes and ines
|
||||
DrawRectangle(screenWidth/4*2 - 60, 100, 120, 60, RED);
|
||||
DrawRectangleGradientH(screenWidth/4*2 - 90, 170, 180, 130, MAROON, GOLD);
|
||||
DrawRectangleLines(screenWidth/4*2 - 40, 320, 80, 60, ORANGE); // NOTE: Uses QUADS internally, not lines
|
||||
|
||||
// Triangle shapes and lines
|
||||
DrawTriangle((Vector2){screenWidth/4.0f *3.0f, 80.0f},
|
||||
(Vector2){screenWidth/4.0f *3.0f - 60.0f, 150.0f},
|
||||
(Vector2){screenWidth/4.0f *3.0f + 60.0f, 150.0f}, VIOLET);
|
||||
|
||||
DrawTriangleLines((Vector2){screenWidth/4.0f*3.0f, 160.0f},
|
||||
(Vector2){screenWidth/4.0f*3.0f - 20.0f, 230.0f},
|
||||
(Vector2){screenWidth/4.0f*3.0f + 20.0f, 230.0f}, DARKBLUE);
|
||||
|
||||
// Polygon shapes and lines
|
||||
DrawPoly((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, BROWN);
|
||||
DrawPolyLinesEx((Vector2){screenWidth/4.0f*3, 320}, 6, 80, 0, 6, BEIGE);
|
||||
|
||||
// NOTE: We draw all LINES based shapes together to optimize internal drawing,
|
||||
// this way, all LINES are rendered in a single draw pass
|
||||
DrawLine(18, 42, screenWidth - 18, 42, BLACK);
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadTexture(explosion); // Unload texture
|
||||
UnloadSound(fxBoom); // Unload sound
|
||||
|
||||
CloseAudioDevice();
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 811 KiB |
Loading…
Reference in New Issue