-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,28 @@ | ||
#pragma once | ||
#include <SFML/Window.hpp> | ||
#include <SFML/Graphics.hpp> | ||
#include "AppDraw.h" | ||
#include "Settings.h" | ||
|
||
|
||
class App | ||
class App : public AppDraw | ||
{ | ||
public: | ||
// main | ||
//-------------------------- | ||
App(); | ||
|
||
bool Init(); | ||
|
||
bool KeyDown(const sf::Event::KeyEvent& key); | ||
void Graph(); // draw graphics | ||
void Gui(); // draw gui | ||
void Gui(); // draw Gui | ||
|
||
|
||
// vars | ||
//-------------------------- | ||
float dt = 1.f; // frame delta time | ||
|
||
int iFontH = 18; // font height | ||
|
||
|
||
// sfml vars | ||
//-------------------------- | ||
sf::RenderWindow* pWindow = nullptr; | ||
sf::Sprite* pBackgr = nullptr; | ||
|
||
sf::Font* pFont = nullptr; | ||
sf::Text text; | ||
|
||
sf::String s; | ||
sf::Color clr; | ||
|
||
|
||
// gui util ----- | ||
void SetupGuiClr(); | ||
void Sep(int y); // dummy separator | ||
void Line(bool dark = false); //-- | ||
|
||
|
||
// sfml drawing utils | ||
|
||
// set text color | ||
//-------------------------- | ||
void Clr(sf::Uint8 r, sf::Uint8 g, sf::Uint8 b) | ||
{ | ||
clr = sf::Color(r,g,b); | ||
} | ||
|
||
// write out text, from s | ||
int Txt(int x, int y); | ||
|
||
// fill rectangle | ||
void Rect(int x, int y, | ||
int sx, int sy, | ||
sf::Uint8 r, sf::Uint8 g, sf::Uint8 b); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "AppDraw.h" | ||
|
||
|
||
// draw utils | ||
//------------------------------------------------------------------ | ||
|
||
// write out text | ||
int AppDraw::Txt(int x, int y, bool draw) | ||
{ | ||
text.setString(str); | ||
//text.setStyle(bold ? sf::Text::Bold : sf::Text::Regular); | ||
text.setColor(clr); | ||
text.setPosition(x, y); | ||
if (draw) pWindow->draw(text); | ||
return text.getLocalBounds().width; // advance x pos | ||
} | ||
|
||
// clear rect | ||
void AppDraw::Rect(int x, int y, int sx, int sy, | ||
sf::Uint8 r, sf::Uint8 g, sf::Uint8 b) | ||
{ | ||
pBackgr->setScale(sx-x, sy-y); | ||
pBackgr->setPosition(x, y); | ||
pBackgr->setColor(sf::Color(b, g, r)); | ||
pWindow->draw(*pBackgr); | ||
} | ||
|
||
// frame rect, inefficient | ||
void AppDraw::Frame(int x, int y, int sx, int sy, int d, | ||
sf::Uint8 r, sf::Uint8 g, sf::Uint8 b) | ||
{ | ||
Rect(x, y, sx-d, y+d, r, g, b); // top | ||
Rect(x, sy-d, sx-d, sy, r, g, b); // bottom | ||
Rect(x, y, x+d, sy-d, r, g, b); // left | ||
Rect(sx-d,y, sx, sy, r, g, b); // right | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
#include <SFML/Window.hpp> | ||
#include <SFML/Graphics.hpp> | ||
|
||
|
||
class AppDraw | ||
{ | ||
public: | ||
|
||
// sfml draw | ||
//-------------------------- | ||
sf::RenderWindow* pWindow = nullptr; | ||
sf::Sprite* pBackgr = nullptr; | ||
|
||
sf::Font* pFont = nullptr; | ||
sf::Text text; | ||
|
||
sf::String str; | ||
sf::Color clr; | ||
bool bold = false; | ||
|
||
float dt = 1.f; // frame delta time | ||
|
||
|
||
// set text color | ||
//-------------------------- | ||
void Clr(sf::Uint8 r, sf::Uint8 g, sf::Uint8 b) | ||
{ | ||
clr = sf::Color(r,g,b); | ||
} | ||
|
||
// write out text, from s | ||
// returns width, x advance | ||
int Txt(int x, int y, bool draw=true); | ||
|
||
// fill rect | ||
void Rect(int x, int y, int sx, int sy, sf::Uint8 r, sf::Uint8 g, sf::Uint8 b); | ||
// frame rect | ||
void Frame(int x, int y, int sx, int sy, int d, sf::Uint8 r, sf::Uint8 g, sf::Uint8 b); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters