ScummVM API documentation
button.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * This code is based on the CRAB engine
24 *
25 * Copyright (c) Arvind Raja Yadav
26 *
27 * Licensed under MIT
28 *
29 */
30
31//=============================================================================
32// Author: Arvind
33// Purpose: Button class
34//=============================================================================
35#ifndef CRAB_BUTTON_H
36#define CRAB_BUTTON_H
37
38#include "crab/GameParam.h"
39#include "crab/image/ImageManager.h"
40#include "crab/input/hotkey.h"
41#include "crab/music/MusicManager.h"
42#include "crab/text/TextManager.h"
43#include "crab/ui/Caption.h"
44#include "crab/ui/element.h"
45#include "crab/ui/HoverInfo.h"
46
47namespace Crab {
48
49namespace pyrodactyl {
50namespace ui {
51enum ButtonAction {
52 BUAC_IGNORE,
53 BUAC_LCLICK,
54 BUAC_RCLICK,
55 BUAC_GRABBED
56};
57
59 ImageKey _normal, _select, _hover;
60
61 bool operator==(const ButtonImage &img) {
62 return _normal == img._normal && _select == img._select && _hover == img._hover; }
63
64
65 ButtonImage() {
66 _normal = 0;
67 _select = 0;
68 _hover = 0;
69 }
70
71 void load(rapidxml::xml_node<char> *node, const bool &echo = true) {
72 if (nodeValid(node)) {
73 loadImgKey(_normal, "img_b", node, echo);
74 loadImgKey(_select, "img_s", node, echo);
75 loadImgKey(_hover, "img_h", node, echo);
76 }
77 }
78
79 void saveState(rapidxml::xml_document<> &doc, rapidxml::xml_node<char> *root) {
80 root->append_attribute(doc.allocate_attribute("img_b", g_engine->_stringPool->get(_normal)));
81 root->append_attribute(doc.allocate_attribute("img_s", g_engine->_stringPool->get(_select)));
82 root->append_attribute(doc.allocate_attribute("img_h", g_engine->_stringPool->get(_hover)));
83 }
84};
85
86class Button : public Element {
87public:
88 bool _visible, _mousePressed;
89
90 // We need to keep track of keyboard and mouse hovering separately
91 bool _hoverMouse, _hoverKey, _hoverPrev;
92
93 // Can the player move this button?
94 bool _canmove;
95
96 // The button images
97 ButtonImage _img;
98
99 // The sound effect played when button is clicked
100 pyrodactyl::music::ChunkKey _seClick, _seHover;
101
102 // Text shown when mouse is hovered over the button
103 HoverInfo _tooltip;
104
105 // Text shown all times on the button
106 Caption _caption;
107
108 // A hotkey is a keyboard key(s) that are equivalent to pressing a button
110
111 Button();
112 ~Button() {}
113 void reset();
114
115 void setUI(Rect *parent = nullptr);
116
117 void load(rapidxml::xml_node<char> *node, const bool &echo = true);
118 void init(const Button &ref, const int &xOffset = 0, const int &yOffset = 0);
119
120 void img(Button &b) {
121 _img = b._img;
122 }
123
124 void img(ButtonImage &image) {
125 _img = image;
126 }
127
128 ButtonImage img() {
129 return _img;
130 }
131
132 void draw(const int &xOffset = 0, const int &yOffset = 0, Rect *clip = nullptr);
133
134 ButtonAction handleEvents(const Common::Event &event, const int &xOffset = 0, const int &yOffset = 0);
135
136 // Special functions to only draw parts of a button (used in special situations like world map)
137 void imageCaptionOnlyDraw(const int &xOffset = 0, const int &yOffset = 0, Rect *clip = nullptr);
138 void hoverInfoOnlyDraw(const int &xOffset = 0, const int &yOffset = 0, Rect *clip = nullptr);
139};
140} // End of namespace ui
141} // End of namespace pyrodactyl
142
143} // End of namespace Crab
144
145#endif // CRAB_BUTTON_H
Definition: hotkey.h:43
Definition: button.h:86
Definition: Caption.h:41
Definition: element.h:42
Definition: HoverInfo.h:41
Engine * g_engine
Definition: events.h:218
Definition: Rectangle.h:42
Definition: button.h:58