18 #ifndef ZENI_WIDGET_HXX
19 #define ZENI_WIDGET_HXX
44 delete_m_renderer(
false)
95 #if SDL_VERSION_ATLEAST(2,0,0)
99 on_mouse_wheel(pos, event.
y);
105 const Point2f projected = projector.unproject(Point2f(
float(pos.x),
float(pos.y)));
106 on_mouse_wheel(Point2i(
int(projected.x),
int(projected.y)), event.
y);
127 if(delete_m_renderer)
129 m_renderer = renderer;
130 delete_m_renderer =
true;
134 give_Renderer(const_cast<Widget_Render_Function * const &>(renderer));
135 delete_m_renderer =
false;
143 : m_upper_left(upper_left_),
144 m_lower_right(lower_right_)
153 return Point2f(m_upper_left.
x, m_lower_right.
y);
157 return m_lower_right;
161 return Point2f(m_lower_right.
x, m_upper_left.
y);
165 return m_lower_right.
y - m_upper_left.
y;
169 return m_lower_right.
x - m_upper_left.
x;
173 return Point2f(0.5
f * (m_upper_left.
x + m_lower_right.
x),
174 0.5f * (m_upper_left.
y + m_lower_right.
y));
178 return m_upper_left.
x < pos.
x && pos.
x < m_lower_right.
x &&
179 m_upper_left.
y < pos.
y && pos.
y < m_lower_right.
y;
182 template <
typename T1,
typename T2>
184 const T2 *
const &second_,
const bool &delete_second_)
185 : m_first(const_cast<T1 *
const &>(first_)),
186 delete_m_first(delete_first_),
187 m_second(const_cast<T2 *
const &>(second_)),
188 delete_m_second(delete_second_)
192 template <
typename T1,
typename T2>
200 template <
typename T1,
typename T2>
205 template <
typename T1,
typename T2>
210 template <
typename T1,
typename T2>
215 template <
typename T1,
typename T2>
220 template <
typename T1,
typename T2>
223 m_first->render_to(rect);
225 m_second->render_to(rect);
228 template <
typename T1,
typename T2>
233 template <
typename T1,
typename T2>
235 const T2 *
const &second_,
const bool &delete_second_)
241 : font_name(font_name_),
254 tex_coord_ul(0.0
f, 0.0
f),
255 tex_coord_ll(0.0
f, 1.0
f),
256 tex_coord_lr(1.0
f, 1.0
f),
257 tex_coord_ur(1.0
f, 0.0
f)
267 tex_coord_ul(tex_coord_ul_),
268 tex_coord_ll(tex_coord_ll_),
269 tex_coord_lr(tex_coord_lr_),
270 tex_coord_ur(tex_coord_ur_)
276 bg_normal(
get_Colors()[
"default_button_bg_normal"]),
277 bg_clicked(
get_Colors()[
"default_button_bg_clicked"]),
278 bg_hovered_strayed(
get_Colors()[
"default_button_bg_hovered_strayed"]),
279 text_normal(
get_Colors()[
"default_button_text_normal"]),
280 text_clicked(
get_Colors()[
"default_button_text_clicked"]),
281 text_hovered_strayed(
get_Colors()[
"default_button_text_hovered_strayed"])
286 const Color &text_normal_,
const Color &text_clicked_,
const Color &text_hovered_strayed_)
288 bg_normal(bg_normal_),
289 bg_clicked(bg_clicked_),
290 bg_hovered_strayed(bg_hovered_strayed_),
291 text_normal(text_normal_),
292 text_clicked(text_clicked_),
293 text_hovered_strayed(text_hovered_strayed_)
298 : border_color(
get_Colors()[
"default_button_bg_normal"]),
299 check_color(
get_Colors()[
"default_button_bg_normal"])
304 : border_color(border_color_),
305 check_color(check_color_)
310 : line_color(
get_Colors()[
"default_button_bg_normal"]),
311 slider_color(
get_Colors()[
"default_button_bg_normal"])
316 : line_color(line_color_),
317 slider_color(slider_color_)
321 Widget_Button::Widget_Button(
const Point2f &upper_left_,
const Point2f &lower_right_)
331 Text_Button::Text_Button(
const Point2f &upper_left_,
const Point2f &lower_right_,
340 const bool &checked_,
const bool &toggleable_)
356 const bool &checked_,
const bool &toggleable_)
357 :
Check_Box(upper_left_, lower_right_, checked_, toggleable_),
358 m_radio_button_set(&radio_button_set_)
360 radio_button_set_.lend_Radio_Button(*
this);
364 if(m_radio_button_set)
365 m_radio_button_set->unlend_Radio_Button(*
this);
369 for(std::set<Radio_Button *>::iterator it = m_radio_buttons.begin(); it != m_radio_buttons.end(); ++it)
370 (*it)->set_checked((*it) == &radio_button);
374 for(std::set<Radio_Button *>::iterator it = m_radio_buttons.begin(); it != m_radio_buttons.end(); ++it)
375 (*it)->set_checked(
false);
378 void Radio_Button_Set::lend_Radio_Button(
Radio_Button &radio_button) {
379 m_radio_buttons.insert(&radio_button);
382 void Radio_Button_Set::unlend_Radio_Button(Radio_Button &radio_button) {
383 m_radio_buttons.erase(&radio_button);
384 radio_button.m_radio_button_set = 0;
396 return m_slider_radius;
400 return m_slider_position;
408 m_slider_radius = radius_;
412 if(slider_position_ < 0.0
f)
413 m_slider_position = 0.0f;
414 else if(slider_position_ > 1.0
f)
415 m_slider_position = 1.0f;
417 m_slider_position = slider_position_;
421 return m_mouse_wheel_inverted;
425 m_mouse_wheel_inverted =
invert;
429 return m_mouse_wheel_continuous_rate;
433 m_mouse_wheel_continuous_rate = mouse_wheel_continuous_rate;
437 return m_line_segment;
445 assert(range_.first <= range_.second);
454 const int clamped = value < m_range.first ? m_range.first : value > m_range.second ? m_range.second :
value;
459 return m_button_renderer;
463 if(delete_m_button_renderer)
464 delete m_button_renderer;
465 m_button_renderer = renderer;
466 delete_m_button_renderer =
true;
468 m_normal_button.lend_Renderer(m_button_renderer);
469 for(std::vector<Selector_Button *>::iterator it = m_selector_buttons.begin(); it != m_selector_buttons.end(); ++it)
470 (*it)->lend_Renderer(m_button_renderer);
475 delete_m_button_renderer =
false;
483 return m_slider_renderer;
487 if(delete_m_slider_renderer)
488 delete m_slider_renderer;
489 m_slider_renderer = renderer;
490 delete_m_slider_renderer =
true;
492 m_selector_slider.lend_Renderer(m_slider_renderer);
497 delete_m_button_renderer =
false;
505 return m_slider_bg_renderer;
509 if(delete_m_slider_bg_renderer)
510 delete m_slider_bg_renderer;
511 m_slider_bg_renderer = renderer;
512 delete_m_slider_bg_renderer =
true;
517 delete_m_slider_bg_renderer =
false;
531 m_normal_button.font_name = m_font;
532 for(std::vector<Selector_Button *>::iterator it = m_selector_buttons.begin(); it != m_selector_buttons.end(); ++it)
533 (*it)->font_name = m_font;
557 return size_t(m_lines.size());
577 m_text.
color = text_color_;
581 m_justify = justify_;
590 for(
unsigned int i = 0;
i != begin; ++
i)
591 new_text += m_lines[
i].unformatted;
593 if(m_lines[end].endled)
594 new_text += m_lines[
end].unformatted.substr(1
u);
596 new_text += m_lines[
end].unformatted;
599 new_text += m_lines[
i].unformatted;
602 m_text.
text = new_text;
605 invalidate_edit_pos();
609 return m_bg_renderer;
613 if(delete_m_bg_renderer)
614 delete m_bg_renderer;
615 m_bg_renderer = renderer;
616 delete_m_bg_renderer =
true;
621 delete_m_bg_renderer =
false;
628 void Text_Box::invalidate_edit_pos() {
630 m_cursor_index.
x = -1;
631 m_cursor_index.
y = -1;
634 Widget_Input_Repeater::Widget_Input_Repeater(
Widget &widget_,
635 const int &repeat_delay_,
636 const int &repeat_interval_)
637 : m_widget(&widget_),
638 m_repeat_delay(repeat_delay_),
639 m_repeat_interval(repeat_interval_),
659 m_widgets.push_back(&widget);
663 m_busy_one = &widget;
669 std::vector<Widget *>::iterator it = std::find(m_widgets.begin(), m_widgets.end(), &widget);
670 if(it != m_widgets.end())
673 if(m_busy_one == &widget) {
Widget_Renderer_Pair< T1, T2 > * make_Widget_Renderer_Pair(const T1 *const &first_, const bool &delete_first_, const T2 *const &second_, const bool &delete_second_)
Point2f get_end_point_b() const
The Video Rendering Singleton.
Colors & get_Colors()
Get access to the singleton.
void set_slider_radius(const float &radius_)
const Font & get_Font() const
void lend_Slider_Renderer(const Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget no ownership.
const Point3f & get_end_point_a() const
void fax_BG_Renderer(const Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget a copy.
void give_BG_Renderer(Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget ownership.
void invert_mouse_wheel(const bool &invert)
void set_font_name(const String &font_name_)
void lend_Text_Button_Renderer(const Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget no ownership.
const Point3f & get_end_point_b() const
void set_mouse_wheel_continuous_rate(const float &mouse_wheel_continuous_rate)
const Range & get_range() const
void fax_Text_Button_Renderer(const Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget a copy.
void set_slider_position(const float &slider_position_)
const float & get_slider_position() const
const Widget_Render_Function * get_Slider_Renderer() const
Get the current Widget_Render_Function.
size_t get_max_lines() const
A 3D Point represented with floats.
void erase_lines(const unsigned int &begin, const unsigned int &end)
DECLSPEC Uint32 SDLCALL SDL_GetMouseState(int *x, int *y)
Retrieve the current state of the mouse.
void give_Slider_BG_Renderer(Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget ownership.
Keyboard button event structure (event.key.*)
A Featureful 3-Space Vector Class.
Widget_Renderer_Texture(const String &texture_)
const float & get_mouse_wheel_continuous_rate() const
void set_font(const String &font_)
Set the current font.
void give_Slider_Renderer(Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget ownership.
void set_justify(const JUSTIFY &justify_)
virtual void pop_world_stack()=0
Pop a model view matrix off the stack.
const String & get_Font() const
Get the current font.
void set_end_points(const Point2f &end_point_a_, const Point2f &end_point_b_)
const Collision::Line_Segment & get_line_segment() const
void set_value(const int &value)
void fax_Slider_Renderer(const Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget a copy.
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
size_t get_num_lines() const
const Widget_Render_Function * get_BG_Renderer() const
Get the current Widget_Render_Function.
void give_Text_Button_Renderer(Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget ownership.
void set_text_color(const Color &text_color_)
Widget_Renderer_Text(const String &font_name_, const String &text_, const Color &color_)
std::pair< int, int > Range
Mouse wheel event structure (event.wheel.*)
virtual void push_world_stack()=0
Push a model view matrix onto the stack.
const Color & get_text_color() const
void lend_Slider_BG_Renderer(const Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget no ownership.
Vector3f unproject(const Vector3f &screen_coord) const
Map screen coordinates ([viewport.first.x, viewport.second.x], [viewport.first.y, viewport...
const bool & is_toggling() const
void fax_Slider_BG_Renderer(const Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget a copy.
GLenum GLenum GLuint texture
EGLSurface EGLint void ** value
virtual void translate_scene(const Vector3f &direction)=0
Translate the scene.
Mouse motion event structure (event.motion.*)
void lend_BG_Renderer(const Widget_Render_Function *const &renderer)
Set the current Widget_Render_Function, giving the Widget no ownership.
Point2f get_end_point_a() const
void set_checked(const bool &checked_)
void set_text(const String &text_)
void set_range(const Range &range_)
const String & get_text() const
const String & get_font_name() const
Fonts & get_Fonts()
Get access to the singleton.
const bool & is_checked() const
Video & get_Video()
Get access to the singleton.
void seek(const int &edit_pos)
const float & get_slider_radius() const
const bool & is_mouse_wheel_inverted() const
A 2D Point represented with floats.
const Widget_Render_Function * get_Text_Button_Renderer() const
Get the current Widget_Render_Function.
const JUSTIFY & get_justify() const
const Widget_Render_Function * get_Slider_BG_Renderer() const
Get the current Widget_Render_Function.
A 2D Point represented with integers.