Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
MenuItem.h
Go to the documentation of this file.
1
2/*
3 ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
4 ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
5 █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
6 ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
7 ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
8 ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
9 /vvvvvvvvvvvvvvvvvvv \=========================================,
10 `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
11 Katana Engine \/ © 2012 - Shuriken Studios LLC
12 http://www.shurikenstudios.com
13*/
14
15#pragma once
16
17namespace KatanaEngine
18{
19
20 class MenuScreen;
21
24 typedef void(*OnSelect)(MenuScreen *pMenuScreen);
25
28 {
29 friend class MenuScreen;
30
31 public:
32
33
35 MenuItem();
36
41 MenuItem(std::string text);
42
43 virtual ~MenuItem() { }
44
47 virtual void Update(const GameTime& gameTime) { }
48
51 virtual void Draw(SpriteBatch& spriteBatch);
52
55 virtual void Select(MenuScreen *pMenuScreen);
56
59 virtual void SetText(const std::string text) { m_text = text; }
60
64 virtual void SetTextOffset(const Vector2 offset) { m_textOffset = offset; }
65
68 virtual bool IsSelected() const { return m_isSelected; }
69
73 virtual void SetSelected(const bool isSelected) { m_isSelected = isSelected; }
74
77 virtual bool IsDisplayed() const { return m_isDisplayed; }
78
81 virtual void SetDisplayed(const bool isDisplayed) { m_isDisplayed = isDisplayed; }
82
85 virtual void SetFont(Font *pFont) { m_pFont = pFont; }
86
89 virtual void SetPosition(const Vector2 position) { m_position = position; }
90
93 virtual void SetColor(const Color color) { m_color = color; }
94
97 virtual void SetAlpha(const float alpha) { m_alpha = alpha; }
98
101 virtual void SetTextAlign(TextAlign textAlign) { m_textAlign = textAlign; }
102
108 virtual void SetMenuScreen(MenuScreen *pMenuScreen) { m_pMenuScreen = pMenuScreen; }
109
112 virtual void SetSelectCallback(OnSelect callback) { m_onSelect = callback; }
113
116 virtual int GetIndex() const { return m_index; }
117
118
119 protected:
120
123 virtual void SetIndex(const int index) { m_index = index; }
124
127 virtual MenuScreen *GetMenuScreen() const { return m_pMenuScreen; }
128
131 virtual Vector2 GetPosition() const { return m_position; }
132
135 virtual std::string GetText() const { return m_text; }
136
137
138 private:
139
140 int m_index;
141
142 std::string m_text;
143
144 void *m_onSelect;
145
146 bool m_isSelected;
147
148 bool m_isDisplayed;
149
150 Font *m_pFont;
151
152 Color m_color;
153
154 float m_alpha;
155
156 Vector2 m_position;
157
158 Vector2 m_textOffset;
159
160 MenuScreen *m_pMenuScreen;
161
162 TextAlign m_textAlign;
163
164 };
165}
Represents a four-component color using red, green, blue, and alpha data.
Definition Color.h:21
Represents a font or true-type font.
Definition Font.h:21
Contains timing values for game updates and rendering.
Definition GameTime.h:21
Class for menu items contained in a MenuScreen.
Definition MenuItem.h:28
virtual void SetAlpha(const float alpha)
Sets the alpha value (opacity) of the menu item.
Definition MenuItem.h:97
MenuItem()
Instantiate a menu item.
Definition MenuItem.cpp:19
virtual int GetIndex() const
Gets the index of the menu item.
Definition MenuItem.h:116
virtual bool IsSelected() const
Determines whether or not this menu item is the one that is currently selected.
Definition MenuItem.h:68
virtual Vector2 GetPosition() const
Gets the position of the menu item.
Definition MenuItem.h:131
virtual void SetFont(Font *pFont)
Sets the font of the menu item.
Definition MenuItem.h:85
virtual void SetColor(const Color color)
Sets the color of the menu item.
Definition MenuItem.h:93
virtual void SetDisplayed(const bool isDisplayed)
Sets whether or not this menu item is currently displayed.
Definition MenuItem.h:81
virtual bool IsDisplayed() const
Determines whether or not this menu item is currently displayed.
Definition MenuItem.h:77
virtual void SetIndex(const int index)
Sets the index of the menu item.
Definition MenuItem.h:123
virtual void SetPosition(const Vector2 position)
Sets the screen position of the menu item.
Definition MenuItem.h:89
virtual void SetMenuScreen(MenuScreen *pMenuScreen)
Sets containing menu screen.
Definition MenuItem.h:108
virtual void SetTextAlign(TextAlign textAlign)
Sets the text alignment for the menu item.
Definition MenuItem.h:101
virtual void Select(MenuScreen *pMenuScreen)
Called when the picks this menu option.
Definition MenuItem.cpp:46
virtual MenuScreen * GetMenuScreen() const
Gets the menu screen that contains this item.
Definition MenuItem.h:127
virtual void Draw(SpriteBatch &spriteBatch)
Called when the game determines it is time to draw a frame.
Definition MenuItem.cpp:38
virtual void Update(const GameTime &gameTime)
Called when the game has determined that screen logic needs to be processed.
Definition MenuItem.h:47
virtual void SetSelected(const bool isSelected)
Sets whether or not this menu item is the one that is currently selected.
Definition MenuItem.h:73
virtual void SetTextOffset(const Vector2 offset)
Sets the offset from the items normal position. Usually used to animate the currently selected menu i...
Definition MenuItem.h:64
virtual void SetSelectCallback(OnSelect callback)
Sets the callback function for when the menu item is selected.
Definition MenuItem.h:112
virtual void SetText(const std::string text)
Sets the text of the menu item.
Definition MenuItem.h:59
virtual std::string GetText() const
Gets the text of the menu item.
Definition MenuItem.h:135
Base class for all game menu screens.
Definition MenuScreen.h:23
Enables a group of sprites to be drawn using the same settings.
Definition SpriteBatch.h:48
Defines a vector with 2 components (x and y).
Definition Vector2.h:21
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18
void(* OnSelect)(MenuScreen *pMenuScreen)
Callback function for when a menu item is selected.
Definition MenuItem.h:24
TextAlign
Defines the states for text alignment.
Definition SpriteBatch.h:21