From d6778349d8359d47311d678633e844077af25330 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sat, 28 Oct 2017 11:37:47 -0700 Subject: [PATCH 01/11] Renamed in makefile --- makefile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/makefile b/makefile index 2b69f33..b9882bf 100644 --- a/makefile +++ b/makefile @@ -12,8 +12,8 @@ BUTTON_INC = lgl_abstract_button.h lgl_button.h lgl_cmdbutton.h lgl_endbutton.h BUTTON_SRC = lgl_abstract_button.cpp lgl_button.cpp lgl_cmdbutton.cpp lgl_endbutton.cpp #Everything else -INC = lgl_bar.h lgl_multibutton.h lgl_endmultibutton.h lgl_fullscreen.h lgl_elbow.h lgl_elbowbutton.h futuregl.h -SRC = lgl_bar.cpp lgl_multibutton.cpp lgl_endmultibutton.cpp lgl_fullscreen.cpp lgl_elbow.cpp futuregl.cpp +INC = lgl_bar.h lgl_multibutton.h lgl_endmultibutton.h lgl_fullscreen.h lgl_elbow.h lgl_elbowbutton.h lgl.h +SRC = lgl_bar.cpp lgl_multibutton.cpp lgl_endmultibutton.cpp lgl_fullscreen.cpp lgl_elbow.cpp lgl.cpp EXE_1 = test_1 EXE_2 = test_2 @@ -23,20 +23,20 @@ build: $(SRC) $(BUTTON_SRC) $(CORE_SRC) $(INC) $(CORE_INC) $(BUTTON_INC) $(CPP) -c -fPIC $(CORE_SRC) $(CFLAGS) $(CPP) -c -fPIC $(BUTTON_SRC) $(CFLAGS) $(CPP) -c -fPIC $(SRC) $(CFLAGS) - $(CPP) -shared -Wl,-soname,libfuturegl.so -o libfuturegl.so *.o + $(CPP) -shared -Wl,-soname,liblgl.so -o liblgl.so *.o test: $(SRC) $(BUTTON_SRC) $(TEST_SRC_1) $(TEST_SRC_2) $(CORE_SRC) $(INC) $(CORE_INC) $(BUTTON_INC) $(CPP) -o $(EXE_1) $(TEST_SRC_1) $(BUTTON_SRC) $(SRC) $(CORE_SRC) $(CFLAGS) -I. $(CPP) -o $(EXE_2) $(TEST_SRC_2) $(BUTTON_SRC) $(SRC) $(CORE_SRC) $(CFLAGS) -I. install: - [ -d /usr/include/futuregl ] || mkdir /usr/include/futuregl - cp -f *.h /usr/include/futuregl/ - cp -f libfuturegl.so /usr/lib/ - chmod a+r -R /usr/include/futuregl - chmod a+r /usr/lib/libfuturegl.so + [ -d /usr/include/lgl ] || mkdir /usr/include/lgl + cp -f *.h /usr/include/lgl/ + cp -f liblgl.so /usr/lib/ + chmod a+r -R /usr/include/lgl + chmod a+r /usr/lib/liblgl.so uninstall: - [ -d /usr/include/futuregl ] && rm -f /usr/include/futuregl/*.h - [ -d /usr/include/futuregl/* ] && rmdir /usr/include/futuregl - rm -f /usr/lib/libfuturegl.so + [ -d /usr/include/lgl ] && rm -f /usr/include/lgl/*.h + [ -d /usr/include/lgl/* ] && rmdir /usr/include/lgl + rm -f /usr/lib/liblgl.so clean: for file in $$(ls *.o); do rm $$file; done for file in $$(ls *.so); do rm $$file; done From 7f4672df34ecd4fb30bbf36a29c6096120610560 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sat, 28 Oct 2017 18:00:20 -0700 Subject: [PATCH 02/11] Added a.out to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9b94d32..33fc4be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +a.out *.o *.gch test_1 From 10fbe10dbc674d64938a8523320e87225a3bcf46 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sat, 28 Oct 2017 18:00:32 -0700 Subject: [PATCH 03/11] Refactor and restructure, started with just labels --- component_test.cpp | 57 ++++++++ lgl.cpp | 243 -------------------------------- lgl.h | 75 ---------- lgl_abstract_button.cpp | 25 ---- lgl_abstract_button.h | 52 ------- lgl_bar.cpp | 32 ----- lgl_bar.h | 46 ------ lgl_button.cpp | 34 ----- lgl_button.h | 41 ------ lgl_const.h => lgl_callable.cpp | 22 +-- lgl_callable.h | 42 ++++++ lgl_clickable.cpp | 32 +++++ lgl_clickable.h | 39 +++++ lgl_cmdbutton.cpp | 36 ----- lgl_cmdbutton.h | 35 ----- lgl_elbow.cpp | 127 ----------------- lgl_elbow.h | 59 -------- lgl_elbowbutton.h | 73 ---------- lgl_endbutton.cpp | 37 ----- lgl_endbutton.h | 40 ------ lgl_endmultibutton.cpp | 43 ------ lgl_endmultibutton.h | 29 ---- lgl_fullscreen.cpp | 53 ------- lgl_fullscreen.h | 50 ------- lgl_label.cpp | 31 ++++ lgl_label.h | 42 ++++++ lgl_multibutton.cpp | 46 ------ lgl_multibutton.h | 51 ------- lgl_object.cpp | 198 ++++++++++++++++++++++++++ lgl_object.h | 63 +++++++-- lgl_shapes.cpp | 54 ------- lgl_shapes.h | 34 ----- lgl_utils.cpp | 138 ------------------ lgl_utils.h | 37 ----- makefile | 12 +- test1.cpp | 152 -------------------- test2.cpp | 118 ---------------- test_config.conf | 24 ---- 38 files changed, 505 insertions(+), 1817 deletions(-) create mode 100644 component_test.cpp delete mode 100644 lgl.cpp delete mode 100644 lgl.h delete mode 100644 lgl_abstract_button.cpp delete mode 100644 lgl_abstract_button.h delete mode 100644 lgl_bar.cpp delete mode 100644 lgl_bar.h delete mode 100644 lgl_button.cpp delete mode 100644 lgl_button.h rename lgl_const.h => lgl_callable.cpp (50%) create mode 100644 lgl_callable.h create mode 100644 lgl_clickable.cpp create mode 100644 lgl_clickable.h delete mode 100644 lgl_cmdbutton.cpp delete mode 100644 lgl_cmdbutton.h delete mode 100644 lgl_elbow.cpp delete mode 100644 lgl_elbow.h delete mode 100644 lgl_elbowbutton.h delete mode 100644 lgl_endbutton.cpp delete mode 100644 lgl_endbutton.h delete mode 100644 lgl_endmultibutton.cpp delete mode 100644 lgl_endmultibutton.h delete mode 100644 lgl_fullscreen.cpp delete mode 100644 lgl_fullscreen.h create mode 100644 lgl_label.cpp create mode 100644 lgl_label.h delete mode 100644 lgl_multibutton.cpp delete mode 100644 lgl_multibutton.h create mode 100644 lgl_object.cpp delete mode 100644 lgl_shapes.cpp delete mode 100644 lgl_shapes.h delete mode 100644 lgl_utils.cpp delete mode 100644 lgl_utils.h delete mode 100644 test1.cpp delete mode 100644 test2.cpp delete mode 100644 test_config.conf diff --git a/component_test.cpp b/component_test.cpp new file mode 100644 index 0000000..271dbb4 --- /dev/null +++ b/component_test.cpp @@ -0,0 +1,57 @@ +#include +#include +#include + +#include "lgl_label.h" + +using lgl::label; +using lgl::color; +using std::cout; +using std::vector; + +int main(int argc, char * argv[]){ + lgl::colors = vector({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.6f}}); + lgl::scale_factor = 2.0f; + + label l1(0, 0, 0, "l1"); + label l2(0, 1, 0, "l2"); + label l3(0, 2, 0, "l3"); + label l4(0, 3, 0, "l4"); + label l5(0, 4, 0, "l5"); + label l6(0, 5, 0, "l6"); + label l7(1, 0, 1, "l7"); + label l8(1, 2, 1, "l8"); + label l9(1, 4, 1, "l9"); + label l10(2, 0, 2, "l10"); + label l11(2, 3, 2, "l11"); + label l12(3, 0, 5, "l12"); + + glfwInit(); + + GLFWwindow * window = glfwCreateWindow(400, 400, "Test", NULL, NULL); + + glfwMakeContextCurrent(window); + glOrtho(0, 400, 0, 400, -1, 1); + + while(true){ + glClear(GL_COLOR_BUFFER_BIT); + l1.draw(1); + l2.draw(1); + l3.draw(1); + l4.draw(1); + l5.draw(1); + l6.draw(1); + l7.draw(1); + l8.draw(1); + l9.draw(1); + l10.draw(1); + l11.draw(1); + l12.draw(1); + glfwSwapBuffers(window); + usleep(10000); + } + + glfwTerminate(); + + return 0; +} diff --git a/lgl.cpp b/lgl.cpp deleted file mode 100644 index b0f174d..0000000 --- a/lgl.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of Lgl. - - Lgl is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Lgl is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Lgl. If not, see . -*/ - -#include "lgl.h" -#include -#include - -using namespace std; - -lgl::lgl(int era) : era(era){ - buttons.clear(); - cmdbuttons.clear(); - endbuttons.clear(); - multibuttons.clear(); - endmultibuttons.clear(); - - elbows.clear(); - elbowbuttons.clear(); - - bars.clear(); - fullscreens.clear(); -} - -int lgl::button(int corner_x, int corner_y, int size, int color, std::string text){ - lgl_button button(corner_x, corner_y, size, era, color, text); - buttons.push_back(button); - return 0; -} - -int lgl::cmdbutton(int corner_x, int corner_y, int color, std::string text){ - lgl_cmdbutton cmdbutton(corner_x, corner_y, era, color, text); - cmdbuttons.push_back(cmdbutton); - return 0; -} - -int lgl::endbutton(int corner_x, int corner_y, int orientation, int color, std::string text){ - lgl_endbutton endbutton(corner_x, corner_y, orientation, era, color, text); - endbuttons.push_back(endbutton); - return 0; -} - -int lgl::multibutton(int corner_x, int corner_y, int extend, int color){ - lgl_multibutton multibutton(corner_x, corner_y, extend, era, color); - multibuttons.push_back(multibutton); - return 0; -} - -int lgl::endmultibutton(int corner_x, int corner_y, int color){ - lgl_endmultibutton endmultibutton(corner_x, corner_y, era, color); - endmultibuttons.push_back(endmultibutton); - return 0; -} - -int lgl::elbow(int corner_x, int corner_y, int length, int size, int orientation_x, int orientation_y, int color, std::string text){ - lgl_elbow elbow(corner_x, corner_y, length, size, orientation_x, orientation_y, era, color, text); - elbows.push_back(elbow); - return 0; -} - -int lgl::elbowbutton(int corner_x, int corner_y, int length, int size, int orientation_x, int orientation_y, int color, std::string text){ - lgl_elbowbutton elbowbutton(corner_x, corner_y, length, size, orientation_x, orientation_y, era, color, text); - elbowbuttons.push_back(elbowbutton); - return 0; -} - -int lgl::bar(int corner_x, int corner_y, int length, int color){ - lgl_bar bar(corner_x, corner_y, length, era, color); - bars.push_back(bar); - return 0; -} - -int lgl::fullscreen(int corner_x, int corner_y, int size_x, int size_y, int color, std::string main_text, std::string sub_text){ - lgl_fullscreen fullscreen(corner_x, corner_y, size_x, size_y, era, color, main_text, sub_text); - fullscreens.push_back(fullscreen); - return 0; -} - -int lgl::setmultibutton(int id, int value, bool end){ - if(!end){ - if(id >= multibuttons.size()){ - return -1; - } - multibuttons[id].setvalue(value); - } - else{ - if(id >= endmultibuttons.size()){ - return -1; - } - endmultibuttons[id].setvalue(value); - } - - return 0; -} - -int lgl::draw(){ - - for(int i = 0; i < buttons.size(); i++) buttons[i].draw(); - for(int i = 0; i < cmdbuttons.size(); i++) cmdbuttons[i].draw(); - for(int i = 0; i < endbuttons.size(); i++) endbuttons[i].draw(); - for(int i = 0; i < multibuttons.size(); i++) multibuttons[i].draw(); - for(int i = 0; i < endmultibuttons.size(); i++) endmultibuttons[i].draw(); - for(int i = 0; i < elbows.size(); i++) elbows[i].draw(); - for(int i = 0; i < elbowbuttons.size(); i++) elbowbuttons[i].draw(); - for(int i = 0; i < bars.size(); i++) bars[i].draw(); - for(int i = 0; i < fullscreens.size(); i++) fullscreens[i].draw(); - - return 0; -} - -string lgl::getclicked(int mouse_x, int mouse_y){ - string clicked_title = ""; - - for(int i = 0; i < buttons.size(); i++){ - if(buttons[i].clicked(mouse_x, mouse_y)) clicked_title = buttons[i].text; - } - for(int i = 0; i < cmdbuttons.size(); i++){ - if(cmdbuttons[i].clicked(mouse_x, mouse_y)) clicked_title = cmdbuttons[i].text; - } - for(int i = 0; i < endbuttons.size(); i++){ - if(endbuttons[i].clicked(mouse_x, mouse_y)) clicked_title = endbuttons[i].text; - } - for(int i = 0; i < elbowbuttons.size(); i++){ - if(elbowbuttons[i].clicked(mouse_x, mouse_y)) clicked_title = elbowbuttons[i].gettext(); - } - - return clicked_title; -} - -vector split_string(string data, char splitter){ - vector tokens = vector(); - string tmp = ""; - for(int i = 0; i < data.length(); i++){ - if(data[i] == splitter){ - tokens.push_back(tmp); - tmp = ""; - } - else{ - tmp += data[i]; - } - } - tokens.push_back(tmp); - return tokens; -} - -int lgl::load_config(string path){ - - fstream configfile; - configfile.open(path.c_str()); - - while(!configfile.eof()){ - string line; - getline(configfile, line); - - vector data = split_string(line, ' '); - - if(data[0] == "button"){ - button(atoi(data[1].c_str()), // corner_x - atoi(data[2].c_str()), // corner_y - atoi(data[3].c_str()), // size - atoi(data[4].c_str()), // color - data[5]); // text - } - else if(data[0] == "cmdbutton"){ - cmdbutton(atoi(data[1].c_str()), // corner_x - atoi(data[2].c_str()), // corner_y - atoi(data[3].c_str()), // color - data[4]); // text - } - else if(data[0] == "endbutton"){ - endbutton(atoi(data[1].c_str()), // corner_x - atoi(data[2].c_str()), // corner_y - atoi(data[3].c_str()), // orientation - atoi(data[4].c_str()), // color - data[5]); // text - } - else if(data[0] == "multibutton"){ - multibutton(atoi(data[1].c_str()), // corner_x - atoi(data[2].c_str()), // corner_y - atoi(data[3].c_str()), // extend - atoi(data[4].c_str())); //color - } - else if(data[0] == "endmultibutton"){ - endmultibutton(atoi(data[1].c_str()), // corner_x - atoi(data[2].c_str()), // corner_y - atoi(data[3].c_str())); //color - } - else if(data[0] == "elbow"){ - elbow(atoi(data[1].c_str()), // corner_x - atoi(data[2].c_str()), // corner_y - atoi(data[3].c_str()), // length - atoi(data[4].c_str()), // size - atoi(data[5].c_str()), // orientation_x - atoi(data[6].c_str()), // orientation_y - atoi(data[7].c_str()), // color - data[8]); // text - } - else if(data[0] == "elbowbutton"){ - elbowbutton(atoi(data[1].c_str()), // corner_x - atoi(data[2].c_str()), // corner_y - atoi(data[3].c_str()), // length - atoi(data[4].c_str()), // size - atoi(data[5].c_str()), // orientation_x - atoi(data[6].c_str()), // orientation_y - atoi(data[7].c_str()), // color - data[8]); // text - } - else if(data[0] == "bar"){ - bar(atoi(data[1].c_str()), // corner_x - atoi(data[2].c_str()), // corner_y - atoi(data[3].c_str()), // length - atoi(data[4].c_str())); // color - } - else if(data[0] == "fullscreen"){ - fullscreen(atoi(data[1].c_str()), // corner_x - atoi(data[2].c_str()), // corner_y - atoi(data[3].c_str()), // size_x - atoi(data[4].c_str()), // size_y - atoi(data[5].c_str()), // color - data[6], // main_text - data[7]); // sub_text - } - } - - configfile.close(); - - return 0; -} diff --git a/lgl.h b/lgl.h deleted file mode 100644 index 2ae5ed6..0000000 --- a/lgl.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of Lgl. - - Lgl is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Lgl is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Lgl. If not, see . -*/ - -#pragma once - -#include -#include -#include "lgl_object.h" - -#include "lgl_button.h" -#include "lgl_cmdbutton.h" -#include "lgl_endbutton.h" -#include "lgl_multibutton.h" -#include "lgl_endmultibutton.h" -#include "lgl_elbow.h" -#include "lgl_elbowbutton.h" -#include "lgl_bar.h" -#include "lgl_fullscreen.h" - -class lgl { - -public: - lgl(int era); - - int button(int corner_x, int corner_y, int size, int color, std::string text); - int cmdbutton(int corner_x, int corner_y, int color, std::string text); - int endbutton(int corner_x, int corner_y, int orientation, int color, std::string text); - int multibutton(int corner_x, int corner_y, int extend, int color); - int endmultibutton(int corner_x, int corner_y, int color); - - int elbow(int corner_x, int corner_y, int length, int size, int orientation_x, int orientation_y, int color, std::string text); - int elbowbutton(int corner_x, int corner_y, int length, int size, int orientation_x, int orientation_y, int color, std::string text); - int bar(int corner_x, int corner_y, int length, int color); - - int fullscreen(int corner_x, int corner_y, int size_x, int size_y, int color, std::string main_text, std::string sub_text); - - int setmultibutton(int id, int value, bool end=false); - - int draw(); - - std::string getclicked(int mouse_x, int mouse_y); - - int load_config(std::string path); - -private: - int era; - - std::vector buttons; - std::vector cmdbuttons; - std::vector endbuttons; - std::vector multibuttons; - std::vector endmultibuttons; - - std::vector elbows; - std::vector elbowbuttons; - - std::vector bars; - std::vector fullscreens; -}; diff --git a/lgl_abstract_button.cpp b/lgl_abstract_button.cpp deleted file mode 100644 index 9aa789f..0000000 --- a/lgl_abstract_button.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_abstract_button.h" - -bool lgl_abstract_button::clicked(int click_x, int click_y){ - if(click_x < data.x2 && click_x > data.x1 && click_y < data.y2 && click_y > data.y1) return true; - else return false; -} diff --git a/lgl_abstract_button.h b/lgl_abstract_button.h deleted file mode 100644 index ab14813..0000000 --- a/lgl_abstract_button.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include -#include "lgl_object.h" - -typedef struct { - int x1; - int x2; - int y1; - int y2; - -} button_data; - -class lgl_abstract_button : public lgl_object { -public: -lgl_abstract_button(int era, int color, std::string text) : lgl_object(era, color) { - this->text = text; - - data.x1 = 0; - data.x2 = 0; - data.y1 = 0; - data.y2 = 0; - } - - virtual bool clicked(int click_x, int click_y); - - std::string text; - - virtual int draw() = 0; - -protected: - button_data data; -}; diff --git a/lgl_bar.cpp b/lgl_bar.cpp deleted file mode 100644 index 5ce6910..0000000 --- a/lgl_bar.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_bar.h" -#include "lgl_shapes.h" -#include "lgl_utils.h" - -using namespace std; - -int lgl_bar::draw(){ - - lgl_utils::colors(era, color); - - lgl_shapes::rectangle(data.x1, data.x2, data.y1, data.y2); - -} diff --git a/lgl_bar.h b/lgl_bar.h deleted file mode 100644 index 5d5e8cd..0000000 --- a/lgl_bar.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include "lgl_object.h" -#include "lgl_const.h" - -typedef struct{ - int x1; - int x2; - int y1; - int y2; -} bar_data; - -class lgl_bar : public lgl_object { -public: - lgl_bar(int corner_x, int corner_y, int length, int era, int color) : lgl_object(era, color){ - data.x1 = corner_x*(lgl_const::button_width + lgl_const::gap); - data.x2 = corner_x*(lgl_const::button_width + lgl_const::gap) - + length*lgl_const::button_width; - data.y1 = corner_y*(lgl_const::button_height + lgl_const::gap) - - lgl_const::button_height/2 - lgl_const::gap*2; - data.y2 = corner_y*(lgl_const::button_height + lgl_const::gap) - lgl_const::gap*2; - } - - int draw(); -private: - bar_data data; -}; diff --git a/lgl_button.cpp b/lgl_button.cpp deleted file mode 100644 index d0c4a62..0000000 --- a/lgl_button.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_button.h" -#include "lgl_shapes.h" -#include "lgl_utils.h" - -using namespace std; - -int lgl_button::draw(){ - lgl_utils::colors(era, color); - - lgl_shapes::rectangle(data.x1, data.x2, data.y1, data.y2); - - lgl_utils::draw_text(data.x1+5, data.y1+5, 3, text); - - return 0; -} diff --git a/lgl_button.h b/lgl_button.h deleted file mode 100644 index 4798c4c..0000000 --- a/lgl_button.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include "lgl_abstract_button.h" -#include "lgl_const.h" - -class lgl_button : public lgl_abstract_button { -public: - lgl_button(int corner_x, int corner_y, int size, int era, int color, std::string text) : lgl_abstract_button(era, color, text){ - data.x1 = corner_x*(lgl_const::button_width + lgl_const::gap); - data.y1 = corner_y*(lgl_const::button_height + lgl_const::gap); - data.x2 = corner_x*(lgl_const::button_width + lgl_const::gap) + lgl_const::button_width; - data.y2 = corner_y*(lgl_const::button_height + lgl_const::gap) + lgl_const::button_height*size - + lgl_const::gap*(size-1); - - this->size = size; - } - - int draw(); - -private: - int size; -}; diff --git a/lgl_const.h b/lgl_callable.cpp similarity index 50% rename from lgl_const.h rename to lgl_callable.cpp index ffb227c..9c96952 100644 --- a/lgl_const.h +++ b/lgl_callable.cpp @@ -1,26 +1,28 @@ /* - Copyright 2015 Carter Turnbaugh + Copyright 2017 Carter Turnbaugh - This file is part of FutureGL. + This file is part of LGL. - FutureGL is free software: you can redistribute it and/or modify + LGL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - FutureGL is distributed in the hope that it will be useful, + LGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . + along with LGL. If not, see . */ -#pragma once +#include "lgl_callable.h" -namespace lgl_const { - const int button_width = 90; - const int button_height = 36; - const int gap = 2; +using namespace lgl; + +callable_function::callable_function(void (*function)()) : m_function(function) {} + +void callable_function::call(){ + m_function(); } diff --git a/lgl_callable.h b/lgl_callable.h new file mode 100644 index 0000000..08ab078 --- /dev/null +++ b/lgl_callable.h @@ -0,0 +1,42 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#pragma once + +#include + +using std::string; + +namespace lgl { + + class callable { + public: + virtual void call() = 0; + }; + + class callable_function : public callable{ + public: + callable_function(void (*function)()); + + void call(); + private: + void (*m_function)(); + }; + +}; diff --git a/lgl_clickable.cpp b/lgl_clickable.cpp new file mode 100644 index 0000000..54356f8 --- /dev/null +++ b/lgl_clickable.cpp @@ -0,0 +1,32 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#include "lgl_clickable.h" + +using namespace lgl; + +clickable::clickable(callable * call_on_click) : m_call_on_click(call_on_click) {} + +bool clickable::try_click(int click_x, int click_y){ + bool was_clicked = clicked(click_x, click_y); + if(was_clicked){ + m_call_on_click->call(); + } + return was_clicked; +} diff --git a/lgl_clickable.h b/lgl_clickable.h new file mode 100644 index 0000000..42d0f6d --- /dev/null +++ b/lgl_clickable.h @@ -0,0 +1,39 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#pragma once + +#include "lgl_callable.h" + +namespace lgl { + + class clickable { + public: + clickable(callable * call_on_click); + + bool try_click(int click_x, int click_y); + + protected: + virtual bool clicked(int click_x, int click_y) = 0; + + private: + callable * m_call_on_click; + }; + +}; diff --git a/lgl_cmdbutton.cpp b/lgl_cmdbutton.cpp deleted file mode 100644 index f814170..0000000 --- a/lgl_cmdbutton.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_cmdbutton.h" -#include "lgl_utils.h" -#include "lgl_shapes.h" - -using namespace std; - -int lgl_cmdbutton::draw(){ - lgl_utils::colors(era, color); - - lgl_shapes::rectangle(data.x1+lgl_const::button_height/2, data.x2-lgl_const::button_height/2, data.y1, data.y2); - lgl_shapes::arc(data.x1+lgl_const::button_height/2, data.y1+lgl_const::button_height/2, lgl_const::button_height/2, 90, 270); - lgl_shapes::arc(data.x2-lgl_const::button_height/2, data.y1+lgl_const::button_height/2, lgl_const::button_height/2, -90, 90); - - lgl_utils::draw_text(data.x1+lgl_const::button_height/2+5, data.y1+5, 3, text); - - return 0; -} diff --git a/lgl_cmdbutton.h b/lgl_cmdbutton.h deleted file mode 100644 index cf8ecb5..0000000 --- a/lgl_cmdbutton.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include "lgl_abstract_button.h" -#include "lgl_const.h" - -class lgl_cmdbutton : public lgl_abstract_button { -public: - lgl_cmdbutton(int corner_x, int corner_y, int era, int color, std::string text) : lgl_abstract_button(era, color, text){ - data.x1 = corner_x*(lgl_const::button_width + lgl_const::gap); - data.y1 = corner_y*(lgl_const::button_height + lgl_const::gap); - data.x2 = corner_x*(lgl_const::button_width + lgl_const::gap) + lgl_const::button_width; - data.y2 = corner_y*(lgl_const::button_height + lgl_const::gap) + lgl_const::button_height; - } - - int draw(); -}; diff --git a/lgl_elbow.cpp b/lgl_elbow.cpp deleted file mode 100644 index 73b90d8..0000000 --- a/lgl_elbow.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_elbow.h" - -#include - -#include "lgl_utils.h" -#include "lgl_shapes.h" -#include "lgl_const.h" - -using namespace std; - -int lgl_elbow::draw(){ - lgl_utils::colors(era, color); - - if(elbow.x_orient == 0){ - if(elbow.y_orient == 0) draw_x0_y0(); - else draw_x0_y1(); - } - else{ - if(elbow.y_orient == 0) draw_x1_y0(); - else draw_x1_y1(); - } -} - -int lgl_elbow::draw_x0_y0(){ - // Button rectangle - lgl_shapes::rectangle(elbow.x, elbow.x+lgl_const::button_width, elbow.y, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29); - // Button arc - lgl_shapes::arc(elbow.x+45, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29, 45, 90, 180); - // Filler box - lgl_shapes::rectangle(elbow.x+45, elbow.x+lgl_const::button_width+27, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 74); - // Bar - lgl_shapes::rectangle(elbow.x+lgl_const::button_width+27, elbow.x+lgl_const::button_width+elbow.length+27, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29 + 27, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 74); - - glColor3f(0.0, 0.0, 0.0); - - // Erase inner arc portion - lgl_shapes::arc(elbow.x+lgl_const::button_width+27, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29, 27, 90, 180); - lgl_utils::draw_text(elbow.x+5, elbow.y+5, 3, text); -} - -int lgl_elbow::draw_x1_y0(){ - // Button rectangle - lgl_shapes::rectangle(elbow.x+elbow.length+27, elbow.x+elbow.length+27+lgl_const::button_width, elbow.y, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29); - // Button arc - lgl_shapes::arc(elbow.x+elbow.length+27+(lgl_const::button_width-45), - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29, 45, 0, 90); - // Filler box - lgl_shapes::rectangle(elbow.x+elbow.length, elbow.x+elbow.length+27+(lgl_const::button_width-45), - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 74); - // Bar - lgl_shapes::rectangle(elbow.x, elbow.x+elbow.length, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29 + 27, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 74); - - glColor3f(0.0, 0.0, 0.0); - - // Erase inner arc portion - lgl_shapes::arc(elbow.x+elbow.length, - elbow.y+(elbow.size-1)*lgl_const::gap+elbow.size*lgl_const::button_height + 29, 27, 0, 90); - lgl_utils::draw_text(elbow.x+elbow.length+27+5, elbow.y+5, 3, text); -} - -int lgl_elbow::draw_x0_y1(){ - // Button rectangle - lgl_shapes::rectangle(elbow.x, elbow.x+lgl_const::button_width, elbow.y+45, - elbow.y+elbow.size*lgl_const::button_height+elbow.size*lgl_const::gap+45+29); - // Button arc - lgl_shapes::arc(elbow.x+45, elbow.y+45, 45, 180, 270); - // Filler box - lgl_shapes::rectangle(elbow.x+45, elbow.x+lgl_const::button_width+27, elbow.y, elbow.y+45); - // Bar - lgl_shapes::rectangle(elbow.x+lgl_const::button_width+27, elbow.x+lgl_const::button_width+elbow.length+27, - elbow.y, elbow.y+18); - - glColor3f(0.0, 0.0, 0.0); - - // Erase inner arc portion - lgl_shapes::arc(elbow.x+lgl_const::button_width+27, elbow.y+45, 27, 180, 270); - lgl_utils::draw_text(elbow.x+5, elbow.y+lgl_const::button_height*(elbow.size+2)-15, 3, text); -} - -int lgl_elbow::draw_x1_y1(){ - // Button rectangle - lgl_shapes::rectangle(elbow.x+elbow.length+27, elbow.x+elbow.length+27+lgl_const::button_width, elbow.y+45, - elbow.y+elbow.size*lgl_const::button_height+elbow.size*lgl_const::gap+45+29); - // Button arc - lgl_shapes::arc(elbow.x+elbow.length+27+(lgl_const::button_width-45), elbow.y+45, 45, -90, 0); - // Filler box - lgl_shapes::rectangle(elbow.x+elbow.length, elbow.x+elbow.length+27+(lgl_const::button_width-45), - elbow.y, elbow.y+45); - // Bar - lgl_shapes::rectangle(elbow.x, elbow.x+elbow.length, elbow.y, elbow.y+18); - - glColor3f(0.0, 0.0, 0.0); - - // Erase inner arc portion - lgl_shapes::arc(elbow.x+elbow.length, elbow.y+45, 27, -90, 0); - lgl_utils::draw_text(elbow.x+elbow.length+27+5, elbow.y+lgl_const::button_height*(elbow.size+2)-15, 3, text); -} diff --git a/lgl_elbow.h b/lgl_elbow.h deleted file mode 100644 index be276d8..0000000 --- a/lgl_elbow.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include "lgl_object.h" -#include "lgl_const.h" -#include - -typedef struct { - int x; - int y; - int length; - int size; - int x_orient; - int y_orient; -} elbow_data; - -class lgl_elbow : public lgl_object { -public: - lgl_elbow(int corner_x, int corner_y, int length, int size, int orientation_x, int orientation_y, int era, int color, std::string text) : lgl_object(era, color){ - elbow.x = corner_x*(lgl_const::button_width + lgl_const::gap); - elbow.y = corner_y*(lgl_const::button_height + lgl_const::gap); - elbow.length = length*(lgl_const::button_width + lgl_const::gap) - 27; - elbow.size = size - 1; - elbow.x_orient = orientation_x; - elbow.y_orient = orientation_y; - - this->text = text; - } - - virtual int draw(); - - std::string text; - -protected: - elbow_data elbow; - - int draw_x0_y0(); - int draw_x1_y0(); - int draw_x0_y1(); - int draw_x1_y1(); -}; diff --git a/lgl_elbowbutton.h b/lgl_elbowbutton.h deleted file mode 100644 index 2542d26..0000000 --- a/lgl_elbowbutton.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include "lgl_elbow.h" -#include "lgl_abstract_button.h" -#include "lgl_const.h" - -class lgl_elbowbutton : public lgl_elbow, public lgl_abstract_button { -public: - lgl_elbowbutton(int corner_x, int corner_y, int length, int size, int orientation_x, int orientation_y, int era, int color, std::string text) -: lgl_elbow(corner_x, corner_y, length, size, orientation_x, orientation_y, era, color, text), lgl_abstract_button(era, color, text){ - if(orientation_x == 0){ - if(orientation_y == 0){ - data.x1 = corner_x*(lgl_const::button_width + lgl_const::gap); - data.y1 = corner_y*(lgl_const::button_height + lgl_const::gap) - lgl_const::gap; - data.x2 = corner_x*(lgl_const::button_width + lgl_const::gap) - + lgl_const::button_width; - data.y2 = (corner_y + size)*(lgl_const::button_height + lgl_const::gap); - } - else{ - data.x1 = corner_x*(lgl_const::button_width + lgl_const::gap); - data.y1 = corner_y*(lgl_const::button_height + lgl_const::gap) + 35; - data.x2 = corner_x*(lgl_const::button_width + lgl_const::gap) - + lgl_const::button_width; - data.y2 = (corner_y + size)*(lgl_const::button_height + lgl_const::gap) + 36; - } - } - else { - if(orientation_y == 0){ - data.x1 = corner_x*(lgl_const::button_width + lgl_const::gap) + length + 27; - data.y1 = corner_y*(lgl_const::button_height + lgl_const::gap) - lgl_const::gap; - data.x2 = corner_x*(lgl_const::button_width + lgl_const::gap) - + length*lgl_const::button_width + 27 + lgl_const::button_width; - data.y2 = (corner_y + size)*(lgl_const::button_height + lgl_const::gap); - } - else{ - data.x1 = corner_x*(lgl_const::button_width + lgl_const::gap) - + length*lgl_const::button_width + 27; - data.y1 = corner_y*(lgl_const::button_height + lgl_const::gap) + 35; - data.x2 = corner_x*(lgl_const::button_width + lgl_const::gap) - + length*lgl_const::button_width + 27 + lgl_const::button_width; - data.y2 = (corner_y + size)*(lgl_const::button_height + lgl_const::gap) + 36; - } - } - } - - int draw(){ - lgl_elbow::draw(); - return 0; - } - - std::string gettext(){ - return lgl_abstract_button::text; - } -}; diff --git a/lgl_endbutton.cpp b/lgl_endbutton.cpp deleted file mode 100644 index 49a4d5d..0000000 --- a/lgl_endbutton.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_endbutton.h" -#include "lgl_utils.h" -#include "lgl_shapes.h" - -using namespace std; - -int lgl_endbutton::draw(){ - lgl_utils::colors(era, color); - - lgl_shapes::rectangle(data.x1+(lgl_const::button_height/2 * orientation), data.x2+(lgl_const::button_height/2 * (orientation - 1)), data.y1, data.y2); - - if(orientation == 1) lgl_shapes::arc(data.x1+lgl_const::button_height/2, data.y1+lgl_const::button_height/2, lgl_const::button_height/2, 90, 270); - if(orientation == 0) lgl_shapes::arc(data.x2-lgl_const::button_height/2, data.y1+lgl_const::button_height/2, lgl_const::button_height/2, -90, 90); - - lgl_utils::draw_text(data.x1+(lgl_const::button_height/2 * orientation)+5, data.y1+5, 3, text); - - return 0; -} diff --git a/lgl_endbutton.h b/lgl_endbutton.h deleted file mode 100644 index 8103fe2..0000000 --- a/lgl_endbutton.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include "lgl_abstract_button.h" -#include "lgl_const.h" - -class lgl_endbutton : public lgl_abstract_button { -public: - lgl_endbutton(int corner_x, int corner_y, int orientation, int era, int color, std::string text) : lgl_abstract_button(era, color, text){ - data.x1 = corner_x*(lgl_const::button_width + lgl_const::gap); - data.y1 = corner_y*(lgl_const::button_height + lgl_const::gap); - data.x2 = corner_x*(lgl_const::button_width + lgl_const::gap) + lgl_const::button_width; - data.y2 = corner_y*(lgl_const::button_height + lgl_const::gap) + lgl_const::button_height; - - this->orientation = orientation; - } - - int draw(); -private: - int orientation; - -}; diff --git a/lgl_endmultibutton.cpp b/lgl_endmultibutton.cpp deleted file mode 100644 index edf998b..0000000 --- a/lgl_endmultibutton.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_endmultibutton.h" -#include "lgl_utils.h" -#include "lgl_shapes.h" - -using namespace std; - -int lgl_endmultibutton::draw(){ - - if(value < 0) value = 0; - if(value > 999) value = 999; - - lgl_utils::colors(era, color); - - lgl_shapes::rectangle(data.x1, data.x1+10, data.y1, data.y2); - lgl_shapes::rectangle(data.x1+54, data.x2-lgl_const::button_height/2, data.y1, data.y2); - lgl_shapes::arc(data.x1+72, data.y1+lgl_const::button_height/2, lgl_const::button_height/2, -90, 90); - - string number = lgl_utils::its(value); - if(value < 10) number = "0"+number; - - lgl_utils::draw_text(data.x1+15, data.y1+5, 2, number, 0); - - return 0; -} diff --git a/lgl_endmultibutton.h b/lgl_endmultibutton.h deleted file mode 100644 index 562171d..0000000 --- a/lgl_endmultibutton.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include "lgl_multibutton.h" - -class lgl_endmultibutton : public lgl_multibutton { -public: - lgl_endmultibutton(int corner_x, int corner_y, int era, int color) : lgl_multibutton(corner_x, corner_y, 0, era, color){} - - int draw(); -}; diff --git a/lgl_fullscreen.cpp b/lgl_fullscreen.cpp deleted file mode 100644 index 45b89c5..0000000 --- a/lgl_fullscreen.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_fullscreen.h" - -#include - -#include "lgl_shapes.h" -#include "lgl_utils.h" -#include "lgl_const.h" - -using namespace std; - -int lgl_fullscreen::draw(){ - lgl_utils::colors(era, color); - - lgl_shapes::rectangle(fullscreen.x+18*4/5, fullscreen.x+fullscreen.x_size-18*4/5, fullscreen.y, fullscreen.y+(lgl_const::button_height*4/5)); - lgl_shapes::rectangle(fullscreen.x+18, fullscreen.x+fullscreen.x_size-18, fullscreen.y+fullscreen.y_size-lgl_const::button_height, fullscreen.y+fullscreen.y_size); - - lgl_shapes::arc(fullscreen.x+18*4/5, fullscreen.y+18*4/5, 18*4/5, 90, 270); - lgl_shapes::arc(fullscreen.x+18, fullscreen.y+fullscreen.y_size-18, 18, 90, 270); - lgl_shapes::arc(fullscreen.x+fullscreen.x_size-18*4/5, fullscreen.y+18*4/5, 18*4/5, -90, 90); - lgl_shapes::arc(fullscreen.x+fullscreen.x_size-18, fullscreen.y+fullscreen.y_size-18, 18, -90, 90); - - glColor3f(0.0, 0.0, 0.0); - - lgl_shapes::rectangle(fullscreen.x+fullscreen.x_size*1/9, fullscreen.x+fullscreen.x_size*1/9+sub_text.length()*12, fullscreen.y, fullscreen.y+(lgl_const::button_height*4/5)); - lgl_shapes::rectangle(fullscreen.x+fullscreen.x_size*5/9, fullscreen.x+fullscreen.x_size*5/9+main_text.length()*14, fullscreen.y+fullscreen.y_size-lgl_const::button_height, fullscreen.y+fullscreen.y_size); - - lgl_utils::draw_text(fullscreen.x+fullscreen.x_size*1/9, fullscreen.y, 2, sub_text, 1); - lgl_utils::draw_text(fullscreen.x+fullscreen.x_size*5/9, fullscreen.y+fullscreen.y_size-lgl_const::button_height, 1, main_text, 1); - - glColor3f(0.0, 0.0, 0.0); - - lgl_shapes::rectangle(fullscreen.x+fullscreen.x_size*33/36, fullscreen.x+fullscreen.x_size*17/18, fullscreen.y, fullscreen.y+(lgl_const::button_height*4/5)); - lgl_shapes::rectangle(fullscreen.x+fullscreen.x_size*1/18, fullscreen.x+fullscreen.x_size*3/36, fullscreen.y+fullscreen.y_size-lgl_const::button_height, fullscreen.y+fullscreen.y_size); -} diff --git a/lgl_fullscreen.h b/lgl_fullscreen.h deleted file mode 100644 index f9bce18..0000000 --- a/lgl_fullscreen.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include "lgl_object.h" -#include "lgl_const.h" -#include - -typedef struct { - int x; - int y; - int x_size; - int y_size; -} fullscreen_data; - -class lgl_fullscreen : public lgl_object { -public: - lgl_fullscreen(int corner_x, int corner_y, int size_x, int size_y, int era, int color, std::string main_text, std::string sub_text) : lgl_object(era, color){ - fullscreen.x = fullscreen.x*(lgl_const::button_width + lgl_const::gap); - fullscreen.y = fullscreen.y*(lgl_const::button_height + lgl_const::gap); - fullscreen.x_size = fullscreen.x_size; - fullscreen.y_size = fullscreen.y_size; - - this->main_text = main_text; - this->sub_text = sub_text; - } - - int draw(); -private: - fullscreen_data fullscreen; - std::string main_text; - std::string sub_text; -}; diff --git a/lgl_label.cpp b/lgl_label.cpp new file mode 100644 index 0000000..21b1924 --- /dev/null +++ b/lgl_label.cpp @@ -0,0 +1,31 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#include "lgl_label.h" + +using namespace lgl; + +label::label(int column, int row, int height, string text) + : m_column(column), m_row(row), m_height(height), m_text(text) {} + +void label::draw_shapes(){ + full_rectangle(m_column, m_column, m_row, m_row + m_height); + + draw_text(m_column, m_row, m_text); +} diff --git a/lgl_label.h b/lgl_label.h new file mode 100644 index 0000000..d79ba75 --- /dev/null +++ b/lgl_label.h @@ -0,0 +1,42 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#pragma once + +#include "lgl_object.h" + +#include + +using std::string; + +namespace lgl { + + class label : public object { + public: + label(int column, int row, int height, string text); + + protected: + void draw_shapes(); + + private: + int m_column, m_row, m_height; + string m_text; + }; + +}; diff --git a/lgl_multibutton.cpp b/lgl_multibutton.cpp deleted file mode 100644 index 933f2f8..0000000 --- a/lgl_multibutton.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_multibutton.h" -#include "lgl_utils.h" -#include "lgl_shapes.h" - -using namespace std; - -int lgl_multibutton::setvalue(int value){ - this->value = value; -} - -int lgl_multibutton::draw(){ - - if(value < 0) value = 0; - if(value > 99) value = 99; - - lgl_utils::colors(era, color); - - lgl_shapes::rectangle(data.x1, data.x1+10, data.y1, data.y2); - lgl_shapes::rectangle(data.x1+54, data.x1+lgl_const::button_width, data.y1, data.y2+lgl_const::gap*extend); - - string number = lgl_utils::its(value); - if(value < 10) number = "0"+number; - - lgl_utils::draw_text(data.x1+15, data.y1+lgl_const::gap, 2, number, 0); - - return 0; -} diff --git a/lgl_multibutton.h b/lgl_multibutton.h deleted file mode 100644 index 9e493bf..0000000 --- a/lgl_multibutton.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#include "lgl_object.h" -#include "lgl_const.h" - -typedef struct { - int x1; - int x2; - int y1; - int y2; -} multibutton_data; - -class lgl_multibutton : public lgl_object { -public: - lgl_multibutton(int corner_x, int corner_y, int extend, int era, int color) : lgl_object(era, color){ - data.x1 = corner_x*(lgl_const::button_width + lgl_const::gap); - data.x2 = corner_x*(lgl_const::button_width + lgl_const::gap) + lgl_const::button_width; - data.y1 = corner_y*(lgl_const::button_height + lgl_const::gap); - data.y2 = corner_y*(lgl_const::button_height + lgl_const::gap) + lgl_const::button_height; - - this->extend = extend; - } - - int setvalue(int value); - - virtual int draw(); -protected: - int value; - multibutton_data data; -private: - int extend; -}; diff --git a/lgl_object.cpp b/lgl_object.cpp new file mode 100644 index 0000000..c0907d3 --- /dev/null +++ b/lgl_object.cpp @@ -0,0 +1,198 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#include "lgl_object.h" + +#include +#include +#include + +using namespace lgl; +using std::cerr; +using std::cout; +using std::endl; + +object::object(){ + font = new FTTextureFont(font_path.c_str()); + if(font->Error()){ + cerr << "Font not found" << endl; + return; + } + + font->FaceSize(60); +} + +object::~object(){ + delete font; +} + +void object::draw(int color){ + glColor3f(colors[color].R, colors[color].G, colors[color].B); + + draw_shapes(); +} + +void object::draw_text(int grid_x, int grid_y, string text){ + glColor3f(0.0f, 0.0f, 0.0f); + + int font_size = 61; + + int right = 0; + int top = 0; + + do { + font->FaceSize(font_size - 1); + FTBBox bounding_box = font->BBox(text.c_str(), text.length()); + right = bounding_box.Upper().X(); + top = bounding_box.Upper().Y(); + font_size--; + } while(right > grid_width * 3.0/4.0 || top > grid_height * 3.0/4.0); + + int left = grid_x * (grid_width + gap) + grid_width * 1.0/8.0; + int bottom = grid_y * (grid_height + gap) + gap; + + glTranslated(left, bottom, 0); + + font->Render(text.c_str()); + + glTranslated(-left, -bottom, 0); +} + +void object::full_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top){ + int left = grid_left * (grid_width + gap); + int right = grid_right * (grid_width + gap) + grid_width; + int bottom = grid_bottom * (grid_height + gap); + int top = grid_top * (grid_height + gap) + grid_height; + + glBegin(GL_QUADS); + + glVertex2i(left, top); + glVertex2i(right, top); + glVertex2i(right, bottom); + glVertex2i(left, bottom); + + glEnd(); +} + +void object::half_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top, bool at_top){ + int left = grid_left * (grid_width + gap); + int right = grid_right * (grid_width + gap) + grid_width; + int bottom = grid_bottom * (grid_height + gap); + int top = grid_top * (grid_height + gap); + + if(at_top){ + bottom += grid_height / 2; + } + else{ + top -= grid_height / 2; + } + + glBegin(GL_QUADS); + + glVertex2i(left, top); + glVertex2i(right, top); + glVertex2i(right, bottom); + glVertex2i(left, bottom); + + glEnd(); +} + +float object::get_arc_start_angle(bool left, bool down){ + if(left && down) return 90; + if(left && !down) return 180; + if(!left && down) return 0; + return 270; +} + +float object::get_arc_end_angle(bool left, bool down){ + if(left && down) return 180; + if(left && !down) return 270; + if(!left && down) return 90; + return 360; +} + +void object::full_arc(int grid_x, int grid_y, bool left, bool down){ + int center_x, center_y; + if(left){ + center_x = grid_x * (grid_width + gap) + grid_height; + } + else{ + center_x = grid_x * (grid_width + gap) + grid_width - grid_height; + } + if(down){ + center_y = grid_y * (grid_height + gap); + } + else{ + center_y = grid_y * (grid_height + gap) + grid_height; + } + + float start_angle = get_arc_start_angle(left, down); + float end_angle = get_arc_end_angle(left, down); + float radius = grid_height; + + glBegin(GL_POLYGON); + glVertex2i(center_x,center_y); + for(float i = start_angle; i < end_angle; i+=0.02){ + float angle = i/57.3; + float x2 = center_x+cos(angle)*radius; + float y2 = center_y+sin(angle)*radius; + glVertex2f(x2,y2); + } + glEnd(); +} + +void object::half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down){ + int center_x, center_y; + if(left){ + center_x = grid_x * (grid_width + gap) + grid_height; + } + else{ + center_x = grid_x * (grid_width + gap) + grid_width - grid_height; + } + if(down){ + center_y = grid_y * (grid_height + gap); + if(at_top){ + center_y += grid_height / 2; + } + } + else{ + center_y = grid_y * (grid_height + gap) + grid_height; + if(!at_top){ + center_y -= grid_height / 2; + } + } + + float start_angle = get_arc_start_angle(left, down); + float end_angle = get_arc_end_angle(left, down); + float radius = grid_height / 2.0f; + + glBegin(GL_POLYGON); + glVertex2i(center_x,center_y); + for(float i = start_angle; i < end_angle; i+=0.02){ + float angle = i/57.3; + float x2 = center_x+cos(angle)*radius; + float y2 = center_y+sin(angle)*radius; + glVertex2f(x2,y2); + } + glEnd(); +} + +vector lgl::colors = vector(); +float lgl::scale_factor = 1.0f; +string lgl::font_path = "./font.ttf"; diff --git a/lgl_object.h b/lgl_object.h index d383da4..3a2c54c 100644 --- a/lgl_object.h +++ b/lgl_object.h @@ -1,34 +1,67 @@ /* - Copyright 2015 Carter Turnbaugh + Copyright 2017 Carter Turnbaugh - This file is part of FutureGL. + This file is part of LGL. - FutureGL is free software: you can redistribute it and/or modify + LGL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - FutureGL is distributed in the hope that it will be useful, + LGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . + along with LGL. If not, see . */ #pragma once -class lgl_object { -public: - lgl_object(int era, int color) { - this->era = era; - this->color = color; - } +#include + +#include +#include + +using std::vector; +using std::string; + +namespace lgl { + + struct color{ + float R; + float G; + float B; + }; - virtual int draw() = 0; + const int grid_width = 45; + const int grid_height = 18; + const int gap = 1; + + extern vector colors; + extern float scale_factor; + extern string font_path; + + class object { + public: + object(); + ~object(); + + void draw(int color); + protected: + virtual void draw_shapes() = 0; + + void draw_text(int grid_left, int grid_bottom, string text); -protected: - int era; - int color; + void full_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top); + void half_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top, bool at_top); + void full_arc(int grid_x, int grid_y, bool left, bool down); + void half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down); + private: + float get_arc_start_angle(bool left, bool down); + float get_arc_end_angle(bool left, bool down); + + FTTextureFont * font; + }; }; diff --git a/lgl_shapes.cpp b/lgl_shapes.cpp deleted file mode 100644 index ad4d9a8..0000000 --- a/lgl_shapes.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include -#include -#include - -using namespace std; - -namespace lgl_shapes{ - void rectangle(int corner_x_left, int corner_x_right, int corner_y_bottom, int corner_y_top){ - - glBegin(GL_QUADS); - - glVertex2i(corner_x_left, corner_y_bottom); - glVertex2i(corner_x_right, corner_y_bottom); - glVertex2i(corner_x_right, corner_y_top); - glVertex2i(corner_x_left, corner_y_top); - - glEnd(); - - } - - void arc(int center_x, int center_y, int radius, int start_angle, int end_angle){ - - glBegin(GL_POLYGON); - glVertex2i(center_x,center_y); - for(float i = start_angle; i < end_angle; i+=0.02){ - float angle = i/57.3; - float x2 = center_x+cos(angle)*radius; - float y2 = center_y+sin(angle)*radius; - glVertex2f(x2,y2); - } - glEnd(); - - } - -} diff --git a/lgl_shapes.h b/lgl_shapes.h deleted file mode 100644 index 95fa910..0000000 --- a/lgl_shapes.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#ifndef LGL_SHAPES -#define LGL_SHAPES 0 - -#include -#include -#include - -namespace lgl_shapes{ - void rectangle(int corner_x_left, int corner_x_right, int corner_y_bottom, int corner_y_top); - void arc(int center_x, int center_y, int radius, int start_angle, int end_angle); -} - -#endif diff --git a/lgl_utils.cpp b/lgl_utils.cpp deleted file mode 100644 index af86407..0000000 --- a/lgl_utils.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include "lgl_utils.h" - -using namespace std; - -namespace lgl_utils{ - - const int num_fonts = 5; - const string fonts[] = {"/usr/share/fonts/oxygen/OxygenMono-Regular.ttf", - "/usr/share/fonts/bitstream-vera/VeraMono.ttf", - "/usr/share/fonts/dejavu/DejaVuSansMono.ttf", - "/usr/share/fonts/liberation/LiberationMono-Regular.ttf", - "/usr/share/fonts/gnu-free/FreeSans.ttf"}; - - string its(int in){ - stringstream ss; - ss << in; - return ss.str(); - } - - void colors(int era, int choice){ - if(era == 1){ - if(choice == 1) glColor3f(0.5f, 0.5f, 0.5f); - else if(choice == 2) glColor3f(1.0f, 1.0f, 0.6f); - else if(choice == 3) glColor3f(1.0f, 0.8f, 0.6f); - else if(choice == 4) glColor3f(1.0f, 0.6f, 0.2f); - else if(choice == 5) glColor3f(0.4f, 0.267f, 0.4f); - else if(choice == 6) glColor3f(0.8f, 0.6f, 0.8f); - else if(choice == 7) glColor3f(0.6f, 0.8f, 1.0f); - else if(choice == 8) glColor3f(0.2f, 0.4f, 0.8f); - else if(choice == 9) glColor3f(0.0f, 0.4f, 0.6f); - else if(choice == 10) glColor3f(0.0f, 0.0f, 0.0f); - } - else if(era == 2){ - if(choice == 1) glColor3f(0.5f, 0.5f, 0.5f); - else if(choice == 2) glColor3f(0.6f, 0.6f, 0.9f); - else if(choice == 3) glColor3f(0.6f, 0.6f, 0.8f); - else if(choice == 4) glColor3f(0.8f, 0.6f, 0.8f); - else if(choice == 5) glColor3f(0.8f, 0.0f, 0.6f); - else if(choice == 6) glColor3f(0.8f, 0.4f, 0.4f); - else if(choice == 7) glColor3f(1.0f, 0.6f, 0.4f); - else if(choice == 8) glColor3f(1.0f, 0.6f, 0.0f); - else if(choice == 9) glColor3f(1.0f, 0.8f, 0.4f); - else if(choice == 10) glColor3f(0.0f, 0.0f, 0.0f); - } - else if(era == 3){ - if(choice == 1) glColor3f(0.5f, 0.5f, 0.5f); - else if(choice == 2) glColor3f(0.4f, 0.533f, 0.8f); - else if(choice == 3) glColor3f(0.267f, 0.333f, 0.722f); - else if(choice == 4) glColor3f(0.6f, 0.467f, 0.667f); - else if(choice == 5) glColor3f(0.467f, 0.267f, 0.4f); - else if(choice == 6) glColor3f(0.867f, 0.4f, 0.267f); - else if(choice == 7) glColor3f(0.667f, 0.333f, 0.2f); - else if(choice == 8) glColor3f(0.722f, 0.4f, 0.133f); - else if(choice == 9) glColor3f(0.933f, 0.6f, 0.333f); - else if(choice == 10) glColor3f(0.0f, 0.0f, 0.0f); - } - else if(era == 4){ - if(choice == 1) glColor3f(0.5f, 0.5f, 0.5f); - else if(choice == 2) glColor3f(0.8f, 0.867f, 1.0f); - else if(choice == 3) glColor3f(0.333f, 0.6f, 1.0f); - else if(choice == 4) glColor3f(0.2f, 0.4f, 1.0f); - else if(choice == 5) glColor3f(0.0f, 0.067f, 0.933f); - else if(choice == 6) glColor3f(0.0f, 0.0f, 0.533f); - else if(choice == 7) glColor3f(0.733f, 0.667f, 0.333f); - else if(choice == 8) glColor3f(0.733f, 0.267f, 0.067f); - else if(choice == 9) glColor3f(0.533f, 0.133f, 0.067f); - else if(choice == 10) glColor3f(0.0f, 0.0f, 0.0f); - } - else { - cout << "Coloring is null\n"; - } - } - - int draw_text(int corner_x, int corner_y, int size, string text, int color){ - - if((size > 4 || size < 1) && size < 10 ){ - cerr << "FutureGL Error: FutureGL only supports 4 core font sizes\nPlease adapt your code. Sorry.\n"; - return -1; - } - - colors(1, color); - glTranslated(corner_x, corner_y, 0); - - // Create a texture font from a TrueType file. - - FTFont *font; - bool font_loaded = false; - - for(int i = 0; i < num_fonts; i++){ - font = new FTTextureFont(fonts[i].c_str()); - if(!(font->Error())){ - font_loaded = true; - break; - } - } - - - if(!font_loaded){ - cerr << "FutureGL Error: Font not found\nTried:\n"; - for(int i = 0; i < num_fonts; i++) cerr << "\t" << fonts[i] << "\n"; - return -1; - } - - // Set the font size and render a small text. - - if(size == 1) font->FaceSize(60); - else if(size == 2) font->FaceSize(29); - else if(size == 3) font->FaceSize(10); - else if(size == 4) font->FaceSize(10); - else font->FaceSize(size); - font->Render(text.c_str()); - - delete(font); - - glTranslated(-corner_x, -corner_y, 0); - - return 0; - } -} diff --git a/lgl_utils.h b/lgl_utils.h deleted file mode 100644 index 6b7f5cc..0000000 --- a/lgl_utils.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#pragma once - -#ifndef LGL_UTILS -#define LGL_UTILS 0 - -#include -#include -#include -#include -#include - -namespace lgl_utils{ - std::string its(int in); - void colors(int era, int choice); - int draw_text(int corner_x, int corner_y, int size, std::string text, int color=10); -} - -#endif diff --git a/makefile b/makefile index b9882bf..d438915 100644 --- a/makefile +++ b/makefile @@ -4,16 +4,12 @@ TEST_SRC_1 = test1.cpp TEST_SRC_2 = test2.cpp #The core includes used by almost all files -CORE_INC = lgl_const.h lgl_shapes.h lgl_utils.h lgl_object.h -CORE_SRC = lgl_shapes.cpp lgl_utils.cpp - -#The most common buttons -BUTTON_INC = lgl_abstract_button.h lgl_button.h lgl_cmdbutton.h lgl_endbutton.h -BUTTON_SRC = lgl_abstract_button.cpp lgl_button.cpp lgl_cmdbutton.cpp lgl_endbutton.cpp +CORE_INC = lgl_object.h +CORE_SRC = lgl_object.cpp #Everything else -INC = lgl_bar.h lgl_multibutton.h lgl_endmultibutton.h lgl_fullscreen.h lgl_elbow.h lgl_elbowbutton.h lgl.h -SRC = lgl_bar.cpp lgl_multibutton.cpp lgl_endmultibutton.cpp lgl_fullscreen.cpp lgl_elbow.cpp lgl.cpp +INC = +SRC = EXE_1 = test_1 EXE_2 = test_2 diff --git a/test1.cpp b/test1.cpp deleted file mode 100644 index 61a9f73..0000000 --- a/test1.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include -#include -#include -#include - -#include - -#include - -using namespace std; - -#define WIN_X 1600 -#define WIN_Y 756 - -const float scale = 2.0f; - -futuregl future(3); - -short iter[5]; - -string its(int in){ - stringstream a; - a << in; - return a.str(); -} - -void draw(){ - - future.setmultibutton(0, iter[0]); - future.setmultibutton(1, iter[1]); - future.setmultibutton(2, iter[2]); - future.setmultibutton(3, iter[3]); - future.setmultibutton(4, iter[4]); - - future.draw(); -} - -void futureInit(){ - - future.elbow(0, 4, 2, 4, 0, 0, 6, "FUTURE GUI"); - future.elbow(0, 0, 2, 3, 0, 1, 6, "TEST"); - future.elbow(3, 7, 1, 1, 1, 0, 6, "FUTURE GUI"); - - future.elbowbutton(3, 0, 1, 1, 1, 1, 7, "RESET ALL"); - - // Make sure to track the order of initialization - future.multibutton(4, 2, 1, 3); - future.multibutton(4, 3, 1, 3); - future.multibutton(4, 4, 1, 3); - future.multibutton(4, 5, 1, 3); - future.multibutton(4, 6, 1, 3); - - future.button(3, 2, 1, 4, "INCREASE 0"); - future.button(3, 3, 1, 4, "INCREASE 1"); - future.button(3, 4, 1, 4, "INCREASE 2"); - future.button(3, 5, 1, 4, "INCREASE 3"); - future.button(3, 6, 1, 4, "INCREASE 4"); - - future.button(2, 2, 1, 5, "DECREASE 0"); - future.button(2, 3, 1, 5, "DECREASE 1"); - future.button(2, 4, 1, 5, "DECREASE 2"); - future.button(2, 5, 1, 5, "DECREASE 3"); - future.button(2, 6, 1, 5, "DECREASE 4"); - - future.cmdbutton(1, 2, 8, "RESET 0"); - future.endbutton(1, 3, 1, 8, "RESET 1"); - future.endbutton(1, 4, 1, 8, "RESET 2"); - future.endbutton(1, 5, 1, 8, "RESET 3"); - future.endbutton(1, 6, 1, 8, "RESET 4"); -} - -void mouse(GLFWwindow * window, int button, int state, int mods) { - if(state == GLFW_PRESS){ - if(button == GLFW_MOUSE_BUTTON_LEFT){ - double Mx, My; - glfwGetCursorPos(window, &Mx, &My); - - My = WIN_Y - My; - Mx = Mx/scale; - My = My/scale; - string button = future.getclicked(Mx, My); - - if(button != "") cout << button << " clicked\n"; - - if(button == "INCREASE 0") iter[0]++; - if(button == "INCREASE 1") iter[1]++; - if(button == "INCREASE 2") iter[2]++; - if(button == "INCREASE 3") iter[3]++; - if(button == "INCREASE 4") iter[4]++; - if(button == "DECREASE 0") iter[0]--; - if(button == "DECREASE 1") iter[1]--; - if(button == "DECREASE 2") iter[2]--; - if(button == "DECREASE 3") iter[3]--; - if(button == "DECREASE 4") iter[4]--; - if(button == "RESET 0") iter[0] = 0; - if(button == "RESET 1") iter[1] = 0; - if(button == "RESET 2") iter[2] = 0; - if(button == "RESET 3") iter[3] = 0; - if(button == "RESET 4") iter[4] = 0; - if(button == "RESET ALL"){ - for(int i = 0; i < 5; i++) iter[i] = 0; - } - } - } -} - -int main(int argc, char** argv) { - for(int i = 0; i < 5; i++) iter[i] = 0; - glfwInit(); - GLFWwindow * window = glfwCreateWindow(WIN_X, WIN_Y, "FutureGL Test", NULL, NULL); - if(!window){ - cout << "Error\n"; - return -1; - } - - glfwMakeContextCurrent(window); - glfwSetMouseButtonCallback(window, mouse); - glOrtho(0, WIN_X/scale, 0, WIN_Y/scale, -1.0, 1.0); - cout << "OpenGL init complete\n"; - futureInit(); - cout << "future init complete\n"; - - while(true){ - glClear(GL_COLOR_BUFFER_BIT); - draw(); - glfwSwapBuffers(window); - glfwPollEvents(); - usleep(1000); - } - - glfwTerminate(); - return 0; -} diff --git a/test2.cpp b/test2.cpp deleted file mode 100644 index 533bc1a..0000000 --- a/test2.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - Copyright 2015 Carter Turnbaugh - - This file is part of FutureGL. - - FutureGL is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - FutureGL is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with FutureGL. If not, see . -*/ - -#include -#include -#include -#include - -#include - -#include - -using namespace std; - -#define WIN_X 1600 -#define WIN_Y 756 - -const float scale = 2.0f; - -futuregl future(3); - -short iter[5]; - -string its(int in){ - stringstream a; - a << in; - return a.str(); -} - -void draw(){ - - future.setmultibutton(0, iter[0]); - future.setmultibutton(1, iter[1]); - future.setmultibutton(2, iter[2]); - future.setmultibutton(3, iter[3]); - future.setmultibutton(4, iter[4]); - - future.draw(); -} - -void mouse(GLFWwindow * window, int button, int state, int mods) { - if(state == GLFW_PRESS){ - if(button == GLFW_MOUSE_BUTTON_LEFT){ - double Mx, My; - glfwGetCursorPos(window, &Mx, &My); - - My = WIN_Y - My; - Mx = Mx/scale; - My = My/scale; - string button = future.getclicked(Mx, My); - - if(button != "") cout << button << " clicked\n"; - - if(button == "INCREASE_0") iter[0]++; - if(button == "INCREASE_1") iter[1]++; - if(button == "INCREASE_2") iter[2]++; - if(button == "INCREASE_3") iter[3]++; - if(button == "INCREASE_4") iter[4]++; - if(button == "DECREASE_0") iter[0]--; - if(button == "DECREASE_1") iter[1]--; - if(button == "DECREASE_2") iter[2]--; - if(button == "DECREASE_3") iter[3]--; - if(button == "DECREASE_4") iter[4]--; - if(button == "RESET_0") iter[0] = 0; - if(button == "RESET_1") iter[1] = 0; - if(button == "RESET_2") iter[2] = 0; - if(button == "RESET_3") iter[3] = 0; - if(button == "RESET_4") iter[4] = 0; - if(button == "RESET_ALL"){ - for(int i = 0; i < 5; i++) iter[i] = 0; - } - } - } -} - -int main(int argc, char* argv[]) { - for(int i = 0; i < 5; i++) iter[i] = 2; - glfwInit(); - GLFWwindow * window = glfwCreateWindow(WIN_X, WIN_Y, "FutureGL Test", NULL, NULL); - if(!window){ - cout << "Error\n"; - return -1; - } - cout << "Window create complete\n"; - glfwMakeContextCurrent(window); - glfwSetMouseButtonCallback(window, mouse); - glOrtho(0, WIN_X/scale, 0, WIN_Y/scale, -1.0, 1.0); - cout << "OpenGL init complete\n"; - future.load_config("test_config.conf"); - cout << "future init complete\n"; - - while(true){ - glClear(GL_COLOR_BUFFER_BIT); - draw(); - glfwSwapBuffers(window); - glfwPollEvents(); - usleep(1000); - } - - glfwTerminate(); - return 0; -} diff --git a/test_config.conf b/test_config.conf deleted file mode 100644 index 163412e..0000000 --- a/test_config.conf +++ /dev/null @@ -1,24 +0,0 @@ -elbow 0 4 2 4 0 0 6 FUTURE_GUI -elbow 0 0 2 3 0 1 6 TEST -elbow 3 7 1 1 1 0 6 FUTURE_GUI -elbowbutton 3 0 1 1 1 1 7 RESET_ALL -multibutton 4 2 1 3 -multibutton 4 3 1 3 -multibutton 4 4 1 3 -multibutton 4 5 1 3 -multibutton 4 6 1 3 -button 3 2 1 4 INCREASE_0 -button 3 3 1 4 INCREASE_1 -button 3 4 1 4 INCREASE_2 -button 3 5 1 4 INCREASE_3 -button 3 6 1 4 INCREASE_4 -button 2 2 1 5 DECREASE_0 -button 2 3 1 5 DECREASE_1 -button 2 4 1 5 DECREASE_2 -button 2 5 1 5 DECREASE_3 -button 2 6 1 5 DECREASE_4 -cmdbutton 1 2 8 RESET_0 -endbutton 1 3 1 8 RESET_1 -endbutton 1 4 1 8 RESET_2 -endbutton 1 5 1 8 RESET_3 -endbutton 1 6 1 8 RESET_4 \ No newline at end of file From a671bec4dea714a6dc2724ef5225a8aadac632c6 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sat, 28 Oct 2017 18:14:55 -0700 Subject: [PATCH 04/11] Integrated scale factor (actually, just multiplied by it) --- lgl_button.cpp | 29 +++++++++++++++++++++++++++ lgl_button.h | 35 +++++++++++++++++++++++++++++++++ lgl_clickable.h | 1 + lgl_const.cpp | 23 ++++++++++++++++++++++ lgl_const.h | 39 +++++++++++++++++++++++++++++++++++++ lgl_label.h | 3 +-- lgl_object.cpp | 52 ++++++++++++++++++++++++------------------------- lgl_object.h | 17 ++-------------- 8 files changed, 155 insertions(+), 44 deletions(-) create mode 100644 lgl_button.cpp create mode 100644 lgl_button.h create mode 100644 lgl_const.cpp create mode 100644 lgl_const.h diff --git a/lgl_button.cpp b/lgl_button.cpp new file mode 100644 index 0000000..6982741 --- /dev/null +++ b/lgl_button.cpp @@ -0,0 +1,29 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#include "lgl_button.h" + +using namespace lgl; + +button::button(int column, int row, int height, string text, callable * call_on_click) + : label(column, row, height, text), clickable(call_on_click) {} + +bool button::clicked(int grid_click_x, int grid_click_y){ + return grid_click_x == m_column && (m_row <= grid_click_y && m_row + m_height >= grid_click_y) ; +} diff --git a/lgl_button.h b/lgl_button.h new file mode 100644 index 0000000..0501f82 --- /dev/null +++ b/lgl_button.h @@ -0,0 +1,35 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#pragma once + +#include "lgl_label.h" +#include "lgl_clickable.h" + +namespace lgl { + + class button : public label, public clickable { + public: + button(int column, int row, int height, string text, callable * call_on_click); + + protected: + bool clicked(int grid_click_x, int grid_click_y); + }; + +}; diff --git a/lgl_clickable.h b/lgl_clickable.h index 42d0f6d..1bb3858 100644 --- a/lgl_clickable.h +++ b/lgl_clickable.h @@ -19,6 +19,7 @@ #pragma once +#include "lgl_const.h" #include "lgl_callable.h" namespace lgl { diff --git a/lgl_const.cpp b/lgl_const.cpp new file mode 100644 index 0000000..d77e722 --- /dev/null +++ b/lgl_const.cpp @@ -0,0 +1,23 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#include "lgl_const.h" + +vector lgl::colors = vector(); +float lgl::scale_factor = 1.0f; diff --git a/lgl_const.h b/lgl_const.h new file mode 100644 index 0000000..599bfdc --- /dev/null +++ b/lgl_const.h @@ -0,0 +1,39 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#pragma once + +#include + +using std::vector; + +namespace lgl { + struct color{ + float R; + float G; + float B; + }; + + const int grid_width = 45; + const int grid_height = 18; + const int gap = 1; + + extern vector colors; + extern float scale_factor; +} diff --git a/lgl_label.h b/lgl_label.h index d79ba75..4e206c4 100644 --- a/lgl_label.h +++ b/lgl_label.h @@ -33,8 +33,7 @@ namespace lgl { protected: void draw_shapes(); - - private: + int m_column, m_row, m_height; string m_text; }; diff --git a/lgl_object.cpp b/lgl_object.cpp index c0907d3..3317640 100644 --- a/lgl_object.cpp +++ b/lgl_object.cpp @@ -62,10 +62,10 @@ void object::draw_text(int grid_x, int grid_y, string text){ right = bounding_box.Upper().X(); top = bounding_box.Upper().Y(); font_size--; - } while(right > grid_width * 3.0/4.0 || top > grid_height * 3.0/4.0); + } while(right > grid_width * 3.0/4.0 * scale_factor || top > grid_height * 3.0/4.0 * scale_factor); - int left = grid_x * (grid_width + gap) + grid_width * 1.0/8.0; - int bottom = grid_y * (grid_height + gap) + gap; + int left = (grid_x * (grid_width + gap) + grid_width * 1.0/8.0) * scale_factor; + int bottom = (grid_y * (grid_height + gap) + gap) * scale_factor; glTranslated(left, bottom, 0); @@ -75,10 +75,10 @@ void object::draw_text(int grid_x, int grid_y, string text){ } void object::full_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top){ - int left = grid_left * (grid_width + gap); - int right = grid_right * (grid_width + gap) + grid_width; - int bottom = grid_bottom * (grid_height + gap); - int top = grid_top * (grid_height + gap) + grid_height; + int left = (grid_left * (grid_width + gap)) * scale_factor; + int right = (grid_right * (grid_width + gap) + grid_width) * scale_factor; + int bottom = (grid_bottom * (grid_height + gap)) * scale_factor; + int top = (grid_top * (grid_height + gap) + grid_height) * scale_factor; glBegin(GL_QUADS); @@ -91,16 +91,16 @@ void object::full_rectangle(int grid_left, int grid_right, int grid_bottom, int } void object::half_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top, bool at_top){ - int left = grid_left * (grid_width + gap); - int right = grid_right * (grid_width + gap) + grid_width; - int bottom = grid_bottom * (grid_height + gap); - int top = grid_top * (grid_height + gap); + int left = (grid_left * (grid_width + gap)) * scale_factor; + int right = (grid_right * (grid_width + gap) + grid_width) * scale_factor; + int bottom = (grid_bottom * (grid_height + gap)) * scale_factor; + int top = (grid_top * (grid_height + gap)) * scale_factor; if(at_top){ - bottom += grid_height / 2; + bottom += (grid_height / 2) * scale_factor; } else{ - top -= grid_height / 2; + top -= (grid_height / 2) * scale_factor; } glBegin(GL_QUADS); @@ -130,21 +130,21 @@ float object::get_arc_end_angle(bool left, bool down){ void object::full_arc(int grid_x, int grid_y, bool left, bool down){ int center_x, center_y; if(left){ - center_x = grid_x * (grid_width + gap) + grid_height; + center_x = (grid_x * (grid_width + gap) + grid_height) * scale_factor; } else{ - center_x = grid_x * (grid_width + gap) + grid_width - grid_height; + center_x = (grid_x * (grid_width + gap) + grid_width - grid_height) * scale_factor; } if(down){ - center_y = grid_y * (grid_height + gap); + center_y = (grid_y * (grid_height + gap)) * scale_factor; } else{ - center_y = grid_y * (grid_height + gap) + grid_height; + center_y = (grid_y * (grid_height + gap) + grid_height) * scale_factor; } float start_angle = get_arc_start_angle(left, down); float end_angle = get_arc_end_angle(left, down); - float radius = grid_height; + float radius = grid_height * scale_factor; glBegin(GL_POLYGON); glVertex2i(center_x,center_y); @@ -160,27 +160,27 @@ void object::full_arc(int grid_x, int grid_y, bool left, bool down){ void object::half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down){ int center_x, center_y; if(left){ - center_x = grid_x * (grid_width + gap) + grid_height; + center_x = (grid_x * (grid_width + gap) + grid_height) * scale_factor; } else{ - center_x = grid_x * (grid_width + gap) + grid_width - grid_height; + center_x = (grid_x * (grid_width + gap) + grid_width - grid_height) * scale_factor; } if(down){ - center_y = grid_y * (grid_height + gap); + center_y = grid_y * (grid_height + gap) * scale_factor; if(at_top){ - center_y += grid_height / 2; + center_y += (grid_height / 2) * scale_factor; } } else{ - center_y = grid_y * (grid_height + gap) + grid_height; + center_y = (grid_y * (grid_height + gap) + grid_height) * scale_factor; if(!at_top){ - center_y -= grid_height / 2; + center_y -= (grid_height / 2) * scale_factor; } } float start_angle = get_arc_start_angle(left, down); float end_angle = get_arc_end_angle(left, down); - float radius = grid_height / 2.0f; + float radius = (grid_height / 2.0f) * scale_factor; glBegin(GL_POLYGON); glVertex2i(center_x,center_y); @@ -193,6 +193,4 @@ void object::half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down) glEnd(); } -vector lgl::colors = vector(); -float lgl::scale_factor = 1.0f; string lgl::font_path = "./font.ttf"; diff --git a/lgl_object.h b/lgl_object.h index 3a2c54c..57a1a4f 100644 --- a/lgl_object.h +++ b/lgl_object.h @@ -19,28 +19,15 @@ #pragma once +#include "lgl_const.h" + #include -#include #include -using std::vector; using std::string; namespace lgl { - - struct color{ - float R; - float G; - float B; - }; - - const int grid_width = 45; - const int grid_height = 18; - const int gap = 1; - - extern vector colors; - extern float scale_factor; extern string font_path; class object { From 466ec1d603a9ff2b7bb90d74564f41f4198b5585 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sat, 28 Oct 2017 20:02:51 -0700 Subject: [PATCH 05/11] Better button management --- component_test.cpp | 140 ++++++++++++++++++++++++++++++++++++--------- lgl_button.cpp | 4 +- lgl_button.h | 2 +- lgl_clickable.cpp | 14 +++-- lgl_clickable.h | 13 ++++- lgl_label.cpp | 4 +- lgl_label.h | 2 +- lgl_object.cpp | 15 +++-- lgl_object.h | 8 ++- 9 files changed, 155 insertions(+), 47 deletions(-) diff --git a/component_test.cpp b/component_test.cpp index 271dbb4..d330445 100644 --- a/component_test.cpp +++ b/component_test.cpp @@ -3,55 +3,141 @@ #include #include "lgl_label.h" +#include "lgl_button.h" +#include "lgl_const.h" using lgl::label; using lgl::color; +using lgl::callable_function; +using lgl::button; using std::cout; using std::vector; -int main(int argc, char * argv[]){ - lgl::colors = vector({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.6f}}); - lgl::scale_factor = 2.0f; +void l4_callback(){ + cout << "l4 clicked\n"; +} +void l5_callback(){ + cout << "l5 clicked\n"; +} +void l6_callback(){ + cout << "l6 clicked\n"; +} +void l9_callback(){ + cout << "l9 clicked\n"; +} +void l11_callback(){ + cout << "l11 clicked\n"; +} +void l12_callback(){ + cout << "l12 clicked\n"; +} + +// #globalization +label * l1; +label * l2; +label * l3; +callable_function * l4_func; +button * l4; +callable_function * l5_func; +button * l5; +callable_function * l6_func; +button * l6; +label * l7; +label * l8; +callable_function * l9_func; +button * l9; +label * l10; +callable_function * l11_func; +button * l11; +callable_function * l12_func; +button * l12; + +void mouse(GLFWwindow * window, int button, int state, int mods){ + int mouse_button = button == GLFW_MOUSE_BUTTON_LEFT ? lgl::left_mouse_button : lgl::right_mouse_button; + int mouse_state = state == GLFW_PRESS ? lgl::mouse_down_state : lgl::mouse_up_state; - label l1(0, 0, 0, "l1"); - label l2(0, 1, 0, "l2"); - label l3(0, 2, 0, "l3"); - label l4(0, 3, 0, "l4"); - label l5(0, 4, 0, "l5"); - label l6(0, 5, 0, "l6"); - label l7(1, 0, 1, "l7"); - label l8(1, 2, 1, "l8"); - label l9(1, 4, 1, "l9"); - label l10(2, 0, 2, "l10"); - label l11(2, 3, 2, "l11"); - label l12(3, 0, 5, "l12"); + double Mx, My; + glfwGetCursorPos(window, &Mx, &My); + My = 400 - My; + + l4->try_click(Mx, My, mouse_button, mouse_state); + l5->try_click(Mx, My, mouse_button, mouse_state); + + l6->try_click(Mx, My, mouse_button, mouse_state); + l9->try_click(Mx, My, mouse_button, mouse_state); + l11->try_click(Mx, My, mouse_button, mouse_state); + l12->try_click(Mx, My, mouse_button, mouse_state); +} + +int main(int argc, char * argv[]){ + lgl::colors = vector({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.6f}}); + + l1 = new label(1, 0, 0, 0, "l1"); + l2 = new label(1, 0, 1, 0, "l2"); + l3 = new label(1, 0, 2, 0, "l3"); + l4_func = new callable_function(&l4_callback); + l4 = new button(1, 0, 3, 0, "l4", l4_func); + l5_func = new callable_function(&l5_callback); + l5 = new button(1, 0, 4, 0, "l5", l5_func); + l6_func = new callable_function(&l6_callback); + l6 = new button(1, 0, 5, 0, "l6", l6_func); + l7 = new label(1, 1, 0, 1, "l7"); + l8 = new label(1, 1, 2, 1, "l8"); + l9_func = new callable_function(&l9_callback); + l9 = new button(1, 1, 4, 1, "l9", l9_func); + l10 = new label(1, 2, 0, 2, "l10"); + l11_func = new callable_function(&l11_callback); + l11 = new button(1, 2, 3, 2, "l11", l11_func); + l12_func = new callable_function(&l12_callback); + l12 = new button(1, 3, 0, 5, "l12", l12_func); glfwInit(); GLFWwindow * window = glfwCreateWindow(400, 400, "Test", NULL, NULL); glfwMakeContextCurrent(window); + glfwSetMouseButtonCallback(window, mouse); glOrtho(0, 400, 0, 400, -1, 1); while(true){ glClear(GL_COLOR_BUFFER_BIT); - l1.draw(1); - l2.draw(1); - l3.draw(1); - l4.draw(1); - l5.draw(1); - l6.draw(1); - l7.draw(1); - l8.draw(1); - l9.draw(1); - l10.draw(1); - l11.draw(1); - l12.draw(1); + l1->draw(); + l2->draw(); + l3->draw(); + l4->draw(); + l5->draw(); + l6->draw(); + l7->draw(); + l8->draw(); + l9->draw(); + l10->draw(); + l11->draw(); + l12->draw(); glfwSwapBuffers(window); + glfwPollEvents(); usleep(10000); } glfwTerminate(); + delete l1; + delete l2; + delete l3; + delete l4_func; + delete l4; + delete l5_func; + delete l5; + delete l6_func; + delete l6; + delete l7; + delete l8; + delete l9_func; + delete l9; + delete l10; + delete l11_func; + delete l11; + delete l12_func; + delete l12; + return 0; } diff --git a/lgl_button.cpp b/lgl_button.cpp index 6982741..322689c 100644 --- a/lgl_button.cpp +++ b/lgl_button.cpp @@ -21,8 +21,8 @@ using namespace lgl; -button::button(int column, int row, int height, string text, callable * call_on_click) - : label(column, row, height, text), clickable(call_on_click) {} +button::button(int color, int column, int row, int height, string text, callable * call_on_click) + : label(color, column, row, height, text), clickable(call_on_click) {} bool button::clicked(int grid_click_x, int grid_click_y){ return grid_click_x == m_column && (m_row <= grid_click_y && m_row + m_height >= grid_click_y) ; diff --git a/lgl_button.h b/lgl_button.h index 0501f82..7e97e06 100644 --- a/lgl_button.h +++ b/lgl_button.h @@ -26,7 +26,7 @@ namespace lgl { class button : public label, public clickable { public: - button(int column, int row, int height, string text, callable * call_on_click); + button(int color, int column, int row, int height, string text, callable * call_on_click); protected: bool clicked(int grid_click_x, int grid_click_y); diff --git a/lgl_clickable.cpp b/lgl_clickable.cpp index 54356f8..371ab46 100644 --- a/lgl_clickable.cpp +++ b/lgl_clickable.cpp @@ -21,11 +21,15 @@ using namespace lgl; -clickable::clickable(callable * call_on_click) : m_call_on_click(call_on_click) {} - -bool clickable::try_click(int click_x, int click_y){ - bool was_clicked = clicked(click_x, click_y); - if(was_clicked){ +clickable::clickable(callable * call_on_click, int mouse_button, int mouse_state) + : m_call_on_click(call_on_click), m_mouse_button(mouse_button), m_mouse_state(mouse_state) {} + +bool clickable::try_click(int click_x, int click_y, int mouse_button, int mouse_state){ + int grid_x = click_x / ((grid_width + gap) * scale_factor); + int grid_y = click_y / ((grid_height + gap) * scale_factor); + + bool was_clicked = clicked(grid_x, grid_y); + if(was_clicked && mouse_button == m_mouse_button && mouse_state == m_mouse_state){ m_call_on_click->call(); } return was_clicked; diff --git a/lgl_clickable.h b/lgl_clickable.h index 1bb3858..ef2fa49 100644 --- a/lgl_clickable.h +++ b/lgl_clickable.h @@ -24,17 +24,26 @@ namespace lgl { + const int left_mouse_button = 1; + const int right_mouse_button = 2; + const int mouse_down_state = 1; + const int mouse_up_state = 2; + class clickable { public: - clickable(callable * call_on_click); + clickable(callable * call_on_click, int mouse_button=left_mouse_button, + int mouse_state=mouse_down_state); - bool try_click(int click_x, int click_y); + bool try_click(int click_x, int click_y, int mouse_button, int mouse_state); protected: virtual bool clicked(int click_x, int click_y) = 0; private: callable * m_call_on_click; + + int m_mouse_button; + int m_mouse_state; }; }; diff --git a/lgl_label.cpp b/lgl_label.cpp index 21b1924..6d2e4ab 100644 --- a/lgl_label.cpp +++ b/lgl_label.cpp @@ -21,8 +21,8 @@ using namespace lgl; -label::label(int column, int row, int height, string text) - : m_column(column), m_row(row), m_height(height), m_text(text) {} +label::label(int color, int column, int row, int height, string text) + : object(color), m_column(column), m_row(row), m_height(height), m_text(text) {} void label::draw_shapes(){ full_rectangle(m_column, m_column, m_row, m_row + m_height); diff --git a/lgl_label.h b/lgl_label.h index 4e206c4..fcfaf32 100644 --- a/lgl_label.h +++ b/lgl_label.h @@ -29,7 +29,7 @@ namespace lgl { class label : public object { public: - label(int column, int row, int height, string text); + label(int color, int column, int row, int height, string text); protected: void draw_shapes(); diff --git a/lgl_object.cpp b/lgl_object.cpp index 3317640..29fa733 100644 --- a/lgl_object.cpp +++ b/lgl_object.cpp @@ -28,10 +28,12 @@ using std::cerr; using std::cout; using std::endl; -object::object(){ +string lgl::font_path = "./font.ttf"; + +object::object(int color) : m_color(color){ font = new FTTextureFont(font_path.c_str()); if(font->Error()){ - cerr << "Font not found" << endl; + cerr << "Font not found at " << font_path << endl; return; } @@ -42,8 +44,12 @@ object::~object(){ delete font; } -void object::draw(int color){ - glColor3f(colors[color].R, colors[color].G, colors[color].B); +void object::set_color(int color){ + m_color = color; +} + +void object::draw(){ + glColor3f(colors[m_color].R, colors[m_color].G, colors[m_color].B); draw_shapes(); } @@ -193,4 +199,3 @@ void object::half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down) glEnd(); } -string lgl::font_path = "./font.ttf"; diff --git a/lgl_object.h b/lgl_object.h index 57a1a4f..d5090de 100644 --- a/lgl_object.h +++ b/lgl_object.h @@ -32,10 +32,12 @@ namespace lgl { class object { public: - object(); + object(int color); ~object(); - void draw(int color); + void set_color(int color); + + void draw(); protected: virtual void draw_shapes() = 0; @@ -45,6 +47,8 @@ namespace lgl { void half_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top, bool at_top); void full_arc(int grid_x, int grid_y, bool left, bool down); void half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down); + + int m_color; private: float get_arc_start_angle(bool left, bool down); float get_arc_end_angle(bool left, bool down); From ebc91f1855f1b2e916c2ee41dd179cdfe92d4283 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sat, 28 Oct 2017 21:42:24 -0700 Subject: [PATCH 06/11] Buttons change colors --- component_test.cpp | 5 ++--- lgl_button.cpp | 16 ++++++++++++++-- lgl_button.h | 4 ++-- lgl_clickable.cpp | 2 +- lgl_clickable.h | 8 ++++---- lgl_object.cpp | 6 +++++- lgl_object.h | 4 ++++ 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/component_test.cpp b/component_test.cpp index d330445..812ee8f 100644 --- a/component_test.cpp +++ b/component_test.cpp @@ -70,7 +70,7 @@ void mouse(GLFWwindow * window, int button, int state, int mods){ } int main(int argc, char * argv[]){ - lgl::colors = vector({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.6f}}); + lgl::colors = vector({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.6f}, {1.0f, 0.6f, 0.2f}}); l1 = new label(1, 0, 0, 0, "l1"); l2 = new label(1, 0, 1, 0, "l2"); @@ -101,6 +101,7 @@ int main(int argc, char * argv[]){ while(true){ glClear(GL_COLOR_BUFFER_BIT); + glfwWaitEvents(); l1->draw(); l2->draw(); l3->draw(); @@ -114,8 +115,6 @@ int main(int argc, char * argv[]){ l11->draw(); l12->draw(); glfwSwapBuffers(window); - glfwPollEvents(); - usleep(10000); } glfwTerminate(); diff --git a/lgl_button.cpp b/lgl_button.cpp index 322689c..bffc093 100644 --- a/lgl_button.cpp +++ b/lgl_button.cpp @@ -18,12 +18,24 @@ */ #include "lgl_button.h" +#include using namespace lgl; +using std::cout; + button::button(int color, int column, int row, int height, string text, callable * call_on_click) : label(color, column, row, height, text), clickable(call_on_click) {} -bool button::clicked(int grid_click_x, int grid_click_y){ - return grid_click_x == m_column && (m_row <= grid_click_y && m_row + m_height >= grid_click_y) ; +bool button::clicked(int grid_click_x, int grid_click_y, int mouse_button, int mouse_state){ + bool clicked = grid_click_x == m_column && (m_row <= grid_click_y && m_row + m_height >= grid_click_y); + if(clicked && mouse_state == m_mouse_state && mouse_button == m_mouse_button){ + if(colors.size() > m_original_color + 1){ + set_color(m_original_color + 1); + } + } + else{ + reset_color(); + } + return clicked; } diff --git a/lgl_button.h b/lgl_button.h index 7e97e06..1ca1eb7 100644 --- a/lgl_button.h +++ b/lgl_button.h @@ -27,9 +27,9 @@ namespace lgl { class button : public label, public clickable { public: button(int color, int column, int row, int height, string text, callable * call_on_click); - + protected: - bool clicked(int grid_click_x, int grid_click_y); + bool clicked(int grid_click_x, int grid_click_y, int mouse_button, int mouse_state); }; }; diff --git a/lgl_clickable.cpp b/lgl_clickable.cpp index 371ab46..a986b33 100644 --- a/lgl_clickable.cpp +++ b/lgl_clickable.cpp @@ -28,7 +28,7 @@ bool clickable::try_click(int click_x, int click_y, int mouse_button, int mouse_ int grid_x = click_x / ((grid_width + gap) * scale_factor); int grid_y = click_y / ((grid_height + gap) * scale_factor); - bool was_clicked = clicked(grid_x, grid_y); + bool was_clicked = clicked(grid_x, grid_y, mouse_button, mouse_state); if(was_clicked && mouse_button == m_mouse_button && mouse_state == m_mouse_state){ m_call_on_click->call(); } diff --git a/lgl_clickable.h b/lgl_clickable.h index ef2fa49..9f5d376 100644 --- a/lgl_clickable.h +++ b/lgl_clickable.h @@ -37,13 +37,13 @@ namespace lgl { bool try_click(int click_x, int click_y, int mouse_button, int mouse_state); protected: - virtual bool clicked(int click_x, int click_y) = 0; + virtual bool clicked(int click_x, int click_y, int mouse_button, int mouse_state) = 0; - private: - callable * m_call_on_click; - int m_mouse_button; int m_mouse_state; + + private: + callable * m_call_on_click; }; }; diff --git a/lgl_object.cpp b/lgl_object.cpp index 29fa733..b94e0af 100644 --- a/lgl_object.cpp +++ b/lgl_object.cpp @@ -30,7 +30,7 @@ using std::endl; string lgl::font_path = "./font.ttf"; -object::object(int color) : m_color(color){ +object::object(int color) : m_color(color), m_original_color(color){ font = new FTTextureFont(font_path.c_str()); if(font->Error()){ cerr << "Font not found at " << font_path << endl; @@ -48,6 +48,10 @@ void object::set_color(int color){ m_color = color; } +void object::reset_color(){ + m_color = m_original_color; +} + void object::draw(){ glColor3f(colors[m_color].R, colors[m_color].G, colors[m_color].B); diff --git a/lgl_object.h b/lgl_object.h index d5090de..aa4f5f9 100644 --- a/lgl_object.h +++ b/lgl_object.h @@ -36,8 +36,10 @@ namespace lgl { ~object(); void set_color(int color); + void reset_color(); void draw(); + protected: virtual void draw_shapes() = 0; @@ -49,6 +51,8 @@ namespace lgl { void half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down); int m_color; + int m_original_color; + private: float get_arc_start_angle(bool left, bool down); float get_arc_end_angle(bool left, bool down); From b8fb47044bfbb3de10e45632e9800383429eacaa Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sat, 28 Oct 2017 23:49:46 -0700 Subject: [PATCH 07/11] Added elbows --- component_test.cpp | 56 +++++++++++++++++----------------------------- lgl_button.cpp | 3 --- lgl_elbow.cpp | 49 ++++++++++++++++++++++++++++++++++++++++ lgl_elbow.h | 42 ++++++++++++++++++++++++++++++++++ lgl_object.cpp | 32 +++++++++++++++++++++----- lgl_object.h | 3 ++- 6 files changed, 140 insertions(+), 45 deletions(-) create mode 100644 lgl_elbow.cpp create mode 100644 lgl_elbow.h diff --git a/component_test.cpp b/component_test.cpp index 812ee8f..620f132 100644 --- a/component_test.cpp +++ b/component_test.cpp @@ -5,11 +5,13 @@ #include "lgl_label.h" #include "lgl_button.h" #include "lgl_const.h" +#include "lgl_elbow.h" using lgl::label; using lgl::color; using lgl::callable_function; using lgl::button; +using lgl::elbow; using std::cout; using std::vector; @@ -22,15 +24,6 @@ void l5_callback(){ void l6_callback(){ cout << "l6 clicked\n"; } -void l9_callback(){ - cout << "l9 clicked\n"; -} -void l11_callback(){ - cout << "l11 clicked\n"; -} -void l12_callback(){ - cout << "l12 clicked\n"; -} // #globalization label * l1; @@ -44,13 +37,11 @@ callable_function * l6_func; button * l6; label * l7; label * l8; -callable_function * l9_func; -button * l9; -label * l10; -callable_function * l11_func; -button * l11; -callable_function * l12_func; -button * l12; +label * l9; +elbow * e1; +elbow * e2; +elbow * e3; +elbow * e4; void mouse(GLFWwindow * window, int button, int state, int mods){ int mouse_button = button == GLFW_MOUSE_BUTTON_LEFT ? lgl::left_mouse_button : lgl::right_mouse_button; @@ -62,11 +53,7 @@ void mouse(GLFWwindow * window, int button, int state, int mods){ l4->try_click(Mx, My, mouse_button, mouse_state); l5->try_click(Mx, My, mouse_button, mouse_state); - l6->try_click(Mx, My, mouse_button, mouse_state); - l9->try_click(Mx, My, mouse_button, mouse_state); - l11->try_click(Mx, My, mouse_button, mouse_state); - l12->try_click(Mx, My, mouse_button, mouse_state); } int main(int argc, char * argv[]){ @@ -83,13 +70,11 @@ int main(int argc, char * argv[]){ l6 = new button(1, 0, 5, 0, "l6", l6_func); l7 = new label(1, 1, 0, 1, "l7"); l8 = new label(1, 1, 2, 1, "l8"); - l9_func = new callable_function(&l9_callback); - l9 = new button(1, 1, 4, 1, "l9", l9_func); - l10 = new label(1, 2, 0, 2, "l10"); - l11_func = new callable_function(&l11_callback); - l11 = new button(1, 2, 3, 2, "l11", l11_func); - l12_func = new callable_function(&l12_callback); - l12 = new button(1, 3, 0, 5, "l12", l12_func); + l9 = new label(1, 1, 4, 1, "l9"); + e1 = new elbow(1, 1, 6, 0, true, true, ""); + e2 = new elbow(1, 2, 0, 2, true, false, ""); + e3 = new elbow(1, 7, 6, 3, false, true, ""); + e4 = new elbow(1, 7, 0, 0, false, false, ""); glfwInit(); @@ -111,9 +96,10 @@ int main(int argc, char * argv[]){ l7->draw(); l8->draw(); l9->draw(); - l10->draw(); - l11->draw(); - l12->draw(); + e1->draw(); + e2->draw(); + e3->draw(); + e4->draw(); glfwSwapBuffers(window); } @@ -130,13 +116,11 @@ int main(int argc, char * argv[]){ delete l6; delete l7; delete l8; - delete l9_func; delete l9; - delete l10; - delete l11_func; - delete l11; - delete l12_func; - delete l12; + delete e1; + delete e2; + delete e3; + delete e4; return 0; } diff --git a/lgl_button.cpp b/lgl_button.cpp index bffc093..6dc2139 100644 --- a/lgl_button.cpp +++ b/lgl_button.cpp @@ -18,12 +18,9 @@ */ #include "lgl_button.h" -#include using namespace lgl; -using std::cout; - button::button(int color, int column, int row, int height, string text, callable * call_on_click) : label(color, column, row, height, text), clickable(call_on_click) {} diff --git a/lgl_elbow.cpp b/lgl_elbow.cpp new file mode 100644 index 0000000..b853eb1 --- /dev/null +++ b/lgl_elbow.cpp @@ -0,0 +1,49 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#include "lgl_elbow.h" + +#include + +using namespace lgl; + +elbow::elbow(int color, int column, int row, int length, bool right, bool down, string text) + : object(color), m_column(column), m_row(row), m_length(length), + m_right(right), m_down(down), m_text(text) {} + +void elbow::draw_shapes(){ + int right_adj = m_right ? 1 : -2; + int left_adj = m_right ? 2 : -1; + length_adjusted_rectangle(m_column, m_row, left_adj, right_adj); + + if(m_right){ + half_rectangle(m_column + 1, m_column + 1 + m_length, m_row, m_down); + } + else{ + half_rectangle(m_column - 1 - m_length, m_column - 1, m_row, m_down); + } + + full_arc(m_column, m_row, m_right, m_down); + + set_color(0); + + half_arc(m_column, m_row, m_right, !m_down, m_down); + + reset_color(); +} diff --git a/lgl_elbow.h b/lgl_elbow.h new file mode 100644 index 0000000..6eac254 --- /dev/null +++ b/lgl_elbow.h @@ -0,0 +1,42 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#pragma once + +#include "lgl_object.h" + +#include + +using std::string; + +namespace lgl { + + class elbow : public object { + public: + elbow(int color, int column, int row, int length, bool right, bool down, string text); + + protected: + void draw_shapes(); + + int m_column, m_row, m_length; + bool m_right, m_down; + string m_text; + }; + +}; diff --git a/lgl_object.cpp b/lgl_object.cpp index b94e0af..39e6787 100644 --- a/lgl_object.cpp +++ b/lgl_object.cpp @@ -46,10 +46,14 @@ object::~object(){ void object::set_color(int color){ m_color = color; + + glColor3f(colors[m_color].R, colors[m_color].G, colors[m_color].B); } void object::reset_color(){ m_color = m_original_color; + + glColor3f(colors[m_color].R, colors[m_color].G, colors[m_color].B); } void object::draw(){ @@ -100,11 +104,11 @@ void object::full_rectangle(int grid_left, int grid_right, int grid_bottom, int glEnd(); } -void object::half_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top, bool at_top){ +void object::half_rectangle(int grid_left, int grid_right, int grid_y, bool at_top){ int left = (grid_left * (grid_width + gap)) * scale_factor; int right = (grid_right * (grid_width + gap) + grid_width) * scale_factor; - int bottom = (grid_bottom * (grid_height + gap)) * scale_factor; - int top = (grid_top * (grid_height + gap)) * scale_factor; + int bottom = (grid_y * (grid_height + gap)) * scale_factor; + int top = (grid_y * (grid_height + gap) + grid_height) * scale_factor; if(at_top){ bottom += (grid_height / 2) * scale_factor; @@ -123,6 +127,24 @@ void object::half_rectangle(int grid_left, int grid_right, int grid_bottom, int glEnd(); } +void object::length_adjusted_rectangle(int grid_x, int grid_y, short left_adj, short right_adj){ + int left = (grid_x * (grid_width + gap) + + left_adj * grid_height / 2) * scale_factor; + int right = (grid_x * (grid_width + gap) + grid_width + + right_adj * grid_height / 2) * scale_factor; + int bottom = (grid_y * (grid_height + gap)) * scale_factor; + int top = (grid_y * (grid_height + gap) + grid_height) * scale_factor; + + glBegin(GL_QUADS); + + glVertex2i(left, top); + glVertex2i(right, top); + glVertex2i(right, bottom); + glVertex2i(left, bottom); + + glEnd(); +} + float object::get_arc_start_angle(bool left, bool down){ if(left && down) return 90; if(left && !down) return 180; @@ -170,10 +192,10 @@ void object::full_arc(int grid_x, int grid_y, bool left, bool down){ void object::half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down){ int center_x, center_y; if(left){ - center_x = (grid_x * (grid_width + gap) + grid_height) * scale_factor; + center_x = (grid_x * (grid_width + gap) + grid_width + grid_height / 2) * scale_factor; } else{ - center_x = (grid_x * (grid_width + gap) + grid_width - grid_height) * scale_factor; + center_x = (grid_x * (grid_width + gap) - grid_height / 2) * scale_factor; } if(down){ center_y = grid_y * (grid_height + gap) * scale_factor; diff --git a/lgl_object.h b/lgl_object.h index aa4f5f9..32b1a19 100644 --- a/lgl_object.h +++ b/lgl_object.h @@ -46,7 +46,8 @@ namespace lgl { void draw_text(int grid_left, int grid_bottom, string text); void full_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top); - void half_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top, bool at_top); + void half_rectangle(int grid_left, int grid_right, int grid_y, bool at_top); + void length_adjusted_rectangle(int grid_x, int grid_y, short left_adj, short right_adj); void full_arc(int grid_x, int grid_y, bool left, bool down); void half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down); From 5b25cd5bb34f6320aa6142971b9cab6d599e2ff0 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sun, 29 Oct 2017 14:57:34 -0700 Subject: [PATCH 08/11] Added capped buttons, reorganized for better code --- component_test.cpp | 6 ++--- lgl_button.cpp | 3 +++ lgl_button.h | 2 ++ lgl_elbow.cpp | 44 +++++++++++++++++++++++++++++++---- lgl_elbow.h | 3 +++ lgl_label.cpp | 46 +++++++++++++++++++++++++++++++++++-- lgl_label.h | 6 ++++- lgl_object.cpp | 57 +--------------------------------------------- lgl_object.h | 10 ++++---- 9 files changed, 105 insertions(+), 72 deletions(-) diff --git a/component_test.cpp b/component_test.cpp index 620f132..a6a43ac 100644 --- a/component_test.cpp +++ b/component_test.cpp @@ -60,12 +60,12 @@ int main(int argc, char * argv[]){ lgl::colors = vector({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.6f}, {1.0f, 0.6f, 0.2f}}); l1 = new label(1, 0, 0, 0, "l1"); - l2 = new label(1, 0, 1, 0, "l2"); - l3 = new label(1, 0, 2, 0, "l3"); + l2 = new label(1, 0, 1, false, true, "l2"); + l3 = new label(1, 0, 2, true, false, "l3"); l4_func = new callable_function(&l4_callback); l4 = new button(1, 0, 3, 0, "l4", l4_func); l5_func = new callable_function(&l5_callback); - l5 = new button(1, 0, 4, 0, "l5", l5_func); + l5 = new button(1, 0, 4, true, true, "l5", l5_func); l6_func = new callable_function(&l6_callback); l6 = new button(1, 0, 5, 0, "l6", l6_func); l7 = new label(1, 1, 0, 1, "l7"); diff --git a/lgl_button.cpp b/lgl_button.cpp index 6dc2139..4f038e2 100644 --- a/lgl_button.cpp +++ b/lgl_button.cpp @@ -24,6 +24,9 @@ using namespace lgl; button::button(int color, int column, int row, int height, string text, callable * call_on_click) : label(color, column, row, height, text), clickable(call_on_click) {} +button::button(int color, int column, int row, bool left_cap, bool right_cap, string text, callable * call_on_click) + : label(color, column, row, left_cap, right_cap, text), clickable(call_on_click) {} + bool button::clicked(int grid_click_x, int grid_click_y, int mouse_button, int mouse_state){ bool clicked = grid_click_x == m_column && (m_row <= grid_click_y && m_row + m_height >= grid_click_y); if(clicked && mouse_state == m_mouse_state && mouse_button == m_mouse_button){ diff --git a/lgl_button.h b/lgl_button.h index 1ca1eb7..1cfbb4b 100644 --- a/lgl_button.h +++ b/lgl_button.h @@ -27,6 +27,8 @@ namespace lgl { class button : public label, public clickable { public: button(int color, int column, int row, int height, string text, callable * call_on_click); + button(int color, int column, int row, bool left_cap, bool right_cap, + string text, callable * call_on_click); protected: bool clicked(int grid_click_x, int grid_click_y, int mouse_button, int mouse_state); diff --git a/lgl_elbow.cpp b/lgl_elbow.cpp index b853eb1..c56ce4c 100644 --- a/lgl_elbow.cpp +++ b/lgl_elbow.cpp @@ -39,11 +39,47 @@ void elbow::draw_shapes(){ half_rectangle(m_column - 1 - m_length, m_column - 1, m_row, m_down); } - full_arc(m_column, m_row, m_right, m_down); + elbow_outside(); set_color(0); - - half_arc(m_column, m_row, m_right, !m_down, m_down); - + elbow_inside(); reset_color(); } + +void elbow::elbow_outside(){ + int center_x, center_y; + if(m_right){ + center_x = (m_column * (grid_width + gap) + grid_height) * scale_factor; + } + else{ + center_x = (m_column * (grid_width + gap) + grid_width - grid_height) * scale_factor; + } + if(m_down){ + center_y = (m_row * (grid_height + gap)) * scale_factor; + } + else{ + center_y = (m_row * (grid_height + gap) + grid_height) * scale_factor; + } + + arc(center_x, center_y, grid_height * scale_factor, + get_arc_start_angle(m_right, m_down), get_arc_end_angle(m_right, m_down)); +} + +void elbow::elbow_inside(){ + int center_x, center_y; + if(m_right){ + center_x = (m_column * (grid_width + gap) + grid_width + grid_height / 2) * scale_factor; + } + else{ + center_x = (m_column * (grid_width + gap) - grid_height / 2) * scale_factor; + } + if(m_down){ + center_y = m_row * (grid_height + gap) * scale_factor; + } + else{ + center_y = (m_row * (grid_height + gap) + grid_height) * scale_factor; + } + + arc(center_x, center_y, (grid_height / 2.0f) * scale_factor, + get_arc_start_angle(m_right, m_down), get_arc_end_angle(m_right, m_down)); +} diff --git a/lgl_elbow.h b/lgl_elbow.h index 6eac254..cf7e6c4 100644 --- a/lgl_elbow.h +++ b/lgl_elbow.h @@ -34,6 +34,9 @@ namespace lgl { protected: void draw_shapes(); + void elbow_outside(); + void elbow_inside(); + int m_column, m_row, m_length; bool m_right, m_down; string m_text; diff --git a/lgl_label.cpp b/lgl_label.cpp index 6d2e4ab..422fffb 100644 --- a/lgl_label.cpp +++ b/lgl_label.cpp @@ -22,10 +22,52 @@ using namespace lgl; label::label(int color, int column, int row, int height, string text) - : object(color), m_column(column), m_row(row), m_height(height), m_text(text) {} + : object(color), m_column(column), m_row(row), m_height(height), m_text(text), + m_left_cap(false), m_right_cap(false) {} + +label::label(int color, int column, int row, bool left_cap, bool right_cap, string text) + : object(color), m_column(column), m_row(row), m_height(0), m_text(text), + m_left_cap(left_cap), m_right_cap(right_cap) {} void label::draw_shapes(){ - full_rectangle(m_column, m_column, m_row, m_row + m_height); + if(!m_left_cap && !m_right_cap){ + full_rectangle(m_column, m_column, m_row, m_row + m_height); + } + else{ + short left_adj = m_left_cap ? 1 : 0; + short right_adj = m_right_cap ? -1 : 0; + + length_adjusted_rectangle(m_column, m_row, left_adj, right_adj); + } + + if(m_left_cap){ + cap(true); + } + if(m_right_cap){ + cap(false); + } draw_text(m_column, m_row, m_text); } + +void label::cap(bool left){ + int center_x; + if(left){ + center_x = (m_column * (grid_width + gap) + grid_height / 2) * scale_factor; + } + else{ + center_x = (m_column * (grid_width + gap) + grid_width - grid_height / 2) * scale_factor; + } + + float start_angle, end_angle; + if(left){ + start_angle = 90; + end_angle = 270; + } + else{ + start_angle = -90; + end_angle = 90; + } + + arc(center_x, m_row * (grid_height + gap) + grid_height / 2, grid_height / 2, start_angle, end_angle); +} diff --git a/lgl_label.h b/lgl_label.h index fcfaf32..c9f0e88 100644 --- a/lgl_label.h +++ b/lgl_label.h @@ -30,12 +30,16 @@ namespace lgl { class label : public object { public: label(int color, int column, int row, int height, string text); + label(int color, int column, int row, bool left_cap, bool right_cap, string text); protected: void draw_shapes(); - + + void cap(bool left); + int m_column, m_row, m_height; string m_text; + bool m_left_cap, m_right_cap; }; }; diff --git a/lgl_object.cpp b/lgl_object.cpp index 39e6787..3e8aa72 100644 --- a/lgl_object.cpp +++ b/lgl_object.cpp @@ -159,61 +159,7 @@ float object::get_arc_end_angle(bool left, bool down){ return 360; } -void object::full_arc(int grid_x, int grid_y, bool left, bool down){ - int center_x, center_y; - if(left){ - center_x = (grid_x * (grid_width + gap) + grid_height) * scale_factor; - } - else{ - center_x = (grid_x * (grid_width + gap) + grid_width - grid_height) * scale_factor; - } - if(down){ - center_y = (grid_y * (grid_height + gap)) * scale_factor; - } - else{ - center_y = (grid_y * (grid_height + gap) + grid_height) * scale_factor; - } - - float start_angle = get_arc_start_angle(left, down); - float end_angle = get_arc_end_angle(left, down); - float radius = grid_height * scale_factor; - - glBegin(GL_POLYGON); - glVertex2i(center_x,center_y); - for(float i = start_angle; i < end_angle; i+=0.02){ - float angle = i/57.3; - float x2 = center_x+cos(angle)*radius; - float y2 = center_y+sin(angle)*radius; - glVertex2f(x2,y2); - } - glEnd(); -} - -void object::half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down){ - int center_x, center_y; - if(left){ - center_x = (grid_x * (grid_width + gap) + grid_width + grid_height / 2) * scale_factor; - } - else{ - center_x = (grid_x * (grid_width + gap) - grid_height / 2) * scale_factor; - } - if(down){ - center_y = grid_y * (grid_height + gap) * scale_factor; - if(at_top){ - center_y += (grid_height / 2) * scale_factor; - } - } - else{ - center_y = (grid_y * (grid_height + gap) + grid_height) * scale_factor; - if(!at_top){ - center_y -= (grid_height / 2) * scale_factor; - } - } - - float start_angle = get_arc_start_angle(left, down); - float end_angle = get_arc_end_angle(left, down); - float radius = (grid_height / 2.0f) * scale_factor; - +void object::arc(int center_x, int center_y, float radius, float start_angle, float end_angle){ glBegin(GL_POLYGON); glVertex2i(center_x,center_y); for(float i = start_angle; i < end_angle; i+=0.02){ @@ -224,4 +170,3 @@ void object::half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down) } glEnd(); } - diff --git a/lgl_object.h b/lgl_object.h index 32b1a19..baea064 100644 --- a/lgl_object.h +++ b/lgl_object.h @@ -48,16 +48,14 @@ namespace lgl { void full_rectangle(int grid_left, int grid_right, int grid_bottom, int grid_top); void half_rectangle(int grid_left, int grid_right, int grid_y, bool at_top); void length_adjusted_rectangle(int grid_x, int grid_y, short left_adj, short right_adj); - void full_arc(int grid_x, int grid_y, bool left, bool down); - void half_arc(int grid_x, int grid_y, bool left, bool at_top, bool down); + float get_arc_start_angle(bool left, bool down); + float get_arc_end_angle(bool left, bool down); + void arc(int center_x, int center_y, float radius, float start_angle, float end_angle); int m_color; int m_original_color; - private: - float get_arc_start_angle(bool left, bool down); - float get_arc_end_angle(bool left, bool down); - + private: FTTextureFont * font; }; }; From d7804366c31777944d33a29e9d460bf661f70bc1 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Sun, 29 Oct 2017 22:19:05 -0700 Subject: [PATCH 09/11] Added indicators --- component_test.cpp | 18 +++++++++++++ lgl_elbow.cpp | 4 +-- lgl_indicator.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++ lgl_indicator.h | 44 ++++++++++++++++++++++++++++++ lgl_label.cpp | 2 ++ lgl_object.cpp | 15 ++++++++--- lgl_object.h | 2 ++ 7 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 lgl_indicator.cpp create mode 100644 lgl_indicator.h diff --git a/component_test.cpp b/component_test.cpp index a6a43ac..a6e5f02 100644 --- a/component_test.cpp +++ b/component_test.cpp @@ -6,12 +6,14 @@ #include "lgl_button.h" #include "lgl_const.h" #include "lgl_elbow.h" +#include "lgl_indicator.h" using lgl::label; using lgl::color; using lgl::callable_function; using lgl::button; using lgl::elbow; +using lgl::indicator; using std::cout; using std::vector; @@ -42,6 +44,10 @@ elbow * e1; elbow * e2; elbow * e3; elbow * e4; +indicator * i1; +indicator * i2; +indicator * i3; +indicator * i4; void mouse(GLFWwindow * window, int button, int state, int mods){ int mouse_button = button == GLFW_MOUSE_BUTTON_LEFT ? lgl::left_mouse_button : lgl::right_mouse_button; @@ -75,6 +81,10 @@ int main(int argc, char * argv[]){ e2 = new elbow(1, 2, 0, 2, true, false, ""); e3 = new elbow(1, 7, 6, 3, false, true, ""); e4 = new elbow(1, 7, 0, 0, false, false, ""); + i1 = new indicator(1, 2, 1, false, false, "1001"); + i2 = new indicator(1, 2, 2, true, false, "01010"); + i3 = new indicator(1, 2, 3, false, true, "001011"); + i4 = new indicator(1, 2, 4, true, true, "0001100"); glfwInit(); @@ -100,6 +110,10 @@ int main(int argc, char * argv[]){ e2->draw(); e3->draw(); e4->draw(); + i1->draw(); + i2->draw(); + i3->draw(); + i4->draw(); glfwSwapBuffers(window); } @@ -121,6 +135,10 @@ int main(int argc, char * argv[]){ delete e2; delete e3; delete e4; + delete i1; + delete i2; + delete i3; + delete i4; return 0; } diff --git a/lgl_elbow.cpp b/lgl_elbow.cpp index c56ce4c..61cb208 100644 --- a/lgl_elbow.cpp +++ b/lgl_elbow.cpp @@ -41,9 +41,9 @@ void elbow::draw_shapes(){ elbow_outside(); - set_color(0); + temp_color(0); elbow_inside(); - reset_color(); + set_color(); } void elbow::elbow_outside(){ diff --git a/lgl_indicator.cpp b/lgl_indicator.cpp new file mode 100644 index 0000000..dc9474e --- /dev/null +++ b/lgl_indicator.cpp @@ -0,0 +1,67 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#include "lgl_indicator.h" + +using namespace lgl; + +indicator::indicator(int color, int column, int row, bool left_cap, bool right_cap, string text) + : object(color), m_column(column), m_row(row), m_left_cap(left_cap), m_right_cap(right_cap), m_text(text) {} + +void indicator::draw_shapes(){ + full_rectangle(m_column, m_column, m_row, m_row); + + short left_adj = m_left_cap ? 0 : 1; + short right_adj = m_right_cap ? 0 : -1; + + temp_color(0); + length_adjusted_rectangle(m_column, m_row, left_adj, right_adj); + set_color(); + + if(m_left_cap){ + cap(true); + } + if(m_right_cap){ + cap(false); + } + + draw_text(m_column, m_row, m_text); +} + +void indicator::cap(bool left){ + int center_x; + if(left){ + center_x = (m_column * (grid_width + gap) + grid_height / 2) * scale_factor; + } + else{ + center_x = (m_column * (grid_width + gap) + grid_width - grid_height / 2) * scale_factor; + } + + float start_angle, end_angle; + if(left){ + start_angle = 90; + end_angle = 270; + } + else{ + start_angle = -90; + end_angle = 90; + } + + arc(center_x, m_row * (grid_height + gap) + grid_height / 2, grid_height / 2, start_angle, end_angle); +} diff --git a/lgl_indicator.h b/lgl_indicator.h new file mode 100644 index 0000000..659e80c --- /dev/null +++ b/lgl_indicator.h @@ -0,0 +1,44 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#pragma once + +#include "lgl_object.h" + +#include + +using std::string; + +namespace lgl { + + class indicator : public object { + public: + indicator(int color, int column, int row, bool left_cap, bool right_cap, string text); + + protected: + void draw_shapes(); + + void cap(bool left); + + int m_column, m_row; + string m_text; + bool m_left_cap, m_right_cap; + }; + +}; diff --git a/lgl_label.cpp b/lgl_label.cpp index 422fffb..fa06f01 100644 --- a/lgl_label.cpp +++ b/lgl_label.cpp @@ -47,7 +47,9 @@ void label::draw_shapes(){ cap(false); } + temp_color(0); draw_text(m_column, m_row, m_text); + set_color(); } void label::cap(bool left){ diff --git a/lgl_object.cpp b/lgl_object.cpp index 3e8aa72..8cbad49 100644 --- a/lgl_object.cpp +++ b/lgl_object.cpp @@ -50,6 +50,14 @@ void object::set_color(int color){ glColor3f(colors[m_color].R, colors[m_color].G, colors[m_color].B); } +void object::set_color(){ + glColor3f(colors[m_color].R, colors[m_color].G, colors[m_color].B); +} + +void object::temp_color(int color){ + glColor3f(colors[color].R, colors[color].G, colors[color].B); +} + void object::reset_color(){ m_color = m_original_color; @@ -63,8 +71,6 @@ void object::draw(){ } void object::draw_text(int grid_x, int grid_y, string text){ - glColor3f(0.0f, 0.0f, 0.0f); - int font_size = 61; int right = 0; @@ -76,9 +82,10 @@ void object::draw_text(int grid_x, int grid_y, string text){ right = bounding_box.Upper().X(); top = bounding_box.Upper().Y(); font_size--; - } while(right > grid_width * 3.0/4.0 * scale_factor || top > grid_height * 3.0/4.0 * scale_factor); + } while(right > (grid_width - grid_height) * scale_factor + || top > grid_height * 7.0/8.0 * scale_factor); - int left = (grid_x * (grid_width + gap) + grid_width * 1.0/8.0) * scale_factor; + int left = (grid_x * (grid_width + gap) + grid_height / 2) * scale_factor; int bottom = (grid_y * (grid_height + gap) + gap) * scale_factor; glTranslated(left, bottom, 0); diff --git a/lgl_object.h b/lgl_object.h index baea064..df1bdd0 100644 --- a/lgl_object.h +++ b/lgl_object.h @@ -36,6 +36,8 @@ namespace lgl { ~object(); void set_color(int color); + void set_color(); + void temp_color(int color); void reset_color(); void draw(); From cbff23cce462834d115a9570d779cfe6d5d5ce11 Mon Sep 17 00:00:00 2001 From: Carter Turnbaugh Date: Fri, 10 Nov 2017 22:33:27 -0800 Subject: [PATCH 10/11] Putting it all together --- component_test.cpp => component_test.2pp | 0 lgl_button.h | 2 +- lgl_const.h | 4 +- lgl_core.cpp | 143 +++++++++++++++++++++++ lgl_core.h | 65 +++++++++++ lgl_elbow.cpp | 26 +++++ lgl_elbow.h | 5 + lgl_indicator.cpp | 24 +++- lgl_indicator.h | 9 +- lgl_label.cpp | 16 +++ lgl_label.h | 5 + lgl_object.cpp | 3 + lgl_object.h | 7 +- test.cpp | 59 ++++++++++ 14 files changed, 361 insertions(+), 7 deletions(-) rename component_test.cpp => component_test.2pp (100%) create mode 100644 lgl_core.cpp create mode 100644 lgl_core.h create mode 100644 test.cpp diff --git a/component_test.cpp b/component_test.2pp similarity index 100% rename from component_test.cpp rename to component_test.2pp diff --git a/lgl_button.h b/lgl_button.h index 1cfbb4b..b7fbd01 100644 --- a/lgl_button.h +++ b/lgl_button.h @@ -29,7 +29,7 @@ namespace lgl { button(int color, int column, int row, int height, string text, callable * call_on_click); button(int color, int column, int row, bool left_cap, bool right_cap, string text, callable * call_on_click); - + protected: bool clicked(int grid_click_x, int grid_click_y, int mouse_button, int mouse_state); }; diff --git a/lgl_const.h b/lgl_const.h index 599bfdc..c2ab5ac 100644 --- a/lgl_const.h +++ b/lgl_const.h @@ -30,8 +30,8 @@ namespace lgl { float B; }; - const int grid_width = 45; - const int grid_height = 18; + const int grid_width = 60; + const int grid_height = 24; const int gap = 1; extern vector colors; diff --git a/lgl_core.cpp b/lgl_core.cpp new file mode 100644 index 0000000..7c19556 --- /dev/null +++ b/lgl_core.cpp @@ -0,0 +1,143 @@ +#include "lgl_core.h" + +#include "lgl_button.h" +#include "lgl_elbow.h" +#include "lgl_label.h" + +#include + +#include + +using std::cout; + +using std::min_element; +using std::max_element; + +using namespace lgl; + +core::core(){} + +core::~core(){ + for(int i = 0; i < objects.size(); i++){ + delete objects[i]; + } +} + +void core::initialize(){ + glfwInit(); + + int x_min = (*min_element(objects.begin(), objects.end(), [](object * i, object * j) + {return i->max_grid_left() < j->max_grid_left();}))->max_grid_left(); + int x_max = (*max_element(objects.begin(), objects.end(), [](object * i, object * j) + {return i->max_grid_right() < j->max_grid_right();}))->max_grid_right() + 1; + int y_min = (*min_element(objects.begin(), objects.end(), [](object * i, object * j) + {return i->max_grid_top() < j->max_grid_top();}))->max_grid_top(); + int y_max = (*max_element(objects.begin(), objects.end(), [](object * i, object * j) + {return i->max_grid_bottom() < j->max_grid_bottom();}))->max_grid_bottom() + 1; + + m_mouse_y_max = y_max * (grid_height + gap) - gap; + m_window_width = (x_max - x_min) * (grid_width + gap) - gap; + m_window_height = (y_max - y_min) * (grid_height + gap) - gap; + + m_window = glfwCreateWindow(m_window_width, m_window_height, "Test", NULL, NULL); + + glfwMakeContextCurrent(m_window); + + glfwSetWindowUserPointer(m_window, this); + + glfwSetKeyCallback(m_window, s_keyboard_callback); + glfwSetMouseButtonCallback(m_window, s_mouse_callback); + + glOrtho(x_min * (grid_width + gap), x_max * (grid_width + gap) - gap, + y_min * (grid_height + gap), y_max * (grid_height + gap) - gap, -1, 1); +} + +void core::loop(){ + while(true){ + glfwWaitEvents(); + glClear(GL_COLOR_BUFFER_BIT); + + for(int i = 0; i < objects.size(); i++){ + objects[i]->draw(); + } + + glfwSwapBuffers(m_window); + } +} + +void core::mouse_callback(int button, int state, int modifiers){ + if(button == GLFW_MOUSE_BUTTON_LEFT){ + button = left_mouse_button; + } + else if(button == GLFW_MOUSE_BUTTON_RIGHT){ + button = right_mouse_button; + } + if(state == GLFW_PRESS){ + state = mouse_down_state; + } + else if(state == GLFW_RELEASE){ + state = mouse_up_state; + } + + double click_x, reversed_click_y; + glfwGetCursorPos(m_window, &click_x, &reversed_click_y); + int click_y = m_mouse_y_max - (int) reversed_click_y; + + for(clickable * c : clickable_objects){ + c->try_click((int) click_x, click_y, button, state); + } + + glfwPostEmptyEvent(); +} + +void core::s_mouse_callback(GLFWwindow * window, int button, int state, int modifiers){ + ((core *) glfwGetWindowUserPointer(window))->mouse_callback(button, state, modifiers); +} + +void core::keyboard_callback(int key, int scancode, int action, int mods){ + glfwPostEmptyEvent(); +} + +void core::s_keyboard_callback(GLFWwindow * window, int key, int scancode, int action, int mods){ + ((core *) glfwGetWindowUserPointer(window))->keyboard_callback(key, scancode, action, mods); +} + +void core::add_button(int color, int column, int row, int height, string text, callable * call_on_click){ + button * b = new button(color, column, row, height, text, call_on_click); + objects.push_back(b); + clickable_objects.push_back(b); +} + +void core::add_button(int color, int column, int row, bool left_cap, bool right_cap, + string text, callable * call_on_click){ + button * b = new button(color, column, row, left_cap, right_cap, text, call_on_click); + objects.push_back(b); + clickable_objects.push_back(b); +} + +void core::add_elbow(int color, int column, int row, int length, bool right, bool down, string text){ + elbow * e = new elbow(color, column, row, length, right, down, text); + objects.push_back(e); +} + +int core::add_indicator(int color, int column, int row, bool left_cap, bool right_cap){ + indicator * i = new indicator(color, column, row, left_cap, right_cap); + objects.push_back(i); + indicator_objects.push_back(i); + cout << indicator_objects.size() - 1; + return indicator_objects.size() - 1; +} + +void core::set_indicator(int index, string text){ + indicator_objects[index]->set_text(text); +} + +void core::add_label(int color, int column, int row, int height, string text){ + label * l = new label(color, column, row, height, text); + objects.push_back(l); +} + +void core::add_label(int color, int column, int row, bool left_cap, bool right_cap, string text){ + label * l = new label(color, column, row, left_cap, right_cap, text); + objects.push_back(l); +} diff --git a/lgl_core.h b/lgl_core.h new file mode 100644 index 0000000..a3115be --- /dev/null +++ b/lgl_core.h @@ -0,0 +1,65 @@ +/* + Copyright 2017 Carter Turnbaugh + + This file is part of LGL. + + LGL is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LGL is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LGL. If not, see . +*/ + +#pragma once + +#include "lgl_object.h" +#include "lgl_clickable.h" +#include "lgl_indicator.h" + +#include + +namespace lgl { + + class core { + public: + core(); + ~core(); + + void initialize(); + void loop(); + + void add_button(int color, int column, int row, int height, string text, callable * call_on_click); + void add_button(int color, int column, int row, bool left_cap, bool right_cap, + string text, callable * call_on_click); + void add_elbow(int color, int column, int row, int length, bool right, bool down, string text); + int add_indicator(int color, int column, int row, bool left_cap, bool right_cap); + void add_label(int color, int column, int row, int height, string text); + void add_label(int color, int column, int row, bool left_cap, bool right_cap, string text); + + void set_indicator(int index, string text); + + protected: + void mouse_callback(int button, int state, int modifiers); + static void s_mouse_callback(GLFWwindow * window, int button, int state, int modifiers); + + void keyboard_callback(int key, int scancode, int action, int mods); + static void s_keyboard_callback(GLFWwindow * window, int key, int scancode, int action, int mods); + + private: + GLFWwindow * m_window; + + vector objects; + vector clickable_objects; + vector indicator_objects; + + int m_mouse_y_max, m_window_width, m_window_height; + }; + +}; diff --git a/lgl_elbow.cpp b/lgl_elbow.cpp index 61cb208..18cfac9 100644 --- a/lgl_elbow.cpp +++ b/lgl_elbow.cpp @@ -27,6 +27,32 @@ elbow::elbow(int color, int column, int row, int length, bool right, bool down, : object(color), m_column(column), m_row(row), m_length(length), m_right(right), m_down(down), m_text(text) {} +int elbow::max_grid_left(){ + if(m_right){ + return m_column; + } + else{ + return m_column - 1 - m_length; + } +} + +int elbow::max_grid_right(){ + if(m_right){ + return m_column + 1 + m_length; + } + else{ + return m_column; + } +} + +int elbow::max_grid_top(){ + return m_row; +} + +int elbow::max_grid_bottom(){ + return m_row; +} + void elbow::draw_shapes(){ int right_adj = m_right ? 1 : -2; int left_adj = m_right ? 2 : -1; diff --git a/lgl_elbow.h b/lgl_elbow.h index cf7e6c4..37fdca7 100644 --- a/lgl_elbow.h +++ b/lgl_elbow.h @@ -31,6 +31,11 @@ namespace lgl { public: elbow(int color, int column, int row, int length, bool right, bool down, string text); + int max_grid_left(); + int max_grid_right(); + int max_grid_top(); + int max_grid_bottom(); + protected: void draw_shapes(); diff --git a/lgl_indicator.cpp b/lgl_indicator.cpp index dc9474e..ec21cc3 100644 --- a/lgl_indicator.cpp +++ b/lgl_indicator.cpp @@ -21,8 +21,28 @@ using namespace lgl; -indicator::indicator(int color, int column, int row, bool left_cap, bool right_cap, string text) - : object(color), m_column(column), m_row(row), m_left_cap(left_cap), m_right_cap(right_cap), m_text(text) {} +indicator::indicator(int color, int column, int row, bool left_cap, bool right_cap) + : object(color), m_column(column), m_row(row), m_left_cap(left_cap), m_right_cap(right_cap), m_text("") {} + +int indicator::max_grid_left(){ + return m_column; +} + +int indicator::max_grid_right(){ + return m_column; +} + +int indicator::max_grid_top(){ + return m_row; +} + +int indicator::max_grid_bottom(){ + return m_row; +} + +void indicator::set_text(string text){ + m_text = text; +} void indicator::draw_shapes(){ full_rectangle(m_column, m_column, m_row, m_row); diff --git a/lgl_indicator.h b/lgl_indicator.h index 659e80c..51cc9cb 100644 --- a/lgl_indicator.h +++ b/lgl_indicator.h @@ -29,7 +29,14 @@ namespace lgl { class indicator : public object { public: - indicator(int color, int column, int row, bool left_cap, bool right_cap, string text); + indicator(int color, int column, int row, bool left_cap, bool right_cap); + + int max_grid_left(); + int max_grid_right(); + int max_grid_top(); + int max_grid_bottom(); + + void set_text(string text); protected: void draw_shapes(); diff --git a/lgl_label.cpp b/lgl_label.cpp index fa06f01..afcea0f 100644 --- a/lgl_label.cpp +++ b/lgl_label.cpp @@ -29,6 +29,22 @@ label::label(int color, int column, int row, bool left_cap, bool right_cap, stri : object(color), m_column(column), m_row(row), m_height(0), m_text(text), m_left_cap(left_cap), m_right_cap(right_cap) {} +int label::max_grid_left(){ + return m_column; +} + +int label::max_grid_right(){ + return m_column; +} + +int label::max_grid_top(){ + return m_row + m_height; +} + +int label::max_grid_bottom(){ + return m_row; +} + void label::draw_shapes(){ if(!m_left_cap && !m_right_cap){ full_rectangle(m_column, m_column, m_row, m_row + m_height); diff --git a/lgl_label.h b/lgl_label.h index c9f0e88..60921be 100644 --- a/lgl_label.h +++ b/lgl_label.h @@ -32,6 +32,11 @@ namespace lgl { label(int color, int column, int row, int height, string text); label(int color, int column, int row, bool left_cap, bool right_cap, string text); + int max_grid_left(); + int max_grid_right(); + int max_grid_top(); + int max_grid_bottom(); + protected: void draw_shapes(); diff --git a/lgl_object.cpp b/lgl_object.cpp index 8cbad49..b92f760 100644 --- a/lgl_object.cpp +++ b/lgl_object.cpp @@ -21,12 +21,15 @@ #include #include +#include #include using namespace lgl; using std::cerr; using std::cout; using std::endl; +using std::min; +using std::max; string lgl::font_path = "./font.ttf"; diff --git a/lgl_object.h b/lgl_object.h index df1bdd0..c101edb 100644 --- a/lgl_object.h +++ b/lgl_object.h @@ -40,6 +40,11 @@ namespace lgl { void temp_color(int color); void reset_color(); + virtual int max_grid_left() = 0; + virtual int max_grid_right() = 0; + virtual int max_grid_top() = 0; + virtual int max_grid_bottom() = 0; + void draw(); protected: @@ -57,7 +62,7 @@ namespace lgl { int m_color; int m_original_color; - private: + private: FTTextureFont * font; }; }; diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..0331a2b --- /dev/null +++ b/test.cpp @@ -0,0 +1,59 @@ +#include + +#include "lgl_core.h" +#include "lgl_callable.h" + +using namespace std; + +void l4_callback(){ + cout << "l4 clicked\n"; +} +void l5_callback(){ + cout << "l5 clicked\n"; +} +void l6_callback(){ + cout << "l6 clicked\n"; +} +void l9_callback(){ + cout << "l9 clicked\n"; +} + +int main(int argc, char * argv[]){ + + lgl::colors = vector({{0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.6f}, {1.0f, 0.6f, 0.2f}}); + + lgl::core gui; + + gui.add_label(1, 0, 0, 0, "l1"); + gui.add_label(1, 0, 1, true, false, "l2"); + gui.add_label(1, 0, 2, true, false, "l3"); + lgl::callable_function l4_func(&l4_callback); + gui.add_button(1, 0, 3, 0, "l4", &l4_func); + lgl::callable_function l5_func(&l5_callback); + gui.add_button(1, 0, 4, true, false, "l5", &l5_func); + lgl::callable_function l6_func(&l6_callback); + gui.add_button(1, 0, 5, 0, "l6", &l6_func); + gui.add_label(1, 1, 0, 1, "l7"); + gui.add_label(1, 1, 2, 1, "l8"); + lgl::callable_function l9_func(&l9_callback); + gui.add_button(1, 1, 4, 1, "l9", &l9_func); + gui.add_elbow(1, 1, 6, 0, true, true, ""); + gui.add_elbow(1, 2, 0, 2, true, false, ""); + gui.add_elbow(1, 7, 6, 3, false, true, ""); + gui.add_elbow(1, 7, 0, 0, false, false, ""); + int i_one = gui.add_indicator(1, 2, 1, false, false); + int i_two = gui.add_indicator(1, 2, 2, false, true); + int i_three = gui.add_indicator(1, 2, 3, false, true); + int i_four = gui.add_indicator(1, 2, 4, false, true); + + gui.set_indicator(i_one, "1221"); + gui.set_indicator(i_two, "3323"); + gui.set_indicator(i_three, "1001"); + gui.set_indicator(i_four, "9968"); + + gui.initialize(); + + gui.loop(); + + return 0; +} From f5b9e1201db707d886b4622a954258efaf1c61c2 Mon Sep 17 00:00:00 2001 From: Carter Turn Date: Sat, 5 May 2018 21:59:22 -0700 Subject: [PATCH 11/11] Added titles to windows --- lgl_core.cpp | 4 ++-- lgl_core.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lgl_core.cpp b/lgl_core.cpp index 7c19556..35a017f 100644 --- a/lgl_core.cpp +++ b/lgl_core.cpp @@ -15,7 +15,7 @@ using std::max_element; using namespace lgl; -core::core(){} +core::core(string window_title) : m_window_title(window_title) {} core::~core(){ for(int i = 0; i < objects.size(); i++){ @@ -39,7 +39,7 @@ void core::initialize(){ m_window_width = (x_max - x_min) * (grid_width + gap) - gap; m_window_height = (y_max - y_min) * (grid_height + gap) - gap; - m_window = glfwCreateWindow(m_window_width, m_window_height, "Test", NULL, NULL); + m_window = glfwCreateWindow(m_window_width, m_window_height, m_window_title.c_str(), NULL, NULL); glfwMakeContextCurrent(m_window); diff --git a/lgl_core.h b/lgl_core.h index a3115be..619b7fe 100644 --- a/lgl_core.h +++ b/lgl_core.h @@ -29,7 +29,7 @@ namespace lgl { class core { public: - core(); + core(string window_title = ""); ~core(); void initialize(); @@ -54,6 +54,7 @@ namespace lgl { private: GLFWwindow * m_window; + string m_window_title; vector objects; vector clickable_objects;