up to raylib 5.0
This commit is contained in:
parent
99688efcd0
commit
bc0dbdf9da
@ -10,14 +10,14 @@ set(PROJECT_VERSION 1.0)
|
||||
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION})
|
||||
|
||||
##############################################################
|
||||
set(RAYLIB_DIR "/home/sillysagiri/Panda/04-WORKSPACE/00-PROGRAMMING/_Git Clone/raylib-4.5.0")
|
||||
set(IMGUI_DIR "/home/sillysagiri/Panda/04-WORKSPACE/00-PROGRAMMING/_Git Clone/imgui-docking")
|
||||
set(RLIMGUI_DIR "/home/sillysagiri/Panda/04-WORKSPACE/00-PROGRAMMING/_Git Clone/rlImGui")
|
||||
set(INIFILE_DIR "/home/sillysagiri/Panda/04-WORKSPACE/00-PROGRAMMING/_Git Clone/inifile-cpp")
|
||||
# set(RAYLIB_DIR "path/to/raylib")
|
||||
# set(IMGUI_DIR "path/to/imgui-docking")
|
||||
# set(RLIMGUI_DIR "path/to/rlImGui")
|
||||
# set(INIFILE_DIR "path/to/inifile-cpp")
|
||||
|
||||
### Fallback link
|
||||
set(RAYLIB_LINK "https://github.com/raysan5/raylib/archive/refs/tags/4.5.0.zip")
|
||||
set(IMGUI_LINK "https://github.com/ocornut/imgui/archive/refs/tags/v1.89.7.zip")
|
||||
set(RAYLIB_LINK "https://github.com/raysan5/raylib/archive/refs/tags/5.0.zip")
|
||||
set(IMGUI_LINK "https://github.com/ocornut/imgui/archive/refs/tags/v1.90.zip")
|
||||
set(RLIMGUI_LINK "https://github.com/raylib-extras/rlImGui/archive/refs/heads/main.zip")
|
||||
set(INIFILE_LINK "https://github.com/Rookfighter/inifile-cpp/archive/refs/heads/master.zip")
|
||||
|
||||
@ -61,15 +61,14 @@ endif()
|
||||
|
||||
##############################################################
|
||||
# yes... im using glob... dont judge me....
|
||||
file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "src/*.cpp")
|
||||
|
||||
file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS
|
||||
"src/*.cpp"
|
||||
"src/**/*.cpp"
|
||||
file(GLOB VENDOR_SOURCES CONFIGURE_DEPENDS
|
||||
"${imgui_SOURCE_DIR}/*.cpp"
|
||||
"${imgui_SOURCE_DIR}/misc/cpp/*.cpp"
|
||||
"${rlimgui_SOURCE_DIR}/*.cpp")
|
||||
|
||||
set(PROJECT_INCLUDE
|
||||
set(PROJECT_INCLUDE
|
||||
"src"
|
||||
${imgui_SOURCE_DIR}
|
||||
${imgui_SOURCE_DIR}/backends
|
||||
@ -78,11 +77,11 @@ set(PROJECT_INCLUDE
|
||||
|
||||
set(PROJECT_LIBRARY raylib)
|
||||
|
||||
set(PROJECT_DEFINITION "")
|
||||
set(PROJECT_DEFINITION "_PANDA_CORE_")
|
||||
|
||||
##############################################################
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC ${PROJECT_SOURCES})
|
||||
add_library(${PROJECT_NAME} STATIC ${PROJECT_SOURCES} ${VENDOR_SOURCES})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_INCLUDE})
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC ${PROJECT_LIBRARY})
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC ${PROJECT_DEFINITION})
|
||||
|
@ -34,15 +34,6 @@ namespace panda
|
||||
|
||||
struct Sprite {
|
||||
Texture *texture;
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float scaleX = 1.0f;
|
||||
float scaleY = 1.0f;
|
||||
float rotation = 0.0f;
|
||||
|
||||
void Load(const char* path);
|
||||
void Unload();
|
||||
void Draw(Color color);
|
||||
|
||||
void SetPivot(Vector2 ratio);
|
||||
void SetPivotRatio(Vector2 ratio);
|
||||
@ -50,10 +41,10 @@ namespace panda
|
||||
void SetFlipX(bool x);
|
||||
void SetFlipY(bool y);
|
||||
|
||||
Vector2 GetPivot();
|
||||
Vector2 GetPivotFlip();
|
||||
bool GetFlipX();
|
||||
bool GetFlipY();
|
||||
Vector2 GetPivot() const;
|
||||
Vector2 GetPivotFlip() const;
|
||||
bool GetFlipX() const;
|
||||
bool GetFlipY() const;
|
||||
|
||||
private:
|
||||
bool flipX = false;
|
||||
@ -105,9 +96,22 @@ namespace panda
|
||||
void DrawTextureAtlas(std::string AtlasKey, std::string key, int x, int y);
|
||||
void DrawTextureAtlasPro(std::string AtlasKey, std::string key, int x, int y, Color color, bool flipX = false, bool flipY = false);
|
||||
|
||||
// ### gridmap
|
||||
// Draw GridMap using cam, use this inside BeginMode2D
|
||||
void DrawGridMap(Texture texture, Camera2D cam);
|
||||
// This is quick version without cam, does not support zoom
|
||||
void DrawGridMapQuick(Texture texture, Vector2 offset);
|
||||
Texture LoadDefaultGridMap();
|
||||
|
||||
// ### draw
|
||||
void DrawTextureTiled(Texture texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint);
|
||||
void DrawRenderTexture(const RenderTexture &buffer, const float &x, const float &y, const Color &color);
|
||||
|
||||
// ## sprite
|
||||
void DrawSprite(const panda::Sprite &sprite, const float &x, const float &y, const Color &color);
|
||||
void DrawSpriteV(const panda::Sprite &sprite, const Vector2 &pos, const Color &color);
|
||||
void DrawSpriteEx(const panda::Sprite &sprite, const Vector2 &pos, const Vector2 &scale, const float &rotation, const Color &color);
|
||||
Vector2 GetPointInSprite(const Vector2 &point, const panda::Sprite &sprite, const Vector2 &pos, const Vector2 &scale, const float &rotation);
|
||||
|
||||
// ### texture utils
|
||||
Rectangle GetTextureRect(const Texture &tex, bool flipX, bool flipY);
|
||||
|
@ -4,39 +4,6 @@
|
||||
|
||||
|
||||
namespace panda {
|
||||
void Sprite::Load(const char* path)
|
||||
{
|
||||
texture = new Texture(LoadTexture(path));
|
||||
}
|
||||
|
||||
void Sprite::Unload()
|
||||
{
|
||||
UnloadTexture(*texture);
|
||||
}
|
||||
|
||||
void Sprite::Draw(Color color)
|
||||
{
|
||||
Vector2 pivot_temp = (flipX || flipY) ? Vector2{pivotX_flip, pivotY_flip} : Vector2{pivotX, pivotY};
|
||||
|
||||
panda::Matrix matrix;
|
||||
matrix.translate(-pivot_temp.x, -pivot_temp.y);
|
||||
matrix.scale(scaleX, scaleY);
|
||||
matrix.rotate(rotation * DEG2RAD);
|
||||
matrix.translate(x, y);
|
||||
|
||||
DrawTexturePro(
|
||||
*texture,
|
||||
panda::GetTextureRect(*texture, flipX, flipY),
|
||||
{
|
||||
matrix.tx, matrix.ty,
|
||||
scaleX*texture->width,
|
||||
scaleY*texture->height
|
||||
},
|
||||
{0.0f, 0.0f},
|
||||
rotation, color
|
||||
);
|
||||
}
|
||||
|
||||
void Sprite::SetPivot(Vector2 p)
|
||||
{
|
||||
pivotX = p.x;
|
||||
@ -70,22 +37,22 @@ namespace panda {
|
||||
CalculatePivotFlip();
|
||||
}
|
||||
|
||||
Vector2 Sprite::GetPivot()
|
||||
Vector2 Sprite::GetPivot() const
|
||||
{
|
||||
return {pivotX, pivotY};
|
||||
}
|
||||
|
||||
Vector2 Sprite::GetPivotFlip()
|
||||
Vector2 Sprite::GetPivotFlip() const
|
||||
{
|
||||
return {pivotX_flip, pivotY_flip};
|
||||
}
|
||||
|
||||
bool Sprite::GetFlipX()
|
||||
bool Sprite::GetFlipX() const
|
||||
{
|
||||
return flipX;
|
||||
}
|
||||
|
||||
bool Sprite::GetFlipY()
|
||||
bool Sprite::GetFlipY() const
|
||||
{
|
||||
return flipY;
|
||||
}
|
||||
@ -95,4 +62,46 @@ namespace panda {
|
||||
pivotX_flip = flipX ? texture->width-pivotX : pivotX;
|
||||
pivotY_flip = flipY ? texture->height-pivotY : pivotY;
|
||||
}
|
||||
|
||||
void DrawSprite(const panda::Sprite &sprite, const float &x, const float &y, const Color &color)
|
||||
{
|
||||
DrawSpriteEx(sprite, {x, y}, {1.0f, 1.0f}, 0.0f, color);
|
||||
}
|
||||
|
||||
void DrawSpriteV(const panda::Sprite &sprite, const Vector2 &pos, const Color &color)
|
||||
{
|
||||
DrawSpriteEx(sprite, pos, {1.0f, 1.0f}, 0.0f, color);
|
||||
}
|
||||
|
||||
void DrawSpriteEx(const panda::Sprite &sprite, const Vector2 &pos, const Vector2 &scale, const float &rotation, const Color &color)
|
||||
{
|
||||
Vector2 dest = GetPointInSprite({0.0f, 0.0f}, sprite, pos, scale, rotation);
|
||||
|
||||
DrawTexturePro(
|
||||
*sprite.texture,
|
||||
panda::GetTextureRect(*sprite.texture, sprite.GetFlipX(), sprite.GetFlipY()),
|
||||
{
|
||||
dest.x, dest.y,
|
||||
scale.x*sprite.texture->width,
|
||||
scale.y*sprite.texture->height
|
||||
},
|
||||
{0.0f, 0.0f},
|
||||
rotation, color
|
||||
);
|
||||
}
|
||||
|
||||
Vector2 GetPointInSprite(const Vector2 &point, const panda::Sprite &sprite, const Vector2 &pos, const Vector2 &scale, const float &rotation)
|
||||
{
|
||||
Vector2 pivot_temp = (sprite.GetFlipX() || sprite.GetFlipY()) ? sprite.GetPivotFlip() : sprite.GetPivot();
|
||||
|
||||
panda::Matrix matrix;
|
||||
matrix.translate(-pivot_temp.x, -pivot_temp.y);
|
||||
matrix.translate(point.x, point.y);
|
||||
matrix.scale(scale.x, scale.y);
|
||||
matrix.rotate(rotation * DEG2RAD);
|
||||
matrix.translate(pos.x, pos.y);
|
||||
|
||||
return { matrix.tx, matrix.ty };
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include "GridMap.hpp"
|
||||
|
||||
void DrawGridMap(Texture texture, Camera2D cam)
|
||||
void panda::DrawGridMap(Texture texture, Camera2D cam)
|
||||
{
|
||||
Vector2 topLeft = GetScreenToWorld2D({0.0f, 0.0f}, cam);
|
||||
Vector2 botRight = GetScreenToWorld2D({(float)GetScreenWidth(), (float)GetScreenHeight()}, cam);
|
||||
@ -15,7 +15,7 @@ void DrawGridMap(Texture texture, Camera2D cam)
|
||||
);
|
||||
}
|
||||
|
||||
void DrawGridMapQuick(Texture texture, Vector2 offset)
|
||||
void panda::DrawGridMapQuick(Texture texture, Vector2 offset)
|
||||
{
|
||||
float offsetX = (int)offset.x % texture.width;
|
||||
float offsetY = (int)offset.y % texture.width;
|
||||
@ -28,7 +28,7 @@ void DrawGridMapQuick(Texture texture, Vector2 offset)
|
||||
);
|
||||
}
|
||||
|
||||
Texture LoadDefaultGridMap()
|
||||
Texture panda::LoadDefaultGridMap()
|
||||
{
|
||||
Image image = GenImageColor(100, 100, WHITE);
|
||||
ImageDrawLine(&image, image.width*0.5f, 0, image.width*0.5f, image.height, {0, 0, 0, 120});
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "Panda.hpp"
|
||||
|
||||
// Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest.
|
||||
void DrawTextureTiled(Texture texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint)
|
||||
void panda::DrawTextureTiled(Texture texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint)
|
||||
{
|
||||
if ((texture.id <= 0) || (scale <= 0.0f)) return; // Wanna see a infinite loop?!...just delete this line!
|
||||
if ((source.width == 0) || (source.height == 0)) return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user