New Repository
Had my private email in a old commit of the first repository
This commit is contained in:
commit
f25d3cc8da
20 changed files with 6534 additions and 0 deletions
13
src/gui/Views/View.cpp
Normal file
13
src/gui/Views/View.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "View.h"
|
||||
#include <raylibs/raygui.h>
|
||||
|
||||
void View::draw()
|
||||
{
|
||||
BeginDrawing();
|
||||
ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
void View::update()
|
||||
{
|
||||
}
|
43
src/gui/Views/View.h
Normal file
43
src/gui/Views/View.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
#include "raylib.h"
|
||||
#include <types.hpp>
|
||||
|
||||
class View
|
||||
{
|
||||
friend class ViewManager;
|
||||
public:
|
||||
View(rectu rect) : m_rect(rect) {}
|
||||
virtual ~View() = default;
|
||||
virtual void draw();
|
||||
virtual void update();
|
||||
virtual void onMouseDown(vec2d mousePos) {}
|
||||
virtual void onMouseUp(vec2d mousePos) {}
|
||||
virtual void onMouseMove(vec2d mousePos) {}
|
||||
virtual void onKeyDown(int key) {}
|
||||
virtual void onKeyUp(int key) {}
|
||||
virtual void onKeyPress(int key) {}
|
||||
virtual void onFocus() {}
|
||||
virtual void onBlur() {}
|
||||
|
||||
virtual void onResize(vec2d factor)
|
||||
{
|
||||
m_rect.width = static_cast<rectu::type>(static_cast<float>(m_rect.width) * factor.x);
|
||||
m_rect.height = static_cast<rectu::type>(static_cast<float>(m_rect.height) * factor.y);
|
||||
}
|
||||
|
||||
|
||||
|
||||
vec2u getPosition() const { return {m_rect.x, m_rect.y}; }
|
||||
vec2u getSize() const { return {m_rect.width, m_rect.height}; }
|
||||
const rectu& getRect() const { return m_rect; }
|
||||
void setPosition(vec2u pos) { m_rect.x = pos.x; m_rect.y = pos.y; }
|
||||
void setSize(vec2u size) { m_rect.width = size.x; m_rect.height = size.y; }
|
||||
void setRect(rectu &rect) { m_rect = rect; }
|
||||
virtual void Resize(float multiplier)
|
||||
{
|
||||
m_rect.width = static_cast<rectu::type>(static_cast<float>(m_rect.width) * multiplier);
|
||||
m_rect.height = static_cast<rectu::type>(static_cast<float>(m_rect.height) * multiplier);
|
||||
}
|
||||
private:
|
||||
rectu m_rect;
|
||||
};
|
21
src/gui/Views/ViewManager.cpp
Normal file
21
src/gui/Views/ViewManager.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "ViewManager.h"
|
||||
|
||||
ViewManager::ViewManager()
|
||||
{
|
||||
m_viewportSize = { GetScreenWidth(), GetScreenHeight() };
|
||||
m_mainView = new View({ 0, 0, m_viewportSize.x, m_viewportSize.y });
|
||||
}
|
||||
|
||||
void ViewManager::update()
|
||||
{
|
||||
if (IsWindowResized())
|
||||
{
|
||||
m_viewportSize = { GetScreenWidth(), GetScreenHeight() };
|
||||
m_mainView->onResize({ static_cast<float>(m_viewportSize.x), static_cast<float>(m_viewportSize.y) });
|
||||
}
|
||||
m_mainView->update();
|
||||
}
|
||||
|
||||
void ViewManager::draw()
|
||||
{
|
||||
}
|
16
src/gui/Views/ViewManager.h
Normal file
16
src/gui/Views/ViewManager.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
#include "View.h"
|
||||
#include <vector>
|
||||
#include <types.hpp>
|
||||
|
||||
class ViewManager
|
||||
{
|
||||
vec2u m_viewportSize;
|
||||
public:
|
||||
ViewManager();
|
||||
~ViewManager();
|
||||
void update();
|
||||
void draw();
|
||||
private:
|
||||
View* m_mainView;
|
||||
};
|
60
src/gui/drawing_helper.cpp
Normal file
60
src/gui/drawing_helper.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include "drawing_helper.hpp"
|
||||
|
||||
namespace sva
|
||||
{
|
||||
std::vector<std::string> split(const std::string& str, char delim)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
std::string token;
|
||||
std::istringstream tokenStream(str);
|
||||
while (std::getline(tokenStream, token, delim))
|
||||
{
|
||||
tokens.push_back(token);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Color sva::GetThemeColor(GuiControlProperty property)
|
||||
{
|
||||
return GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL));
|
||||
}
|
||||
|
||||
void sva::DrawText(const std::string& text, vec2i pos, int size, Color color, TEXT_ALIGNMENT alignment)
|
||||
{
|
||||
switch (alignment)
|
||||
{
|
||||
case TEXT_ALIGN_LEFT:
|
||||
return DrawText(text.c_str(), pos.x, pos.y, size, color);
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
if (text.find('\n') != std::string::npos)
|
||||
{
|
||||
std::vector<std::string> lines = split(text, '\n');
|
||||
for (auto& line : lines)
|
||||
{
|
||||
pos.x -= MeasureText(line.c_str(), size);
|
||||
DrawText(line.c_str(), pos.x, pos.y, size, color);
|
||||
pos.y += size;
|
||||
}
|
||||
return;
|
||||
}
|
||||
pos.x -= MeasureText(text.c_str(), size);
|
||||
return DrawText(text.c_str(), pos.x, pos.y, size, color);
|
||||
|
||||
case TEXT_ALIGN_CENTER:
|
||||
if (text.find('\n') != std::string::npos)
|
||||
{
|
||||
std::vector<std::string> lines = sva::split(text, '\n');
|
||||
for (auto& line : lines)
|
||||
{
|
||||
pos.x -= MeasureText(line.c_str(), size) / 2;
|
||||
DrawText(line.c_str(), pos.x, pos.y, size, color);
|
||||
pos.y += size;
|
||||
}
|
||||
return;
|
||||
}
|
||||
pos.x -= MeasureText(text.c_str(), size) / 2;
|
||||
DrawText(text.c_str(), pos.x, pos.y, size, color);
|
||||
}
|
||||
}
|
29
src/gui/drawing_helper.hpp
Normal file
29
src/gui/drawing_helper.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
#include <raylib.h>
|
||||
#include <raylibs/raygui.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
namespace sva
|
||||
{
|
||||
template<typename T>
|
||||
struct TVector2
|
||||
{
|
||||
T x, y;
|
||||
};
|
||||
typedef TVector2<int> vec2i;
|
||||
typedef TVector2<float> vec2f;
|
||||
|
||||
enum TEXT_ALIGNMENT
|
||||
{
|
||||
TEXT_ALIGN_LEFT,
|
||||
TEXT_ALIGN_CENTER,
|
||||
TEXT_ALIGN_RIGHT
|
||||
};
|
||||
|
||||
|
||||
Color GetThemeColor(GuiControlProperty property);
|
||||
|
||||
void DrawText(const std::string& text, vec2i pos, int size, Color color = GetColor(GuiGetStyle(DEFAULT, TEXT_COLOR_NORMAL)), TEXT_ALIGNMENT alignment = TEXT_ALIGN_LEFT);
|
||||
}
|
2
src/gui/raygui.cpp
Normal file
2
src/gui/raygui.cpp
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define RAYGUI_IMPLEMENTATION
|
||||
#include <raylibs/raygui.h>
|
42
src/gui/themes/dark.h
Normal file
42
src/gui/themes/dark.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// //
|
||||
// StyleAsCode exporter v2.0 - Style data exported as a values array //
|
||||
// //
|
||||
// USAGE: On init call: GuiLoadStyleDark(); //
|
||||
// //
|
||||
// more info and bugs-report: github.com/raysan5/raygui //
|
||||
// feedback and support: ray[at]raylibtech.com //
|
||||
// //
|
||||
// Copyright (c) 2020-2023 raylib technologies (@raylibtech) //
|
||||
// //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define DARK_STYLE_PROPS_COUNT 8
|
||||
|
||||
// Custom style name: dark
|
||||
static const GuiStyleProp darkStyleProps[DARK_STYLE_PROPS_COUNT] = {
|
||||
{ 0, 0, 0x7b7b7bff }, // DEFAULT_BORDER_COLOR_NORMAL
|
||||
{ 0, 1, 0x595959ff }, // DEFAULT_BASE_COLOR_NORMAL
|
||||
{ 0, 2, 0xdededeff }, // DEFAULT_TEXT_COLOR_NORMAL
|
||||
{ 0, 9, 0x232323ff }, // DEFAULT_BORDER_COLOR_DISABLED
|
||||
{ 0, 10, 0x606060ff }, // DEFAULT_BASE_COLOR_DISABLED
|
||||
{ 0, 11, 0x9f9f9fff }, // DEFAULT_TEXT_COLOR_DISABLED
|
||||
{ 0, 18, 0x68cbd0ff }, // DEFAULT_LINE_COLOR
|
||||
{ 0, 19, 0x262626ff }, // DEFAULT_BACKGROUND_COLOR
|
||||
};
|
||||
|
||||
// Style loading function: dark
|
||||
static void GuiLoadStyleDark(void)
|
||||
{
|
||||
// Load style properties provided
|
||||
// NOTE: Default properties are propagated
|
||||
for (int i = 0; i < DARK_STYLE_PROPS_COUNT; i++)
|
||||
{
|
||||
GuiSetStyle(darkStyleProps[i].controlId, darkStyleProps[i].propertyId, darkStyleProps[i].propertyValue);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
// TODO: Custom user style setup: Set specific properties here (if required)
|
||||
// i.e. Controls specific BORDER_WIDTH, TEXT_PADDING, TEXT_ALIGNMENT
|
||||
}
|
152
src/main.cpp
Normal file
152
src/main.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
#include <iostream>
|
||||
#include <raylib.h>
|
||||
#include <raylibs/raygui.h>
|
||||
#include "sva.hpp"
|
||||
|
||||
|
||||
#include "gui/drawing_helper.hpp"
|
||||
|
||||
#define RESOURCES_PATH "G:\\School\\Belegarbeit\\sortiva\\res\\"
|
||||
|
||||
|
||||
int screenWidth = 1280;
|
||||
int screenHeight = 720;
|
||||
|
||||
enum GAME_STATES
|
||||
{
|
||||
SVA_STATE_TITLE,
|
||||
SVA_STATE_GAMEPLAY,
|
||||
};
|
||||
|
||||
GAME_STATES gameState = SVA_STATE_TITLE;
|
||||
|
||||
void UpdateDrawFrame(); // Update and Draw one frame
|
||||
|
||||
#include "gui/themes/dark.h"
|
||||
#include <filesystem>
|
||||
#include "gui/Views/ViewManager.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
sva_console_init();
|
||||
|
||||
if(!DirectoryExists(RESOURCES_PATH))
|
||||
{
|
||||
std::cerr << "Resources folder not found!" << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "Sortiva - Sorting Algorithm Visualizer");
|
||||
|
||||
SetWindowIcon(LoadImage(RESOURCES_PATH "/images/sva-logo.png"));
|
||||
|
||||
SetWindowMinSize(screenWidth, screenHeight);
|
||||
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
||||
SetExitKey(0);
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
GuiLoadStyleDark();
|
||||
GuiSetStyle(DEFAULT, TEXT_SIZE, 20);
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
if (IsWindowResized())
|
||||
{
|
||||
screenWidth = GetScreenWidth();
|
||||
screenHeight = GetScreenHeight();
|
||||
}
|
||||
UpdateDrawFrame();
|
||||
}
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Render Functions
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
void RenderGameplayState();
|
||||
|
||||
|
||||
Rectangle ButtonRects[] = {
|
||||
{50, 150, 150, 40},
|
||||
{50, 200, 150, 40},
|
||||
{50, 300, 150, 40},
|
||||
};
|
||||
|
||||
void UpdateDrawFrame()
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(GetColor(GuiGetStyle(DEFAULT, BACKGROUND_COLOR)));
|
||||
|
||||
switch (gameState)
|
||||
{
|
||||
case SVA_STATE_TITLE:
|
||||
sva::DrawText("Sortiva", {screenWidth/2, 20}, 100, sva::GetThemeColor(TEXT_COLOR_NORMAL), sva::TEXT_ALIGN_CENTER);
|
||||
|
||||
if(GuiButton(ButtonRects[0], "Öffnen"))
|
||||
{
|
||||
gameState = SVA_STATE_GAMEPLAY;
|
||||
}
|
||||
if(GuiButton(ButtonRects[1], "Speichern"))
|
||||
{
|
||||
gameState = SVA_STATE_GAMEPLAY;
|
||||
}
|
||||
if(GuiButton(ButtonRects[2], "Schließen"))
|
||||
{
|
||||
CloseWindow();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
break;
|
||||
case SVA_STATE_GAMEPLAY:
|
||||
if(IsKeyPressed(KEY_ESCAPE))
|
||||
{
|
||||
gameState = SVA_STATE_TITLE;
|
||||
}
|
||||
RenderGameplayState();
|
||||
break;
|
||||
}
|
||||
EndDrawing();
|
||||
}
|
||||
#include <numbers>
|
||||
|
||||
#define PI_2 std::numbers::pi_v<float> / 2
|
||||
|
||||
#define sin3(x) pow((-cos(PI_2+ ##x)),3)
|
||||
|
||||
#include <cmath>
|
||||
|
||||
Vector2 heart_position = Vector2{static_cast<float>(screenWidth)/2, static_cast<float>(screenHeight)/2.5f};
|
||||
Vector2 heart_function(float t, float scale)
|
||||
{
|
||||
return Vector2{
|
||||
((16 * static_cast<float>(sin3(t))) * scale) + heart_position.x,
|
||||
((13 * cos(t) - 5 * cos(2*t) - 2 * cos(3*t) - cos(4*t)) * -scale) + heart_position.y
|
||||
};
|
||||
}
|
||||
|
||||
#define STEPS 1000
|
||||
#define STEP_SIZE 0.01f
|
||||
|
||||
void RenderGameplayState()
|
||||
{
|
||||
for (int i = 0; i < STEPS; i++)
|
||||
{
|
||||
Vector2 pos = heart_function(static_cast<float>(i) * STEP_SIZE, 20);
|
||||
Vector2 pos2 = heart_function(static_cast<float>(i) * STEP_SIZE + STEP_SIZE, 20);
|
||||
DrawLine(
|
||||
pos.x,
|
||||
pos.y,
|
||||
pos2.x,
|
||||
pos2.y,
|
||||
GetColor(GuiGetStyle(DEFAULT, LINE_COLOR))
|
||||
);
|
||||
|
||||
}
|
||||
}
|
17
src/sva.hpp
Normal file
17
src/sva.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
inline const char* ASCII_TITLE = R"(
|
||||
__
|
||||
(_ _ ___|_ o _
|
||||
__)(_) | |_ | \_/(_|
|
||||
|
||||
|
||||
|
||||
)";
|
||||
|
||||
inline void sva_console_init()
|
||||
{
|
||||
std::cout << ASCII_TITLE;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue