Skip to content

Commit

Permalink
Basic ImGui SFML app with few controls
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Apr 8, 2017
1 parent 85809bf commit 546c985
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
34 changes: 30 additions & 4 deletions source/AppMain.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <SFML/Graphics.hpp>
#include "../libs/imgui.h"
#include "../libs/imgui-SFML.h"
#include "AppMain.h"
#include "App.h"
using namespace sf;
using namespace sf; using namespace ImGui::SFML;



Expand All @@ -15,17 +17,31 @@ bool AppMain::Run()
// Create window
//------------------------------------------------
//VideoMode vm = VideoMode::getDesktopMode();
VideoMode vm = VideoMode(600, 400);
VideoMode vm = VideoMode(800, 600);

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

window->setVerticalSyncEnabled(true);
//window->setPosition(Vector2i(0,0));


// ImGui
//------------------
Init(*window);
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = 0; io.LogFilename = 0; // nope
io.Fonts->ClearFonts();
// font
ImFont* fnt = io.Fonts->AddFontFromFileTTF(
"data/DejaVuLGCSans.ttf", 18);
Texture* fntTex = new Texture;
createFontTexture(*fntTex);
setFontTexture(*fntTex);


// Init app
App* app = new App();
app->Init();
Expand Down Expand Up @@ -61,6 +77,8 @@ bool AppMain::Run()
Event e;
while (window->pollEvent(e))
{
ProcessEvent(e);

switch (e.type)
{
case Event::KeyPressed:
Expand All @@ -73,19 +91,27 @@ bool AppMain::Run()
}
}
sf::Time time = timer.restart();
Update(*window, time);
app->dt = time.asSeconds();

// Draw
//------------------
window->clear();
app->Gui();

window->resetGLStates();

app->Graph();

ImGui::Render();

window->display();

//Sleep(0.20f);
}

// dtor
//------------------
ImGui::Shutdown();
delete window;
delete app;
return true;
Expand Down
1 change: 1 addition & 0 deletions source/App_Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
void App::Graph()
{
// clear screen
pWindow->clear();
//Rect(0,0, xWindow,yWindow, 0,0,0);

// test
Expand Down
56 changes: 56 additions & 0 deletions source/App_Gui.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "../libs/imgui.h"
#include "../libs/imgui-SFML.h"
#include "App.h"
#include "Util.h"
using namespace std; using namespace ImGui; using namespace SFML;


// Gui draw and process
///-----------------------------------------------------------------------------
void App::Gui()
{

// window
SetNextWindowPos( ImVec2(0, 40), ImGuiSetCond_Always);
SetNextWindowSize(ImVec2(400, 300), ImGuiSetCond_Always);

bool open = true;
const int flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize;

Begin("Window", &open, flags);


// Pattern Properties
//---------------------------------------------
Text("Properties");

bool e; // edited, changed


// editbox
static char ed[100]={0};

PushItemWidth(140);
e = InputText("Edit", ed, sizeof(ed));
PopItemWidth();

// sliders
static int i = 0;
e = SliderInt("SldInt", &i, 0, 255, ""); SameLine(); Text((""+i2s(i)).c_str());

static float f = 0.f;
e = SliderFloat("SldFlt", &f, 0.f, 1.f, ""); SameLine(); Text((""+f2s(f,3)).c_str());

// check
static bool b = false;
e = Checkbox("Check", &b);

// button
e = Button("Save"); //if (e) Save();

// combobox
static int c = 0;
e = Combo("Cmb", &c, "aaa\0bbb\0\0");

End();
}

0 comments on commit 546c985

Please sign in to comment.