├── Documentation └── PinGUI user manual.docx ├── Errorlog.txt ├── LICENSE ├── PinGUI ├── CameraManager.cpp ├── CameraManager.h ├── CropManager.cpp ├── CropManager.hpp ├── ElementDataStorage.hpp ├── ErrorManager.h ├── FloatDataStorage.hpp ├── GL_Vertex.cpp ├── GL_Vertex.h ├── GUIManager.cpp ├── GUIManager.h ├── GUI_CollisionManager.cpp ├── GUI_ColorManager.cpp ├── GUI_ColorManager.h ├── GUI_Cursor.cpp ├── GUI_Cursor.h ├── GUI_Element.cpp ├── GUI_Element.h ├── GUI_Elements │ ├── ArrowBoard.cpp │ ├── ArrowBoard.h │ ├── Button.cpp │ ├── Button.h │ ├── ClipBoard.cpp │ ├── ClipBoard.h │ ├── ComboBox.cpp │ ├── ComboBox.h │ ├── ComboBoxItem.cpp │ ├── ComboBoxItem.h │ ├── CrossBox.cpp │ ├── CrossBox.h │ ├── HorizontalScroller.cpp │ ├── HorizontalScroller.h │ ├── IconButton.cpp │ ├── IconButton.h │ ├── Image.cpp │ ├── Image.h │ ├── Scroller.cpp │ ├── Scroller.h │ ├── VerticalScroller.cpp │ ├── VerticalScroller.h │ ├── VolumeBoard.cpp │ ├── VolumeBoard.h │ ├── Window.cpp │ ├── Window.h │ ├── WindowButton.cpp │ ├── WindowButton.h │ ├── WindowExit.cpp │ ├── WindowExit.h │ ├── WindowMover.cpp │ ├── WindowMover.h │ ├── WindowTab.cpp │ ├── WindowTab.h │ ├── Window_Arrow.cpp │ └── Window_Arrow.h ├── GUI_Sprite.cpp ├── GUI_Sprite.h ├── Input_Manager.cpp ├── Input_Manager.h ├── IntegerDataStorage.hpp ├── PINGUI.cpp ├── PINGUI.h ├── PinGUI_Rect.hpp ├── PinGUI_Vector.hpp ├── Shader_Program.cpp ├── Shader_Program.h ├── Shaders │ ├── fragmentShader.txt │ └── vertexShader.txt ├── SheetManager.cpp ├── SheetManager.h ├── TextManager │ ├── AdjustableText.cpp │ ├── AdjustableText.h │ ├── FloatText.cpp │ ├── FloatText.h │ ├── Fonts │ │ └── Oswald-Light.ttf │ ├── Images │ │ ├── TextManagerSheet.png │ │ ├── WindowSheet.png │ │ └── console_settings_icon.png │ ├── IntegerText.cpp │ ├── IntegerText.h │ ├── StringText.cpp │ ├── StringText.h │ ├── Text.cpp │ ├── Text.h │ ├── TextManager.cpp │ ├── TextManager.h │ ├── TextStorage.cpp │ └── TextStorage.h ├── VBO_Manager.cpp ├── VBO_Manager.h ├── clFunction.hpp └── stuff.h ├── README.md ├── _config.yml ├── buildinfo └── demo ├── FPS_Timer.cpp ├── FPS_Timer.h ├── build info ├── dog.png └── main.cpp /Documentation/PinGUI user manual.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/Documentation/PinGUI user manual.docx -------------------------------------------------------------------------------- /Errorlog.txt: -------------------------------------------------------------------------------- 1 | Error 1 : Scroller was unable to be loaded due to a incorrect ratio 2 | - It means the scroller wasnt able to create the scroller because of the size of realWidth/realHeight and the fact it wasnt too big 3 | for example : width 300 and realWidth 305 etc. 4 | 5 | Error 2 : ComboboxList was cannot be loaded due to cropped area. Move it to normal area 6 | - Comboboxes cannot crop their lists on click. Moving it to normal area (where it cannot be cropped after popup) will fix this. 7 | Note: this doesn´t happen if you dont have a scroller active in your window tab 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | PinGUI 4 | Copyright (c) 2017 Lubomir Barantal 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | **/ 19 | -------------------------------------------------------------------------------- /PinGUI/CameraManager.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "CameraManager.h" 26 | 27 | namespace PinGUI{ 28 | 29 | GLint CameraManager::_matricesLocations[1]; 30 | 31 | glm::mat4 CameraManager::_staticCameraMatrix; 32 | 33 | int CameraManager::_screenWidth; 34 | 35 | int CameraManager::_screenHeight; 36 | 37 | void CameraManager::init(int screenWidth, int screenHeight){ 38 | 39 | _screenWidth = screenWidth; 40 | _screenHeight = screenHeight; 41 | 42 | glm::mat4 orthoMatrix = glm::ortho(0.0f, (float)_screenWidth, 0.0f, (float)_screenHeight); 43 | 44 | glm::vec3 translate(0.0f, 0.0f, 0.0f); 45 | 46 | _staticCameraMatrix = glm::translate(orthoMatrix,translate); 47 | } 48 | 49 | glm::mat4 CameraManager::getCameraMatrix(){ 50 | return _staticCameraMatrix; 51 | } 52 | 53 | void CameraManager::setMatrixLocation(cameraType type, GLint location){ 54 | 55 | _matricesLocations[type] = location; 56 | } 57 | 58 | GLint CameraManager::getMatrixLocation(cameraType type){ 59 | return _matricesLocations[type]; 60 | } 61 | } 62 | 63 | -------------------------------------------------------------------------------- /PinGUI/CameraManager.h: -------------------------------------------------------------------------------- 1 | #ifndef CAMERAMANAGER_H 2 | #define CAMERAMANAGER_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | /** 29 | GLM is included in here 30 | **/ 31 | #include 32 | #include 33 | 34 | #include "GUI_Sprite.h" 35 | 36 | namespace PinGUI{ 37 | 38 | enum cameraType{ 39 | PROJECTION, 40 | }; 41 | 42 | class CameraManager 43 | { 44 | private: 45 | 46 | static GLint _matricesLocations[1]; 47 | 48 | static glm::mat4 _staticCameraMatrix; 49 | 50 | static int _screenWidth; 51 | 52 | static int _screenHeight; 53 | 54 | public: 55 | 56 | //sets up the orthographic matrix and screen dimensions 57 | static void init(int screenWidth, int screenHeight); 58 | 59 | static glm::mat4 getCameraMatrix(); 60 | 61 | static void setMatrixLocation(cameraType type, GLint location); 62 | 63 | static GLint getMatrixLocation(cameraType type); 64 | }; 65 | } 66 | 67 | 68 | #endif // CAMERAMANAGER_H 69 | -------------------------------------------------------------------------------- /PinGUI/CropManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CROPMANAGER_HPP 2 | #define CROPMANAGER_HPP 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | 30 | #include "GUI_Sprite.h" 31 | #include "PinGUI_Rect.hpp" 32 | #include "GUI_CollisionManager.cpp" 33 | #include "clFunction.hpp" 34 | #include "GL_Vertex.h" 35 | 36 | #define NORMALIZE_CONSTANT 1 37 | 38 | enum orientation 39 | { 40 | UP, 41 | DOWN, 42 | LEFT, 43 | RIGHT 44 | }; 45 | 46 | class CropManager{ 47 | 48 | private : 49 | 50 | static int _cropVar; 51 | 52 | static int _cropSize; 53 | 54 | static PinGUI::Rect _lastCropRect; 55 | 56 | 57 | /** 58 | COLLIDER RECTANGLES 59 | **/ 60 | 61 | //Normal checking 62 | static void repairRect(int& var, const int& maxVar); 63 | 64 | static void doCropping(PinGUI::Rect& cropRect, GUIRect& dstRect); 65 | 66 | static void cropHorizontally(PinGUI::Rect& cropRect, GUIRect& dstRect); 67 | 68 | static void cropVertically(PinGUI::Rect& cropRect, GUIRect& dstRect); 69 | 70 | static void finishCropping(int& targetVar, int& maxVar); 71 | 72 | /** 73 | SPRITES 74 | **/ 75 | 76 | static void changeUV(orientation orient, vboData* dataPointer, PinGUI::Vector2 percentage); 77 | 78 | static void cropSpriteVertically(GUI_Sprite*& sprite, PinGUI::Rect& cropRect); 79 | 80 | static void cropSpriteHorizontally(GUI_Sprite*& sprite, PinGUI::Rect& cropRect); 81 | 82 | public : 83 | 84 | //Cropping GUIRectangles 85 | static void cropRect(PinGUI::Rect cropRect, GUIRect& dstRect); 86 | 87 | /** CROPPING SPRITES **/ 88 | static void cropSprite(GUI_Sprite* sprite, PinGUI::Rect cropRect); 89 | 90 | }; 91 | #endif // CROPMANAGER_HPP 92 | -------------------------------------------------------------------------------- /PinGUI/ElementDataStorage.hpp: -------------------------------------------------------------------------------- 1 | #ifndef ELEMENTDATASTORAGE_HPP 2 | #define ELEMENTDATASTORAGE_HPP 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "IntegerDataStorage.hpp" 29 | #include "FloatDataStorage.hpp" 30 | 31 | enum dataType{ 32 | PINGUI_INT, 33 | PINGUI_FLOAT 34 | }; 35 | 36 | class ElementDataStorage 37 | { 38 | private: 39 | IntegerDataStorage _int; 40 | 41 | FloatDataStorage _float; 42 | 43 | public: 44 | ElementDataStorage(int* var) 45 | { 46 | _int.init(var); 47 | } 48 | ElementDataStorage(float* var) 49 | { 50 | _float.init(var); 51 | } 52 | ~ElementDataStorage() 53 | { 54 | }; 55 | 56 | IntegerDataStorage* getInt(){ 57 | return &_int; 58 | } 59 | 60 | FloatDataStorage* getFloat(){ 61 | return &_float; 62 | } 63 | }; 64 | 65 | #endif // ELEMENTDATASTORAGE_HPP 66 | 67 | -------------------------------------------------------------------------------- /PinGUI/ErrorManager.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/PinGUI/ErrorManager.h -------------------------------------------------------------------------------- /PinGUI/FloatDataStorage.hpp: -------------------------------------------------------------------------------- 1 | #ifndef FLOATDATASTORAGE_HPP 2 | #define FLOATDATASTORAGE_HPP 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | class FloatDataStorage 29 | { 30 | private: 31 | float* _var; 32 | float _last_var; 33 | 34 | public: 35 | FloatDataStorage(): 36 | _var(nullptr), 37 | _last_var(0) 38 | { 39 | } 40 | FloatDataStorage(float* var): 41 | _var(var), 42 | _last_var(*var) 43 | { 44 | } 45 | ~FloatDataStorage(){}; 46 | 47 | void init(float* var){ 48 | _var = var; 49 | _last_var = *var; 50 | } 51 | 52 | void equalVar(){ 53 | _last_var = *_var; 54 | } 55 | 56 | bool changed(){ 57 | 58 | if (_last_var != *_var){ 59 | 60 | _last_var = *_var; 61 | return true; 62 | } return false; 63 | } 64 | 65 | float getVar(){ 66 | return *_var; 67 | } 68 | 69 | float* getVar_P(){ 70 | return _var; 71 | } 72 | }; 73 | 74 | #endif // FLOATDATASTORAGE_HPP 75 | -------------------------------------------------------------------------------- /PinGUI/GL_Vertex.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "GL_Vertex.h" 26 | 27 | namespace PinGUI{ 28 | VertexColor::VertexColor(){ 29 | 30 | } 31 | 32 | 33 | VertexPosition::VertexPosition(){ 34 | 35 | } 36 | 37 | 38 | VertexUV::VertexUV(){ 39 | 40 | } 41 | 42 | Vertex::Vertex(){ 43 | 44 | } 45 | 46 | void Vertex::setPosition(float X, float Y){ 47 | position.x = X; 48 | position.y = Y; 49 | } 50 | 51 | void Vertex::setColor(GLubyte R,GLubyte G, GLubyte B, GLubyte A){ 52 | color.r = R; 53 | color.g = G; 54 | color.b = B; 55 | color.a = A; 56 | } 57 | 58 | void Vertex::setUV(float U, float V){ 59 | uv.u = U; 60 | uv.v = V; 61 | } 62 | 63 | void Vertex::addUV(float U, float V){ 64 | uv.u += U; 65 | uv.v += V; 66 | } 67 | 68 | void Vertex::setU(float U){ 69 | uv.u = U; 70 | } 71 | 72 | void Vertex::setV(float V){ 73 | uv.v = V; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /PinGUI/GL_Vertex.h: -------------------------------------------------------------------------------- 1 | #ifndef GL_VERTEX_H 2 | #define GL_VERTEX_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | 30 | namespace PinGUI{ 31 | 32 | class VertexColor{ 33 | public: 34 | GLubyte r; 35 | GLubyte g; 36 | GLubyte b; 37 | GLubyte a; 38 | 39 | VertexColor(); 40 | VertexColor(GLubyte R,GLubyte G, GLubyte B, GLubyte A): 41 | r(R), 42 | g(G), 43 | b(B), 44 | a(A){ 45 | }; 46 | void setColor(GLubyte R,GLubyte G, GLubyte B, GLubyte A) 47 | { 48 | r = R; 49 | g = G; 50 | b = B; 51 | a = A; 52 | }; 53 | }; 54 | 55 | 56 | 57 | class VertexPosition{ 58 | public: 59 | float x; 60 | float y; 61 | VertexPosition(); 62 | VertexPosition(float X, float Y): 63 | x(X), 64 | y(Y){ 65 | }; 66 | 67 | }; 68 | 69 | class VertexUV{ 70 | public: 71 | float u; 72 | float v; 73 | VertexUV(); 74 | VertexUV(float U, float V): 75 | u(U), 76 | v(V){ 77 | }; 78 | }; 79 | 80 | 81 | class Vertex{ 82 | public: 83 | VertexPosition position; 84 | VertexColor color; 85 | VertexUV uv; 86 | 87 | Vertex(); 88 | Vertex(VertexColor Color, VertexPosition Position, VertexUV UV): 89 | color(Color), 90 | position(Position), 91 | uv(UV) 92 | {}; 93 | void setPosition(float X, float Y); 94 | void setColor(GLubyte R,GLubyte G, GLubyte B, GLubyte A); 95 | void setUV(float U, float V); 96 | void addUV(float U, float V); 97 | void setU(float U); 98 | void setV(float V); 99 | }; 100 | 101 | } 102 | 103 | #endif // GL_VERTEX_H 104 | -------------------------------------------------------------------------------- /PinGUI/GUI_CollisionManager.cpp: -------------------------------------------------------------------------------- 1 | #ifndef GUI_COLLISIONMANAGER_CPP 2 | #define GUI_COLLISIONMANAGER_CPP 3 | 4 | 5 | /** 6 | 7 | PinGUI 8 | 9 | Copyright (c) 2017 Lubomir Barantal 10 | 11 | This software is provided 'as-is', without any express or implied 12 | warranty. In no event will the authors be held liable for any damages 13 | arising from the use of this software. 14 | 15 | Permission is granted to anyone to use this software for any purpose, 16 | including commercial applications, and to alter it and redistribute it 17 | freely, subject to the following restrictions: 18 | 19 | 1. The origin of this software must not be misrepresented; you must not 20 | claim that you wrote the original software. If you use this software 21 | in a product, an acknowledgment in the product documentation would be 22 | appreciated but is not required. 23 | 2. Altered source versions must be plainly marked as such, and must not be 24 | misrepresented as being the original software. 25 | 3. This notice may not be removed or altered from any source distribution. 26 | 27 | **/ 28 | 29 | #include 30 | #include 31 | #include "PinGUI_Rect.hpp" 32 | 33 | /** 34 | In this file are going to be defined different types of collisions in GUIManager created by Pins 2016 35 | **/ 36 | 37 | namespace GUI_CollisionManager{ 38 | 39 | //Function for handling the rectangular collision check between gui elements and cursor 40 | static bool isColliding(PinGUI::Rect collider1, GUIRect collider2){ 41 | 42 | if (collider1.x < collider2.rect.x + collider2.rect.w && collider1.x + collider1.w > collider2.rect.x && collider1.y < collider2.rect.y + collider2.rect.h && collider1.y + collider1.h > collider2.rect.y){ 43 | 44 | return true; 45 | } else return false; 46 | } 47 | 48 | //Normal listener for click 49 | static bool clicked(SDL_Event* e){ 50 | 51 | switch(e->type){ 52 | 53 | case SDL_MOUSEBUTTONDOWN : { 54 | 55 | if (e->button.button==SDL_BUTTON_LEFT){ 56 | return true; 57 | } 58 | } 59 | } 60 | return false; 61 | } 62 | } 63 | 64 | #endif //GUI_COLLISIONMANAGER_CPP 65 | -------------------------------------------------------------------------------- /PinGUI/GUI_ColorManager.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "GUI_ColorManager.h" 26 | 27 | SDL_Color GUI_ColorManager::_COLORS[COLOR_NUM]; 28 | 29 | void GUI_ColorManager::initColors(){ 30 | 31 | SDL_Color tmpColor; 32 | 33 | /*************************CLIPBOARDS*************************/ 34 | //Normal color 35 | tmpColor.r = CLIPBOARD_NORMAL_COLOR_R; 36 | tmpColor.g = CLIPBOARD_NORMAL_COLOR_G; 37 | tmpColor.b = CLIPBOARD_NORMAL_COLOR_B; 38 | tmpColor.a = CLIPBOARD_NORMAL_COLOR_A; 39 | GUI_ColorManager::changeColor(tmpColor,CLIPBOARD_NCOLOR); 40 | 41 | //Target color 42 | tmpColor.r = CLIPBOARD_ON_AIM_COLOR_R; 43 | tmpColor.g = CLIPBOARD_ON_AIM_COLOR_G; 44 | tmpColor.b = CLIPBOARD_ON_AIM_COLOR_B; 45 | tmpColor.a = CLIPBOARD_ON_AIM_COLOR_A; 46 | GUI_ColorManager::changeColor(tmpColor,CLIPBOARD_TCOLOR); 47 | 48 | } 49 | 50 | void GUI_ColorManager::changeColor(SDL_Color color, colorType type){ 51 | _COLORS[type] = color; 52 | } 53 | 54 | SDL_Color GUI_ColorManager::getColor(colorType type){ 55 | return _COLORS[type]; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /PinGUI/GUI_ColorManager.h: -------------------------------------------------------------------------------- 1 | #ifndef GUI_COLORMANAGER_H 2 | #define GUI_COLORMANAGER_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | 30 | #define COLOR_NUM 2 31 | 32 | /** 33 | Defined colors 34 | **/ 35 | 36 | #define CLIPBOARD_NORMAL_COLOR_R 255; 37 | #define CLIPBOARD_NORMAL_COLOR_G 255; 38 | #define CLIPBOARD_NORMAL_COLOR_B 255; 39 | #define CLIPBOARD_NORMAL_COLOR_A 255; 40 | 41 | #define CLIPBOARD_ON_AIM_COLOR_R 200; 42 | #define CLIPBOARD_ON_AIM_COLOR_G 200; 43 | #define CLIPBOARD_ON_AIM_COLOR_B 255; 44 | #define CLIPBOARD_ON_AIM_COLOR_A 255; 45 | 46 | 47 | enum colorType{ 48 | CLIPBOARD_NCOLOR, 49 | CLIPBOARD_TCOLOR 50 | }; 51 | 52 | class GUI_ColorManager{ 53 | private: 54 | static SDL_Color _COLORS[COLOR_NUM]; 55 | public: 56 | static void initColors(); 57 | 58 | static void changeColor(SDL_Color color, colorType type); 59 | 60 | static SDL_Color getColor(colorType type); 61 | }; 62 | 63 | #endif // GUI_COLORMANAGER_H 64 | -------------------------------------------------------------------------------- /PinGUI/GUI_Cursor.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "GUI_Cursor.h" 26 | #include 27 | 28 | PinGUI::Rect GUI_Cursor::_collisionRect; 29 | 30 | void GUI_Cursor::initCursor(){ 31 | 32 | _collisionRect.w = CURSOR_WIDTH; 33 | _collisionRect.h = CURSOR_HEIGHT; 34 | _collisionRect.x = 0; 35 | _collisionRect.y = 0; 36 | 37 | } 38 | 39 | void GUI_Cursor::updateCursor(){ 40 | 41 | int x,y; 42 | 43 | SDL_GetMouseState(&x,&y); 44 | _collisionRect.x = float(x); 45 | _collisionRect.y = float(y); 46 | 47 | _collisionRect.y = PinGUI::Input_Manager::_screenHeight - _collisionRect.y; 48 | } 49 | 50 | 51 | PinGUI::Rect GUI_Cursor::getCollider(){ 52 | return _collisionRect; 53 | } 54 | 55 | GUIPos GUI_Cursor::getX(){ 56 | return _collisionRect.x; 57 | } 58 | 59 | GUIPos GUI_Cursor::getY(){ 60 | return _collisionRect.y; 61 | } 62 | -------------------------------------------------------------------------------- /PinGUI/GUI_Cursor.h: -------------------------------------------------------------------------------- 1 | #ifndef GUI_CURSOR_H 2 | #define GUI_CURSOR_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "SDL.h" 29 | 30 | #include "PinGUI_Rect.hpp" 31 | #include "Input_Manager.h" 32 | #include "stuff.h" 33 | 34 | #define CURSOR_WIDTH 1 35 | #define CURSOR_HEIGHT 1 36 | 37 | class GUI_Cursor 38 | { 39 | private: 40 | static PinGUI::Rect _collisionRect; 41 | public: 42 | 43 | static void initCursor(); 44 | 45 | static void updateCursor(); 46 | 47 | static PinGUI::Rect getCollider(); 48 | 49 | static GUIPos getX(); 50 | 51 | static GUIPos getY(); 52 | }; 53 | 54 | #endif // GUI_CURSOR_H 55 | -------------------------------------------------------------------------------- /PinGUI/GUI_Element.h: -------------------------------------------------------------------------------- 1 | #ifndef GUI_ELEMENT_H 2 | #define GUI_ELEMENT_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "GUI_Sprite.h" 34 | #include "GUI_Cursor.h" 35 | #include "GUI_CollisionManager.cpp" 36 | #include "GUI_ColorManager.h" 37 | #include "Input_Manager.h" 38 | #include "stuff.h" 39 | #include "SheetManager.h" 40 | #include "PinGUI_Rect.hpp" 41 | #include "clFunction.hpp" 42 | #include "CropManager.hpp" 43 | 44 | class GUIManager; 45 | 46 | enum elementType{ 47 | UNDEFINED, 48 | CLIPBOARD, 49 | ARROWBOX, 50 | VOLUMEBOARD, 51 | CROSSBOX, 52 | WINDOW, 53 | WINDOWMOVER, 54 | WINDOWTAB, 55 | WINDOWSCROLLER, 56 | WINDOWARROW, 57 | WINDOWEXIT, 58 | HORIZONTAL_SCROLLER, 59 | VERTICAL_SCROLLER, 60 | COMBOBOX, 61 | COMBOBOX_ITEM 62 | }; 63 | 64 | enum CHANGER{ 65 | MINUS, 66 | PLUS 67 | }; 68 | 69 | class GUI_Element : public std::enable_shared_from_this 70 | { 71 | protected: 72 | PinGUI::Vector2 _position; 73 | 74 | std::vector> _SPRITES; 75 | 76 | std::vector _COLLIDERS; 77 | 78 | bool _aimON; 79 | 80 | bool _collidable; 81 | 82 | bool _show; 83 | 84 | bool _exist; 85 | 86 | //It means element is a subElement to another element 87 | bool _networkedElement; 88 | 89 | bool _allowCropp; 90 | 91 | /** 92 | Private methods 93 | **/ 94 | void initPosition(const PinGUI::Rect& rect); 95 | 96 | void initPosition(GUIPos x, GUIPos y); 97 | 98 | public: 99 | 100 | typedef GUI_Element*& manip_Element; 101 | 102 | GUI_Element(); 103 | virtual ~GUI_Element(); 104 | 105 | void addSprite(PinGUI::Rect rect,SDL_Surface* source,SDL_Color color); 106 | void addSprite(PinGUI::Rect rect,SDL_Surface* source); 107 | void addSprite(GUIPos x, GUIPos y, SDL_Surface* source); 108 | 109 | void changeSprite(GUIPos x, GUIPos y, SDL_Surface* source, std::size_t pos); 110 | 111 | void addCollider(GUIPos x, GUIPos y, int w, int h); 112 | void addCollider(PinGUI::Rect tmpRect); 113 | 114 | void deleteSprite(int pos); 115 | void deleteCollider(int pos); 116 | 117 | std::size_t getCollidersCount(); 118 | 119 | virtual void atWithdraw() {}; 120 | 121 | virtual bool cursorOn(); 122 | 123 | //Virtual methods - every element can modify its own behavior via these functions 124 | virtual void turnOnAim(); 125 | 126 | virtual void turnOffAim(); 127 | 128 | virtual bool collide(bool& needUpdate, manip_Element manipulatingElement); 129 | 130 | virtual void manipulatingMod(manip_Element manipulatingElement){}; 131 | 132 | virtual void endManipulatingMod(manip_Element manipulatingElement); 133 | 134 | virtual bool listenForClick(manip_Element manipulatingElement); 135 | 136 | virtual void onClick() {}; 137 | 138 | virtual void onAim(); 139 | 140 | virtual void onEndAim(){}; 141 | 142 | virtual void draw(int& pos); 143 | 144 | virtual void update(){}; 145 | 146 | virtual bool changed() { return false;} 147 | 148 | virtual void info(); 149 | 150 | virtual elementType getElementType(); 151 | 152 | virtual void normalizeElement(const PinGUI::Vector2& vect); 153 | 154 | virtual void setShow(bool state); 155 | 156 | virtual void moveElement(const PinGUI::Vector2& vect); 157 | 158 | virtual void moveTo(PinGUI::Vector2 vect); 159 | 160 | virtual void cropElement(PinGUI::Rect& rect); 161 | 162 | virtual void doAdditionalFunc(){}; 163 | 164 | virtual void setWritingAvailability(bool state){}; 165 | 166 | virtual void setAllowCrop(bool state); 167 | 168 | virtual void putElementToManager(std::shared_ptr m); 169 | 170 | virtual void setAlpha(Uint8 a); 171 | 172 | virtual void setExist(bool state); 173 | 174 | bool isAllowedCrop(); 175 | 176 | //Normal methods 177 | GLuint getTexture(int pos = 0); 178 | 179 | vboData* getVBOData(int pos = 0); 180 | 181 | PinGUI::Rect* getCollider(int pos = 0); 182 | 183 | GUIRect* getGUICollider(int pos = 0); 184 | 185 | void setCollider(PinGUI::Rect rect,int pos = 0); 186 | 187 | void setCollidable(bool col){_collidable = col;} 188 | 189 | bool getCollidable(); 190 | 191 | /// By default it returns first sprite, if you put -1 here, it will return the back of the container 192 | std::shared_ptr getSprite(unsigned int pos = 0); 193 | 194 | void loadData(std::vector* vboData); 195 | 196 | void moveCollider(GUIRect& rect,const PinGUI::Vector2& vect); 197 | 198 | void moveCollider(PinGUI::Rect& rect,const PinGUI::Vector2& vect); 199 | 200 | 201 | bool getShow(); 202 | 203 | float getX(); 204 | 205 | float getY(); 206 | 207 | void setX(float x); 208 | 209 | void setY(float y); 210 | 211 | void setNetworking(bool state); 212 | 213 | bool getNetworking(); 214 | 215 | bool exist(); 216 | 217 | float getTopPoint(int pos = 0); 218 | 219 | PinGUI::Vector2 getPositionVector(); 220 | 221 | PinGUI::Vector2* getPositionVector_P(); 222 | 223 | bool isAiming(); 224 | 225 | void setAim(bool state); 226 | }; 227 | 228 | #endif // GUI_ELEMENT_H 229 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/ArrowBoard.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "ArrowBoard.h" 26 | 27 | ArrowBoard::ArrowBoard(PinGUI::Rect rect, int* var, int max, std::shared_ptr clip, int min, int ratio ): 28 | _clipBoard(clip), 29 | _max(max), 30 | _ratio(ratio), 31 | _min(min), 32 | _storageType(PINGUI_INT) 33 | { 34 | init(); 35 | 36 | //Init pos 37 | initPosition(rect); 38 | 39 | calculateY(rect.y,rect.h); 40 | 41 | _dataStorage = std::make_shared(var); 42 | } 43 | 44 | ArrowBoard::ArrowBoard(PinGUI::Rect rect, float* var, int max, std::shared_ptr clip, int min, int ratio): 45 | _clipBoard(clip), 46 | _max(max), 47 | _ratio(ratio), 48 | _min(min), 49 | _storageType(PINGUI_FLOAT) 50 | { 51 | init(); 52 | 53 | //Init pos 54 | initPosition(rect); 55 | 56 | calculateY(rect.y,rect.h); 57 | 58 | _dataStorage = std::make_shared(var); 59 | } 60 | 61 | void ArrowBoard::init(){ 62 | 63 | _collidable = false; 64 | 65 | //Create a network between this and clipboard 66 | _clipBoard->setNetworking(true); 67 | } 68 | 69 | ArrowBoard::~ArrowBoard() 70 | { 71 | _ARROWS.clear(); 72 | } 73 | 74 | void ArrowBoard::addArrows(PinGUI::Rect& rect, std::vector>& _ELEMENTS, PinGUI::manipulationState state){ 75 | 76 | PinGUI::basicPointer f1,f2; 77 | f1._function = boost::bind(&ArrowBoard::incVar,this); 78 | f2._function = boost::bind(&ArrowBoard::decVar,this); 79 | 80 | switch (state){ 81 | 82 | case PinGUI::HORIZONTAL : { 83 | 84 | rect.y = calculateY(rect.y,_clipBoard->getSprite()->getH()); 85 | 86 | rect.x = _clipBoard->getSprite()->getX() - PINGUI_WINDOW_SCROLLER_ARROW_SIDE_W - ARROW_OFFSET; 87 | 88 | auto tmpArrow = std::make_shared(rect,SheetManager::getSurface(BOARD),LEFT,ARROW_ONLY); 89 | 90 | tmpArrow->setClickFunction(f2); 91 | _ARROWS.push_back(tmpArrow); 92 | 93 | //Second one 94 | rect.x = (_clipBoard->getSprite()->getX()+_clipBoard->getSprite()->getW()) + ARROW_OFFSET; 95 | 96 | tmpArrow = std::make_shared(rect,SheetManager::getSurface(BOARD),RIGHT,ARROW_ONLY); 97 | tmpArrow->setClickFunction(f1); 98 | 99 | _ARROWS.push_back(tmpArrow); 100 | 101 | break; 102 | } 103 | 104 | case PinGUI::VERTICAL : { 105 | 106 | rect.x = (_clipBoard->getSprite()->getX()+_clipBoard->getSprite()->getW()) + ARROW_OFFSET; 107 | 108 | float tmpY = rect.y; 109 | rect.y = calculateY(rect.y, _clipBoard->getSprite()->getH()) + HORIZONTAL_ARROWS_OFFSET/2; 110 | 111 | auto tmpArrow = std::make_shared(rect,SheetManager::getSurface(BOARD),UP,ARROW_ONLY); 112 | _ARROWS.push_back(tmpArrow); 113 | 114 | tmpArrow->setClickFunction(f1); 115 | 116 | //Second one 117 | rect.y = calculateY(tmpY,_clipBoard->getSprite()->getH()) - ((HORIZONTAL_ARROWS_OFFSET*2) / 2); 118 | 119 | tmpArrow = std::make_shared(rect,SheetManager::getSurface(BOARD),DOWN,ARROW_ONLY); 120 | _ARROWS.push_back(tmpArrow); 121 | 122 | tmpArrow->setClickFunction(f2); 123 | 124 | break; 125 | } 126 | } 127 | 128 | for (std::size_t i = 0; i < _ARROWS.size(); i++){ 129 | _ELEMENTS.push_back(_ARROWS[i]); 130 | _ARROWS[i]->setNetworking(true); 131 | } 132 | } 133 | 134 | float ArrowBoard::calculateY(float y, int h){ 135 | 136 | y = (y + (h/2))-(PINGUI_WINDOW_SCROLLER_ARROW_UPDOWN_H/2); 137 | return y; 138 | } 139 | 140 | float ArrowBoard::calculateX(float x, int w){ 141 | 142 | x = x+(ARROW_W+ARROW_OFFSET)+w+ARROW_OFFSET; 143 | return x; 144 | } 145 | 146 | void ArrowBoard::info(){ 147 | std::cout << "Arrowboard element. Address: " << this << std::endl; 148 | } 149 | 150 | void ArrowBoard::moveElement(const PinGUI::Vector2& vect){ 151 | 152 | _clipBoard->moveElement(vect); 153 | 154 | for (std::size_t i = 0; i < _ARROWS.size(); i++) 155 | _ARROWS[i]->moveElement(vect); 156 | } 157 | 158 | void ArrowBoard::incVar(){ 159 | 160 | switch(_storageType){ 161 | 162 | case PINGUI_INT : { 163 | 164 | auto _var = _dataStorage->getInt()->getVar_P(); 165 | 166 | if (*_var + _ratio <= _max) 167 | *_var += _ratio; 168 | 169 | break; 170 | } 171 | case PINGUI_FLOAT : { 172 | 173 | auto _var = _dataStorage->getFloat()->getVar_P(); 174 | 175 | if (*_var + _ratio <= _max) 176 | *_var += _ratio; 177 | 178 | break; 179 | } 180 | } 181 | } 182 | 183 | void ArrowBoard::decVar(){ 184 | 185 | switch(_storageType){ 186 | 187 | case PINGUI_INT : { 188 | 189 | auto _var = _dataStorage->getInt()->getVar_P(); 190 | 191 | if (*_var - _ratio >= _min) 192 | *_var -= _ratio; 193 | 194 | break; 195 | } 196 | case PINGUI_FLOAT : { 197 | 198 | auto _var = _dataStorage->getFloat()->getVar_P(); 199 | 200 | if (*_var - _ratio >= _min) 201 | *_var -= _ratio; 202 | 203 | break; 204 | } 205 | } 206 | } 207 | 208 | void ArrowBoard::cropElement(PinGUI::Rect& rect){ 209 | 210 | GUI_Element::cropElement(rect); 211 | _clipBoard->cropElement(rect); 212 | 213 | for (std::size_t i = 0; i < _ARROWS.size(); i++) 214 | _ARROWS[i]->cropElement(rect); 215 | } 216 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/ArrowBoard.h: -------------------------------------------------------------------------------- 1 | #ifndef ARROWBOARD_H 2 | #define ARROWBOARD_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 ¼ubomír Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "../GUI_Elements/ClipBoard.h" 34 | #include "../GUI_Elements/Window_Arrow.h" 35 | #include "../SheetManager.h" 36 | #include "../ElementDataStorage.hpp" 37 | 38 | #define ARROW_OFFSET 3 39 | #define HORIZONTAL_ARROWS_OFFSET 4 40 | 41 | #define ARROWBOARD_COLLIDER_X 2 42 | #define ARROWBOARD_COLLIDER_Y 2 43 | #define ARROWBOARD_COLLIDER_W -4,5 44 | #define ARROWBOARD_COLLIDER_H -3 45 | 46 | class ArrowBoard: public GUI_Element 47 | { 48 | private: 49 | 50 | std::shared_ptr _clipBoard; 51 | 52 | std::vector> _ARROWS; 53 | 54 | dataType _storageType; 55 | 56 | std::shared_ptr _dataStorage; 57 | 58 | int _max; 59 | int _min; 60 | 61 | int _ratio; 62 | 63 | /** 64 | Private methods 65 | **/ 66 | float calculateY(float y, int h); 67 | float calculateX(float x, int w); 68 | 69 | void incVar(); 70 | void decVar(); 71 | 72 | void init(); 73 | 74 | public: 75 | ArrowBoard(PinGUI::Rect rect, int* var, int max, std::shared_ptr clip, int min = 0, int ratio = 1); 76 | ArrowBoard(PinGUI::Rect rect, float* var, int max, std::shared_ptr clip, int min = 0, int ratio = 1); 77 | 78 | ~ArrowBoard(); 79 | 80 | void addArrows(PinGUI::Rect& rect, std::vector>& _ELEMENTS, PinGUI::manipulationState state = PinGUI::VERTICAL); 81 | 82 | void info() override; 83 | 84 | void moveElement(const PinGUI::Vector2& vect) override; 85 | 86 | void cropElement(PinGUI::Rect& rect) override; 87 | 88 | }; 89 | 90 | #endif // ARROWBOARD_H 91 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/Button.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "Button.h" 26 | 27 | Button::Button() 28 | { 29 | 30 | } 31 | 32 | Button::Button(GUIPos x, GUIPos y, std::string name, PinGUI::basicPointer f, clipboardData data): 33 | _func(f) 34 | { 35 | initPosition(x, y); 36 | 37 | _maxSize = int(name.size()); 38 | 39 | initSprites(name,data); 40 | } 41 | 42 | Button::Button(GUIPos x, GUIPos y, std::string name, PinGUI::basicPointer f, clipboardData data, int maxSize): 43 | _func(f) 44 | { 45 | _maxSize = maxSize; 46 | 47 | initPosition(x, y); 48 | 49 | initSprites(name,data); 50 | } 51 | 52 | Button::Button(GUIPos x, GUIPos y, std::string name, clipboardData data, int maxSize) 53 | { 54 | _maxSize = maxSize; 55 | 56 | initPosition(x, y); 57 | 58 | initSprites(name, data); 59 | } 60 | 61 | Button::Button(GUIPos x, GUIPos y, std::string name, clipboardData data) 62 | { 63 | _maxSize = int(name.size()); 64 | 65 | initPosition(x, y); 66 | 67 | initSprites(name,data); 68 | } 69 | 70 | Button::Button(GUIPos x, GUIPos y, PinGUI::basicPointer f): 71 | _func(f) 72 | { 73 | initPosition(x, y); 74 | } 75 | 76 | Button::~Button() 77 | { 78 | //dtor 79 | } 80 | 81 | void Button::initSprites(std::string name, clipboardData& data){ 82 | 83 | SDL_Surface* tmpSurface; 84 | int tmp_width, tmp_height; 85 | 86 | fakeInputText(tmp_width,tmp_height,data); 87 | 88 | addCollider(_position.x,_position.y,tmp_width,tmp_height); 89 | 90 | _textStorage = std::make_shared(data.texter); 91 | initText(); 92 | 93 | tmpSurface = SheetManager::createClipboard(tmp_width,tmp_height); 94 | 95 | addSprite(_position.x,_position.y,tmpSurface); 96 | 97 | setClipboardText(name); 98 | 99 | getSprite()->setColor(0,255,0); 100 | getSprite()->setAlpha(75); 101 | } 102 | 103 | void Button::onClick(){ 104 | 105 | _func.exec(); 106 | PinGUI::Input_Manager::turnOnTMPState(); 107 | } 108 | 109 | void Button::onAim(){ 110 | 111 | //Define with your behavior.. 112 | 113 | } 114 | 115 | void Button::onEndAim(){ 116 | 117 | //Define with your behavior.. 118 | } 119 | 120 | void Button::setWritingAvailability(bool state){ 121 | 122 | if (state){ 123 | getSprite()->setColor(0,255,0); 124 | getSprite()->setAlpha(150); 125 | } else { 126 | getSprite()->setAlpha(75); 127 | } 128 | } 129 | 130 | bool Button::listenForClick(manip_Element manipulatingElement){ 131 | 132 | return GUI_Element::listenForClick(manipulatingElement); 133 | } 134 | 135 | void Button::setFunction(PinGUI::basicPointer func) { 136 | _func = func; 137 | } -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/Button.h: -------------------------------------------------------------------------------- 1 | #ifndef BUTTON_H 2 | #define BUTTON_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 ¼ubomír Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "../GUI_Elements/ClipBoard.h" 29 | 30 | class Button: public ClipBoard 31 | { 32 | protected: 33 | 34 | PinGUI::basicPointer _func; 35 | 36 | /** 37 | Private methods 38 | **/ 39 | void initSprites(std::string name, clipboardData& data); 40 | 41 | public: 42 | Button(); 43 | Button(GUIPos x, GUIPos y, std::string name, clipboardData data); 44 | Button(GUIPos x, GUIPos y, std::string name, PinGUI::basicPointer f, clipboardData data); 45 | Button(GUIPos x, GUIPos y, std::string name, PinGUI::basicPointer f, clipboardData data, int maxSize); 46 | Button(GUIPos x, GUIPos y, std::string name, clipboardData data, int maxSize); 47 | Button(GUIPos x, GUIPos y, PinGUI::basicPointer f); 48 | ~Button(); 49 | 50 | void onClick() override; 51 | 52 | void onAim() override; 53 | 54 | void onEndAim() override; 55 | 56 | void setWritingAvailability(bool state) override; 57 | 58 | bool listenForClick(manip_Element manipulatingElement) override; 59 | 60 | void setFunction(PinGUI::basicPointer func); 61 | 62 | }; 63 | 64 | #endif // BUTTON_H 65 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/ClipBoard.h: -------------------------------------------------------------------------------- 1 | #ifndef CLIPBOARD_H 2 | #define CLIPBOARD_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | 29 | #include "../TextManager/TextStorage.h" 30 | #include "../GUI_Element.h" 31 | #include "../stuff.h" 32 | 33 | #define CLIPBOARD_WIDTH_OFFSET 6 34 | #define CLIPBOARD_HEIGHT_OFFSET 2 35 | 36 | #define CLIPBOARD_HEIGHT 5 37 | #define WIDTH_PER_CHAR 5 38 | #define WIDTH_PER_DIGIT 4 39 | 40 | #define CLIPBOARD_COLLIDER_X -1 41 | #define CLIPBOARD_COLLIDER_Y 0 42 | #define CLIPBOARD_COLLIDER_W 2 43 | #define CLIPBOARD_COLLIDER_H 1 44 | 45 | #define CLIPBOARD_FLOAT_SIZE 7 46 | 47 | class clipboardData{ 48 | public: 49 | std::shared_ptr texter; 50 | 51 | clipboardData() 52 | { 53 | 54 | } 55 | 56 | clipboardData(std::shared_ptr Texter) : 57 | texter(Texter) 58 | { 59 | 60 | } 61 | }; 62 | 63 | class ClipBoard: public GUI_Element 64 | { 65 | protected: 66 | 67 | //Type of clipboard 68 | clipboard_type _type; 69 | 70 | //Max value 71 | int _maxValue; 72 | 73 | //Min value 74 | int _minValue; 75 | 76 | //Max size of chars (or ints if its INT only clipboard) 77 | unsigned int _maxSize; 78 | 79 | int _widthPerChar; 80 | 81 | //Text storage unit 82 | std::shared_ptr _textStorage; 83 | 84 | //This indicates if i have rounded or rectangle shape (important for collisions) 85 | element_shape _shape; 86 | 87 | //Bool to check the negative values 88 | bool _negativeInput; 89 | 90 | bool _exitAtEnter; 91 | 92 | //Function that activates after you hit "Enter" in writing mode 93 | PinGUI::stringFuncPointer _func; 94 | 95 | /** 96 | Private methods 97 | **/ 98 | void setMaxSize(int& maxSize); 99 | void calculateMaxSize(); 100 | 101 | PinGUI::Rect getSpriteRect(const int& tmp_width, const int& tmp_height, const PinGUI::Vector2 position); 102 | 103 | //Changing the sprite color to see if i have collision or not 104 | void manipulatingMod(manip_Element manipulatingElement) override; 105 | 106 | void setWritingAvailability(bool state); 107 | 108 | void initClipBoard(int& maxSize, clipboardData& data, PinGUI::Vector2& position, int width = 0); 109 | 110 | void initText(unsigned int sizeOfAdjustText = 0, unsigned int maxSizeOfAdjustText = 0); 111 | void initText(int* var); 112 | void initText(float* var); 113 | void initText(std::string* var); 114 | 115 | void initStorage(); 116 | 117 | void fakeInputText(int& width, int& height, const clipboardData& data); 118 | 119 | bool pressedEnter(); 120 | 121 | bool pressedESC(); 122 | 123 | bool containsText(); 124 | 125 | public: 126 | 127 | ClipBoard(); 128 | 129 | //Basic textbox for text input 130 | ClipBoard(PinGUI::Vector2 position, int maxSize, clipboard_type type, clipboardData data, unsigned int maxSizeOfAdjustText = 0, element_shape shape = ROUNDED, bool delegated = false); 131 | 132 | //Textbox with fixed sprite width 133 | ClipBoard(PinGUI::Vector2 position, int width, int maxSize, clipboard_type type, clipboardData data, unsigned int maxSizeOfAdjustText = 0, element_shape shape = ROUNDED); 134 | 135 | //String variable textbox 136 | ClipBoard(PinGUI::Vector2 position, int maxSize, clipboard_type type, clipboardData data, std::string* var, element_shape shape = ROUNDED); 137 | 138 | //Integer 139 | ClipBoard(PinGUI::Vector2 position, int maxSize, clipboard_type type, clipboardData data, int* var, bool negativeInput = true,element_shape shape = ROUNDED); 140 | 141 | //Float 142 | ClipBoard(PinGUI::Vector2 position, int maxSize, clipboard_type type, clipboardData data, float* var, bool negativeInput = true,element_shape shape = ROUNDED); 143 | 144 | //Init of sprites etc. 145 | void init(PinGUI::Vector2 position, int maxSize, clipboardData data, clipboard_type type = NORMAL, element_shape shape = ROUNDED); 146 | 147 | void onClick() override; 148 | void info() override; 149 | void setShow(bool state) override; 150 | 151 | ~ClipBoard(); 152 | 153 | std::shared_ptr getStorage(){return _textStorage;} 154 | 155 | void normalizeElement(const PinGUI::Vector2& vect) override; 156 | 157 | bool listenForClick(manip_Element manipulatingElement) override; 158 | 159 | void moveElement(const PinGUI::Vector2& vect) override; 160 | 161 | void cropElement(PinGUI::Rect& rect) override; 162 | 163 | void setClipboardText(std::string text); 164 | void setClipboardText(std::string text, PinGUI::Rect collider); 165 | 166 | void setMinValue(int minV); 167 | 168 | bool changed(); 169 | 170 | void setEnterFunc(PinGUI::stringFuncPointer f); 171 | 172 | void clearClipBoard(); 173 | 174 | void setExitAtEnter(bool state); 175 | 176 | }; 177 | 178 | #endif // CLIPBOARD_H 179 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/ComboBox.h: -------------------------------------------------------------------------------- 1 | #ifndef COMBOBOX_H 2 | #define COMBOBOX_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | 30 | #include "../GUI_Elements/ClipBoard.h" 31 | #include "../GUI_Elements/VerticalScroller.h" 32 | #include "../GUI_Elements/ComboBoxItem.h" 33 | 34 | #define DEFAULT_NUM_OF_COMBO_ITEMS 4 35 | #define DEFAULT_LENGTH_OF_KEYCOMBO_WORD 10 36 | 37 | #define POSITION_OF_COMBO_ARROW_X 13 38 | 39 | class ComboBox: public ClipBoard 40 | { 41 | private: 42 | 43 | std::vector>* _ELEMENTS; 44 | 45 | //Also scroller 46 | std::shared_ptr _scroller; 47 | 48 | //Crop area 49 | GUIRect _cropRect; 50 | 51 | //ITEMS 52 | std::vector> _ITEMS; 53 | 54 | //Maximum number of Items(that are allowed without scrolling) 55 | unsigned int _maxNumberOfItems; 56 | 57 | //The main collider for offseting the chosen text 58 | PinGUI::Rect _offsetCollider; 59 | 60 | //ClipboardData 61 | clipboardData _data; 62 | 63 | //The main option 64 | std::shared_ptr _mainItem; 65 | 66 | bool* _needUpdate; 67 | 68 | PinGUI::comboBoxFuncPointer _func; 69 | 70 | PinGUI::Vector2 _rollbackVect; 71 | 72 | bool _clickable; 73 | 74 | /** 75 | Private methods 76 | **/ 77 | void initMainSprites(const GUIPos& x, const GUIPos& y, clipboardData& data); 78 | 79 | void loadCropArea(PinGUI::Vector2 vect); 80 | 81 | void updateCropArea(PinGUI::Vector2 vect); 82 | 83 | void findLongestWord(std::vector& itemList); 84 | 85 | GUIPos getPosOfNextItem(); 86 | 87 | void hideContent(); 88 | 89 | void uploadContent(); 90 | 91 | void loadScroller(); 92 | 93 | void reMoveTabs(); 94 | 95 | public: 96 | ComboBox(GUIPos x, 97 | GUIPos y, 98 | std::vector itemList, 99 | clipboardData data, 100 | std::vector>* ELEMENTS, 101 | int maxNumOfItems, 102 | bool* update); 103 | 104 | ComboBox(GUIPos x, 105 | GUIPos y, 106 | std::vector itemList, 107 | clipboardData data, 108 | std::vector>* ELEMENTS, 109 | int maxNumOfItems, 110 | bool* update, 111 | int maxSize); 112 | 113 | ~ComboBox(); 114 | 115 | void initScroller(); 116 | 117 | void setFunc(PinGUI::comboBoxFuncPointer func); 118 | 119 | std::vector getStringVector(); 120 | 121 | void addItem(std::string name); 122 | 123 | void deleteItem(std::string name); 124 | 125 | void clearComboBox(); 126 | 127 | void setUnclickable(); 128 | 129 | void moveElement(const PinGUI::Vector2& vect) override; 130 | 131 | void onClick() override; 132 | 133 | bool listenForClick(manip_Element manipulatingElement) override; 134 | 135 | void setShow(bool state) override; 136 | 137 | void cropElement(PinGUI::Rect& rect) override; 138 | 139 | elementType getElementType() override; 140 | }; 141 | 142 | #endif // COMBOBOX_H 143 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/ComboBoxItem.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "ComboBoxItem.h" 26 | 27 | ComboBoxItem::ComboBoxItem(PinGUI::Vector2 position, 28 | std::string itemText, 29 | std::shared_ptr* mainComboBoxItem, 30 | PinGUI::basicPointer functionP, 31 | int maxSize, 32 | clipboardData& data): 33 | _function(functionP), 34 | _mainComboBoxItem(mainComboBoxItem), 35 | _option(0) 36 | { 37 | init(position,maxSize,data,NORMAL,RECTANGLED); 38 | 39 | _maxSize = maxSize; 40 | _position = position; 41 | 42 | //ComboBox owns full control of this element (be careful) 43 | _networkedElement = true; 44 | 45 | setClipboardText(itemText); 46 | 47 | setShow(false); 48 | } 49 | 50 | ComboBoxItem::~ComboBoxItem() 51 | { 52 | //dtor 53 | } 54 | 55 | void ComboBoxItem::onClick(){ 56 | 57 | //Tmp disabling it 58 | PinGUI::Input_Manager::setTarget(false); 59 | 60 | if (*_mainComboBoxItem) 61 | (*_mainComboBoxItem)->setCollidable(true); 62 | 63 | *_mainComboBoxItem = std::dynamic_pointer_cast(shared_from_this()); 64 | 65 | this->setCollidable(false); 66 | 67 | _function.exec(); 68 | 69 | PinGUI::Input_Manager::setTarget(true); 70 | 71 | } 72 | 73 | bool ComboBoxItem::listenForClick(manip_Element manipulatingElement){ 74 | return GUI_Element::listenForClick(manipulatingElement); 75 | } 76 | 77 | void ComboBoxItem::cropElement(PinGUI::Rect& rect){ 78 | 79 | ClipBoard::cropElement(rect); 80 | } 81 | 82 | void ComboBoxItem::setOption(int opt){ 83 | _option = opt; 84 | } 85 | 86 | int ComboBoxItem::getOption(void){ 87 | return _option; 88 | } 89 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/ComboBoxItem.h: -------------------------------------------------------------------------------- 1 | #ifndef COMBOBOXITEM_H 2 | #define COMBOBOXITEM_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "../GUI_Elements/ClipBoard.h" 29 | 30 | 31 | class ComboBoxItem: public ClipBoard 32 | { 33 | private: 34 | 35 | std::shared_ptr* _mainComboBoxItem; 36 | 37 | //Callback function 38 | PinGUI::basicPointer _function; 39 | 40 | int _option; 41 | 42 | public: 43 | ComboBoxItem(PinGUI::Vector2 position, 44 | std::string itemText, 45 | std::shared_ptr* mainComboBoxItem, 46 | PinGUI::basicPointer functionP, 47 | int maxSize, 48 | clipboardData& data); 49 | 50 | ~ComboBoxItem(); 51 | 52 | void onClick() override; 53 | 54 | bool listenForClick(manip_Element manipulatingElement) override; 55 | 56 | void cropElement(PinGUI::Rect& rect) override; 57 | 58 | void setOption(int opt); 59 | int getOption(void); 60 | }; 61 | 62 | #endif // COMBOBOXITEM_H 63 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/CrossBox.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "CrossBox.h" 26 | 27 | CrossBox::CrossBox(GUIPos x, GUIPos y, bool* var): 28 | _var(var), 29 | _last_var(*_var) 30 | { 31 | PinGUI::Rect tmp; 32 | tmp.x = x; 33 | tmp.y = y; 34 | 35 | initPosition(tmp); 36 | 37 | if (*_var) 38 | addSprite(tmp, SheetManager::getSurface(NON_CHECKBOX)); 39 | else 40 | addSprite(tmp, SheetManager::getSurface(CHECKBOX)); 41 | 42 | tmp.x += CHECKBOX_COLLIDER_X; 43 | tmp.y += CHECKBOX_COLLIDER_Y; 44 | tmp.w = _SPRITES[0]->getW()+CHECKBOX_COLLIDER_W; 45 | tmp.h = _SPRITES[0]->getH()+CHECKBOX_COLLIDER_H; 46 | 47 | addCollider(tmp); 48 | } 49 | 50 | CrossBox::~CrossBox() 51 | { 52 | //dtor 53 | } 54 | 55 | void CrossBox::onClick(){ 56 | 57 | if (*_var){ 58 | 59 | *_var = false; 60 | _SPRITES[0]->changeTexture(SheetManager::getSurface(CHECKBOX)); 61 | } else { 62 | 63 | *_var = true; 64 | _SPRITES[0]->changeTexture(SheetManager::getSurface(NON_CHECKBOX)); 65 | } 66 | 67 | _last_var = *_var; 68 | } 69 | 70 | void CrossBox::setWritingAvailability(bool state){ 71 | 72 | if (state){ 73 | getSprite()->changeColor(GUI_ColorManager::getColor(CLIPBOARD_TCOLOR)); 74 | } else { 75 | getSprite()->changeColor(GUI_ColorManager::getColor(CLIPBOARD_NCOLOR)); 76 | } 77 | } 78 | 79 | void CrossBox::info(){ 80 | std::cout << "Crossbox element. Address: " << this << std::endl; 81 | } 82 | 83 | bool CrossBox::hasChanged(){ 84 | return (_last_var!=*_var); 85 | } 86 | 87 | void CrossBox::update(){ 88 | 89 | if (hasChanged()) 90 | change(); 91 | } 92 | 93 | void CrossBox::change(){ 94 | _last_var = *_var; 95 | 96 | switch(_last_var){ 97 | 98 | case true : { 99 | _SPRITES[0]->changeTexture(SheetManager::getSurface(NON_CHECKBOX)); 100 | break; 101 | } 102 | case false : { 103 | _SPRITES[0]->changeTexture(SheetManager::getSurface(CHECKBOX)); 104 | break; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/CrossBox.h: -------------------------------------------------------------------------------- 1 | #ifndef CROSSBOX_H 2 | #define CROSSBOX_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | 30 | #include "../GUI_Element.h" 31 | 32 | #define CHECKBOX_COLLIDER_X 1 33 | #define CHECKBOX_COLLIDER_Y 1 34 | #define CHECKBOX_COLLIDER_W -1 35 | #define CHECKBOX_COLLIDER_H -1 36 | 37 | class CrossBox: public GUI_Element 38 | { 39 | private: 40 | 41 | bool* _var; 42 | 43 | bool _last_var; 44 | 45 | /** 46 | Private methods 47 | **/ 48 | void onClick() override; 49 | 50 | void setWritingAvailability(bool state) override; 51 | 52 | bool hasChanged(); 53 | 54 | void change(); 55 | public: 56 | CrossBox(GUIPos x, GUIPos y, bool* var); 57 | ~CrossBox(); 58 | 59 | void info() override; 60 | 61 | void update() override; 62 | }; 63 | 64 | #endif // CROSSBOX_H 65 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/HorizontalScroller.h: -------------------------------------------------------------------------------- 1 | #ifndef HORIZONTALSCROLLER_H 2 | #define HORIZONTALSCROLLER_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | 30 | #include "../GUI_Elements/Scroller.h" 31 | 32 | #define NORMALIZE_FL 0.09 33 | 34 | /** 35 | When manipulating with sprites, remember, 36 | Sprite 0 - background sprite 37 | Sprite 1 - Actual scroll fill 38 | 39 | Collider 0 - collider of fill 40 | **/ 41 | 42 | class HorizontalScroller: public Scroller 43 | { 44 | private: 45 | 46 | /** Private methods **/ 47 | int useNormalizer(CHANGER change, int diff) override; 48 | 49 | void checkLimits() override; 50 | 51 | int calculateScrollerSize(const int& value, int& totalValue) override; 52 | 53 | void manageScrollerFill(const int& value) override; 54 | 55 | void calculateRatio(const int& totalValue) override; 56 | 57 | void decide() override; 58 | 59 | void initOldPos() override; 60 | 61 | void incScroller() override; 62 | 63 | void decScroller() override; 64 | 65 | void moveOldPos(const PinGUI::Vector2& vect) override; 66 | 67 | //This one is from GUI_Element 68 | void onClick() override; 69 | 70 | int getDiff() override; 71 | 72 | public: 73 | HorizontalScroller(PinGUI::Vector2 pos, int value, bool* update, std::vector>* _ELEMENTS); 74 | ~HorizontalScroller(); 75 | 76 | void createArrows(std::vector>* _ELEMENTS) override; 77 | 78 | void modifyArrowPos() override; 79 | 80 | void reloadScroller(int value, int totalValue) override; 81 | }; 82 | 83 | #endif // HORIZONTALSCROLLER_H 84 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/IconButton.cpp: -------------------------------------------------------------------------------- 1 | #include "IconButton.h" 2 | 3 | /** 4 | 5 | PinGUI 6 | 7 | Copyright (c) 2017 Lubomir Barantal 8 | 9 | This software is provided 'as-is', without any express or implied 10 | warranty. In no event will the authors be held liable for any damages 11 | arising from the use of this software. 12 | 13 | Permission is granted to anyone to use this software for any purpose, 14 | including commercial applications, and to alter it and redistribute it 15 | freely, subject to the following restrictions: 16 | 17 | 1. The origin of this software must not be misrepresented; you must not 18 | claim that you wrote the original software. If you use this software 19 | in a product, an acknowledgment in the product documentation would be 20 | appreciated but is not required. 21 | 2. Altered source versions must be plainly marked as such, and must not be 22 | misrepresented as being the original software. 23 | 3. This notice may not be removed or altered from any source distribution. 24 | 25 | **/ 26 | 27 | IconButton::IconButton() 28 | { 29 | } 30 | 31 | 32 | IconButton::~IconButton() 33 | { 34 | } 35 | 36 | IconButton::IconButton(GUIPos x, GUIPos y, SDL_Surface* iconPictureSurface, PinGUI::basicPointer f): 37 | Button(x, y, f), 38 | _customCollisionSprite(false), 39 | _collisionSprite(nullptr) 40 | { 41 | //Background sprite 42 | addSprite(x, y, SheetManager::getSurface(BOARD)); 43 | 44 | //Now creating the sprite for icon button 45 | addSprite(x, y, iconPictureSurface); 46 | 47 | getSprite(0)->setAlpha(0); 48 | getSprite(0)->setColor(150, 150, 200); 49 | 50 | getSprite(0)->setW(getSprite(1)->getW()); 51 | getSprite(0)->setH(getSprite(1)->getH()); 52 | 53 | addCollider(getSprite(0)->getCollider()); 54 | 55 | getSprite(1)->offsetToRect(*getCollider()); 56 | } 57 | 58 | //With this constructor its possible to set the size of the icon collider to the selected width and height 59 | IconButton::IconButton(GUIPos x, GUIPos y, SDL_Surface* iconSurface, float width, float height, PinGUI::basicPointer f) : 60 | Button(x, y, f), 61 | _customCollisionSprite(false), 62 | _collisionSprite(nullptr) 63 | { 64 | //Background sprite 65 | addSprite(x,y, SheetManager::getSurface(BACKGROUND)); 66 | 67 | //Now creating the sprite for icon button 68 | addSprite(x, y, iconSurface); 69 | 70 | getSprite(0)->setAlpha(0); 71 | getSprite(0)->setColor(150, 150, 200); 72 | 73 | getSprite(0)->setRW(int(width)); 74 | getSprite(0)->setRH(int(height)); 75 | 76 | addCollider(getSprite(0)->getCollider()); 77 | 78 | getSprite(1)->offsetToRect(*getCollider()); 79 | } 80 | 81 | //This functions sets the image of the icon to the selected image 82 | void IconButton::setCollisionSprite(SDL_Surface* iconSurface) 83 | { 84 | if (_collisionSprite) 85 | _collisionSprite.reset(); 86 | 87 | _collisionSprite = std::make_shared(_position,iconSurface); 88 | 89 | _collisionSprite->offsetToRect(*getCollider()); 90 | 91 | _customCollisionSprite = true; 92 | } 93 | 94 | void IconButton::setWritingAvailability(bool state) { 95 | 96 | if (state) { 97 | getSprite()->setAlpha(255); 98 | } 99 | else { 100 | getSprite()->setAlpha(0); 101 | } 102 | } 103 | 104 | void IconButton::turnOffAim() { 105 | 106 | if (_customCollisionSprite) 107 | rotateSprites(); 108 | 109 | GUI_Element::turnOffAim(); 110 | } 111 | 112 | void IconButton::turnOnAim() { 113 | 114 | if (_customCollisionSprite) 115 | rotateSprites(); 116 | 117 | GUI_Element::turnOnAim(); 118 | } 119 | 120 | void IconButton::rotateSprites() { 121 | 122 | std::shared_ptr tmpSprite = _SPRITES[1]; 123 | 124 | _SPRITES[1] = _collisionSprite; 125 | _collisionSprite = tmpSprite; 126 | } 127 | 128 | void IconButton::offsetTo(orientation orient, GUIPos distance) { 129 | 130 | for (std::size_t i = 1; i < _SPRITES.size(); i++) 131 | { 132 | switch (orient) 133 | { 134 | case LEFT: { 135 | _SPRITES[i]->setX(_COLLIDERS[0].rect.getX() + distance); 136 | break; 137 | } 138 | case RIGHT: { 139 | _SPRITES[i]->setX(((_COLLIDERS[0].rect.getX() + _COLLIDERS[0].rect.getW()) - _SPRITES[i]->getW()) - distance); 140 | break; 141 | } 142 | default:break; 143 | } 144 | } 145 | 146 | } -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/IconButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | /** 3 | 4 | PinGUI 5 | 6 | Copyright (c) 2017 Lubomir Barantal 7 | 8 | This software is provided 'as-is', without any express or implied 9 | warranty. In no event will the authors be held liable for any damages 10 | arising from the use of this software. 11 | 12 | Permission is granted to anyone to use this software for any purpose, 13 | including commercial applications, and to alter it and redistribute it 14 | freely, subject to the following restrictions: 15 | 16 | 1. The origin of this software must not be misrepresented; you must not 17 | claim that you wrote the original software. If you use this software 18 | in a product, an acknowledgment in the product documentation would be 19 | appreciated but is not required. 20 | 2. Altered source versions must be plainly marked as such, and must not be 21 | misrepresented as being the original software. 22 | 3. This notice may not be removed or altered from any source distribution. 23 | 24 | **/ 25 | 26 | #include "Button.h" 27 | 28 | class IconButton:public Button 29 | { 30 | protected: 31 | 32 | //If you binded custom collision sprite 33 | bool _customCollisionSprite; 34 | 35 | std::shared_ptr _collisionSprite; 36 | 37 | 38 | /* 39 | Private methods 40 | */ 41 | void rotateSprites(); 42 | public: 43 | IconButton(); 44 | ~IconButton(); 45 | 46 | //Creating the icon with its positions, filePath to its icon picture and a pointer to a void function 47 | IconButton(GUIPos x, GUIPos y, SDL_Surface* iconPictureSurface, PinGUI::basicPointer f); 48 | 49 | //With this constructor its possible to set the size of the icon collider to the selected width and height 50 | IconButton(GUIPos x, GUIPos y, SDL_Surface* iconSurface, float width, float height, PinGUI::basicPointer f); 51 | 52 | //This functions sets the image of the icon to the selected image 53 | void setCollisionSprite(SDL_Surface* iconSurface); 54 | 55 | void setWritingAvailability(bool state) override; 56 | 57 | void turnOffAim() override; 58 | 59 | void turnOnAim() override; 60 | 61 | void offsetTo(orientation orient, GUIPos distance); 62 | }; 63 | 64 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/Image.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "Image.h" 26 | 27 | Image::Image(SDL_Surface* imageSurface , GUIPos x, GUIPos y) 28 | { 29 | _position.x = x; 30 | _position.y = y; 31 | 32 | addSprite(x, y, imageSurface); 33 | 34 | _collidable = false; 35 | } 36 | 37 | Image::Image(SDL_Surface* imageSurface, GUIPos x, GUIPos y, int width, int height){ 38 | 39 | _position.x = x; 40 | _position.y = y; 41 | 42 | addSprite(x, y, imageSurface); 43 | getSprite()->setRH(height); 44 | getSprite()->setRW(width); 45 | 46 | _collidable = false; 47 | } 48 | 49 | void Image::changeImage(SDL_Surface* imageSurface) 50 | { 51 | deleteSprite(0); 52 | addSprite(_position.x, _position.y, imageSurface); 53 | } 54 | 55 | Image::~Image() 56 | { 57 | //dtor 58 | } 59 | 60 | void Image::normalizeElement(const PinGUI::Vector2& vect){ 61 | 62 | //Have to store the oldPosition because the position will be modified in moveTo function 63 | PinGUI::Vector2 oldPosition(_position); 64 | 65 | moveTo(vect); 66 | 67 | //Flip Y 68 | oldPosition.y += getSprite()->getH(); 69 | oldPosition.y *= -1; 70 | 71 | moveElement(oldPosition); 72 | } 73 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/Image.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGE_H 2 | #define IMAGE_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "../GUI_Element.h" 29 | 30 | class Image: public GUI_Element 31 | { 32 | private: 33 | 34 | 35 | public: 36 | Image(SDL_Surface* imageSurface, GUIPos x, GUIPos y); 37 | Image(SDL_Surface* imageSurface, GUIPos x, GUIPos y, int width, int height); 38 | ~Image(); 39 | 40 | void normalizeElement(const PinGUI::Vector2& vect) override; 41 | 42 | void changeImage(SDL_Surface* imageSurface); 43 | }; 44 | 45 | #endif // IMAGE_H 46 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/Scroller.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "Scroller.h" 26 | 27 | 28 | Scroller::Scroller(PinGUI::Vector2 pos, bool* update): 29 | _update(update), 30 | _oldDiff(0) 31 | { 32 | _position = pos; 33 | } 34 | 35 | Scroller::~Scroller() 36 | { 37 | _ARROWS.clear(); 38 | } 39 | 40 | void Scroller::loadScrollMover(int value, int totalValue){ 41 | 42 | int diff = totalValue - value; 43 | 44 | PinGUI::Rect tmpRect; 45 | tmpRect.x = _ARROWS[1]->getSprite()->getX(); 46 | tmpRect.y = _ARROWS[1]->getSprite()->getY(); 47 | 48 | addSprite(tmpRect,SheetManager::getSurface(WINDOW_SCROLLER_FILL)); 49 | manageScrollerFill(calculateScrollerSize(value,totalValue)); 50 | calculateRatio(totalValue - value); 51 | 52 | // In case the realSize was not big enough to load the scroller 53 | if (_ratio>0){ 54 | 55 | addCollider(getSprite(1)->getCollider()); 56 | 57 | initOldPos(); 58 | 59 | _collidable = true; 60 | *_update = true; 61 | 62 | _oldDiff = 0; 63 | } else { 64 | 65 | deleteSprite(1); 66 | ErrorManager::infoLog("Scroller info:","Scroller was unable to load due to small ratio"); 67 | } 68 | } 69 | 70 | void Scroller::hideScroller(){ 71 | 72 | //Need to delete the actual sprite and collider 73 | if (_SPRITES.size()>1) deleteSprite(1); 74 | if (_COLLIDERS.size()>0){ 75 | 76 | deleteCollider(0); 77 | } 78 | 79 | *_update = true; 80 | setShow(false); 81 | } 82 | 83 | void Scroller::setWritingAvailability(bool state){ 84 | 85 | if (_SPRITES.size()>1){ 86 | 87 | if (state){ 88 | getSprite(1)->setColor(200,200,200); 89 | } else { 90 | getSprite(1)->setColor(255,255,255); 91 | } 92 | } 93 | } 94 | 95 | void Scroller::attachScrollerToInput(){ 96 | 97 | if (_SPRITES.size()>1){ 98 | 99 | PinGUI::basicPointer f(boost::bind(&Scroller::checkForWheelMove,this)); 100 | 101 | PinGUI::Input_Manager::setWheeledInfo(getSprite(1),_update,f); 102 | } 103 | } 104 | 105 | void Scroller::checkForWheelMove(){ 106 | 107 | checkLimits(); 108 | decide(); 109 | _COLLIDERS[0] = getSprite(1)->getCollider(); 110 | } 111 | 112 | void Scroller::manipulatingMod(manip_Element manipulatingElement){ 113 | 114 | if (!PinGUI::Input_Manager::isKeyPressed(SDL_BUTTON_LEFT)){ 115 | 116 | endManipulatingMod(manipulatingElement); 117 | checkLimits(); 118 | 119 | } else if (*_update){ 120 | 121 | checkLimits(); 122 | decide(); 123 | } 124 | 125 | _COLLIDERS[0] = getSprite(1)->getCollider(); 126 | } 127 | 128 | bool Scroller::listenForClick(manip_Element manipulatingElement){ 129 | 130 | if (!PinGUI::Input_Manager::hasAlreadyClicked()){ 131 | 132 | if (PinGUI::Input_Manager::isKeyPressed(SDL_BUTTON_LEFT)){ 133 | 134 | PinGUI::Input_Manager::setAlreadyClick(true); 135 | 136 | onClick(); 137 | 138 | manipulatingElement = this; 139 | } 140 | 141 | return true; 142 | } 143 | 144 | return false; 145 | } 146 | 147 | PinGUI::scrollFuncPointer Scroller::getFuncPointer(){ 148 | 149 | return _cameraRoll; 150 | } 151 | 152 | void Scroller::setShow(bool state){ 153 | 154 | _show = state; 155 | for (std::size_t i = 0; i < _ARROWS.size(); i++){ 156 | 157 | _ARROWS[i]->setShow(state); 158 | } 159 | } 160 | 161 | void Scroller::setCamRollFunction(PinGUI::scrollFuncPointer f){ 162 | _cameraRoll = f; 163 | } 164 | 165 | void Scroller::manageFunctionality(){ 166 | 167 | checkLimits(); 168 | 169 | _COLLIDERS[0].rect.y = getSprite(1)->getY(); 170 | _COLLIDERS[0].rect.x = getSprite(1)->getX(); 171 | 172 | decide(); 173 | *_update = true; 174 | } 175 | 176 | void Scroller::moveElement(const PinGUI::Vector2& vect){ 177 | 178 | moveOldPos(vect); 179 | GUI_Element::moveElement(vect); 180 | 181 | for (std::size_t i = 0; i < _ARROWS.size(); i++) 182 | _ARROWS[i]->moveElement(vect); 183 | } 184 | 185 | void Scroller::initNormalizer(const int& totalValue, const int& numOfPixels){ 186 | 187 | _NORMALIZER._PLUS = totalValue - (_ratio * numOfPixels); 188 | _NORMALIZER._MINUS = 0; 189 | 190 | if (_NORMALIZER._PLUS==0) 191 | _NORMALIZER._PLUS++; 192 | 193 | _NORMALIZER._RATIO = numOfPixels/_NORMALIZER._PLUS; 194 | } 195 | 196 | void Scroller::info(){ 197 | std::cout << "Scroller. Address: " << this << std::endl; 198 | } 199 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/Scroller.h: -------------------------------------------------------------------------------- 1 | #ifndef SCROLLER_H 2 | #define SCROLLER_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | #include 28 | 29 | #include "../GUI_Elements/Window_Arrow.h" 30 | 31 | #define WINDOW_SCROLLER_ARROW_MOVEMENT 7 32 | 33 | #define SCROLLING_NORMALIZE 0.3 34 | 35 | struct scrollNormalizer{ 36 | 37 | int _PLUS; 38 | int _MINUS; 39 | int _RATIO; 40 | }; 41 | 42 | class Scroller: public GUI_Element 43 | { 44 | protected: 45 | 46 | //Scroller cooperates with arrows - it needs to keep those pointers somewhere 47 | std::vector> _ARROWS; 48 | 49 | //Bool to alert the changed state 50 | bool* _update; 51 | 52 | //Ratio of camera 53 | int _ratio; 54 | 55 | //Maximum possible scroll 56 | int _max; 57 | 58 | //This will call the camera manipulation function for window 59 | PinGUI::scrollFuncPointer _cameraRoll; 60 | 61 | //Keep track of addition/dec of var 62 | float _oldPos; 63 | 64 | int _oldDiff; 65 | 66 | //NORMALIZER 67 | scrollNormalizer _NORMALIZER; 68 | 69 | /** Private methods **/ 70 | virtual void initNormalizer(const int& totalValue, const int& numOfPixels); 71 | 72 | virtual int useNormalizer(CHANGER change, int diff) { return 0; } 73 | 74 | virtual void createArrows(std::vector>* _ELEMENTS){}; 75 | 76 | virtual void modifyArrowPos(){} ; 77 | 78 | virtual void checkLimits(){}; 79 | 80 | virtual int calculateScrollerSize(const int& value, int& totalValue) { return 0; } 81 | 82 | virtual void manageScrollerFill(const int& value){}; 83 | 84 | virtual void calculateRatio(const int& totalValue){}; 85 | 86 | virtual void decide(){}; 87 | 88 | virtual void initOldPos(){}; 89 | 90 | virtual void incScroller(){}; 91 | 92 | virtual void decScroller(){}; 93 | 94 | virtual void moveOldPos(const PinGUI::Vector2& vect){}; 95 | 96 | virtual int getDiff() { return 0; } 97 | 98 | void manageFunctionality(); 99 | 100 | public: 101 | Scroller(PinGUI::Vector2 pos, bool* update); 102 | virtual ~Scroller() = 0; 103 | 104 | void setShow(bool state) override; 105 | 106 | void setWritingAvailability(bool state) override; 107 | 108 | void moveElement(const PinGUI::Vector2& vect) override; 109 | 110 | void manipulatingMod(manip_Element manipulatingElement) override; 111 | 112 | bool listenForClick(manip_Element manipulatingElement) override; 113 | 114 | void info() override; 115 | 116 | void loadScrollMover(int value, int totalValue); 117 | 118 | virtual void reloadScroller(int value, int totalValue){}; 119 | 120 | void hideScroller(); 121 | 122 | void attachScrollerToInput(); 123 | 124 | void checkForWheelMove(); 125 | 126 | PinGUI::scrollFuncPointer getFuncPointer(); 127 | void setCamRollFunction(PinGUI::scrollFuncPointer f); 128 | }; 129 | 130 | #endif // SCROLLER_H 131 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/VerticalScroller.h: -------------------------------------------------------------------------------- 1 | #ifndef VERTICALSCROLLER_H 2 | #define VERTICALSCROLLER_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | #include 28 | 29 | #include "../GUI_Elements/Scroller.h" 30 | 31 | class VerticalScroller: public Scroller 32 | { 33 | private: 34 | 35 | /** Private methods **/ 36 | int useNormalizer(CHANGER change, int diff) override; 37 | 38 | void checkLimits() override; 39 | 40 | int calculateScrollerSize(const int& value, int& totalValue) override; 41 | 42 | void manageScrollerFill(const int& value) override; 43 | 44 | void calculateRatio(const int& totalValue) override; 45 | 46 | void decide() override; 47 | 48 | void initOldPos() override; 49 | 50 | void incScroller() override; 51 | 52 | void decScroller() override; 53 | 54 | void moveOldPos(const PinGUI::Vector2& vect) override; 55 | 56 | int getDiff() override; 57 | 58 | 59 | //From GUI_Element 60 | void onClick() override; 61 | 62 | 63 | public: 64 | VerticalScroller(PinGUI::Vector2 pos, int value, bool* update, std::vector>* _ELEMENTS); 65 | ~VerticalScroller(); 66 | 67 | void createArrows(std::vector>* _ELEMENTS) override; 68 | 69 | void reloadScroller(int value, int totalValue) override; 70 | }; 71 | 72 | #endif // VERTICALSCROLLER_H 73 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/VolumeBoard.h: -------------------------------------------------------------------------------- 1 | #ifndef VOLUMEBOARD_H 2 | #define VOLUMEBOARD_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "../GUI_Element.h" 29 | #include "../ElementDataStorage.hpp" 30 | 31 | #define VOLUMEBOARD_MOVER_OFFSET 0 32 | #define VOLUMEBOARD_MOVER_OFFSET_Y -1 33 | #define VOLUMEBOARD_BAR_LENGTH 209 34 | 35 | #define VOLUMEBOARD_CLIP_OFFSET_X 220 36 | #define VOLUMEBOARD_CLIP_OFFSET_Y -4 37 | 38 | #define VOLUMEBOARD_MOVER_COLLIDER_X 0 39 | #define VOLUMEBOARD_MOVER_COLLIDER_Y -1 40 | #define VOLUMEBOARD_MOVER_COLLIDER_W 0 41 | #define VOLUMEBOARD_MOVER_COLLIDER_H -1 42 | #define VOLUMEBOARD_FILL_OFFSET 1 43 | 44 | /** 45 | Important: 46 | Sprites : 0 - Background 47 | 1 - Fill 48 | 2 - Mover 49 | **/ 50 | 51 | 52 | enum VOLUME_SPRITE{ 53 | VOL_BACKGROUND, 54 | VOL_FILL, 55 | VOL_MOVER 56 | }; 57 | 58 | class VolumeBoard: public GUI_Element 59 | { 60 | private: 61 | std::shared_ptr _clipBoard; 62 | 63 | dataType _storageType; 64 | 65 | std::shared_ptr _dataStorage; 66 | 67 | int _max; 68 | 69 | float _ratio; 70 | 71 | bool* _needUpdate; 72 | 73 | /** 74 | Private methods 75 | **/ 76 | void init(); 77 | 78 | void calculateRatio(); 79 | 80 | void addMover(PinGUI::Rect& tmpRect); 81 | 82 | void addFill(PinGUI::Rect& tmpRect); 83 | 84 | bool needMove(); 85 | 86 | void moveMover(); 87 | 88 | void moveMover(int distance); 89 | 90 | void checkMover(); 91 | 92 | void calculateFill(const float& distance); 93 | 94 | GUIPos calculatePosition(); 95 | 96 | bool listenForClick(manip_Element manipulatingElement) override; 97 | 98 | void onClick() override; 99 | 100 | void manipulatingMod(manip_Element manipulatingElement) override; 101 | 102 | void modifyVar(); 103 | 104 | void checkForColliderPosition(); 105 | 106 | float getVar(); 107 | 108 | public: 109 | VolumeBoard(PinGUI::Vector2 pos, int* var, int max, std::shared_ptr clip, bool* needUpdate); 110 | VolumeBoard(PinGUI::Vector2 pos, float* var, int max, std::shared_ptr clip, bool* needUpdate); 111 | ~VolumeBoard(); 112 | 113 | void update() override; 114 | 115 | void moveElement(const PinGUI::Vector2& vect) override; 116 | 117 | void cropElement(PinGUI::Rect& rect) override; 118 | 119 | void info() override; 120 | 121 | inline float getDistance(){ 122 | return _SPRITES[VOL_MOVER]->getGUIRect().realRect.getX()-(_SPRITES[VOL_BACKGROUND]->getGUIRect_P()->realRect.x); 123 | } 124 | 125 | }; 126 | 127 | 128 | 129 | #endif // VOLUMEBOARD_H 130 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/WindowButton.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "WindowButton.h" 26 | 27 | WindowButton::WindowButton(GUIPos x, GUIPos y, std::string name, clipboardData data): 28 | Button(x,y,name,data) 29 | { 30 | 31 | } 32 | 33 | WindowButton::WindowButton(GUIPos x, GUIPos y, std::string name, clipboardData data, std::shared_ptr target): 34 | Button(x,y,name,data), 35 | _target(target) 36 | { 37 | //ctor 38 | } 39 | 40 | WindowButton::WindowButton(GUIPos x, GUIPos y, std::string name, clipboardData data, std::shared_ptr target, int maxSize): 41 | Button(x,y,name,data,maxSize), 42 | _target(target) 43 | { 44 | 45 | } 46 | 47 | WindowButton::~WindowButton() 48 | { 49 | } 50 | 51 | void WindowButton::onClick(){ 52 | 53 | if (!_target->getShow()) 54 | { 55 | _target->setShow(true); 56 | } 57 | else 58 | _target->setShow(false); 59 | } 60 | 61 | void WindowButton::setWindowTarget(std::shared_ptr target){ 62 | 63 | _target = target; 64 | } 65 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/WindowButton.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWBUTTON_H 2 | #define WINDOWBUTTON_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "../GUI_Elements/Button.h" 29 | #include "../GUI_Elements/Window.h" 30 | 31 | class WindowButton: public Button 32 | { 33 | private: 34 | 35 | std::shared_ptr _target; 36 | 37 | public: 38 | WindowButton(GUIPos x, GUIPos y, std::string name, clipboardData data); 39 | WindowButton(GUIPos x, GUIPos y, std::string name, clipboardData data, std::shared_ptr target); 40 | WindowButton(GUIPos x, GUIPos y, std::string name, clipboardData data, std::shared_ptr target, int maxSize); 41 | ~WindowButton(); 42 | 43 | void onClick() override; 44 | 45 | void setWindowTarget(std::shared_ptr target); 46 | }; 47 | 48 | #endif // WINDOWBUTTON_H 49 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/WindowExit.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "WindowExit.h" 26 | #include 27 | 28 | WindowExit::WindowExit(PinGUI::Rect positionRect, GUI_Element* windowElement): 29 | _windowElement(windowElement) 30 | { 31 | initPosition(positionRect); 32 | 33 | positionRect.x += positionRect.w + WINDOW_EXIT_X_OFFSET; 34 | positionRect.y -= WINDOW_EXIT_Y_OFFSET; 35 | 36 | //Background sprite 37 | addSprite(positionRect,SheetManager::getSurface(BACKGROUND)); 38 | 39 | getSprite()->setW(WINDOW_EXIT_W_AREA); 40 | getSprite()->setH(WINDOW_EXIT_H_AREA); 41 | 42 | getSprite()->setAlpha(0); 43 | getSprite()->setColor(255,20,20); 44 | 45 | addCollider(getSprite()->getCollider()); 46 | 47 | //Now creating the sprite for the 'X' button 48 | addSprite(positionRect,SheetManager::getSurface(WINDOW_EXITBUTTON)); 49 | 50 | //Also need to offsetTheRect 51 | getSprite(1)->offsetToRect(getSprite()->getCollider()); 52 | } 53 | 54 | WindowExit::~WindowExit() 55 | { 56 | //dtor 57 | } 58 | 59 | void WindowExit::setWritingAvailability(bool state){ 60 | 61 | if (state){ 62 | getSprite()->setAlpha(255); 63 | } else { 64 | getSprite()->setAlpha(0); 65 | } 66 | } 67 | 68 | void WindowExit::onClick(){ 69 | 70 | PinGUI::Input_Manager::turnOnTMPState(); 71 | _windowElement->setShow(false); 72 | } 73 | 74 | void WindowExit::info(){ 75 | std::cout << "WindowExit. Address: " << this << std::endl; 76 | } 77 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/WindowExit.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWEXIT_H 2 | #define WINDOWEXIT_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "../GUI_Element.h" 29 | 30 | /** EXIT BUTTON **/ 31 | #define WINDOW_EXIT_X_OFFSET -15 32 | #define WINDOW_EXIT_Y_OFFSET 12 33 | 34 | #define WINDOW_EXIT_W_AREA 27 35 | #define WINDOW_EXIT_H_AREA 22 36 | 37 | class WindowExit: public GUI_Element 38 | { 39 | private: 40 | GUI_Element* _windowElement; 41 | 42 | public: 43 | WindowExit(PinGUI::Rect positionRect, GUI_Element* windowElement); 44 | ~WindowExit(); 45 | 46 | void onClick() override; 47 | 48 | void setWritingAvailability(bool state) override; 49 | 50 | void info() override; 51 | 52 | }; 53 | 54 | #endif // WINDOWEXIT_H 55 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/WindowMover.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "WindowMover.h" 26 | 27 | WindowMover::WindowMover(PinGUI::Rect tmpRect, bool* windowUpdate) 28 | { 29 | initPosition(tmpRect); 30 | 31 | _windowUpdate = windowUpdate; 32 | 33 | //I add a sprite and a collider, i choose any surface because i want it to have 100% transparency - if you want to change it you need to change the SURFACE by yourself 34 | addSprite(tmpRect,SheetManager::getSurface(BOARD)); 35 | 36 | getSprite()->setW(tmpRect.w); 37 | getSprite()->setH(tmpRect.h); 38 | 39 | addCollider(tmpRect); 40 | 41 | getSprite()->setAlpha(0); 42 | } 43 | 44 | WindowMover::~WindowMover() 45 | { 46 | //dtor 47 | } 48 | 49 | void WindowMover::manipulatingMod(manip_Element manipulatingElement){ 50 | 51 | if (!PinGUI::Input_Manager::isKeyPressed(SDL_BUTTON_LEFT)){ 52 | 53 | endManipulatingMod(manipulatingElement); 54 | optionCollider(); 55 | 56 | return; 57 | } 58 | } 59 | 60 | void WindowMover::onClick(){ 61 | 62 | //Setting the input state 63 | PinGUI::Input_Manager::setInputState(PinGUI::MANIPULATINGMOD); 64 | PinGUI::Input_Manager::setState(PinGUI::GUI); 65 | PinGUI::Input_Manager::createManipulatingModInfo(getSprite()->getX(),getSprite()->getY(),PinGUI::WINDOW_MOVING); 66 | PinGUI::Input_Manager::initManipulation(getSprite(),_windowUpdate); 67 | } 68 | 69 | bool WindowMover::listenForClick(manip_Element manipulatingElement){ 70 | 71 | if (!PinGUI::Input_Manager::hasAlreadyClicked()){ 72 | 73 | if (PinGUI::Input_Manager::isKeyPressed(SDL_BUTTON_LEFT)){ 74 | 75 | PinGUI::Input_Manager::setAlreadyClick(true); 76 | onClick(); 77 | 78 | manipulatingElement = this; 79 | } 80 | return true; 81 | } return false; 82 | } 83 | 84 | void WindowMover::optionCollider(){ 85 | setCollider(getSprite()->getCollider()); 86 | } 87 | 88 | void WindowMover::info(){ 89 | std::cout << "WindowMover element. Address: " << this << std::endl; 90 | } 91 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/WindowMover.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOWMOVER_H 2 | #define WINDOWMOVER_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "../GUI_Element.h" 29 | 30 | /** 31 | This element contains a sprite with transparency at 100% 32 | It is used for moving the window 33 | **/ 34 | 35 | 36 | class WindowMover: public GUI_Element 37 | { 38 | private: 39 | bool* _windowUpdate; 40 | 41 | /** 42 | Private methods 43 | **/ 44 | 45 | void optionCollider(); 46 | 47 | public: 48 | WindowMover(PinGUI::Rect tmpRect, bool* windowUpdate); 49 | ~WindowMover(); 50 | 51 | void onClick() override; 52 | 53 | void manipulatingMod(manip_Element manipulatingElement) override; 54 | 55 | bool listenForClick(manip_Element manipulatingElement) override ; 56 | 57 | void info() override; 58 | 59 | void modifyWindow(); 60 | }; 61 | 62 | #endif // WINDOWMOVER_H 63 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/WindowTab.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "WindowTab.h" 26 | 27 | WindowTab::WindowTab(PinGUI::Rect positionRect,std::shared_ptr* mainTab, bool* tabChange): 28 | _tabChange(tabChange), 29 | _mainTab(mainTab) 30 | { 31 | initPosition(positionRect); 32 | 33 | _guiManager = std::make_shared(); 34 | 35 | initSprites(positionRect); 36 | } 37 | 38 | WindowTab::~WindowTab() 39 | { 40 | } 41 | 42 | void WindowTab::initSprites(PinGUI::Rect& positionRect){ 43 | 44 | addSprite(positionRect,SheetManager::createWindowTab(positionRect.w,positionRect.h)); 45 | getSprite()->setAlpha(DEFAULT_WINDOWTAB_ALPHA); 46 | 47 | addCollider(positionRect); 48 | } 49 | 50 | std::shared_ptr WindowTab::getGUI(){ 51 | return _guiManager; 52 | } 53 | 54 | void WindowTab::render(){ 55 | _guiManager->render(); 56 | } 57 | 58 | void WindowTab::setWritingAvailability(bool state){ 59 | 60 | if (*_mainTab != shared_from_this() ){ 61 | 62 | if (state){ 63 | 64 | getSprite()->setColor(235,235,235); 65 | getSprite()->setAlpha(ON_COLLIDE_WINDOWTAB_ALPHA); 66 | } else { 67 | 68 | getSprite()->changeColor(GUI_ColorManager::getColor(CLIPBOARD_NCOLOR)); 69 | getSprite()->setAlpha(DEFAULT_WINDOWTAB_ALPHA); 70 | } 71 | } else { 72 | 73 | getSprite()->setColor(0,235,0); 74 | getSprite()->setAlpha(CHOOSED_WINDOWTAP_ALPHA); 75 | } 76 | 77 | } 78 | 79 | void WindowTab::onClick(){ 80 | 81 | //Setting the old mainTab to collidable state 82 | (*_mainTab)->setCollidable(true); 83 | 84 | (*_mainTab)->getSprite()->setAlpha(0); 85 | 86 | //Rollback the tab camera(if needed) - and do some additional stuff..... 87 | WindowTab::_function.exec(); 88 | 89 | //Now need to setup this tab as the main 90 | *_mainTab = std::dynamic_pointer_cast(shared_from_this()); 91 | 92 | //Allerting the window to update itself 93 | *_tabChange = true; 94 | 95 | //No longer collidable 96 | setCollidable(false); 97 | } 98 | 99 | bool WindowTab::listenForClick(manip_Element manipulatingElement){ 100 | 101 | if (!PinGUI::Input_Manager::hasAlreadyClicked()){ 102 | 103 | if (PinGUI::Input_Manager::clicked(SDL_BUTTON_LEFT)){ 104 | 105 | WindowTab::onClick(); 106 | return true; 107 | } 108 | return false; 109 | } 110 | return false; 111 | } 112 | 113 | void WindowTab::setTabText(std::shared_ptr text){ 114 | _tabText = text; 115 | } 116 | 117 | 118 | void WindowTab::info(){ 119 | std::cout << "WindowMover element. Address: " << this << std::endl; 120 | } 121 | 122 | void WindowTab::setMainTab(std::shared_ptr* mainTab){ 123 | _mainTab = mainTab; 124 | } 125 | 126 | void WindowTab::setTabDimensions(PinGUI::Rect& rect){ 127 | _tabDimensions.x = rect.w; 128 | _tabDimensions.y = rect.h; 129 | } 130 | 131 | void WindowTab::setTabDimensions(PinGUI::Vector2 dims){ 132 | _tabDimensions.x = dims.x; 133 | _tabDimensions.y = dims.y; 134 | } 135 | 136 | void WindowTab::setTabHeight(int height){ 137 | _tabDimensions.y = height; 138 | } 139 | 140 | void WindowTab::setTabWidth(int width){ 141 | _tabDimensions.x = width; 142 | } 143 | 144 | PinGUI::Vector2 WindowTab::getTabDimensions(){ 145 | return _tabDimensions; 146 | } 147 | 148 | void WindowTab::setRollBackFunction(PinGUI::basicPointer Function){ 149 | _function = Function; 150 | } 151 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/WindowTab.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/PinGUI/GUI_Elements/WindowTab.h -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/Window_Arrow.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "Window_Arrow.h" 26 | 27 | Window_Arrow::Window_Arrow(PinGUI::Rect tmpRect,SDL_Surface* surface,orientation orient, arrowCollider colliderType): 28 | _arrowCollider(colliderType) 29 | { 30 | initPosition(tmpRect); 31 | 32 | _collidable = true; 33 | 34 | _networkedElement = true; 35 | 36 | //The background 37 | if (colliderType==WHOLE_RECT) addSprite(tmpRect,surface); 38 | 39 | //Arrow surface 40 | addSprite(tmpRect,chooseRightDirect(orient)); 41 | 42 | createCollider(tmpRect,colliderType,orient); 43 | 44 | if ((orient == UP || orient == DOWN)&& colliderType==WHOLE_RECT) 45 | getSprite(-1)->setY(getSprite(-1)->getY()-BASIC_ARROW_Y_OFFSET); 46 | } 47 | 48 | 49 | Window_Arrow::~Window_Arrow() 50 | { 51 | //dtor 52 | } 53 | 54 | void Window_Arrow::createCollider(PinGUI::Rect& tmpRect, arrowCollider& colliderType, orientation& orient){ 55 | 56 | switch(colliderType){ 57 | 58 | case WHOLE_RECT : { 59 | 60 | getSprite(-1)->offsetToRect(tmpRect); 61 | setUpBackgroundSprite(tmpRect); 62 | break; 63 | } 64 | case ARROW_ONLY : { 65 | 66 | tmpRect.y += 1; 67 | if (orient==UP || orient==DOWN) { 68 | tmpRect.w = PINGUI_WINDOW_SCROLLER_ARROW_UPDOWN_W; 69 | tmpRect.h = PINGUI_WINDOW_SCROLLER_ARROW_UPDOWN_H-1; 70 | } else { 71 | tmpRect.w = PINGUI_WINDOW_SCROLLER_ARROW_SIDE_W; 72 | tmpRect.h = PINGUI_WINDOW_SCROLLER_ARROW_SIDE_H-1; 73 | } 74 | break; 75 | } 76 | } 77 | addCollider(tmpRect); 78 | } 79 | 80 | SDL_Surface* Window_Arrow::chooseRightDirect(orientation& orient){ 81 | 82 | switch(orient){ 83 | 84 | case UP : return SheetManager::getSurface(WINDOW_ARROW_UP); 85 | case DOWN : return SheetManager::getSurface(WINDOW_ARROW_DOWN); 86 | case LEFT : return SheetManager::getSurface(WINDOW_ARROW_LEFT); 87 | case RIGHT : return SheetManager::getSurface(WINDOW_ARROW_RIGHT); 88 | } 89 | 90 | return nullptr; 91 | } 92 | 93 | void Window_Arrow::setUpBackgroundSprite(const PinGUI::Rect& tmpRect){ 94 | 95 | getSprite()->setX(tmpRect.x); 96 | getSprite()->setY(tmpRect.y); 97 | getSprite()->setW(tmpRect.w); 98 | getSprite()->setH(tmpRect.h); 99 | getSprite()->setColor(40,40,40); 100 | getSprite()->setAlpha(0); 101 | } 102 | 103 | void Window_Arrow::setWritingAvailability(bool state){ 104 | 105 | if (_arrowCollider==WHOLE_RECT) highlightRect(state); 106 | else highlightArrow(state); 107 | } 108 | 109 | void Window_Arrow::highlightRect(const bool& state){ 110 | 111 | if (state){ 112 | getSprite()->setAlpha(255); 113 | } else { 114 | getSprite()->setAlpha(0); 115 | } 116 | } 117 | 118 | void Window_Arrow::highlightArrow(const bool& state){ 119 | 120 | if (state){ 121 | getSprite()->setColor(100,100,150); 122 | } else { 123 | getSprite()->setColor(255,255,255); 124 | } 125 | } 126 | 127 | void Window_Arrow::setClickFunction(PinGUI::basicPointer method){ 128 | _clFunction = method; 129 | } 130 | 131 | void Window_Arrow::onClick(){ 132 | _clFunction.exec(); 133 | } 134 | -------------------------------------------------------------------------------- /PinGUI/GUI_Elements/Window_Arrow.h: -------------------------------------------------------------------------------- 1 | #ifndef WINDOW_ARROW_H 2 | #define WINDOW_ARROW_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "../GUI_Element.h" 29 | 30 | #define BASIC_ARROW_Y_OFFSET 2 31 | 32 | #define WINDOW_ARROW_WIDTH 11 33 | #define WINDOW_ARROW_HEIGHT 11 34 | 35 | enum arrowCollider{ 36 | WHOLE_RECT, 37 | ARROW_ONLY 38 | }; 39 | 40 | class Window_Arrow: public GUI_Element 41 | { 42 | private: 43 | 44 | //Collider type 45 | arrowCollider _arrowCollider; 46 | 47 | //Callback function that is called onClick 48 | PinGUI::basicPointer _clFunction; 49 | 50 | /** 51 | Private methods 52 | **/ 53 | SDL_Surface* chooseRightDirect(orientation& orient); 54 | 55 | void setUpBackgroundSprite(const PinGUI::Rect& tmpRect); 56 | 57 | void highlightRect(const bool& state); 58 | 59 | void highlightArrow(const bool& state); 60 | 61 | void createCollider(PinGUI::Rect& tmpRect, arrowCollider& colliderType, orientation& orient); 62 | 63 | public: 64 | Window_Arrow(PinGUI::Rect tmpRect, SDL_Surface* surface, orientation orient, arrowCollider colliderType = WHOLE_RECT); 65 | ~Window_Arrow(); 66 | 67 | void setWritingAvailability(bool state) override; 68 | 69 | void onClick() override; 70 | 71 | void setClickFunction(PinGUI::basicPointer method); 72 | 73 | }; 74 | 75 | #endif // WINDOW_ARROW_H 76 | -------------------------------------------------------------------------------- /PinGUI/GUI_Sprite.h: -------------------------------------------------------------------------------- 1 | #ifndef GUI_SPRITE_H 2 | #define GUI_SPRITE_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "ErrorManager.h" 35 | #include "stuff.h" 36 | #include "PinGUI_Vector.hpp" 37 | #include "PinGUI_Rect.hpp" 38 | 39 | typedef float GUIPos; 40 | 41 | enum vertexPoint{ 42 | topLeft, 43 | topRight, 44 | bottomLeft, 45 | bottomRight 46 | }; 47 | 48 | enum VBO_UV_UPDATE_MODE{ 49 | U, 50 | V, 51 | UV 52 | }; 53 | 54 | class GUI_Sprite 55 | { 56 | private: 57 | 58 | GUIRect _rect; 59 | 60 | SDL_Color _color; 61 | 62 | GLuint _textureID; 63 | 64 | vboData _dataPointer; 65 | 66 | /** 67 | Private methods 68 | **/ 69 | void createTexture(SDL_Surface* surface); 70 | void loadTextSprite(const std::string& text, textInfo*& info); 71 | 72 | void initColor(); 73 | 74 | public: 75 | /** Constructors for normal sprites **/ 76 | GUI_Sprite(PinGUI::Rect rect,SDL_Surface* source); 77 | GUI_Sprite(PinGUI::Vector2 pos, SDL_Surface* source); 78 | GUI_Sprite(PinGUI::Rect rect,SDL_Surface* source,SDL_Color color); 79 | 80 | /** Constructors for Text sprites - initialized using SDL_TTF **/ 81 | GUI_Sprite(const std::string& text, PinGUI::Vector2 pos,textInfo* info); 82 | GUI_Sprite(const std::string& text,textInfo* info); 83 | 84 | ~GUI_Sprite(); 85 | 86 | void createVBO(VBO_UV_UPDATE_MODE mode = UV); 87 | 88 | void updateColors(); 89 | 90 | void updatePositions(); 91 | 92 | void updateUVs(); 93 | 94 | void updateVerticalUVs(); 95 | 96 | void updateHorizontalUVs(); 97 | 98 | void changeTexture(SDL_Surface* surface); 99 | 100 | void moveSprite(const PinGUI::Vector2& vect); 101 | 102 | void offsetToRect(PinGUI::Rect offsetRect); 103 | 104 | /** 105 | Getters and setters 106 | **/ 107 | 108 | GLuint getTexture(){return _textureID;} 109 | 110 | PinGUI::Rect getCollider(){return _rect.rect;} 111 | 112 | GUIRect getGUIRect(); 113 | 114 | GUIRect* getGUIRect_P(); 115 | 116 | void addDimensions(int w, int h); 117 | 118 | void setColor(Uint8 R, Uint8 G, Uint8 B); 119 | 120 | void setPos(PinGUI::Vector2 pos); 121 | 122 | float getX(); 123 | void setX(float x); 124 | 125 | float getY(); 126 | void setY(float y); 127 | 128 | int getW(){return _rect.rect.w;} 129 | void setW(int newW); 130 | void decW(int num); 131 | void incW(int num); 132 | 133 | int getH(){return _rect.rect.h;} 134 | void setH(int newH); 135 | void decH(int num); 136 | 137 | void setRH(int rh); 138 | void setRW(int rw); 139 | 140 | void changeColor(SDL_Color tmp); 141 | void setAlpha(int value); 142 | 143 | vboData* getVBOData(); 144 | void setRect(PinGUI::Rect rect); 145 | }; 146 | 147 | #endif // GUI_SPRITE_H 148 | -------------------------------------------------------------------------------- /PinGUI/IntegerDataStorage.hpp: -------------------------------------------------------------------------------- 1 | #ifndef INTEGERDATASTORAGE_HPP 2 | #define INTEGERDATASTORAGE_HPP 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | class IntegerDataStorage 29 | { 30 | private: 31 | int* _var; 32 | int _last_var; 33 | 34 | public: 35 | IntegerDataStorage(): 36 | _var(nullptr), 37 | _last_var(0) 38 | { 39 | } 40 | 41 | IntegerDataStorage(int* var): 42 | _var(var), 43 | _last_var(*var) 44 | { 45 | } 46 | 47 | ~IntegerDataStorage(){}; 48 | 49 | void init(int* var){ 50 | _var = var; 51 | _last_var = *var; 52 | } 53 | 54 | void equalVar(){ 55 | 56 | _last_var = *_var; 57 | } 58 | 59 | bool changed(){ 60 | 61 | if (_last_var != *_var){ 62 | 63 | _last_var = *_var; 64 | return true; 65 | 66 | } return false; 67 | } 68 | 69 | int getVar(){ 70 | return *_var; 71 | } 72 | 73 | int getLastVar(){ 74 | return _last_var; 75 | } 76 | 77 | int* getVar_P(){ 78 | return _var; 79 | } 80 | }; 81 | 82 | #endif // INTEGERDATASTORAGE_HPP 83 | -------------------------------------------------------------------------------- /PinGUI/PINGUI.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/PinGUI/PINGUI.cpp -------------------------------------------------------------------------------- /PinGUI/PINGUI.h: -------------------------------------------------------------------------------- 1 | #ifndef PINGUI_H 2 | #define PINGUI_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | #include 28 | #include 29 | 30 | #include "GUI_Elements/Window.h" 31 | #include "GUI_Elements/WindowButton.h" 32 | #include "../PinGUI/Shader_Program.h" 33 | 34 | #define WINDOW_STORAGE_SIZE 200 35 | 36 | /** 37 | The main singleton for whole library 38 | **/ 39 | 40 | typedef std::vector> windowVector; 41 | 42 | class PINGUI 43 | { 44 | private: 45 | 46 | static windowVector _ACTIVE_WINDOWS; 47 | 48 | static windowVector _NON_ACTIVE_WINDOWS; 49 | 50 | static std::shared_ptr _mainWindow; 51 | 52 | static std::shared_ptr _collidingWindow; 53 | 54 | static std::shared_ptr _mainGUIManager; 55 | 56 | /** Private methods **/ 57 | 58 | static void checkActiveWindows(); 59 | 60 | static void initStorage(); 61 | 62 | static bool collide(std::shared_ptr win); 63 | 64 | static std::shared_ptr findWindow(const windowVector& vector, const std::string& winName); 65 | 66 | public: 67 | 68 | static std::shared_ptr window; 69 | 70 | static std::shared_ptr winTab; 71 | 72 | static std::shared_ptr GUI; 73 | 74 | static std::shared_ptr TEXT; 75 | 76 | //Functions 77 | 78 | static void initLibrary(int screenWidth, int screenHeight); 79 | 80 | static void normalize(); 81 | 82 | static void processInput(SDL_Event* event = nullptr); 83 | 84 | static void destroy(); 85 | 86 | static void addWindow(std::shared_ptr win, bool showAtCreation = true); 87 | 88 | static void destroyWindow(std::shared_ptr win); 89 | 90 | //Creating a window that is not manager by PINGUI but by other GUI elements(in case that its a part of a element) 91 | static std::shared_ptr createSubWindow(windowDef* def); 92 | 93 | static void createWindow(windowDef* winDef, bool showAtCreation = true); 94 | 95 | static void render(); 96 | 97 | static void update(); 98 | 99 | static void setMainWindow(std::shared_ptr win); 100 | 101 | static int getSizeOfActiveWindows(); 102 | 103 | static void checkMainWindow(); 104 | 105 | static std::shared_ptr getGUI(); 106 | 107 | static PinGUI::basicPointer getFunctionPointer(); 108 | 109 | //Setting the tab target 110 | static void bindTab(std::shared_ptr tab); 111 | 112 | //Setting the tab target via its name 113 | static void bindTab(const std::string& tabName); 114 | 115 | //Binding the window via its name tag 116 | static void bindWindow(const std::string& windowName); 117 | 118 | //Getting just the window ptr 119 | static std::shared_ptr getWindow(const std::string& windowName); 120 | 121 | //Initializing the GUI and TEXT 122 | static void bindGUI(std::shared_ptr win); 123 | static void bindGUI(std::shared_ptr tab); 124 | static void bindGUI(std::shared_ptr gui); 125 | 126 | //Set the GUIManager and TextManager to the default 127 | static void resetGUI(); 128 | }; 129 | 130 | #endif // PINGUI_H 131 | -------------------------------------------------------------------------------- /PinGUI/PinGUI_Vector.hpp: -------------------------------------------------------------------------------- 1 | #ifndef PINGUI_VECTOR_HPP 2 | #define PINGUI_VECTOR_HPP 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | 30 | //In case you use also vector objects from other libraries 31 | namespace PinGUI{ 32 | 33 | template class Vector2{ 34 | public : 35 | //Default variables, x and y 36 | dataType x; 37 | dataType y; 38 | 39 | //Default constructor and destructor 40 | // 0.0 default positions to avoid some problems with random allocations 41 | Vector2(){ 42 | this->x = 0; 43 | this->y = 0; 44 | }; 45 | ~Vector2(){}; 46 | 47 | //Constructor for setting the types at creation 48 | Vector2(dataType X, dataType Y): 49 | x(X), 50 | y(Y) 51 | { 52 | } 53 | 54 | //Overloaded operator = 55 | Vector2& operator=(const Vector2& sourceVect){ 56 | this->x = sourceVect.x; 57 | this->y = sourceVect.y; 58 | 59 | return *this; 60 | } 61 | 62 | //Overloaded operator * ( for example : for timestep use) 63 | Vector2& operator*(const float& num){ 64 | this->x *= num; 65 | this->y *= num; 66 | return *this; 67 | } 68 | 69 | //Overloaded operator += 70 | Vector2& operator+=(const Vector2& sourceVect){ 71 | this->x += sourceVect.x; 72 | this->y += sourceVect.y; 73 | 74 | return *this; 75 | } 76 | 77 | Vector2& operator*=(const Vector2& sourceVect){ 78 | this->x *= sourceVect.x; 79 | this->y *= sourceVect.y; 80 | 81 | return *this; 82 | } 83 | 84 | Vector2& operator-=(const Vector2& sourceVect){ 85 | this->x -= sourceVect.x; 86 | this->y -= sourceVect.y; 87 | 88 | return *this; 89 | } 90 | 91 | //Overloaded operator >= 92 | bool operator>=(const Vector2& sourceVect){ 93 | 94 | if (this->x >= sourceVect.x && this->y>= sourceVect.y) return true; 95 | return false; 96 | } 97 | 98 | 99 | //Operators == and != 100 | bool operator==(const Vector2& sourceVect){ 101 | if (this->x==sourceVect.x && this->y==sourceVect.y) return true; 102 | return false; 103 | } 104 | 105 | bool operator!=(const Vector2& sourceVect){ 106 | if (this->x!=sourceVect.x || this->y!=sourceVect.y) return true; 107 | return false; 108 | } 109 | 110 | void clearVector(){ 111 | this->x = 0; 112 | this->y = 0; 113 | } 114 | 115 | void info(){ 116 | std::cout << "Vector info: X: " << this->x << " Y: " << this->y << std::endl; 117 | } 118 | }; 119 | } 120 | 121 | #endif // PINGUI_VECTOR_HPP 122 | -------------------------------------------------------------------------------- /PinGUI/Shader_Program.cpp: -------------------------------------------------------------------------------- 1 | #include "Shader_Program.h" 2 | 3 | /** 4 | 5 | PinGUI 6 | 7 | Copyright (c) 2017 Lubomir Barantal 8 | 9 | This software is provided 'as-is', without any express or implied 10 | warranty. In no event will the authors be held liable for any damages 11 | arising from the use of this software. 12 | 13 | Permission is granted to anyone to use this software for any purpose, 14 | including commercial applications, and to alter it and redistribute it 15 | freely, subject to the following restrictions: 16 | 17 | 1. The origin of this software must not be misrepresented; you must not 18 | claim that you wrote the original software. If you use this software 19 | in a product, an acknowledgment in the product documentation would be 20 | appreciated but is not required. 21 | 2. Altered source versions must be plainly marked as such, and must not be 22 | misrepresented as being the original software. 23 | 3. This notice may not be removed or altered from any source distribution. 24 | 25 | **/ 26 | 27 | namespace PinGUI{ 28 | 29 | int Shader_Program::_attributes = 0; 30 | 31 | GLuint Shader_Program::_programID = 0; 32 | 33 | GLuint Shader_Program::_vertexShaderID = 0; 34 | 35 | GLuint Shader_Program::_fragmentShaderID = 0; 36 | 37 | GLint Shader_Program::_samplerLocation = 0; 38 | 39 | void Shader_Program::initShaders(){ 40 | 41 | // Compile our color shader 42 | compileShaders("PinGUI/Shaders/vertexShader.txt", "PinGUI/Shaders/fragmentShader.txt"); 43 | 44 | //Now add variables 45 | addAttribute("vertexPosition"); 46 | addAttribute("vertexColor"); 47 | addAttribute("vertexUV"); 48 | addAttribute("instancePos"); 49 | 50 | //Link the shaders 51 | linkShaders(); 52 | 53 | PinGUI::CameraManager::setMatrixLocation(PROJECTION,Shader_Program::getUniformLocation("P")); 54 | 55 | _samplerLocation = Shader_Program::getUniformLocation("sampler"); 56 | } 57 | 58 | void Shader_Program::compileShaders(const std::string& vertexShaderFilePath,const std::string& fragmentShaderFilePath){ 59 | 60 | _vertexShaderID = glCreateShader(GL_VERTEX_SHADER); 61 | if (_vertexShaderID==0){ 62 | ErrorManager::systemError("_vertexShader creation fail"); 63 | } 64 | 65 | _fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER); 66 | if (_fragmentShaderID==0){ 67 | ErrorManager::systemError("_fragmentShader creation fail"); 68 | } 69 | _programID = glCreateProgram(); 70 | 71 | compileShader(vertexShaderFilePath,_vertexShaderID); 72 | compileShader(fragmentShaderFilePath,_fragmentShaderID); 73 | 74 | } 75 | 76 | void Shader_Program::compileShader(const std::string& filePath,GLuint id){ 77 | 78 | std::ifstream vertexFile(filePath); 79 | 80 | if (vertexFile.fail()){ 81 | ErrorManager::fileError(filePath); 82 | } 83 | 84 | std::string fileContent = ""; 85 | std::string line; 86 | 87 | while(std::getline(vertexFile,line)){ 88 | fileContent += line + "\n"; 89 | } 90 | 91 | vertexFile.close(); 92 | 93 | const char* contentsPtr = fileContent.c_str(); 94 | glShaderSource(id,1,&contentsPtr,nullptr); 95 | 96 | glCompileShader(id); 97 | 98 | GLint success = 0; 99 | glGetShaderiv(id,GL_COMPILE_STATUS,&success); 100 | 101 | if (success == GL_FALSE){ 102 | GLint maxLength = 0; 103 | glGetShaderiv(id, GL_INFO_LOG_LENGTH, &maxLength); 104 | 105 | // The maxLength includes the NULL character 106 | std::vector errorLog(maxLength); 107 | glGetShaderInfoLog(id, maxLength, &maxLength, &errorLog[0]); 108 | 109 | glDeleteShader(id); 110 | 111 | ErrorManager::systemError( &(errorLog[0])); 112 | } 113 | } 114 | 115 | void Shader_Program::linkShaders(){ 116 | 117 | //Attach shaders to program 118 | glAttachShader(_programID, _vertexShaderID); 119 | glAttachShader(_programID, _fragmentShaderID); 120 | 121 | //Link our program 122 | glLinkProgram(_programID); 123 | 124 | GLint isLinked = 0; 125 | glGetProgramiv(_programID, GL_LINK_STATUS, (int *)&isLinked); 126 | 127 | //In case of fail 128 | if(isLinked == GL_FALSE) 129 | { 130 | GLint maxLength = 0; 131 | glGetProgramiv(_programID, GL_INFO_LOG_LENGTH, &maxLength); 132 | 133 | std::vector infoLog(maxLength); 134 | glGetProgramInfoLog(_programID, maxLength, &maxLength, &infoLog[0]); 135 | 136 | //Delete program 137 | glDeleteProgram(_programID); 138 | 139 | //Delete shaders 140 | glDeleteShader(_vertexShaderID); 141 | glDeleteShader(_fragmentShaderID); 142 | ErrorManager::systemError(&(infoLog[0])); 143 | } 144 | 145 | //Always detach shaders after a successful link. 146 | glDetachShader(_programID, _vertexShaderID); 147 | glDetachShader(_programID, _fragmentShaderID); 148 | glDeleteShader(_vertexShaderID); 149 | glDeleteShader(_fragmentShaderID); 150 | } 151 | 152 | void Shader_Program::addAttribute(const std::string& attributeName){ 153 | glBindAttribLocation(_programID,_attributes++,attributeName.c_str()); 154 | } 155 | 156 | void Shader_Program::use(){ 157 | 158 | glUseProgram(_programID); 159 | 160 | for (int i=0;i<_attributes;i++){ 161 | glEnableVertexAttribArray(i); 162 | } 163 | 164 | glActiveTexture(GL_TEXTURE0); 165 | 166 | glUniform1i(_samplerLocation, 0); 167 | 168 | //Projection matrix 169 | glUniformMatrix4fv(PinGUI::CameraManager::getMatrixLocation(PROJECTION), 1, GL_FALSE, glm::value_ptr(PinGUI::CameraManager::getCameraMatrix())); 170 | 171 | } 172 | 173 | void Shader_Program::unuse(){ 174 | 175 | glUseProgram(0); 176 | 177 | for (int i=0;i<_attributes;i++){ 178 | glDisableVertexAttribArray(i); 179 | } 180 | 181 | //unbind the texture 182 | glBindTexture(GL_TEXTURE_2D, 0); 183 | 184 | } 185 | 186 | GLuint Shader_Program::getUniformLocation(const std::string& uniformName){ 187 | 188 | GLint loc = glGetUniformLocation(_programID,uniformName.c_str()); 189 | 190 | if (loc == GL_INVALID_INDEX){ 191 | ErrorManager::systemError("Uniform failed to load to shader. " + uniformName); 192 | } 193 | else return loc; 194 | 195 | return 0; 196 | } 197 | } 198 | 199 | -------------------------------------------------------------------------------- /PinGUI/Shader_Program.h: -------------------------------------------------------------------------------- 1 | #ifndef SHADER_PROGRAM_H 2 | #define SHADER_PROGRAM_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "ErrorManager.h" 34 | #include "stuff.h" 35 | #include "CameraManager.h" 36 | 37 | namespace PinGUI{ 38 | class Shader_Program 39 | { 40 | private: 41 | 42 | static int _attributes; 43 | 44 | static GLuint _programID; 45 | 46 | static GLuint _vertexShaderID; 47 | 48 | static GLuint _fragmentShaderID; 49 | 50 | static GLint _samplerLocation; 51 | 52 | /** 53 | Private methods 54 | **/ 55 | static void compileShader(const std::string& filePath,GLuint id); 56 | 57 | public: 58 | 59 | static void initShaders(); 60 | 61 | static void compileShaders(const std::string& vertexShaderFilePath,const std::string& fragmentShaderFilePath); 62 | 63 | static void linkShaders(); 64 | 65 | static void addAttribute(const std::string& attributeName); 66 | 67 | static GLuint getUniformLocation(const std::string& uniformName); 68 | 69 | static void use(); 70 | 71 | static void unuse(); 72 | 73 | }; 74 | } 75 | 76 | #endif // SHADER_PROGRAM_H 77 | -------------------------------------------------------------------------------- /PinGUI/Shaders/fragmentShader.txt: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | in vec4 fragmentColor; 4 | in vec2 fragmentUV; 5 | 6 | out vec4 color; 7 | 8 | uniform sampler2D sampler; 9 | 10 | void main(){ 11 | 12 | vec4 textureColor = texture(sampler, fragmentUV); 13 | 14 | color = textureColor * fragmentColor; 15 | } -------------------------------------------------------------------------------- /PinGUI/Shaders/vertexShader.txt: -------------------------------------------------------------------------------- 1 | #version 440 2 | 3 | in vec2 vertexPosition; 4 | in vec4 vertexColor; 5 | in vec2 vertexUV; 6 | 7 | out vec4 fragmentColor; 8 | out vec2 fragmentUV; 9 | 10 | uniform mat4 P; 11 | 12 | void main(){ 13 | gl_Position.xy = (P* vec4(vertexPosition,0.0, 1.0)).xy; 14 | gl_Position.z = 0.0; 15 | gl_Position.w = 1.0; 16 | 17 | fragmentColor = vertexColor; 18 | fragmentUV = vec2(vertexUV.x, 1.0-vertexUV.y); 19 | } -------------------------------------------------------------------------------- /PinGUI/TextManager/AdjustableText.cpp: -------------------------------------------------------------------------------- 1 | #include "AdjustableText.h" 2 | 3 | /** 4 | 5 | PinGUI 6 | 7 | Copyright (c) 2017 Lubomir Barantal 8 | 9 | This software is provided 'as-is', without any express or implied 10 | warranty. In no event will the authors be held liable for any damages 11 | arising from the use of this software. 12 | 13 | Permission is granted to anyone to use this software for any purpose, 14 | including commercial applications, and to alter it and redistribute it 15 | freely, subject to the following restrictions: 16 | 17 | 1. The origin of this software must not be misrepresented; you must not 18 | claim that you wrote the original software. If you use this software 19 | in a product, an acknowledgment in the product documentation would be 20 | appreciated but is not required. 21 | 2. Altered source versions must be plainly marked as such, and must not be 22 | misrepresented as being the original software. 23 | 3. This notice may not be removed or altered from any source distribution. 24 | 25 | **/ 26 | 27 | AdjustableText::AdjustableText(std::string Text, PinGUI::Vector2 pos, textInfo* info, unsigned int Size, unsigned int maxSize): 28 | Text(Text,pos,info), 29 | _realTextSize(Size), 30 | _realText(Text), 31 | _fakeText(Text), 32 | _maxRealTextSize(maxSize) 33 | { 34 | } 35 | 36 | AdjustableText::~AdjustableText() 37 | { 38 | } 39 | 40 | void AdjustableText::addChar(char* ch, bool change) { 41 | 42 | //I have to perform the text checking because the input manager can resolve only the checking for the actual display text 43 | if (_realText.size() + 1 <= _maxRealTextSize) { 44 | 45 | //Perform normal text addition 46 | Text::addChar(ch, change); 47 | 48 | //Add the char to the realText 49 | _realText += *ch; 50 | 51 | //Calling the adjust function 52 | performAdjust(false); 53 | } 54 | 55 | 56 | } 57 | 58 | void AdjustableText::performAdjust(bool remove) { 59 | 60 | if (!remove) { 61 | 62 | //Check whether its longer than expected size or not 63 | if (_realText.size() > _realTextSize) 64 | adjustRealText(calculateAfterLength()); 65 | } 66 | else { 67 | 68 | //Adjust the text even without checking 69 | adjustRealText(calculateAfterLength()); 70 | } 71 | } 72 | 73 | void AdjustableText::adjustRealText(unsigned int afterLength) { 74 | 75 | 76 | //Substring the realText so it fits to our length 77 | _fakeText = _realText.substr(afterLength, _realTextSize); 78 | 79 | //Update the displayed part 80 | text = _fakeText; 81 | 82 | //Set the changed flag to true to alert the textmanager about change 83 | changed = true; 84 | } 85 | 86 | void AdjustableText::endInputManipulation() { 87 | 88 | if (_realText.size() > _realTextSize) { 89 | 90 | _fakeText = text; 91 | 92 | text = _realText.substr(0, _realTextSize); 93 | 94 | addDots(); 95 | 96 | changed = true; 97 | } 98 | } 99 | 100 | void AdjustableText::addDots() 101 | { 102 | for (std::size_t i = 0; i < 3; i++) 103 | text[text.size() - 1 - i] = '.'; 104 | } 105 | 106 | void AdjustableText::startInputManipulation() { 107 | 108 | if (_realText.size() > _realTextSize) { 109 | 110 | text = _fakeText; 111 | 112 | changed = true; 113 | } 114 | } 115 | 116 | void AdjustableText::removeChar() { 117 | 118 | //Check if its necessary to adjust the text 119 | if (_realText.size() <= _realTextSize) { 120 | 121 | //If not perform normal removal 122 | Text::removeChar(); 123 | 124 | //Save also new realText 125 | _realText = text; 126 | } 127 | else { 128 | 129 | //Remove last char 130 | _realText.pop_back(); 131 | 132 | //Call the adjust function 133 | performAdjust(true); 134 | } 135 | } 136 | 137 | void AdjustableText::setRealTextSize(unsigned int size) { 138 | _realTextSize = size; 139 | } 140 | 141 | unsigned int AdjustableText::getMaxRealTextSize() { 142 | return _maxRealTextSize; 143 | } -------------------------------------------------------------------------------- /PinGUI/TextManager/AdjustableText.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /** 4 | 5 | PinGUI 6 | 7 | Copyright (c) 2017 Lubomir Barantal 8 | 9 | This software is provided 'as-is', without any express or implied 10 | warranty. In no event will the authors be held liable for any damages 11 | arising from the use of this software. 12 | 13 | Permission is granted to anyone to use this software for any purpose, 14 | including commercial applications, and to alter it and redistribute it 15 | freely, subject to the following restrictions: 16 | 17 | 1. The origin of this software must not be misrepresented; you must not 18 | claim that you wrote the original software. If you use this software 19 | in a product, an acknowledgment in the product documentation would be 20 | appreciated but is not required. 21 | 2. Altered source versions must be plainly marked as such, and must not be 22 | misrepresented as being the original software. 23 | 3. This notice may not be removed or altered from any source distribution. 24 | 25 | **/ 26 | 27 | #include "Text.h" 28 | 29 | class AdjustableText:public Text 30 | { 31 | private: 32 | std::string _realText; 33 | 34 | std::string _fakeText; 35 | 36 | unsigned int _realTextSize; 37 | 38 | unsigned int _maxRealTextSize; 39 | 40 | /* 41 | Private methods 42 | */ 43 | inline unsigned int calculateAfterLength() { 44 | return unsigned int(_realText.size() - _realTextSize); 45 | } 46 | 47 | void performAdjust(bool remove); 48 | 49 | void adjustRealText(unsigned int afterLength); 50 | 51 | void addDots(); 52 | 53 | public: 54 | AdjustableText(std::string Text, PinGUI::Vector2 pos, textInfo* info, unsigned int Size, unsigned int maxSize); 55 | ~AdjustableText(); 56 | 57 | void addChar(char* ch, bool change = true) override; 58 | 59 | void removeChar() override; 60 | 61 | void endInputManipulation() override; 62 | 63 | void startInputManipulation() override; 64 | 65 | void setRealTextSize(unsigned int size); 66 | 67 | unsigned int getMaxRealTextSize(); 68 | }; 69 | 70 | -------------------------------------------------------------------------------- /PinGUI/TextManager/FloatText.cpp: -------------------------------------------------------------------------------- 1 | #include "FloatText.h" 2 | 3 | /** 4 | 5 | PinGUI 6 | 7 | Copyright (c) 2017 Lubomir Barantal 8 | 9 | This software is provided 'as-is', without any express or implied 10 | warranty. In no event will the authors be held liable for any damages 11 | arising from the use of this software. 12 | 13 | Permission is granted to anyone to use this software for any purpose, 14 | including commercial applications, and to alter it and redistribute it 15 | freely, subject to the following restrictions: 16 | 17 | 1. The origin of this software must not be misrepresented; you must not 18 | claim that you wrote the original software. If you use this software 19 | in a product, an acknowledgment in the product documentation would be 20 | appreciated but is not required. 21 | 2. Altered source versions must be plainly marked as such, and must not be 22 | misrepresented as being the original software. 23 | 3. This notice may not be removed or altered from any source distribution. 24 | 25 | **/ 26 | 27 | #include 28 | #include 29 | 30 | FloatText::FloatText(PinGUI::Vector2 pos, textInfo* info, float* Variable): 31 | _variable(Variable), 32 | _last_var(*Variable), 33 | _tmpInput(false), 34 | _negative(false), 35 | _tmpFloat(EMPTY_TMP_INPUT) 36 | { 37 | _construct.numOfFloatingNums = 0; 38 | _construct.pointNum = 0; 39 | _construct.baseInt = static_cast((*Variable)); 40 | 41 | reloadString(); 42 | 43 | init(text,pos); 44 | 45 | _sprite = std::make_shared(text,pos,info); 46 | } 47 | 48 | FloatText::~FloatText() 49 | { 50 | //dtor 51 | } 52 | 53 | void FloatText::reloadString(){ 54 | 55 | std::stringstream tmpString; 56 | 57 | tmpString << std::fixed << std::setprecision(FLOAT_TEXT_PRECISION) << *_variable; 58 | 59 | text = tmpString.str(); 60 | } 61 | 62 | void FloatText::needUpdate(textInfo* info, bool& update){ 63 | 64 | if ((*_variable != _last_var) || changed){ 65 | 66 | if (_tmpInput) 67 | _tmpFloat = float(std::atof(text.c_str())); 68 | 69 | getNewText(info); 70 | 71 | update = true; 72 | 73 | changed = false; 74 | 75 | return; 76 | } 77 | 78 | checkPositioned(update); 79 | } 80 | 81 | void FloatText::getNewText(textInfo*& info){ 82 | 83 | if (!_tmpInput){ 84 | 85 | if (changed && (_tmpFloat != EMPTY_TMP_INPUT)){ 86 | 87 | *_variable = _tmpFloat; 88 | _tmpFloat = EMPTY_TMP_INPUT; 89 | } 90 | 91 | 92 | _last_var = *_variable; 93 | 94 | reloadString(); 95 | 96 | } else 97 | _tmpInput = false; 98 | 99 | _sprite.reset(); 100 | _sprite = std::make_shared(text,_position,info); 101 | 102 | if (_haveOffsetRect){ 103 | calculateTextPosition(); 104 | } 105 | } 106 | 107 | bool FloatText::findPoint(){ 108 | 109 | reachedPoint = false; 110 | 111 | for (std::size_t i = 0; i < text.size(); i++){ 112 | 113 | if (!reachedPoint){ 114 | if (text[i]=='.'){ 115 | 116 | return true; 117 | } 118 | } 119 | } 120 | 121 | return false; 122 | } 123 | 124 | void FloatText::addChar(char* ch, bool change){ 125 | 126 | if ((text[0]==' ' && text.size()==1) && *ch != '.'){ 127 | 128 | text[0] = *ch; 129 | _tmpInput = true; 130 | changed = change; 131 | 132 | return; 133 | } 134 | 135 | _tmpInput = true; 136 | text += *ch; 137 | 138 | changed = change; 139 | } 140 | 141 | void FloatText::setChar(char ch, int pos){ 142 | 143 | text[pos] = ch; 144 | 145 | *_variable = float(std::atof(text.c_str())); 146 | 147 | changed = true; 148 | } 149 | 150 | void FloatText::removeChar(){ 151 | 152 | if (text.back() == '-' && _negative) 153 | _negative = false; 154 | text.pop_back(); 155 | 156 | if (text.size()==0) 157 | text.push_back(' '); 158 | 159 | _tmpInput = true; 160 | 161 | changed = true; 162 | } 163 | 164 | float FloatText::getVariableNum(){ 165 | return _tmpFloat; 166 | } 167 | 168 | float FloatText::calculateAddition(char*& ch){ 169 | 170 | unsigned int pointNum = 0; 171 | bool point = false; 172 | float divider = 10.0f; 173 | 174 | for (std::size_t i = 0; i < text.size(); i++){ 175 | 176 | if (!point){ 177 | 178 | if (isPoint(&text[i])) 179 | point = true; 180 | 181 | continue; 182 | } else { 183 | 184 | pointNum++; 185 | } 186 | } 187 | 188 | for (std::size_t i = 0; i < pointNum; i++) 189 | divider *= 10.0f; 190 | 191 | if (point){ 192 | 193 | return (getCharNum(ch) / divider); 194 | } else { 195 | 196 | return (((float(std::atof(text.c_str())*10)) + getCharNum(ch)) - float(std::atof(text.c_str()))); 197 | } 198 | } 199 | 200 | bool FloatText::checkCharAddition(char* ch, int& maxValue, int& minValue){ 201 | 202 | findNegative(); 203 | 204 | if (isPoint(ch)){ 205 | 206 | return (!findPoint()); 207 | } 208 | 209 | if (_negative){ 210 | 211 | std::string tmpText(text); 212 | tmpText.push_back(*ch); 213 | 214 | if (std::atof(tmpText.c_str()) < minValue) 215 | return false; 216 | 217 | } else { 218 | 219 | if (((std::atof(text.c_str()) + calculateAddition(ch) ) > maxValue)) 220 | return false; 221 | } 222 | 223 | if (canWritePoint()) 224 | return true; 225 | else return false; 226 | } 227 | 228 | bool FloatText::canWritePoint(){ 229 | 230 | int pointNum = 0; 231 | bool point = false; 232 | 233 | for (std::size_t i = 0; i < text.size(); i++){ 234 | 235 | if (!point){ 236 | 237 | if (isPoint(&text[i])) 238 | point = true; 239 | 240 | continue; 241 | } else { 242 | 243 | pointNum++; 244 | } 245 | } 246 | 247 | pointNum++; 248 | 249 | if ((pointNum <= FLOAT_TEXT_PRECISION)) 250 | return true; 251 | else 252 | return false; 253 | } 254 | 255 | bool FloatText::isPoint(char* ch){ 256 | return (*ch == '.'); 257 | } 258 | 259 | void FloatText::endInputManipulation(){ 260 | 261 | _tmpInput = false; 262 | 263 | changed = true; 264 | } 265 | 266 | void FloatText::turnOnNegative(){ 267 | _negative = true; 268 | } 269 | 270 | void FloatText::findNegative(){ 271 | 272 | if (std::atof(text.c_str())<0) _negative = true; 273 | else _negative = false; 274 | } 275 | -------------------------------------------------------------------------------- /PinGUI/TextManager/FloatText.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOATTEXT_H 2 | #define FLOATTEXT_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | 30 | #include "Text.h" 31 | 32 | #define FLOAT_TEXT_PRECISION 3 33 | 34 | struct floatTextConstruction{ 35 | 36 | int baseInt; 37 | long pointNum; 38 | int numOfFloatingNums; 39 | }; 40 | 41 | class FloatText: public Text 42 | { 43 | private: 44 | 45 | //In case of storing variable data 46 | float* _variable; 47 | 48 | float _last_var; 49 | 50 | bool reachedPoint; 51 | 52 | bool _tmpInput; 53 | 54 | float _tmpFloat; 55 | 56 | floatTextConstruction _construct; 57 | 58 | bool _negative; 59 | 60 | /** 61 | Private methods 62 | **/ 63 | void reloadString(); 64 | 65 | bool findPoint(); 66 | 67 | bool isPoint(char* ch); 68 | 69 | bool canWritePoint(); 70 | 71 | float calculateAddition(char*& ch); 72 | 73 | void findNegative(); 74 | 75 | public: 76 | FloatText(PinGUI::Vector2 pos, textInfo* info, float* Variable); 77 | ~FloatText(); 78 | 79 | void needUpdate(textInfo* info, bool& update) override; 80 | 81 | void getNewText(textInfo*& info) override; 82 | 83 | void addChar(char* ch, bool change = true) override; 84 | 85 | void setChar(char ch, int pos) override; 86 | 87 | void removeChar() override; 88 | 89 | float getVariableNum() override; 90 | 91 | bool checkCharAddition(char* ch, int& maxValue, int& minValue) override; 92 | 93 | void endInputManipulation() override; 94 | 95 | void turnOnNegative() override; 96 | }; 97 | 98 | #endif // FLOATTEXT_H 99 | -------------------------------------------------------------------------------- /PinGUI/TextManager/Fonts/Oswald-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/PinGUI/TextManager/Fonts/Oswald-Light.ttf -------------------------------------------------------------------------------- /PinGUI/TextManager/Images/TextManagerSheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/PinGUI/TextManager/Images/TextManagerSheet.png -------------------------------------------------------------------------------- /PinGUI/TextManager/Images/WindowSheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/PinGUI/TextManager/Images/WindowSheet.png -------------------------------------------------------------------------------- /PinGUI/TextManager/Images/console_settings_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/PinGUI/TextManager/Images/console_settings_icon.png -------------------------------------------------------------------------------- /PinGUI/TextManager/IntegerText.cpp: -------------------------------------------------------------------------------- 1 | #include "IntegerText.h" 2 | 3 | /** 4 | 5 | PinGUI 6 | 7 | Copyright (c) 2017 Lubomir Barantal 8 | 9 | This software is provided 'as-is', without any express or implied 10 | warranty. In no event will the authors be held liable for any damages 11 | arising from the use of this software. 12 | 13 | Permission is granted to anyone to use this software for any purpose, 14 | including commercial applications, and to alter it and redistribute it 15 | freely, subject to the following restrictions: 16 | 17 | 1. The origin of this software must not be misrepresented; you must not 18 | claim that you wrote the original software. If you use this software 19 | in a product, an acknowledgment in the product documentation would be 20 | appreciated but is not required. 21 | 2. Altered source versions must be plainly marked as such, and must not be 22 | misrepresented as being the original software. 23 | 3. This notice may not be removed or altered from any source distribution. 24 | 25 | **/ 26 | 27 | IntegerText::IntegerText(PinGUI::Vector2 pos, textInfo* info, int* Variable): 28 | _variable(Variable), 29 | _last_var(*Variable), 30 | _tmpInteger(EMPTY_TMP_INPUT), 31 | _tmpInput(false), 32 | _negative(false) 33 | { 34 | reloadString(); 35 | 36 | init(text,pos); 37 | 38 | _sprite = std::make_shared(text,pos,info); 39 | } 40 | 41 | IntegerText::~IntegerText() 42 | { 43 | //dtor 44 | } 45 | 46 | void IntegerText::reloadString(){ 47 | 48 | std::stringstream tmpString; 49 | 50 | tmpString << _last_var; 51 | 52 | text = tmpString.str(); 53 | } 54 | 55 | void IntegerText::needUpdate(textInfo* info, bool& update){ 56 | 57 | if ((*_variable != _last_var) || changed){ 58 | 59 | if (_tmpInput) 60 | _tmpInteger = std::atoi(text.c_str()); 61 | 62 | getNewText(info); 63 | 64 | update = true; 65 | 66 | changed = false; 67 | 68 | return; 69 | } 70 | 71 | checkPositioned(update); 72 | } 73 | 74 | void IntegerText::getNewText(textInfo*& info){ 75 | 76 | if (!_tmpInput){ 77 | 78 | if (changed && (_tmpInteger != EMPTY_TMP_INPUT)){ 79 | 80 | *_variable = _tmpInteger; 81 | _tmpInteger = EMPTY_TMP_INPUT; 82 | } 83 | 84 | _last_var = *_variable; 85 | 86 | reloadString(); 87 | 88 | } else 89 | _tmpInput = false; 90 | 91 | _sprite.reset(); 92 | _sprite = std::make_shared(text,_position,info); 93 | 94 | if (_haveOffsetRect){ 95 | calculateTextPosition(); 96 | } 97 | } 98 | 99 | void IntegerText::addChar(char* ch, bool change){ 100 | 101 | if ((text[0]==' ' && text.size()==1)){ 102 | 103 | text[0] = *ch; 104 | _tmpInput = true; 105 | changed = change; 106 | 107 | return; 108 | } 109 | 110 | _tmpInput = true; 111 | text += *ch; 112 | changed = change; 113 | } 114 | 115 | void IntegerText::setChar(char ch, int pos){ 116 | 117 | text[pos] = ch; 118 | 119 | *_variable = std::atoi(text.c_str()); 120 | 121 | changed = true; 122 | } 123 | 124 | void IntegerText::removeChar(){ 125 | 126 | if (text.back() == '-' && _negative) 127 | _negative = false; 128 | 129 | text.pop_back(); 130 | 131 | if (text.size()==0) 132 | text.push_back(' '); 133 | 134 | _tmpInput = true; 135 | 136 | changed = true; 137 | } 138 | 139 | float IntegerText::getVariableNum(){ 140 | return float(_tmpInteger); 141 | } 142 | 143 | bool IntegerText::checkCharAddition(char* ch, int& maxValue, int& minValue){ 144 | 145 | findNegative(); 146 | 147 | if (_negative){ 148 | 149 | std::string tmpText(text); 150 | tmpText.push_back(*ch); 151 | 152 | if (std::atoi(tmpText.c_str()) >= minValue) 153 | return true; 154 | } else { 155 | if ((getVariableNum()*10) + getCharNum(ch) <= maxValue) return true; 156 | } 157 | return false; 158 | } 159 | 160 | void IntegerText::endInputManipulation(){ 161 | 162 | _tmpInput = false; 163 | changed = true; 164 | } 165 | 166 | void IntegerText::turnOnNegative(){ 167 | _negative = true; 168 | } 169 | 170 | void IntegerText::findNegative(){ 171 | 172 | if (std::atof(text.c_str())<0) _negative = true; 173 | else _negative = false; 174 | } 175 | -------------------------------------------------------------------------------- /PinGUI/TextManager/IntegerText.h: -------------------------------------------------------------------------------- 1 | #ifndef INTEGERTEXT_H 2 | #define INTEGERTEXT_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "Text.h" 29 | 30 | class IntegerText: public Text 31 | { 32 | private: 33 | 34 | //In case of storing variable data 35 | int* _variable; 36 | 37 | int _last_var; 38 | 39 | bool _tmpInput; 40 | 41 | int _tmpInteger; 42 | 43 | bool _negative; 44 | 45 | /** 46 | Private methods 47 | **/ 48 | void reloadString(); 49 | 50 | void findNegative(); 51 | 52 | public: 53 | IntegerText(PinGUI::Vector2 pos, textInfo* info, int* Variable); 54 | ~IntegerText(); 55 | 56 | void needUpdate(textInfo* info, bool& update) override; 57 | 58 | void getNewText(textInfo*& info) override; 59 | 60 | void addChar(char* ch, bool change = true) override; 61 | 62 | void setChar(char ch, int pos) override; 63 | 64 | void removeChar() override; 65 | 66 | float getVariableNum() override; 67 | 68 | bool checkCharAddition(char* ch, int& maxValue, int& minValue) override; 69 | 70 | void endInputManipulation() override; 71 | 72 | void turnOnNegative() override; 73 | }; 74 | 75 | #endif // INTEGERTEXT_H 76 | -------------------------------------------------------------------------------- /PinGUI/TextManager/StringText.cpp: -------------------------------------------------------------------------------- 1 | #include "StringText.h" 2 | 3 | /** 4 | 5 | PinGUI 6 | 7 | Copyright (c) 2017 Lubomir Barantal 8 | 9 | This software is provided 'as-is', without any express or implied 10 | warranty. In no event will the authors be held liable for any damages 11 | arising from the use of this software. 12 | 13 | Permission is granted to anyone to use this software for any purpose, 14 | including commercial applications, and to alter it and redistribute it 15 | freely, subject to the following restrictions: 16 | 17 | 1. The origin of this software must not be misrepresented; you must not 18 | claim that you wrote the original software. If you use this software 19 | in a product, an acknowledgment in the product documentation would be 20 | appreciated but is not required. 21 | 2. Altered source versions must be plainly marked as such, and must not be 22 | misrepresented as being the original software. 23 | 3. This notice may not be removed or altered from any source distribution. 24 | 25 | **/ 26 | 27 | StringText::StringText(PinGUI::Vector2 pos, textInfo* info, std::string* Variable): 28 | _variable(Variable) 29 | { 30 | reloadString(); 31 | 32 | init(text,pos); 33 | 34 | _sprite = std::make_shared(text,pos,info); 35 | } 36 | 37 | StringText::~StringText() 38 | { 39 | //dtor 40 | } 41 | 42 | void StringText::reloadString(){ 43 | 44 | std::stringstream tmpString; 45 | 46 | tmpString.str(""); 47 | tmpString << *_variable; 48 | 49 | text = tmpString.str(); 50 | } 51 | 52 | void StringText::needUpdate(textInfo* info, bool& update){ 53 | 54 | if (changed){ 55 | 56 | getNewText(info); 57 | 58 | update = true; 59 | 60 | changed = false; 61 | 62 | return; 63 | } 64 | 65 | checkPositioned(update); 66 | } 67 | 68 | void StringText::getNewText(textInfo*& info){ 69 | 70 | reloadString(); 71 | 72 | _sprite.reset(); 73 | _sprite = std::make_shared(text,_position,info); 74 | 75 | if (_haveOffsetRect){ 76 | calculateTextPosition(); 77 | } 78 | } 79 | 80 | void StringText::addChar(char* ch, bool change){ 81 | 82 | Text::addChar(ch); 83 | 84 | *_variable = text; 85 | 86 | changed = change; 87 | } 88 | 89 | void StringText::setChar(char ch, int pos){ 90 | 91 | Text::setChar(ch,pos); 92 | 93 | *_variable = text; 94 | } 95 | 96 | void StringText::removeChar(){ 97 | 98 | Text::removeChar(); 99 | 100 | *_variable = text; 101 | } 102 | -------------------------------------------------------------------------------- /PinGUI/TextManager/StringText.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGTEXT_H 2 | #define STRINGTEXT_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "Text.h" 29 | 30 | class StringText: public Text 31 | { 32 | private: 33 | 34 | //In case of storing variable data 35 | std::string* _variable; 36 | 37 | /** 38 | Private methods 39 | **/ 40 | void reloadString(); 41 | 42 | public: 43 | StringText(PinGUI::Vector2 pos, textInfo* info, std::string* Variable); 44 | ~StringText(); 45 | 46 | void needUpdate(textInfo* info, bool& update) override; 47 | 48 | void getNewText(textInfo*& info) override; 49 | 50 | void addChar(char* ch, bool change = true) override; 51 | 52 | void setChar(char ch, int pos) override; 53 | 54 | void removeChar() override; 55 | }; 56 | 57 | #endif // STRINGTEXT_H 58 | -------------------------------------------------------------------------------- /PinGUI/TextManager/Text.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXT_H 2 | #define TEXT_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "../GUI_Sprite.h" 33 | 34 | #define EMPTY_TMP_INPUT -1 35 | 36 | class Text 37 | { 38 | protected: 39 | std::shared_ptr _sprite; 40 | 41 | PinGUI::Vector2 _position; 42 | 43 | std::string text; 44 | 45 | bool active; 46 | 47 | bool changed; 48 | 49 | bool positioned; 50 | 51 | bool _networkedText; 52 | 53 | bool _show; 54 | 55 | //In case of offseting to some rect 56 | PinGUI::Rect _offsetRect; 57 | 58 | bool _haveOffsetRect; 59 | 60 | /** 61 | Private methods 62 | **/ 63 | 64 | void checkPositioned(bool& update); 65 | 66 | void init(std::string Text, PinGUI::Vector2 pos); 67 | 68 | float getCharNum(char* ch); 69 | 70 | public: 71 | Text(); 72 | Text(std::string Text, PinGUI::Vector2 pos, textInfo* info); 73 | ~Text(); 74 | 75 | virtual void needUpdate(textInfo* info, bool& update); 76 | 77 | virtual void immediateChange(textInfo* info, bool& update); 78 | 79 | //For creating a new copy 80 | virtual void getNewText(textInfo*& info); 81 | 82 | virtual void addChar(char* ch, bool change = true); 83 | 84 | virtual void setChar(char ch, int pos); 85 | 86 | virtual void removeChar(); 87 | 88 | virtual float getVariableNum() { return 0.0f; } 89 | 90 | virtual bool checkCharAddition(char* ch, int& maxValue, int& minValue) { return true; } 91 | 92 | virtual bool isZero(); 93 | 94 | virtual void endInputManipulation(){}; 95 | 96 | virtual void startInputManipulation() {}; 97 | 98 | virtual void turnOnNegative() {}; 99 | 100 | void normalizeText(const PinGUI::Vector2& vect); 101 | 102 | void moveText(const PinGUI::Vector2& vect, bool croppedMovement = false); 103 | 104 | void moveTo(PinGUI::Vector2 vect); 105 | 106 | void replaceText(const std::string& newText); 107 | 108 | std::shared_ptr getSprite(); 109 | 110 | bool canAcceptNegativeInput(); 111 | 112 | bool isActive(); 113 | 114 | GUIPos getX(); 115 | 116 | GUIPos getY(); 117 | 118 | std::string getString(); 119 | 120 | void setActive(bool state); 121 | 122 | vboData getVBOData(); 123 | 124 | bool isPositioned(); 125 | 126 | PinGUI::Vector2 getPos(); 127 | 128 | PinGUI::Vector2* getPos_P(); 129 | 130 | void setPos(PinGUI::Vector2 setPos); 131 | 132 | void setOffsetRect(PinGUI::Rect offsetRect); 133 | 134 | void calculateTextPosition(); 135 | 136 | bool isNetworked(); 137 | 138 | void setNetworked(bool state); 139 | 140 | int getTextSize(); 141 | 142 | bool isEmpty(); 143 | 144 | bool isChanged(); 145 | 146 | bool getShow(); 147 | 148 | void setShow(bool state); 149 | }; 150 | 151 | #endif // TEXT_H 152 | -------------------------------------------------------------------------------- /PinGUI/TextManager/TextManager.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTMANAGER_H 2 | #define TEXTMANAGER_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | #include "../TextManager/Text.h" 40 | #include "../TextManager/IntegerText.h" 41 | #include "../TextManager/FloatText.h" 42 | #include "../TextManager/StringText.h" 43 | #include "../TextManager/AdjustableText.h" 44 | 45 | #include "../VBO_Manager.h" 46 | #include "../PinGUI_Vector.hpp" 47 | #include "../CropManager.hpp" 48 | #include "../clFunction.hpp" 49 | #include "../CameraManager.h" 50 | 51 | /** 52 | Main class 53 | **/ 54 | class TextManager 55 | { 56 | private: 57 | 58 | //Storage variables 59 | std::vector> _TEXTS; 60 | 61 | std::vector _mainDataStorage; 62 | 63 | std::shared_ptr _textVBOManager; 64 | 65 | //Font stuff 66 | int _fontSize; 67 | 68 | textInfo _mainTextInfo; 69 | 70 | bool _needUpdate; 71 | 72 | bool _moved; 73 | 74 | //Function to be called everytime when i update text ( useful for dynamic cropping ) 75 | PinGUI::basicPointer _function; 76 | 77 | //Font stuff 78 | void loadTextInfo(); 79 | 80 | //Functions for adding new text 81 | void checkForUpdate(); 82 | 83 | void removeData(std::size_t& position); 84 | 85 | /** 86 | Manipulation with VBOs etc. 87 | **/ 88 | void loadVBO(); 89 | 90 | void updateVBOData(); 91 | 92 | public: 93 | TextManager(); 94 | TextManager(const TextManager& txt); 95 | ~TextManager(); 96 | 97 | //For writing text lines 98 | std::shared_ptr writeText(const std::string& text,GUIPos x, GUIPos y); 99 | std::shared_ptr writeText(GUIPos x, GUIPos y, int* var); 100 | std::shared_ptr writeText(GUIPos x, GUIPos y, float* var); 101 | std::shared_ptr writeText(GUIPos x, GUIPos y, std::string* var); 102 | std::shared_ptr writeAdjustableText(const std::string& text, GUIPos x, GUIPos y, unsigned int size, unsigned int maxSize); 103 | 104 | void immediateChangeText(std::shared_ptr text); 105 | 106 | TTF_Font* loadFont(const std::string& fontPath, int size); 107 | 108 | void setColor(GLubyte R, GLubyte G, GLubyte B, GLubyte A); 109 | 110 | void setFontSize(int size); 111 | 112 | void setUpdate(bool state); 113 | 114 | void renderText(); 115 | 116 | void updateText(); 117 | 118 | void cropText(PinGUI::Rect& cropRect); 119 | 120 | void normalizeText(const PinGUI::Vector2& normalizationVector); 121 | 122 | std::vector>* getMainTextStorage(); 123 | 124 | int getFontSize(); 125 | 126 | std::shared_ptr getLastText(); 127 | 128 | void moveTextManager(const PinGUI::Vector2& vect, bool croppedMovement); 129 | 130 | textInfo* getTextInfo(); 131 | 132 | void setFunction(PinGUI::basicPointer f); 133 | }; 134 | 135 | #endif // TEXTMANAGER_H 136 | -------------------------------------------------------------------------------- /PinGUI/TextManager/TextStorage.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "TextStorage.h" 26 | #include 27 | 28 | 29 | TextStorage::TextStorage(std::shared_ptr text): 30 | _additionalStorage(nullptr), 31 | _texter(text) 32 | { 33 | } 34 | 35 | TextStorage::~TextStorage() 36 | { 37 | for (auto&& txt : _TEXTS){ 38 | 39 | txt->setActive(false); 40 | } 41 | 42 | _TEXTS.clear(); 43 | } 44 | 45 | void TextStorage::destroyStorage() 46 | { 47 | for (std::size_t i = 0; i < _TEXTS.size(); i++) 48 | { 49 | _TEXTS[i]->setActive(false); 50 | } 51 | _TEXTS.clear(); 52 | } 53 | 54 | void TextStorage::addAdjustableText(const std::string& text, GUIPos x, GUIPos y, unsigned int size, unsigned int maxSize) { 55 | _TEXTS.push_back(_texter->writeAdjustableText(text, x, y, size, maxSize)); 56 | } 57 | 58 | void TextStorage::addText(const std::string& text, GUIPos x, GUIPos y){ 59 | 60 | _TEXTS.push_back(_texter->writeText(text,x,y)); 61 | } 62 | 63 | void TextStorage::addText(GUIPos x, GUIPos y, int* var){ 64 | _TEXTS.push_back(_texter->writeText(x,y,var)); 65 | } 66 | 67 | void TextStorage::addText(GUIPos x, GUIPos y, float* var){ 68 | _TEXTS.push_back(_texter->writeText(x,y,var)); 69 | } 70 | 71 | void TextStorage::addText(GUIPos x, GUIPos y, std::string* var){ 72 | _TEXTS.push_back(_texter->writeText(x,y,var)); 73 | } 74 | 75 | void TextStorage::destroyText(int position){ 76 | 77 | _TEXTS[position]->setActive(false); 78 | _TEXTS.erase(_TEXTS.begin()+ position); 79 | } 80 | 81 | void TextStorage::addChar(char* ch, int position, PinGUI::writingModInfo& info){ 82 | 83 | switch (*(_additionalStorage->type)){ 84 | case ADJUSTABLE : 85 | case NORMAL : { 86 | 87 | _TEXTS[position]->addChar(ch); 88 | break; 89 | } 90 | case INT_ONLY : { 91 | 92 | handleIntegerInput(ch,position,info); 93 | break; 94 | } 95 | case INT_FLOAT : { 96 | 97 | handleFloatInput(ch,position,info); 98 | break; 99 | } 100 | } 101 | } 102 | 103 | void TextStorage::handleIntegerInput(char*& ch, int& position, PinGUI::writingModInfo& info){ 104 | 105 | if (info.negativeInput && checkNegativeInput(ch,position)){ 106 | _TEXTS[position]->turnOnNegative(); 107 | return; 108 | } 109 | 110 | //In case that the clipboard contains a variable 111 | if ( isdigit(*ch) && _TEXTS[position]->checkCharAddition(ch,info.maxValue,info.minValue) ){ 112 | 113 | _TEXTS[position]->addChar(ch); 114 | 115 | return; 116 | } 117 | } 118 | 119 | void TextStorage::handleFloatInput(char*& ch, int& position, PinGUI::writingModInfo& info){ 120 | 121 | if (info.negativeInput && checkNegativeInput(ch,position)){ 122 | _TEXTS[position]->turnOnNegative(); 123 | return; 124 | } 125 | 126 | //In case that the clipboard contains a variable 127 | if ( isFloatInput(ch) && _TEXTS[position]->checkCharAddition(ch,info.maxValue,info.minValue) ){ 128 | 129 | _TEXTS[position]->addChar(ch); 130 | 131 | return; 132 | } 133 | } 134 | 135 | bool TextStorage::checkNegativeInput(char*& ch, int& position){ 136 | 137 | 138 | if (isNegativeInput(ch)) 139 | if (_TEXTS[position]->canAcceptNegativeInput()){ 140 | 141 | _TEXTS[position]->addChar(ch); 142 | return true; 143 | } 144 | 145 | return false; 146 | } 147 | 148 | bool TextStorage::isFloatInput(char*& ch){ 149 | 150 | if (isdigit(*ch) || (*ch == '.')) return true; 151 | else return false; 152 | } 153 | 154 | bool TextStorage::isNegativeInput(char*& ch){ 155 | 156 | if ((*ch == '-')) return true; 157 | else return false; 158 | } 159 | 160 | void TextStorage::removeChar(int position){ 161 | 162 | _TEXTS[position]->removeChar(); 163 | } 164 | 165 | std::shared_ptr TextStorage::getText(int position){ 166 | 167 | if (_TEXTS.size() > 0) 168 | return _TEXTS[position]; 169 | else 170 | return nullptr; 171 | } 172 | 173 | void TextStorage::setAdditionalInfo(clipboard_type* Type){ 174 | 175 | _additionalStorage = std::make_shared(Type); 176 | } 177 | 178 | std::vector>* TextStorage::getVector(){ 179 | return &_TEXTS; 180 | } 181 | 182 | void TextStorage::setShow(bool state){ 183 | 184 | for (auto&& txt : _TEXTS){ 185 | 186 | txt->setShow(state); 187 | } 188 | } 189 | 190 | std::shared_ptr TextStorage::getTextManager(){ 191 | return _texter; 192 | } 193 | -------------------------------------------------------------------------------- /PinGUI/TextManager/TextStorage.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTSTORAGE_H 2 | #define TEXTSTORAGE_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include "../TextManager/TextManager.h" 29 | #include "../stuff.h" 30 | 31 | class additionalStorage{ 32 | 33 | public: 34 | clipboard_type* type; 35 | 36 | additionalStorage() 37 | { 38 | }; 39 | additionalStorage(clipboard_type* Type): 40 | type(Type) 41 | { 42 | 43 | }; 44 | ~additionalStorage() 45 | { 46 | }; 47 | }; 48 | 49 | class TextStorage 50 | { 51 | private: 52 | //It is holding pointers to texts and also a pointer to the textmanager 53 | std::vector> _TEXTS; 54 | 55 | std::shared_ptr _texter; 56 | 57 | //Pointer to an additional informations - in case of clipboards, etc. 58 | std::shared_ptr _additionalStorage; 59 | 60 | /** 61 | Private methods 62 | **/ 63 | void handleIntegerInput(char*& ch, int& position, PinGUI::writingModInfo& info); 64 | 65 | void handleFloatInput(char*& ch, int& position, PinGUI::writingModInfo& info); 66 | 67 | bool checkNegativeInput(char*& ch, int& position); 68 | 69 | bool isFloatInput(char*& ch); 70 | 71 | bool isNegativeInput(char*& ch); 72 | 73 | public: 74 | TextStorage(std::shared_ptr text); 75 | ~TextStorage(); 76 | 77 | void addText(const std::string& text, GUIPos x, GUIPos y) ; 78 | 79 | void addText(GUIPos x, GUIPos y, int* var); 80 | 81 | void addText(GUIPos x, GUIPos y, float* var); 82 | 83 | void addText(GUIPos x, GUIPos y, std::string* var); 84 | 85 | void addAdjustableText(const std::string& text, GUIPos x, GUIPos y, unsigned int size, unsigned int maxSize); 86 | 87 | void destroyText(int position = 0); 88 | 89 | void destroyStorage(); 90 | 91 | void addChar(char* ch, int position, PinGUI::writingModInfo& info); 92 | 93 | void removeChar(int position); 94 | 95 | std::shared_ptr getText(int position = 0); 96 | 97 | std::vector>* getVector(); 98 | 99 | std::shared_ptr getTextManager(); 100 | 101 | void setAdditionalInfo(clipboard_type* Type); 102 | 103 | void setShow(bool state); 104 | }; 105 | 106 | #endif // TEXTSTORAGE_H 107 | -------------------------------------------------------------------------------- /PinGUI/VBO_Manager.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | PinGUI 4 | 5 | Copyright (c) 2017 Lubomir Barantal 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | 23 | **/ 24 | 25 | #include "VBO_Manager.h" 26 | 27 | VBO_Manager::VBO_Manager(int limit, bool vao): 28 | _counter(1), 29 | _vboID(0), 30 | _vaoID(0) 31 | { 32 | _limit = limit; 33 | _staticLIMIT = limit; 34 | 35 | if (vao) createVAO(); 36 | 37 | //Need to create the allocation first 38 | initMemory(_limit); 39 | } 40 | 41 | VBO_Manager::VBO_Manager(): 42 | _counter(1), 43 | _vboID(0), 44 | _vaoID(0) 45 | { 46 | 47 | } 48 | 49 | VBO_Manager::~VBO_Manager() 50 | { 51 | glDeleteBuffers(1,&_vboID); 52 | } 53 | 54 | void VBO_Manager::initMemory(const int& limit) 55 | { 56 | glBindBuffer(GL_ARRAY_BUFFER,_vboID); 57 | 58 | glBufferData(GL_ARRAY_BUFFER,limit*sizeof(vboData),nullptr,GL_DYNAMIC_DRAW); 59 | 60 | glBindBuffer(GL_ARRAY_BUFFER,0); 61 | } 62 | 63 | bool VBO_Manager::bufferData(int startPos, const std::vector& dataVector) 64 | { 65 | bool tmp = false; 66 | 67 | glBindBuffer(GL_ARRAY_BUFFER,_vboID); 68 | startPos *= sizeof(vboData); 69 | 70 | //In case of having small memory we need to resize our buffer for desirable amount 71 | if (!canBuffer(startPos,dataVector.size())){ 72 | addNewMemory(); 73 | tmp = true; 74 | } 75 | 76 | glBufferSubData(GL_ARRAY_BUFFER,startPos,dataVector.size()*sizeof(vboData),dataVector.data()); 77 | 78 | return tmp; 79 | } 80 | 81 | void VBO_Manager::addNewMemory(){ 82 | //At first need to make a tmp copy of my current Buffer to be sure that im not losing any of the inserted data 83 | GLuint tmpVBO = 0; 84 | glGenBuffers(1,&tmpVBO); 85 | glBindBuffer(GL_COPY_READ_BUFFER,tmpVBO); 86 | 87 | //Now allocate a memory for the copy 88 | glBufferData(GL_COPY_READ_BUFFER,(_limit*_counter)*sizeof(vboData),nullptr,GL_STATIC_COPY); 89 | 90 | //Increment my counter 91 | _counter++; 92 | 93 | //Now resizing the right buffer and preparing it for copying 94 | glBindBuffer(GL_ARRAY_BUFFER,_vboID); 95 | glBufferData(GL_ARRAY_BUFFER,(_staticLIMIT*_counter)*sizeof(vboData),nullptr,GL_DYNAMIC_DRAW); 96 | 97 | //Copying 98 | glCopyBufferSubData(GL_COPY_READ_BUFFER,GL_ARRAY_BUFFER,0,0,(_limit*(_counter-1))*sizeof(vboData)); 99 | 100 | glDeleteBuffers(1,&tmpVBO); 101 | glBindBuffer(GL_COPY_READ_BUFFER,0); 102 | _limit = (_staticLIMIT*_counter); 103 | } 104 | 105 | 106 | bool VBO_Manager::canBuffer(int startPos,int num){ 107 | int tmp_size = 0; 108 | 109 | glGetBufferParameteriv(GL_ARRAY_BUFFER,GL_BUFFER_SIZE,&tmp_size); 110 | tmp_size /= sizeof(vboData); 111 | 112 | if (tmp_size>=startPos+num) 113 | return true; 114 | else 115 | return false; 116 | } 117 | 118 | void VBO_Manager::createVAO() 119 | { 120 | if (_vaoID==0)glGenVertexArrays(1,&_vaoID); 121 | glBindVertexArray(_vaoID); 122 | 123 | if (_vboID==0) glGenBuffers(1,&_vboID); 124 | glBindBuffer(GL_ARRAY_BUFFER,_vboID); 125 | 126 | //This is the position 127 | glEnableVertexAttribArray(0); 128 | glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,sizeof(PinGUI::Vertex),(void*)offsetof(PinGUI::Vertex,position)); 129 | 130 | //Color attrib pointer 131 | glEnableVertexAttribArray(1); 132 | glVertexAttribPointer(1,4,GL_UNSIGNED_BYTE,GL_TRUE,sizeof(PinGUI::Vertex),(void*)offsetof(PinGUI::Vertex,color)); 133 | 134 | //UV 135 | glEnableVertexAttribArray(2); 136 | glVertexAttribPointer(2,2,GL_FLOAT,GL_TRUE,sizeof(PinGUI::Vertex),(void*)offsetof(PinGUI::Vertex,uv)); 137 | 138 | glDisableVertexAttribArray(3); 139 | 140 | glBindBuffer(GL_ARRAY_BUFFER,0); 141 | 142 | glBindVertexArray(0); 143 | } 144 | 145 | GLuint* VBO_Manager::getVBO_P() 146 | { 147 | return &_vboID; 148 | } 149 | 150 | GLuint VBO_Manager::getVBO() 151 | { 152 | return _vboID; 153 | } 154 | 155 | GLuint VBO_Manager::getVAO() 156 | { 157 | return _vaoID; 158 | } 159 | 160 | GLuint* VBO_Manager::getVAO_P(){ 161 | return &_vaoID; 162 | } 163 | -------------------------------------------------------------------------------- /PinGUI/VBO_Manager.h: -------------------------------------------------------------------------------- 1 | #ifndef VBO_MANAGER_H 2 | #define VBO_MANAGER_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "stuff.h" 33 | 34 | class VBO_Manager 35 | { 36 | private: 37 | 38 | int _counter; 39 | int _limit; 40 | int _staticLIMIT; 41 | 42 | GLuint _vboID; 43 | GLuint _vaoID; 44 | 45 | //Creation of VBO memory 46 | void initMemory(const int& limit); 47 | 48 | bool canBuffer(int startPos,int num); 49 | 50 | void addNewMemory(); 51 | 52 | public: 53 | VBO_Manager(int limit, bool vao = true); 54 | VBO_Manager(); 55 | ~VBO_Manager(); 56 | 57 | //Buffering the data 58 | bool bufferData(int startPos, const std::vector& dataVector); 59 | 60 | //Creation of VAOs 61 | void createVAO(); 62 | GLuint createVAO(GLuint* vboID); 63 | 64 | GLuint* getVBO_P(); 65 | GLuint getVBO(); 66 | GLuint getVAO(); 67 | GLuint* getVAO_P(); 68 | 69 | 70 | }; 71 | 72 | #endif // VBO_MANAGER_H 73 | -------------------------------------------------------------------------------- /PinGUI/clFunction.hpp: -------------------------------------------------------------------------------- 1 | #ifndef CLFUNCTION_HPP 2 | #define CLFUNCTION_HPP 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | 28 | #include 29 | #include 30 | 31 | #include "PINGUI_Vector.hpp" 32 | 33 | namespace PinGUI{ 34 | 35 | class basicPointer{ 36 | public : 37 | std::function _function; 38 | 39 | basicPointer() 40 | { 41 | 42 | } 43 | 44 | basicPointer(std::function f) : 45 | _function(f) 46 | { 47 | 48 | } 49 | 50 | basicPointer(const basicPointer& p2) : 51 | _function(p2._function) 52 | { 53 | 54 | } 55 | 56 | void exec(){ 57 | 58 | if (_function){ 59 | 60 | _function(); 61 | } 62 | 63 | } 64 | }; 65 | 66 | class scrollFuncPointer{ 67 | public : 68 | std::function)> _function; 69 | 70 | void exec(PinGUI::Vector2 vect){ 71 | 72 | if (_function){ 73 | 74 | _function(vect); 75 | } 76 | } 77 | }; 78 | 79 | class comboBoxFuncPointer{ 80 | public : 81 | std::function _function; 82 | 83 | void exec(int option){ 84 | 85 | if (_function){ 86 | 87 | _function(option); 88 | } 89 | } 90 | }; 91 | 92 | class stringFuncPointer{ 93 | public : 94 | std::function _function; 95 | 96 | void exec(std::string text){ 97 | 98 | if (_function){ 99 | 100 | _function(text); 101 | } 102 | } 103 | }; 104 | 105 | } 106 | 107 | 108 | #endif // CLFUNCTION_HPP 109 | -------------------------------------------------------------------------------- /PinGUI/stuff.h: -------------------------------------------------------------------------------- 1 | #ifndef STUFF_H 2 | #define STUFF_H 3 | 4 | /** 5 | 6 | PinGUI 7 | 8 | Copyright (c) 2017 Lubomir Barantal 9 | 10 | This software is provided 'as-is', without any express or implied 11 | warranty. In no event will the authors be held liable for any damages 12 | arising from the use of this software. 13 | 14 | Permission is granted to anyone to use this software for any purpose, 15 | including commercial applications, and to alter it and redistribute it 16 | freely, subject to the following restrictions: 17 | 18 | 1. The origin of this software must not be misrepresented; you must not 19 | claim that you wrote the original software. If you use this software 20 | in a product, an acknowledgment in the product documentation would be 21 | appreciated but is not required. 22 | 2. Altered source versions must be plainly marked as such, and must not be 23 | misrepresented as being the original software. 24 | 3. This notice may not be removed or altered from any source distribution. 25 | 26 | **/ 27 | #define BLANK "Blank" 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "GL_Vertex.h" 34 | 35 | class textInfo{ 36 | public: 37 | textInfo(TTF_Font* Font,SDL_Color Color): 38 | font(Font), 39 | color(Color) 40 | { 41 | }; 42 | 43 | textInfo(){}; 44 | 45 | ~textInfo(){ 46 | TTF_CloseFont(font); 47 | } 48 | 49 | TTF_Font* font; 50 | SDL_Color color; 51 | }; 52 | 53 | struct vboData{ 54 | PinGUI::Vertex vertices[6]; 55 | }; 56 | 57 | /** 58 | Class for storing data for VBO´s (normal VBO and instances) 59 | **/ 60 | class BufferData{ 61 | public: 62 | std::vector vboDATA; 63 | }; 64 | 65 | /** 66 | Enum for different clipboards 67 | **/ 68 | enum clipboard_type{ 69 | NORMAL, 70 | ADJUSTABLE, 71 | INT_ONLY, 72 | INT_FLOAT, 73 | UNCLICKABLE 74 | }; 75 | 76 | enum element_shape{ 77 | ROUNDED, 78 | RECTANGLED 79 | }; 80 | 81 | enum windowElementType 82 | { 83 | NONE, 84 | MOVER_ONLY, 85 | EXIT_ONLY, 86 | BOTH 87 | }; 88 | 89 | namespace PinGUI{ 90 | 91 | enum gameState{ 92 | GAME, 93 | GUI 94 | }; 95 | 96 | enum inputState{ 97 | GAMEINPUT, 98 | WRITINGMOD, 99 | MANIPULATINGMOD 100 | }; 101 | 102 | enum manipulationState{ 103 | HORIZONTAL, 104 | VERTICAL, 105 | WINDOW_MOVING 106 | }; 107 | 108 | struct writingModInfo{ 109 | clipboard_type inputType; 110 | int max; 111 | int maxValue; 112 | int minValue; 113 | bool negativeInput; 114 | }; 115 | 116 | struct manipulatingModInfo{ 117 | int lastX; 118 | int lastY; 119 | manipulationState manipState; 120 | }; 121 | } 122 | 123 | #endif // STUFF_H 124 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PinGUI 2 | 3 | C++/SDL2/OpenGL created by Lubomir "Pinsius" Barantal 4 | 5 | Extensions: 6 | Glew for OpenGL functions. 7 | http://glew.sourceforge.net/ 8 | 9 | SDL + its extensions: 10 | SDL_TTF 11 | SDL_Image 12 | https://www.libsdl.org/ 13 | 14 | GLM library for matrix operations 15 | http://glm.g-truc.net/0.9.8/index.html 16 | 17 | Boost (for bind function) 18 | http://www.boost.org/ 19 | 20 | 21 | I stopped to continue the development of this GUI library, as I´ve decided to dedicate my spare time to development of my own game engine. However, I was able to create my first editor prototypes using this library, it served well, but needed much more effort and time for its development. The code doesn´t have best architecture, but its working, and you may use it as you want. Thanks. 22 | I won´t delete the description below, so it stays as before. 23 | 24 | Some of its features are : 25 | - Text creation (using SDL_TTF extension) 26 | - Dynamic text handling(if you write a variable, library will automatically update the text if the variable changes) 27 | - Basic gui elements (that can be networked together so elements can consist of other elements and create pure new style) 28 | - Advanced window creation options 29 | - Multitabbing (window can has more tabs with different content) 30 | - Scrolling 31 | - Windows have its own coordinate system ( [0;0] is the left corner of the window) 32 | - Each tab can have its own settings (for example font) 33 | 34 | Video : https://www.youtube.com/watch?v=YxVG0uQdU_Y 35 | 36 | 37 | This library was developed primary for learning purposes but now i consider it to be able 38 | to handle also the GUI in my projects ( even if it still needs lot of improvements). 39 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-leap-day -------------------------------------------------------------------------------- /buildinfo: -------------------------------------------------------------------------------- 1 | Link against: 2 | SDL2.lib 3 | SDL2main.lib 4 | //SDL2_mixer.lib - no need as it has no sound yet 5 | SDL2_image.lib 6 | SDL2_ttf.lib 7 | glew32.lib 8 | opengl32.lib 9 | 10 | Another dependencies you need to incluse: 11 | boost 12 | glm 13 | -------------------------------------------------------------------------------- /demo/FPS_Timer.cpp: -------------------------------------------------------------------------------- 1 | #include "FPS_Timer.h" 2 | 3 | /** 4 | This file is part of PinGUI demo 5 | 6 | Copyright (c) 2017 Lubomir Barantal 7 | 8 | This software is provided 'as-is', without any express or implied 9 | warranty. In no event will the authors be held liable for any damages 10 | arising from the use of this software. 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 1. The origin of this software must not be misrepresented; you must not 15 | claim that you wrote the original software. If you use this software 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 2. Altered source versions must be plainly marked as such, and must not be 19 | misrepresented as being the original software. 20 | 3. This notice may not be removed or altered from any source distribution. 21 | **/ 22 | 23 | FPS_Timer::FPS_Timer(): 24 | fps_ticks(0), 25 | cap_ticks(0), 26 | countedFrames(0), 27 | FPS(60) 28 | { 29 | SCREEN_TICK_PER_FRAME = 1000 / FPS; 30 | } 31 | 32 | FPS_Timer::~FPS_Timer() 33 | { 34 | 35 | } 36 | 37 | void FPS_Timer::initFPS(void) 38 | { 39 | fps_ticks = SDL_GetTicks(); 40 | } 41 | 42 | void FPS_Timer::initCap(void) 43 | { 44 | cap_ticks = SDL_GetTicks(); 45 | } 46 | 47 | void FPS_Timer::delay(void) 48 | { 49 | int frameTicks = SDL_GetTicks() - cap_ticks; 50 | 51 | if (frameTicks < SCREEN_TICK_PER_FRAME){ 52 | SDL_Delay( SCREEN_TICK_PER_FRAME - frameTicks ); 53 | } 54 | } 55 | 56 | void FPS_Timer::setFPS(int fps){ 57 | 58 | FPS = fps; 59 | SCREEN_TICK_PER_FRAME = 1000 / FPS; 60 | } 61 | 62 | int FPS_Timer::tellTime(){ 63 | return (int)(SDL_GetTicks()/1000.0f); 64 | } 65 | 66 | bool FPS_Timer::updateTime(double& time){ 67 | 68 | int old_time = time; 69 | time = SDL_GetTicks()/1000.0f; 70 | 71 | if (time!=old_time) return true; 72 | return false; 73 | } 74 | -------------------------------------------------------------------------------- /demo/FPS_Timer.h: -------------------------------------------------------------------------------- 1 | #ifndef FPS_TIMER_H 2 | #define FPS_TIMER_H 3 | 4 | /** 5 | This file is part of PinGUI demo 6 | 7 | Copyright (c) 2017 Lubomir Barantal 8 | 9 | This software is provided 'as-is', without any express or implied 10 | warranty. In no event will the authors be held liable for any damages 11 | arising from the use of this software. 12 | Permission is granted to anyone to use this software for any purpose, 13 | including commercial applications, and to alter it and redistribute it 14 | freely, subject to the following restrictions: 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original software. 21 | 3. This notice may not be removed or altered from any source distribution. 22 | **/ 23 | 24 | #include 25 | 26 | class FPS_Timer 27 | { 28 | private: 29 | 30 | Uint32 fps_ticks; 31 | Uint32 cap_ticks; 32 | int countedFrames; 33 | int FPS; 34 | int SCREEN_TICK_PER_FRAME; 35 | 36 | public: 37 | FPS_Timer(); 38 | ~FPS_Timer(); 39 | 40 | void initFPS(); 41 | void initCap(); 42 | 43 | void delay(); 44 | int tellTime(); 45 | bool updateTime(double& time); 46 | void setFPS(int fps); 47 | }; 48 | 49 | #endif // FPS_TIMER_H 50 | -------------------------------------------------------------------------------- /demo/build info: -------------------------------------------------------------------------------- 1 | 2 | Linked against: 3 | -lmingw32 -lSDL2main -lSDL2 -lSDL2_image 4 | -lSDL2_ttf -lopengl32 -lglew32 5 | 6 | Extensions you need: SDL2,SDL2_image,SDL2_TTF,GLEW,glm,boost 7 | -------------------------------------------------------------------------------- /demo/dog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/demo/dog.png -------------------------------------------------------------------------------- /demo/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pinsius/PinGUI/eb1d39937e28c7f0a030f3dcd61e3d1a67c1feb1/demo/main.cpp --------------------------------------------------------------------------------