From cc7dfbc03d5a2fb4bfd94ffbe56e9ba778e3d735 Mon Sep 17 00:00:00 2001 From: kacperks Date: Tue, 1 Nov 2022 11:36:12 +0100 Subject: [PATCH] Button Class & MIT License Added. --- GUI.cpp | 41 ++++++++++++++++++++++++ LICENSE.txt | 21 ++++++++++++ XtreemNodes.cbp | 2 ++ XtreemNodes.depend | 55 +++++++++++++++++++++++++++++++ XtreemNodes.layout | 80 ++++++++++++++++++++++++++-------------------- include/GUI.h | 23 +++++++++++++ 6 files changed, 187 insertions(+), 35 deletions(-) create mode 100644 GUI.cpp create mode 100644 LICENSE.txt create mode 100644 include/GUI.h diff --git a/GUI.cpp b/GUI.cpp new file mode 100644 index 0000000..443d33a --- /dev/null +++ b/GUI.cpp @@ -0,0 +1,41 @@ +#include "GUI.h" + +Button::Button(sf::Image* normal,sf::Image* clicked,std::string words,sf::Vector2f location) { + this->normal.SetImage(*normal); + this->clicked.SetImage(*clicked); + this->currentSpr=&this->normal; + current =false; + this->normal.SetPosition(location); + this->clicked.SetPosition(location); + String.SetText(words); + String.SetPosition(location.x+3,location.y+3); + String.SetSize(14); +} +void Button::checkClick (sf::Vector2f mousePos) { + if (mousePos.x>currentSpr->GetPosition().x && mousePos.x<(currentSpr->GetPosition().x + currentSpr->GetSize().x)) { + if(mousePos.y>currentSpr->GetPosition().y && mousePos.y<(currentSpr->GetPosition().y + currentSpr->GetSize().y)) { + setState(!current); + } + } +} +void Button::setState(bool which) { + current = which; + if (current) { + currentSpr=&clicked; + return; + } + currentSpr=&normal; +} +void Button::setText(std::string words) { + String.SetText(words); +} +bool Button::getVar() { + return current; +} +sf::Sprite* Button::getSprite() { + return currentSpr; +} + +sf::String * Button::getText() { + return &String; +} diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..4b6a894 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +--------------------------------- +Copyright (c) 2021-2022 MCL +Copyright (c) 2022 Cube-Software +--------------------------------- +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/XtreemNodes.cbp b/XtreemNodes.cbp index 85ee749..7678d56 100644 --- a/XtreemNodes.cbp +++ b/XtreemNodes.cbp @@ -41,9 +41,11 @@ + + diff --git a/XtreemNodes.depend b/XtreemNodes.depend index 9432871..c7159cb 100644 --- a/XtreemNodes.depend +++ b/XtreemNodes.depend @@ -58,3 +58,58 @@ 1667167831 source:c:\development\xtreemminer\mapblock.cpp "MapBlock.h" +1667294728 source:/home/kacperks/projects/XtreemNodes/MapBlock.cpp + "MapBlock.h" + +1667294728 /home/kacperks/projects/XtreemNodes/include/MapBlock.h + "Base.h" + + + +1667294728 /home/kacperks/projects/XtreemNodes/include/Base.h + +1667294728 source:/home/kacperks/projects/XtreemNodes/main.cpp + + + "Utilities.h" + "MapBlock.h" + "Base.h" + "NodeRenderer.h" + "TextureHandler.h" + + + "FastNoiseLite.h" + + + +1667294728 /home/kacperks/projects/XtreemNodes/include/Utilities.h + +1667294728 /home/kacperks/projects/XtreemNodes/include/NodeRenderer.h + "Base.h" + "MapBlock.h" + + +1667294728 /home/kacperks/projects/XtreemNodes/include/TextureHandler.h + "stb_image.h" + "Base.h" + +1667088826 /home/kacperks/projects/XtreemNodes/include/stb_image.h + "stb_image.h" + + + + + + + + + + + + + + + +1667294728 /home/kacperks/projects/XtreemNodes/include/FastNoiseLite.h + + diff --git a/XtreemNodes.layout b/XtreemNodes.layout index 74fc247..3139691 100644 --- a/XtreemNodes.layout +++ b/XtreemNodes.layout @@ -2,54 +2,64 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + diff --git a/include/GUI.h b/include/GUI.h new file mode 100644 index 0000000..3127bdc --- /dev/null +++ b/include/GUI.h @@ -0,0 +1,23 @@ +#ifndef GUI +#defome GUI + +#include + +class Button { +public: + Button (sf::Image* normal,sf::Image* clicked,std::string,sf::Vector2f location); + void checkClick (sf::Vector2f); + void setState(bool); + void setText(std::string); + bool getVar(); + sf::Sprite* getSprite(); + sf::String * getText(); +private: + sf::Sprite normal; + sf::Sprite clicked; + sf::Sprite* currentSpr; + sf::String String; + bool current; +}; + +#endif // GUI