1 /*
2  * client/GraphicMenuItem.cpp
3  *
4  * This file is part of Leges Motus, a networked, 2D shooter set in zero gravity.
5  *
6  * Copyright 2009-2010 Andrew Ayer, Nathan Partlan, Jeffrey Pfau
7  *
8  * Leges Motus is free and open source software.  You may redistribute it and/or
9  * modify it under the terms of version 2, or (at your option) version 3, of the
10  * GNU General Public License (GPL), as published by the Free Software Foundation.
11  *
12  * Leges Motus is distributed in the hope that it will be useful, but WITHOUT ANY
13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14  * PARTICULAR PURPOSE.  See the full Graphic of the GNU General Public License for
15  * further detail.
16  *
17  * For a full copy of the GNU General Public License, please see the COPYING file
18  * in the root of the source code tree.  You may also retrieve a copy from
19  * <http://www.gnu.org/licenses/gpl-2.0.txt>, or request a copy by writing to the
20  * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307  USA
22  *
23  */
24 
25 #include "GraphicMenuItem.hpp"
26 
27 
28 using namespace LM;
29 using namespace std;
30 
31 const Color GraphicMenuItem::PLAIN_COLOR = Color(1.0, 1.0, 1.0, 0.6);
32 const Color GraphicMenuItem::HOVER_COLOR = Color(1.0, 1.0, 1.0, 1.0);
33 const Color GraphicMenuItem::DISABLED_COLOR = Color(0.8, 0.8, 0.8, 0.4);
34 
GraphicMenuItem(Graphic * Graphic,string value,State state)35 GraphicMenuItem::GraphicMenuItem(Graphic* Graphic, string value, State state) : MenuItem(value, state),
36 m_plain(PLAIN_COLOR), m_hover(HOVER_COLOR), m_disabled(DISABLED_COLOR) {
37 	m_graphic = Graphic;
38 	m_hover_scale = 1.0;
39 	m_normal_scale = 1.0;
40 	state_changed(state, state);
41 }
42 
state_changed(State old_state,State new_state)43 void GraphicMenuItem::state_changed(State old_state, State new_state) {
44 	switch (new_state) {
45 	case NORMAL:
46 	case STATIC:
47 		m_graphic->set_color_intensity(m_plain);
48 		m_graphic->set_alpha(m_plain.a);
49 		m_graphic->set_scale_x(m_normal_scale);
50 		m_graphic->set_scale_y(m_normal_scale);
51 		break;
52 	case CLICKED:
53 		//TODO separate case
54 	case HOVER:
55 		m_graphic->set_color_intensity(m_hover);
56 		m_graphic->set_alpha(m_hover.a);
57 		m_graphic->set_scale_x(m_hover_scale);
58 		m_graphic->set_scale_y(m_hover_scale);
59 		break;
60 	case DISABLED:
61 		m_graphic->set_color_intensity(m_disabled);
62 		m_graphic->set_alpha(m_disabled.a);
63 		m_graphic->set_scale_x(m_normal_scale);
64 		m_graphic->set_scale_y(m_normal_scale);
65 		break;
66 	}
67 }
68 
set_plain_color(const Color & color)69 void GraphicMenuItem::set_plain_color(const Color& color) {
70 	m_plain = color;
71 	switch(get_state()) {
72 	case NORMAL:
73 	case STATIC:
74 		m_graphic->set_color_intensity(m_plain);
75 		m_graphic->set_alpha(m_plain.a);
76 		break;
77 	default:
78 		break;
79 	}
80 }
81 
set_hover_color(const Color & color)82 void GraphicMenuItem::set_hover_color(const Color& color) {
83 	m_hover = color;
84 	switch(get_state()) {
85 	case HOVER:
86 		m_graphic->set_color_intensity(m_hover);
87 		m_graphic->set_alpha(m_hover.a);
88 		break;
89 	default:
90 		break;
91 	}
92 }
93 
set_disabled_color(const Color & color)94 void GraphicMenuItem::set_disabled_color(const Color& color) {
95 	m_disabled = color;
96 	switch(get_state()) {
97 	case DISABLED:
98 		m_graphic->set_color_intensity(m_disabled);
99 		m_graphic->set_alpha(m_disabled.a);
100 		break;
101 	default:
102 		break;
103 	}
104 }
105 
set_scale(double factor)106 void GraphicMenuItem::set_scale(double factor) {
107 	m_normal_scale = factor;
108 	if (get_state() != HOVER) {
109 		m_graphic->set_scale_x(m_normal_scale);
110 		m_graphic->set_scale_y(m_normal_scale);
111 	}
112 }
113 
set_hover_scale(double factor)114 void GraphicMenuItem::set_hover_scale(double factor) {
115 	m_hover_scale = factor;
116 	if (get_state() == HOVER) {
117 		m_graphic->set_scale_x(m_hover_scale);
118 		m_graphic->set_scale_y(m_hover_scale);
119 	}
120 }
121 
get_graphic() const122 const Graphic* GraphicMenuItem::get_graphic() const {
123 	return m_graphic;
124 }
125 
get_graphic()126 Graphic* GraphicMenuItem::get_graphic() {
127 	return m_graphic;
128 }
129