Skip to content

Commit

Permalink
Added TinyFileDialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercuber55 committed Nov 1, 2023
1 parent 47a2219 commit 962ad44
Show file tree
Hide file tree
Showing 26 changed files with 509 additions and 442 deletions.
75 changes: 68 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Created by https://www.toptal.com/developers/gitignore/api/c++,sublimetext
# Edit at https://www.toptal.com/developers/gitignore?templates=c++,sublimetext
# Created by https://www.toptal.com/developers/gitignore/api/images,sublimetext,c++
# Edit at https://www.toptal.com/developers/gitignore?templates=images,sublimetext,c++

### C++ ###
# Prerequisites
Expand All @@ -10,7 +10,6 @@
*.lo
*.o
*.obj
*.res

# Precompiled Headers
*.gch
Expand All @@ -36,6 +35,71 @@
*.out
*.app

### Images ###
# JPEG
*.jpg
*.jpeg
*.jpe
*.jif
*.jfif
*.jfi

# JPEG 2000
*.jp2
*.j2k
*.jpf
*.jpx
*.jpm
*.mj2

# JPEG XR
*.jxr
*.hdp
*.wdp

# Graphics Interchange Format
*.gif

# RAW
*.raw

# Web P
*.webp

# Portable Network Graphics
*.png

# Animated Portable Network Graphics
*.apng

# Multiple-image Network Graphics
*.mng

# Tagged Image File Format
*.tiff
*.tif

# Scalable Vector Graphics
*.svg
*.svgz

# Portable Document Format
*.pdf

# X BitMap
*.xbm

# BMP
*.bmp
*.dib

# ICO
*.ico

# 3D Images
*.3dm
*.max

### SublimeText ###
# Cache files for Sublime Text
*.tmlanguage.cache
Expand Down Expand Up @@ -69,7 +133,4 @@ bh_unicode_properties.cache
# https://packagecontrol.io/packages/sublime-github
GitHub.sublime-settings

# End of https://www.toptal.com/developers/gitignore/api/c++,sublimetext

*.wren
*.png
# End of https://www.toptal.com/developers/gitignore/api/images,sublimetext,c++
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "wrenbind17"]
path = wrenbind17
url = https://github.com/matusnovak/wrenbind17
[submodule "Cube2D-Framework"]
path = Cube2D-Framework
url = https://github.com/mastercuber55/Cube2D-Framework
[submodule "libtinyfiledialogs"]
path = libtinyfiledialogs
url = https://github.com/native-toolkit/libtinyfiledialogs
133 changes: 0 additions & 133 deletions Bindings/Engine.cpp

This file was deleted.

40 changes: 40 additions & 0 deletions Bindings/Engine/Engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <wrenbind17/wrenbind17.hpp>
#include <raylib.h>
#include "Rect.hpp"

namespace Wren = wrenbind17;

void BindEngine(Wren::VM & VM) {

auto& Module = VM.module("Engine");

auto& RectCls = Module.klass<ForeignRect>("ForeignRect");
RectCls.ctor<float, float, float, float>();

// Transform
RectCls.var<&ForeignRect::PositionAndScale>("PositionAndScale");
RectCls.var<&ForeignRect::Rotation>("Rotation");

RectCls.var<&ForeignRect::TextureFile>("TextureFile");
RectCls.var<&ForeignRect::Source>("Source");
RectCls.var<&ForeignRect::Tint>("Tint");

RectCls.func<&ForeignRect::SetPosition>("SetPosition");
RectCls.func<&ForeignRect::SetTextureFile>("SetTextureFile");
RectCls.func<&ForeignRect::Draw>("Draw");

RectCls.func<&ForeignRect::GetCenter>("GetCenter");
RectCls.func<&ForeignRect::GetPosition>("GetPosition");

RectCls.func<&ForeignRect::IsColliding>("IsColliding");

Module.append("import \"raylib\" for RL, COLOR, Color, KEY, Vector2");

Module.append(
#include "Rect.wren"
#include "Scene.wren"
#include "SceneManager.wren"
#include "Tools.wren"
);
Module.append("var Shared = {}");
}
90 changes: 90 additions & 0 deletions Bindings/Engine/Rect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#define CGE_WHOLE_FILE { 0, 0, -1, -1 }
std::unordered_map<std::string, Texture> Textures;

struct ForeignRect {

// Transformm
Rectangle PositionAndScale;
double Rotation;

std::string TextureFile;
Rectangle Source;
Color Tint;

// De-Constructers
ForeignRect(float x, float y, float w, float h);
~ForeignRect();

// Setters
void SetTextureFile(std::string TextureFile);

// Getters
Vector2 GetCenter();
void SetPosition(Vector2 NewPosition);
Vector2 GetPosition();
Vector2 GetRectangle();

// Utilities
bool IsColliding(ForeignRect * Other);
void Draw();
};

ForeignRect::ForeignRect(float x, float y, float w, float h) {
this->PositionAndScale.x = x, this->PositionAndScale.y = y;
this->PositionAndScale.width = w, this->PositionAndScale.height = h;
this->Tint = WHITE;
this->Source = CGE_WHOLE_FILE,
this->Rotation = 0.0;
}
ForeignRect::~ForeignRect() {}
void ForeignRect::SetTextureFile(std::string TextureFile) {

this->TextureFile = TextureFile;
if(Textures.find(TextureFile) != Textures.end()) return;
Textures[TextureFile] = LoadTexture(TextureFile.c_str());

if(
this->Source.x == 0 &&
this->Source.y == 0 &&
this->Source.width == -1 &&
this->Source.height == -1
) {
this->Source.width = Textures[TextureFile].width,
this->Source.height = Textures[TextureFile].height;
}

}
void ForeignRect::Draw() {

(this->TextureFile.empty()) ?
DrawRectangleRec(this->PositionAndScale, this->Tint)
:
DrawTexturePro(
Textures[this->TextureFile],
this->Source,
(Rectangle){
this->PositionAndScale.x + this->PositionAndScale.width / 2.0f,
this->PositionAndScale.y + this->PositionAndScale.height / 2.0f,
this->PositionAndScale.width,
this->PositionAndScale.height
},
(Vector2){ this->PositionAndScale.width / 2.0f, this->PositionAndScale.height / 2.0f },
this->Rotation,
this->Tint
);
}
bool ForeignRect::IsColliding(ForeignRect * Other) {
return CheckCollisionRecs(PositionAndScale, Other->PositionAndScale);
}
void ForeignRect::SetPosition(Vector2 Position) {
this->PositionAndScale.x = Position.x, this->PositionAndScale.y = Position.y;
}
Vector2 ForeignRect::GetCenter() {
return {
this->PositionAndScale.x + this->PositionAndScale.width / 2.0f,
this->PositionAndScale.y + this->PositionAndScale.height / 2.0f
};
}
Vector2 ForeignRect::GetPosition() {
return { this->PositionAndScale.x, this->PositionAndScale.y };
}
Loading

0 comments on commit 962ad44

Please sign in to comment.