Skip to content

Commit 56ff413

Browse files
author
Whitney Armstrong
committed
modified: ../../CMakeLists.txt
modified: ../../config.h.in modified: CMakeLists.txt modified: ImGuiDMConfig.h.in modified: include/ImGuiDM.h modified: src/ImGuiDM.cpp modified: src/main.cpp
1 parent bfae78e commit 56ff413

File tree

7 files changed

+61
-117
lines changed

7 files changed

+61
-117
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules" "${CMAKE_SOU
77
#
88
set(IMGUIDM_VERSION_MAJOR 1)
99
set(IMGUIDM_VERSION_MINOR 0)
10+
set(IMGUIDM_FONT_DIR ${CMAKE_INSTALL_PREFIX}/share/imgui_DM/fonts)
11+
12+
1013
configure_file(
1114
"${PROJECT_SOURCE_DIR}/config.h.in"
1215
"${PROJECT_BINARY_DIR}/config.h"

config.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#define IMGUIDM_VERSION_MAJOR @IMGUIDM_VERSION_MAJOR@
22
#define IMGUIDM_VERSION_MINOR @IMGUIDM_VERSION_MINOR@
3+
4+
#define IMGUIDM_FONT_DIR "@IMGUIDM_FONT_DIR@"

src/gui/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
cmake_minimum_required (VERSION 3.5)
22

3+
34
configure_file(
45
"ImGuiDMConfig.h.in"
56
"${PROJECT_BINARY_DIR}/ImGuiDMConfig.h"
@@ -11,6 +12,7 @@ find_package(Threads REQUIRED)
1112
#
1213
add_executable(demo
1314
src/main.cpp
15+
src/helpers.cpp
1416
src/ImGuiDM.cpp
1517
../3rd_party/addons/imguivariouscontrols/imguivariouscontrols.cpp
1618
#../3rd_party/metrics_gui/source/metrics_gui.cpp

src/gui/ImGuiDMConfig.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#define IMGUIDM_MINOR_VERSION @IMGUIDM_MINOR_VERSION@
44
#define IMGUIDM_PATCH_VERSION @IMGUIDM_PATCH_VERSION@
55

6-
#define IMGUIDM_GEOMETRY_DIR "@IMGUIDM_GEOMETRY_DIR@"
6+
#define IMGUIDM_FONT_DIR "@IMGUIDM_FONT_DIR@"
77
#define IMGUIDM_MACRO_DIR "@IMGUIDM_MACRO_DIR@"
88
#define IMGUIDM_DATA_DIR "@IMGUIDM_DATA_DIR@"
99
#define IMGUIDM_CXX_CFLAGS "@IMGUIDM_CXX_CFLAGS@"

src/gui/include/ImGuiDM.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,17 @@ namespace ImGuiDM {
7373
};
7474
//______________________________________________________________________________
7575

76-
class ImGuiDMApplication {
76+
class Application {
7777
public:
78-
Settings settings;
79-
MainMenu menu;
80-
GPSConfig gps_conf;
81-
78+
Settings settings;
79+
MainMenu menu;
80+
GPSConfig gps_conf;
81+
GLFWwindow* window;
8282
public:
8383

84-
ImGuiDMApplication(){}
84+
Application();
8585

86+
GLFWwindow* CreateWindow(int w = 1280, int h = 720);
8687
void Init(GLFWwindow* window);
8788

8889
void Render(){ }

src/gui/src/ImGuiDM.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,43 @@
55
#include <GL/gl3w.h>// This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you.
66
#include <GLFW/glfw3.h>
77

8+
static void error_callback(int error, const char* description)
9+
{
10+
fprintf(stderr, "Error %d: %s\n", error, description);
11+
}
12+
//______________________________________________________________________________
13+
814
namespace ImGuiDM {
915

16+
Application::Application()
17+
{
18+
}
19+
//______________________________________________________________________________
20+
21+
GLFWwindow* Application::CreateWindow(int w, int h)
22+
{
23+
// ---------------------------------------------------------------------------
24+
// Setup window
25+
// ---------------------------------------------------------------------------
26+
glfwSetErrorCallback(error_callback);
27+
if (!glfwInit())
28+
return nullptr;
29+
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
30+
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
31+
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
32+
#if __APPLE__
33+
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
34+
#endif
35+
//GLFWwindow*
36+
window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
37+
glfwMakeContextCurrent(window);
38+
glfwSwapInterval(1); // Enable vsync
39+
gl3wInit();
40+
return window;
41+
}
42+
//______________________________________________________________________________
1043

11-
void ImGuiDMApplication::Init(GLFWwindow* window)
44+
void Application::Init(GLFWwindow* window)
1245
{
1346
// Setup ImGui binding
1447
ImGui::CreateContext();
@@ -19,7 +52,7 @@ namespace ImGuiDM {
1952
//io.NavFlags |= ImGuiNavFlags_EnableGamepad; // Enable Gamepad Controls
2053

2154
// Setup style
22-
ImGui::StyleColorsDark();
55+
ImGui::StyleColorsLight();
2356
//ImGui::StyleColorsClassic();
2457

2558
// Load Fonts

src/gui/src/main.cpp

Lines changed: 11 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -22,105 +22,23 @@
2222
#include <iomanip>
2323
#include <sstream>
2424

25+
#include "helpers.h"
2526

26-
template<class C>
27-
void print_help(C cli)
28-
{
29-
std::cout << make_man_page(cli, "bubble_chamber") << "\n";
30-
}
31-
//______________________________________________________________________________
32-
33-
template<typename T>
34-
void print_usage(T cli, const char* argv0 )
35-
{
36-
//used default formatting
37-
std::cout << "Usage:\n" << usage_lines(cli, argv0)
38-
<< "\nOptions:\n" << documentation(cli) << '\n';
39-
}
40-
//______________________________________________________________________________
41-
42-
bool fexists(const std::string& filename) {
43-
std::ifstream ifile(filename.c_str());
44-
if( ifile ) return true;
45-
return false;
46-
}
47-
//______________________________________________________________________________
48-
49-
std::string exec(const char* cmd) {
50-
std::shared_ptr<FILE> pipe(popen(cmd, "r"), pclose);
51-
if (!pipe) return "ERROR";
52-
char buffer[128];
53-
std::string result = "";
54-
while (!feof(pipe.get())) {
55-
if (fgets(buffer, 128, pipe.get()) != NULL)
56-
result += buffer;
57-
}
58-
return result;
59-
}
60-
//______________________________________________________________________________
61-
62-
void copy_files(const std::vector<std::string>& files)
63-
{
64-
for(const auto& f: files) {
65-
std::string cmd = std::string("cp ") + f + " .";
66-
if( fexists(f) ) {
67-
std::cout << "copying " << f << std::endl;
68-
exec(cmd.c_str());
69-
}
70-
}
71-
}
72-
//______________________________________________________________________________
73-
74-
template<typename T>
75-
void print_man_page(T cli, const char* argv0 ){
76-
//all formatting options (with their default values)
77-
auto fmt = clipp::doc_formatting{}
78-
.start_column(8) //column where usage lines and documentation starts
79-
.doc_column(30) //parameter docstring start col
80-
.indent_size(4) //indent of documentation lines for children of a documented group
81-
.line_spacing(0) //number of empty lines after single documentation lines
82-
.paragraph_spacing(1) //number of empty lines before and after paragraphs
83-
.flag_separator(", ") //between flags of the same parameter
84-
.param_separator(" ") //between parameters
85-
.group_separator(" ") //between groups (in usage)
86-
.alternative_param_separator("|") //between alternative flags
87-
.alternative_group_separator(" | ") //between alternative groups
88-
.surround_group("(", ")") //surround groups with these
89-
.surround_alternatives("(", ")") //surround group of alternatives with these
90-
.surround_alternative_flags("", "") //surround alternative flags with these
91-
.surround_joinable("(", ")") //surround group of joinable flags with these
92-
.surround_optional("[", "]") //surround optional parameters with these
93-
.surround_repeat("", "..."); //surround repeatable parameters with these
94-
//.surround_value("<", ">") //surround values with these
95-
//.empty_label("") //used if parameter has no flags and no label
96-
//.max_alternative_flags_in_usage(1) //max. # of flags per parameter in usage
97-
//.max_alternative_flags_in_doc(2) //max. # of flags per parameter in detailed documentation
98-
//.split_alternatives(true) //split usage into several lines for large alternatives
99-
//.alternatives_min_split_size(3) //min. # of parameters for separate usage line
100-
//.merge_alternative_flags_with_common_prefix(false) //-ab(cdxy|xy) instead of -abcdxy|-abxy
101-
//.merge_joinable_flags_with_common_prefix(true); //-abc instead of -a -b -c
102-
auto mp = make_man_page(cli, argv0, fmt);
103-
mp.prepend_section("DESCRIPTION", "Bubble chamber simulation");
104-
mp.append_section("EXAMPLES", " $ bubble_chamber -h ");
105-
std::cout << mp << "\n";
106-
}
107-
//______________________________________________________________________________
10827

10928
static void error_callback(int error, const char* description)
11029
{
11130
fprintf(stderr, "Error %d: %s\n", error, description);
11231
}
11332
//______________________________________________________________________________
11433

115-
11634
int main(int argc, char** argv)
11735
{
11836
using namespace clipp;
11937
using std::cout;
12038
using CopyMode = ImGuiDM::Settings::CopyMode;
12139
using Mode = ImGuiDM::Settings::Mode;
12240

123-
ImGuiDM::ImGuiDMApplication app;
41+
ImGuiDM::Application app;
12442
auto& menu = app.menu;
12543
auto& S = app.settings;
12644
auto& gps_conf = app.gps_conf;
@@ -144,7 +62,6 @@ int main(int argc, char** argv)
14462
};
14563

14664
cout << "args -> parameter mapping:\n";
147-
;
14865
for(const auto& m0 : result) {
14966
std::cout << "#" << m0.index() << " " << m0.arg() << " -> ";
15067
auto p = m0.param();
@@ -257,29 +174,15 @@ int main(int argc, char** argv)
257174
// ---------------------------------------------------------------------------
258175
// Setup window
259176
// ---------------------------------------------------------------------------
260-
glfwSetErrorCallback(error_callback);
261-
if (!glfwInit())
262-
return 1;
263-
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
264-
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
265-
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
266-
#if __APPLE__
267-
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
268-
#endif
269-
int w = 1280;
270-
int h = 720;
271-
GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui OpenGL3 example", NULL, NULL);
272-
glfwMakeContextCurrent(window);
273-
glfwSwapInterval(1); // Enable vsync
274-
gl3wInit();
275-
276-
//// Setup ImGui binding
277-
//ImGui::CreateContext();
278-
//ImGuiIO& io = ImGui::GetIO();
279-
////(void)io;
280-
//ImGui_ImplGlfwGL3_Init(window, true);
281-
////io.NavFlags |= ImGuiNavFlags_EnableKeyboard; // Enable Keyboard Controls
282-
////io.NavFlags |= ImGuiNavFlags_EnableGamepad; // Enable Gamepad Controls
177+
GLFWwindow* window = app.CreateWindow(1280, 720);
178+
179+
////// Setup ImGui binding
180+
////ImGui::CreateContext();
181+
////ImGuiIO& io = ImGui::GetIO();
182+
//////(void)io;
183+
////ImGui_ImplGlfwGL3_Init(window, true);
184+
//////io.NavFlags |= ImGuiNavFlags_EnableKeyboard; // Enable Keyboard Controls
185+
//////io.NavFlags |= ImGuiNavFlags_EnableGamepad; // Enable Gamepad Controls
283186

284187
app.Init(window);
285188
//// Setup style

0 commit comments

Comments
 (0)