Skip to content

Commit

Permalink
Fps display, string Utils, rename to Txt
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Apr 8, 2017
1 parent e3f6cea commit 85809bf
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 8 deletions.
4 changes: 3 additions & 1 deletion source/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class App

// vars
//--------------------------
float dt = 1.f; // frame delta time

int iFontH = 18; // font height


Expand All @@ -42,7 +44,7 @@ class App
}

// write out text, from s
int Text(int x, int y);
int Txt(int x, int y);

// fill rectangle
void Rect(int x, int y,
Expand Down
8 changes: 5 additions & 3 deletions source/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ bool AppMain::Run()
//VideoMode vm = VideoMode::getDesktopMode();
VideoMode vm = VideoMode(600, 400);

RenderWindow* window;
window = new RenderWindow(vm,
"SFML demo", // title
RenderWindow* window = new RenderWindow(
vm, "SFML demo", // title
Style::Default, //Style::None,
ContextSettings());

Expand Down Expand Up @@ -54,6 +53,7 @@ bool AppMain::Run()

// Loop
//------------------------------------------------
Clock timer;
while (window->isOpen())
{
// Process events
Expand All @@ -72,6 +72,8 @@ bool AppMain::Run()
break;
}
}
sf::Time time = timer.restart();
app->dt = time.asSeconds();

// Draw
//------------------
Expand Down
6 changes: 3 additions & 3 deletions source/App_Graph.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include "App.h"
#include "Util.h"


// Graphics draw
///-----------------------------------------------------------------------------
void App::Graph()
{
// clear screen
pWindow->clear();
//Rect(0,0, xWindow,yWindow, 0,0,0);

// test
Clr(155,215,255);
s = "Cool.";
Text(0, 0);
s = "Fps: " + f2s(1/dt,1,3);
Txt(10, 0);

}
2 changes: 1 addition & 1 deletion source/App_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool App::Init()
//------------------------------------------------------------------

// write out text
int App::Text(int x, int y)
int App::Txt(int x, int y)
{
text.setString(s);
text.setColor(clr);
Expand Down
42 changes: 42 additions & 0 deletions source/Util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "Util.h"
#include <sstream>
#include <iomanip>
#include <regex>
using namespace std;


// string utils
//------------------------------------------------------------------

string i2s(const int v, const char width)
{
ostringstream s;
if (width != 0) s.width(width); //s.fill(fill);
s << fixed << v;
return s.str();
}

string f2s(const float v, const char precision, const char width)
{
ostringstream s;
if (width != 0) s.width(width);
s << fixed << setprecision(precision) << v;
return s.str();
}


vector<string> split(const string& s, const string& reg)
{
regex re(reg);
sregex_token_iterator
first{s.begin(), s.end(), re, -1}, // -1 split
last;
return {first, last};
}

string strlower(const string& s)
{
string ss = s;
transform(ss.begin(), ss.end(), ss.begin(), ::tolower);
return ss;
}
16 changes: 16 additions & 0 deletions source/Util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <vector>
#include <string>
#include <algorithm>


// format int, float to string
std::string i2s(const int v, const char width=0/*, const char fill=' '*/);
std::string f2s(const float v, const char precision=2, const char width=4);

// split string
std::vector<std::string> split(
const std::string& s, const std::string& reg);

// string to lower
std::string strlower(const std::string& s);

0 comments on commit 85809bf

Please sign in to comment.