| 1 | /* |
| 2 | =========================================================================== |
| 3 | blockattack - Block Attack - Rise of the Blocks |
| 4 | Copyright (C) 2005-2020 Poul Sander |
| 5 | |
| 6 | This program is free software: you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation, either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program. If not, see http://www.gnu.org/licenses/ |
| 18 | |
| 19 | Source information and contacts persons can be found at |
| 20 | https://blockattack.net |
| 21 | =========================================================================== |
| 22 | */ |
| 23 | |
| 24 | #include "HelpCommon.hpp" |
| 25 | #include "MenuSystem.h" |
| 26 | #include "global.hpp" |
| 27 | #include "DialogBox.hpp" |
| 28 | |
| 29 | |
| 30 | |
| 31 | template<typename T> void setHelp30FontTemplate(const sago::SagoDataHolder* holder, T& field, const char* text) { |
| 32 | field.SetHolder(holder); |
| 33 | field.SetFont("freeserif"); |
| 34 | field.SetColor({255,255,255,255}); |
| 35 | field.SetFontSize(30); |
| 36 | field.SetOutline(2, {0,0,0,255}); |
| 37 | field.SetText(text); |
| 38 | } |
| 39 | |
| 40 | void setHelp30Font(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) { |
| 41 | setHelp30FontTemplate(holder, field, text); |
| 42 | } |
| 43 | |
| 44 | void setHelp30Font(const sago::SagoDataHolder* holder, sago::SagoTextBox& field, const char* text) { |
| 45 | setHelp30FontTemplate(holder, field, text); |
| 46 | } |
| 47 | |
| 48 | void setHelpBoxFont(const sago::SagoDataHolder* holder, sago::SagoTextBox& field, const char* text) { |
| 49 | field.SetHolder(holder); |
| 50 | field.SetFont("freeserif"); |
| 51 | field.SetColor({255,255,255,255}); |
| 52 | field.SetColor({0,0,0,255}); |
| 53 | field.SetFontSize(20); |
| 54 | field.SetOutline(0, {0,0,0,255}); |
| 55 | field.SetText(text); |
| 56 | } |
| 57 | |
| 58 | void setHelp30FontThinOutline(const sago::SagoDataHolder* holder, sago::SagoTextField& field, const char* text) { |
| 59 | setHelp30Font(holder,field, text); |
| 60 | field.SetOutline(1, {128,128,128,255}); |
| 61 | } |
| 62 | |
| 63 | bool HelpCommonState::IsActive() { |
| 64 | return isActive; |
| 65 | } |
| 66 | |
| 67 | void HelpCommonState::ProcessInput(const SDL_Event& event, bool& processed) { |
| 68 | |
| 69 | UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey); |
| 70 | |
| 71 | if (isConfirmEvent(event) || isEscapeEvent(event)) { |
| 72 | isActive = false; |
| 73 | processed = true; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | extern sago::SagoSprite bExit; |
| 78 | |
| 79 | |
| 80 | void HelpCommonState::Draw(SDL_Renderer* target) { |
| 81 | bExit.Draw(target, SDL_GetTicks(), globalData.xsize-buttonOffset, globalData.ysize-buttonOffset, &globalData.logicalResize); |
| 82 | #if DEBUG |
| 83 | static sago::SagoTextField mousePos; |
| 84 | mousePos.SetHolder(&globalData.spriteHolder->GetDataHolder()); |
| 85 | mousePos.SetFontSize(16); |
| 86 | mousePos.SetOutline(1, {128,128,128,255}); |
| 87 | mousePos.SetText(std::string("Mouse position: ")+std::to_string(globalData.mousex)+std::string(", ")+std::to_string(globalData.mousey)); |
| 88 | mousePos.Draw(target, 0,0); |
| 89 | #endif |
| 90 | } |
| 91 | |
| 92 | void HelpTextBoxState::Draw(SDL_Renderer* target) { |
| 93 | DrawBackground(target); |
| 94 | titleField.Draw(target, 50, 50, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); |
| 95 | DrawRectYellow(target, 40, 90, 600, 900, &globalData.logicalResize); |
| 96 | infoBox.SetMaxWidth(850); |
| 97 | infoBox.Draw(target, 50, 100, sago::SagoTextField::Alignment::left, &globalData.logicalResize); |
| 98 | if (filenameField.GetText().length() > 0) { |
| 99 | DrawRectYellow(target, 40, 700, 50, 900, &globalData.logicalResize); |
| 100 | filenameField.Draw(target, 50, 715, sago::SagoTextField::Alignment::left, &globalData.logicalResize); |
| 101 | } |
| 102 | HelpCommonState::Draw(target); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | void HelpCommonState::Update() { |
| 107 | // If the mouse button is released, make bMouseUp equal true |
| 108 | if ( !(SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) ) { |
| 109 | bMouseUp=true; |
| 110 | } |
| 111 | |
| 112 | if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { |
| 113 | bMouseUp = false; |
| 114 | |
| 115 | int mousex; |
| 116 | int mousey; |
| 117 | globalData.logicalResize.PhysicalToLogical(globalData.mousex, globalData.mousey, mousex, mousey); |
| 118 | |
| 119 | //The Score button: |
| 120 | if ((mousex>globalData.xsize-buttonOffset) && (mousex<globalData.xsize-buttonOffset+bExit.GetWidth()) |
| 121 | && (mousey>globalData.ysize-buttonOffset) && (mousey<globalData.ysize-buttonOffset+bExit.GetHeight())) { |
| 122 | isActive = false; |
| 123 | } |
| 124 | |
| 125 | } |
| 126 | } |