Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
MenuItem.cpp
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#include "KatanaEngine.h"
16
17namespace KatanaEngine
18{
20
21 MenuItem::MenuItem(std::string text)
22 {
23 m_onSelect = nullptr;
24 m_pFont = nullptr;
25
26 m_text = text;
27
28 m_color = Color::White;
29 m_alpha = 1.0f;
30
31 m_position = Vector2::ZERO;
32 m_textOffset = Vector2::ZERO;
33
34 m_textAlign = TextAlign::Left;
35 m_isDisplayed = true;
36 }
37
38 void MenuItem::Draw(SpriteBatch& spriteBatch)
39 {
40 if (m_pFont && m_text.compare("") != 0)
41 {
42 spriteBatch.DrawString(m_pFont, &m_text, m_position + m_textOffset, m_color * m_alpha, m_textAlign);
43 }
44 }
45
46 void MenuItem::Select(MenuScreen *pMenuScreen)
47 {
48 if (m_onSelect) ((OnSelect)m_onSelect)(pMenuScreen);
49 }
50}
static const Color White
White.
Definition Color.h:201
Class for menu items contained in a MenuScreen.
Definition MenuItem.h:28
MenuItem()
Instantiate a menu item.
Definition MenuItem.cpp:19
virtual void Select(MenuScreen *pMenuScreen)
Called when the picks this menu option.
Definition MenuItem.cpp:46
virtual void Draw(SpriteBatch &spriteBatch)
Called when the game determines it is time to draw a frame.
Definition MenuItem.cpp:38
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
void DrawString(const Font *pFont, std::string *text, const Vector2 position, const Color color=Color::White, const TextAlign alignment=TextAlign::Left, const float drawDepth=0)
Adds a string to a batch of sprites to be rendered.
static const Vector2 ZERO
A vector with both of its components set to zero.
Definition Vector2.h:31
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