diff --git a/.gitignore b/.gitignore index 9b94d32..33fc4be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +a.out *.o *.gch test_1 diff --git a/component_test.2pp b/component_test.2pp new file mode 100644 index 0000000..a6e5f02 --- /dev/null +++ b/component_test.2pp @@ -0,0 +1,144 @@ +#include +#include +#include + +#include "lgl_label.h" +#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; + +void l4_callback(){ + cout << "l4 clicked\n"; +} +void l5_callback(){ + cout << "l5 clicked\n"; +} +void l6_callback(){ + cout << "l6 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; +label * l9; +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; + int mouse_state = state == GLFW_PRESS ? lgl::mouse_down_state : lgl::mouse_up_state; + + 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); +} + +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, 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, 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"); + l8 = new label(1, 1, 2, 1, "l8"); + 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, ""); + 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(); + + 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); + glfwWaitEvents(); + l1->draw(); + l2->draw(); + l3->draw(); + l4->draw(); + l5->draw(); + l6->draw(); + l7->draw(); + l8->draw(); + l9->draw(); + e1->draw(); + e2->draw(); + e3->draw(); + e4->draw(); + i1->draw(); + i2->draw(); + i3->draw(); + i4->draw(); + glfwSwapBuffers(window); + } + + 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; + delete e1; + delete e2; + delete e3; + delete e4; + delete i1; + delete i2; + delete i3; + delete i4; + + 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 index d0c4a62..4f038e2 100644 --- a/lgl_button.cpp +++ b/lgl_button.cpp @@ -1,34 +1,41 @@ /* - 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 . */ #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; + +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){ + 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 4798c4c..b7fbd01 100644 --- a/lgl_button.h +++ b/lgl_button.h @@ -1,41 +1,37 @@ /* - 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_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(); +#include "lgl_label.h" +#include "lgl_clickable.h" -private: - int size; +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_callable.cpp b/lgl_callable.cpp new file mode 100644 index 0000000..9c96952 --- /dev/null +++ b/lgl_callable.cpp @@ -0,0 +1,28 @@ +/* + 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_callable.h" + +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..a986b33 --- /dev/null +++ b/lgl_clickable.cpp @@ -0,0 +1,36 @@ +/* + 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, 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, mouse_button, mouse_state); + 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 new file mode 100644 index 0000000..9f5d376 --- /dev/null +++ b/lgl_clickable.h @@ -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 . +*/ + +#pragma once + +#include "lgl_const.h" +#include "lgl_callable.h" + +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, int mouse_button=left_mouse_button, + int mouse_state=mouse_down_state); + + 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, int mouse_button, int mouse_state) = 0; + + int m_mouse_button; + int m_mouse_state; + + 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_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 index ffb227c..c2ab5ac 100644 --- a/lgl_const.h +++ b/lgl_const.h @@ -1,26 +1,39 @@ /* - 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 -namespace lgl_const { - const int button_width = 90; - const int button_height = 36; - const int gap = 2; +#include + +using std::vector; + +namespace lgl { + struct color{ + float R; + float G; + float B; + }; + + const int grid_width = 60; + const int grid_height = 24; + const int gap = 1; + + extern vector colors; + extern float scale_factor; } diff --git a/lgl_core.cpp b/lgl_core.cpp new file mode 100644 index 0000000..35a017f --- /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(string window_title) : m_window_title(window_title) {} + +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, m_window_title.c_str(), 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..619b7fe --- /dev/null +++ b/lgl_core.h @@ -0,0 +1,66 @@ +/* + 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(string window_title = ""); + ~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; + string m_window_title; + + 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 73b90d8..18cfac9 100644 --- a/lgl_elbow.cpp +++ b/lgl_elbow.cpp @@ -1,127 +1,111 @@ /* - 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 . */ #include "lgl_elbow.h" #include -#include "lgl_utils.h" -#include "lgl_shapes.h" -#include "lgl_const.h" +using namespace lgl; -using namespace std; +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) {} -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(); +int elbow::max_grid_left(){ + if(m_right){ + return m_column; } else{ - if(elbow.y_orient == 0) draw_x1_y0(); - else draw_x1_y1(); + return m_column - 1 - m_length; } } -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 elbow::max_grid_right(){ + if(m_right){ + return m_column + 1 + m_length; + } + else{ + return m_column; + } } -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 elbow::max_grid_top(){ + return m_row; } -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 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; + 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); + } + + elbow_outside(); + + temp_color(0); + elbow_inside(); + set_color(); } -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); +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 be276d8..37fdca7 100644 --- a/lgl_elbow.h +++ b/lgl_elbow.h @@ -1,59 +1,50 @@ /* - 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_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; + +#include + +using std::string; + +namespace lgl { -protected: - elbow_data elbow; + class elbow : public object { + 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(); + + void elbow_outside(); + void elbow_inside(); + + int m_column, m_row, m_length; + bool m_right, m_down; + string m_text; + }; - 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_indicator.cpp b/lgl_indicator.cpp new file mode 100644 index 0000000..ec21cc3 --- /dev/null +++ b/lgl_indicator.cpp @@ -0,0 +1,87 @@ +/* + 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) + : 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); + + 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..51cc9cb --- /dev/null +++ b/lgl_indicator.h @@ -0,0 +1,51 @@ +/* + 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); + + 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(); + + 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 new file mode 100644 index 0000000..afcea0f --- /dev/null +++ b/lgl_label.cpp @@ -0,0 +1,91 @@ +/* + 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 color, int column, int row, int height, string 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) {} + +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); + } + 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); + } + + temp_color(0); + draw_text(m_column, m_row, m_text); + set_color(); +} + +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 new file mode 100644 index 0000000..60921be --- /dev/null +++ b/lgl_label.h @@ -0,0 +1,50 @@ +/* + 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 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(); + + 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_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..b92f760 --- /dev/null +++ b/lgl_object.cpp @@ -0,0 +1,182 @@ +/* + 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 +#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"; + +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; + return; + } + + font->FaceSize(60); +} + +object::~object(){ + delete font; +} + +void object::set_color(int color){ + m_color = 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; + + glColor3f(colors[m_color].R, colors[m_color].G, colors[m_color].B); +} + +void object::draw(){ + glColor3f(colors[m_color].R, colors[m_color].G, colors[m_color].B); + + draw_shapes(); +} + +void object::draw_text(int grid_x, int grid_y, string text){ + 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 - grid_height) * scale_factor + || top > grid_height * 7.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); + + 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)) * 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); + + 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_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_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; + } + else{ + top -= (grid_height / 2) * scale_factor; + } + + glBegin(GL_QUADS); + + glVertex2i(left, top); + glVertex2i(right, top); + glVertex2i(right, bottom); + glVertex2i(left, bottom); + + 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; + 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::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){ + 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_object.h b/lgl_object.h index d383da4..c101edb 100644 --- a/lgl_object.h +++ b/lgl_object.h @@ -1,34 +1,68 @@ /* - 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; - } - - virtual int draw() = 0; - -protected: - int era; - int color; +#include "lgl_const.h" + +#include + +#include + +using std::string; + +namespace lgl { + extern string font_path; + + class object { + public: + object(int color); + ~object(); + + void set_color(int color); + void set_color(); + 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: + virtual void draw_shapes() = 0; + + 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_y, bool at_top); + void length_adjusted_rectangle(int grid_x, int grid_y, short left_adj, short right_adj); + 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: + 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 2b69f33..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 futuregl.h -SRC = lgl_bar.cpp lgl_multibutton.cpp lgl_endmultibutton.cpp lgl_fullscreen.cpp lgl_elbow.cpp futuregl.cpp +INC = +SRC = EXE_1 = test_1 EXE_2 = test_2 @@ -23,20 +19,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 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; +} 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