zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Widget.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
219 #ifndef ZENI_WIDGET_H
220 #define ZENI_WIDGET_H
221 
222 #include <Zeni/Collision.h>
223 #include <Zeni/Coordinate.h>
224 #include <Zeni/Font.h>
225 #include <Zeni/Line_Segment.h>
226 #include <Zeni/Projector.h>
227 #include <Zeni/String.h>
228 #include <Zeni/Texture.h>
229 #include <Zeni/Timer.h>
230 #include <Zeni/Quadrilateral.h>
231 #include <Zeni/Vertex2f.h>
232 #include <Zeni/Video.h>
233 
234 #include <vector>
235 #include <set>
236 
237 #include <Zeni/Define.h>
238 
239 namespace Zeni {
240 
241  class Widget_Render_Function;
242 
243  class ZENI_REST_DLL Widget {
244  Widget(const Widget &);
245  Widget & operator=(const Widget &);
246 
247  public:
248  inline Widget();
249  virtual ~Widget();
250 
251  inline const bool & is_busy() const;
252  inline const bool & is_editable() const;
253  inline const float & get_layer() const;
254  inline void set_busy(const bool &busy_);
255  virtual void set_editable(const bool &editable_);
256  inline void set_layer(const float &layer_ = 0.0f);
257 
258 #ifndef ANDROID
259  inline void on_event(const SDL_KeyboardEvent &event);
260  inline void on_event(const SDL_MouseButtonEvent &event);
261  inline void on_event(const SDL_MouseButtonEvent &event, const Projector2D &projector);
262  inline void on_event(const SDL_MouseMotionEvent &event);
263  inline void on_event(const SDL_MouseMotionEvent &event, const Projector2D &projector);
264 #if SDL_VERSION_ATLEAST(2,0,0)
265  inline void on_event(const SDL_MouseWheelEvent &event);
266  inline void on_event(const SDL_MouseWheelEvent &event, const Projector2D &projector);
267 #endif
268 #endif
269 
270 #ifndef ANDROID
271  virtual void on_key(const SDL_Keysym & /*keysym*/, const bool & /*down*/) {}
272 #endif
273  virtual void on_mouse_button(const Point2i &pos, const bool &down, const int &button) = 0;
274  virtual void on_mouse_motion(const Point2i &pos) = 0;
275 #if SDL_VERSION_ATLEAST(2,0,0)
276  virtual void on_mouse_wheel(const Point2i &pos, const int &up) = 0;
277 #endif
278 
279  virtual void perform_logic() {}
280 
281  inline void render() const;
282 
283  inline const Widget_Render_Function * get_Renderer() const;
284  inline void give_Renderer(Widget_Render_Function * const &renderer);
285  inline void lend_Renderer(const Widget_Render_Function * const &renderer);
286  inline void fax_Renderer(const Widget_Render_Function * const &renderer);
287 
288  virtual void render_impl() const;
289 
290  private:
291  float m_layer;
292  bool m_busy;
293  bool m_editable;
294 
295  Widget_Render_Function * m_renderer;
296  bool delete_m_renderer;
297  };
298 
299  class ZENI_REST_DLL Widget_Render_Function {
300  public:
302 
303  virtual void render_to(const Widget &widget) = 0;
304 
305  virtual Widget_Render_Function * get_duplicate() const = 0;
306  };
307 
308  template <typename T1, typename T2>
310  public:
311  inline Widget_Renderer_Pair(const T1 * const &first_, const bool &delete_first_,
312  const T2 * const &second_, const bool &delete_second_);
313  virtual ~Widget_Renderer_Pair();
314 
315  inline const T1 * const & first() const;
316  inline const T2 * const & second() const;
317  inline T1 * const & first();
318  inline T2 * const & second();
319 
320  virtual void render_to(const Widget &widget);
321 
323 
324  private:
325  T1 * m_first;
326  bool delete_m_first;
327 
328  T2 * m_second;
329  bool delete_m_second;
330  };
331 
332  template <typename T1, typename T2>
333  Widget_Renderer_Pair<T1, T2> * make_Widget_Renderer_Pair(const T1 * const &first_, const bool &delete_first_,
334  const T2 * const &second_, const bool &delete_second_);
335 
336  class ZENI_REST_DLL Widget_Renderer_Text : public Widget_Render_Function {
337  public:
338  inline Widget_Renderer_Text(const String &font_name_, const String &text_, const Color &color_);
339 
341  virtual void render_to(const Widget &widget);
342 
343  virtual Widget_Renderer_Text * get_duplicate() const;
344 
348  };
349 
350  class ZENI_REST_DLL Widget_Renderer_Color : public Widget_Render_Function {
351  public:
352  inline Widget_Renderer_Color(const Color &color_);
353 
355  virtual void render_to(const Widget &widget);
356 
357  virtual Widget_Renderer_Color * get_duplicate() const;
358 
360  };
361 
362  class ZENI_REST_DLL Widget_Renderer_Texture : public Widget_Render_Function {
363  public:
364  inline Widget_Renderer_Texture(const String &texture_);
365  inline Widget_Renderer_Texture(const String &texture_,
366  const Point2f &tex_coord_ul_,
367  const Point2f &tex_coord_ll_,
368  const Point2f &tex_coord_lr_,
369  const Point2f &tex_coord_ur_);
370 
372  virtual void render_to(const Widget &widget);
373 
374  virtual Widget_Renderer_Texture * get_duplicate() const;
375 
381  };
382 
383  class ZENI_REST_DLL Widget_Renderer_Tricolor : public Widget_Renderer_Color {
384  public:
385  inline Widget_Renderer_Tricolor();
386  inline Widget_Renderer_Tricolor(const Color &bg_normal_, const Color &bg_clicked_, const Color &bg_hovered_strayed_,
387  const Color &text_normal_, const Color &text_clicked_, const Color &text_hovered_strayed_);
388 
390  virtual void render_to(const Widget &widget);
391 
392  virtual Widget_Renderer_Tricolor * get_duplicate() const;
393 
400  };
401 
402  class ZENI_REST_DLL Widget_Renderer_Check_Box : public Widget_Render_Function {
403  public:
404  inline Widget_Renderer_Check_Box();
405  inline Widget_Renderer_Check_Box(const Color &border_color_, const Color &check_color_);
406 
408  virtual void render_to(const Widget &widget);
409 
410  virtual Widget_Renderer_Check_Box * get_duplicate() const;
411 
414  };
415 
416  class ZENI_REST_DLL Widget_Renderer_Slider : public Widget_Render_Function {
417  public:
418  inline Widget_Renderer_Slider();
419  inline Widget_Renderer_Slider(const Color &line_color_, const Color &slider_color_);
420 
422  virtual void render_to(const Widget &widget);
423 
424  virtual Widget_Renderer_Slider * get_duplicate() const;
425 
428  };
429 
430  class ZENI_REST_DLL Widget_Rectangle {
431  public:
432  inline Widget_Rectangle(const Point2f &upper_left_, const Point2f &lower_right_);
433  virtual ~Widget_Rectangle() {}
434 
435  inline const Point2f & get_upper_left() const;
436  inline Point2f get_lower_left() const;
437  inline const Point2f & get_lower_right() const;
438  inline Point2f get_upper_right() const;
439 
440  virtual void set_upper_left(const Point2f &upper_left_);
441  virtual void set_lower_right(const Point2f &lower_right_);
442 
443  inline float get_height() const;
444  inline float get_width() const;
445  inline Point2f get_center() const;
446 
447  inline bool is_inside(const Point2i &pos) const;
448 
449  private:
450  Point2f m_upper_left;
451  Point2f m_lower_right;
452  };
453 
454  class ZENI_REST_DLL Widget_Button : public Widget, public Widget_Rectangle {
455  Widget_Button(const Widget_Button &);
456  Widget_Button & operator=(const Widget_Button &);
457 
458  public:
459  enum State {NORMAL, CLICKED, HOVERED, STRAYED, UNACTIONABLE};
460 
461  inline Widget_Button(const Point2f &upper_left_, const Point2f &lower_right_);
462 
463  inline const State & get_State() const;
464 
465  virtual void on_mouse_button(const Point2i &pos, const bool &down, const int &button);
466  virtual void on_mouse_motion(const Point2i &pos);
467 #if SDL_VERSION_ATLEAST(2,0,0)
468  virtual void on_mouse_wheel(const Point2i &pos, const int &up);
469 #endif
470 
472  virtual void on_hover() {}
474  virtual void on_unhover() {}
475 
477  virtual void on_click() {}
479  virtual void on_stray() {}
481  virtual void on_unstray() {}
482 
484  virtual void on_accept() {}
486  virtual void on_reject() {}
487 
488  private:
489  State m_state;
490  };
491 
492  class ZENI_REST_DLL Text_Button : public Widget_Button, public Widget_Renderer_Text {
493  Text_Button(const Text_Button &);
494  Text_Button & operator=(const Text_Button &);
495 
496  public:
497  inline Text_Button(const Point2f &upper_left_, const Point2f &lower_right_,
498  const String &font_name_, const String &text_);
499  };
500 
501  class ZENI_REST_DLL Check_Box : public Widget_Button {
502  Check_Box(const Check_Box &);
503  Check_Box & operator=(const Check_Box &);
504 
505  public:
506  inline Check_Box(const Point2f &upper_left_, const Point2f &lower_right_,
507  const bool &checked_ = false, const bool &toggleable_ = true);
508 
509  inline const bool & is_checked() const;
510  inline void set_checked(const bool &checked_);
511  inline const bool & is_toggling() const;
512 
513  virtual void on_accept();
514 
515  virtual void on_click();
516  virtual void on_unstray();
517 
518  virtual void on_reject();
519  virtual void on_stray();
520 
521  private:
522  bool m_checked;
523  bool m_toggling;
524  };
525 
526  class ZENI_REST_DLL Radio_Button;
527  class ZENI_REST_DLL Radio_Button_Set : public Widget {
529  Radio_Button_Set & operator=(const Radio_Button_Set &);
530 
531  friend class Radio_Button;
532 
533  public:
535 
536  virtual void on_mouse_button(const Point2i &pos, const bool &down, const int &button);
537  virtual void on_mouse_motion(const Point2i &pos);
538 
539  inline void accept(Radio_Button &radio_button);
540  inline void clear();
541 
542  virtual void render_impl() const;
543 
544  private:
545  inline void lend_Radio_Button(Radio_Button &radio_button);
546  inline void unlend_Radio_Button(Radio_Button &radio_button);
547 
548 #ifdef _WINDOWS
549 #pragma warning( push )
550 #pragma warning( disable : 4251 )
551 #endif
552  std::set<Radio_Button *> m_radio_buttons;
553 #ifdef _WINDOWS
554 #pragma warning( pop )
555 #endif
556  };
557 
558  class ZENI_REST_DLL Radio_Button : public Check_Box {
559  Radio_Button(const Radio_Button &);
560  Radio_Button & operator=(const Radio_Button &);
561 
562  friend class Radio_Button_Set;
563 
564  public:
565  inline Radio_Button(Radio_Button_Set &radio_button_set_,
566  const Point2f &upper_left_, const Point2f &lower_right_,
567  const bool &checked_ = false, const bool &toggleable_ = true);
568  inline ~Radio_Button();
569 
570  virtual void on_accept();
571 
572  private:
573  Radio_Button_Set * m_radio_button_set;
574  };
575 
576  class ZENI_REST_DLL Slider : public Widget {
577  Slider(const Slider &);
578  Slider & operator=(const Slider &);
579 
580  public:
581  Slider(const Point2f &end_point_a_, const Point2f &end_point_b_,
582  const float &slider_radius_,
583  const float &slider_position_ = ZENI_DEFAULT_SLIDER_POSITION);
584 
585  inline Point2f get_end_point_a() const;
586  inline Point2f get_end_point_b() const;
587  inline const float & get_slider_radius() const;
588  inline const float & get_slider_position() const;
589 
590  inline void set_end_points(const Point2f &end_point_a_, const Point2f &end_point_b_);
591  inline void set_slider_radius(const float &radius_);
592  inline void set_slider_position(const float &slider_position_);
593 
594  virtual void on_mouse_button(const Point2i &pos, const bool &down, const int &button);
595  virtual void on_mouse_motion(const Point2i &pos);
596 #if SDL_VERSION_ATLEAST(2,0,0)
597  virtual void on_mouse_wheel(const Point2i &pos, const int &up);
598 #endif
599 
600  virtual void on_slide();
601  virtual void on_accept();
602 
603  inline const bool & is_mouse_wheel_inverted() const;
604  inline void invert_mouse_wheel(const bool &invert);
605 
606  inline const float & get_mouse_wheel_continuous_rate() const;
607  inline void set_mouse_wheel_continuous_rate(const float &mouse_wheel_continuous_rate);
608 
609  protected:
610  inline const Collision::Line_Segment & get_line_segment() const;
611 
612  private:
613  Collision::Line_Segment m_line_segment;
614  float m_slider_radius;
615 
616  bool m_mouse_wheel_inverted;
617  float m_mouse_wheel_continuous_rate;
618 
619  float m_slider_position;
620  float m_backup_position;
621  bool m_down;
622  };
623 
624  class ZENI_REST_DLL Slider_Int : public Slider {
625  Slider_Int(const Slider_Int &);
626  Slider_Int & operator=(const Slider_Int &);
627 
628  public:
629  typedef std::pair<int, int> Range;
630 
631  Slider_Int(const Range &range,
632  const Point2f &end_point_a_, const Point2f &end_point_b_,
633  const float &slider_radius_,
634  const float &slider_position_ = ZENI_DEFAULT_SLIDER_POSITION);
635 
636  inline const Range & get_range() const;
637  inline void set_range(const Range &range_);
638 
639  inline int get_value() const;
640  inline void set_value(const int &value);
641 
642  virtual void on_slide();
643 #if SDL_VERSION_ATLEAST(2,0,0)
644  virtual void on_mouse_wheel(const Point2i &pos, const int &up);
645 #else
646  virtual void on_mouse_button(const Point2i &pos, const bool &down, const int &button);
647 #endif
648 
649  private:
650 #ifdef _WINDOWS
651 #pragma warning( push )
652 #pragma warning( disable : 4251 )
653 #endif
654  Range m_range;
655 #ifdef _WINDOWS
656 #pragma warning( pop )
657 #endif
658  };
659 
660  class ZENI_REST_DLL Selector : public Widget {
661  Selector(const Selector &);
662  Selector & operator=(const Selector &);
663 
664  class ZENI_REST_DLL Normal_Button : public Text_Button {
665  Normal_Button(const Normal_Button &);
666  Normal_Button & operator=(const Normal_Button &);
667 
668  public:
669  Normal_Button(Selector &selector,
670  const Point2f &upper_left_,
671  const Point2f &lower_right_);
672 
673  void on_accept();
674 
675  private:
676  Selector * m_selector;
677  };
678 
679  class ZENI_REST_DLL Selector_Button : public Text_Button {
680  Selector_Button(const Selector_Button &);
681  Selector_Button & operator=(const Selector_Button &);
682 
683  public:
684  Selector_Button(Selector &selector,
685  const String &option,
686  const Point2f &upper_left_,
687  const Point2f &lower_right_);
688 
689  void on_accept();
690 
691  private:
692  Selector * m_selector;
693  };
694 
695  class ZENI_REST_DLL Selector_Slider : public Widget_Rectangle, public Slider_Int {
696  Selector_Slider(const Selector_Slider &);
697  Selector_Slider & operator=(const Selector_Slider &);
698 
699  public:
700  Selector_Slider(Selector &selector,
701  const float &slider_radius_,
702  const std::pair<float, float> &bg_coordinates_);
703 
704  void set_end_points(const Point2f &end_point_a_, const Point2f &end_point_b_);
705 
706  void on_slide();
707 
708  void render_impl() const;
709 
710  private:
711  Selector * m_selector;
712  };
713 
714  public:
715  typedef std::vector<String> Options;
716 
717  Selector(const Point2f &upper_left_, const Point2f &lower_right_,
718  const Point2f &expanded_upper_left_, const Point2f &expanded_lower_right_,
719  const String &font_);
720  ~Selector();
721 
722  const Options & get_options() const;
723 
724  void add_option(const String &option);
725  void remove_option(const String &option);
726 
727  String get_selected() const;
728  void select_option(const String &option);
729 
730  virtual void on_mouse_button(const Point2i &pos, const bool &down, const int &button);
731  virtual void on_mouse_motion(const Point2i &pos);
732 #if SDL_VERSION_ATLEAST(2,0,0)
733  virtual void on_mouse_wheel(const Point2i &pos, const int &up);
734 #endif
735 
736  virtual void on_accept(const String &option);
737 
738  virtual void render_impl() const;
739 
740  inline const Widget_Render_Function * get_Text_Button_Renderer() const;
741  inline void give_Text_Button_Renderer(Widget_Render_Function * const &renderer);
742  inline void lend_Text_Button_Renderer(const Widget_Render_Function * const &renderer);
743  inline void fax_Text_Button_Renderer(const Widget_Render_Function * const &renderer);
744 
745  inline const Widget_Render_Function * get_Slider_Renderer() const;
746  inline void give_Slider_Renderer(Widget_Render_Function * const &renderer);
747  inline void lend_Slider_Renderer(const Widget_Render_Function * const &renderer);
748  inline void fax_Slider_Renderer(const Widget_Render_Function * const &renderer);
749 
750  inline const Widget_Render_Function * get_Slider_BG_Renderer() const;
751  inline void give_Slider_BG_Renderer(Widget_Render_Function * const &renderer);
752  inline void lend_Slider_BG_Renderer(const Widget_Render_Function * const &renderer);
753  inline void fax_Slider_BG_Renderer(const Widget_Render_Function * const &renderer);
754 
755  inline const String & get_Font() const;
756  inline void set_font(const String &font_);
757 
758  private:
759  const Widget_Render_Function * get_Renderer() const;
760  void give_Renderer(Widget_Render_Function * const &);
761  void lend_Renderer(const Widget_Render_Function * const &);
762  void fax_Renderer(const Widget_Render_Function * const &);
763 
764  float button_height() const;
765  float vertical_offset() const;
766 
767  void decide_visible(const size_t &centered);
768 
769  std::pair<Point2f, Point2f> visible_region() const;
770 
771  void add_selector_button(const String &option);
772 
773  void build_selector_buttons();
774 
775  void clear();
776 
777  Widget_Render_Function * m_button_renderer;
778  bool delete_m_button_renderer;
779  Widget_Render_Function * m_slider_renderer;
780  bool delete_m_slider_renderer;
781  Widget_Render_Function * m_slider_bg_renderer;
782  bool delete_m_slider_bg_renderer;
783  String m_font;
784 
785  Widget_Rectangle m_expanded;
786 
787 #ifdef _WINDOWS
788 #pragma warning( push )
789 #pragma warning( disable : 4251 )
790 #endif
791  Options m_options;
792 #ifdef _WINDOWS
793 #pragma warning( pop )
794 #endif
795  size_t m_option;
796 
797  bool m_selected;
798 
799  Normal_Button m_normal_button;
800 #ifdef _WINDOWS
801 #pragma warning( push )
802 #pragma warning( disable : 4251 )
803 #endif
804  std::vector<Selector_Button *> m_selector_buttons;
805 #ifdef _WINDOWS
806 #pragma warning( pop )
807 #endif
808  Selector_Slider m_selector_slider;
809 
810  size_t view_start;
811  size_t view_end;
812  size_t view_offset;
813  size_t view_hidden;
814  };
815 
816  class ZENI_REST_DLL Text_Box : public Widget_Button {
817  Text_Box(const Text_Box &);
818  Text_Box & operator=(const Text_Box &);
819 
820  public:
821  Text_Box(const Point2f &upper_left_, const Point2f &lower_right_,
822  const String &font_name_, const String &text_, const Color &text_color_,
823  const bool &editable_ = ZENI_DEFAULT_TEXTBOX_EDITABLE,
824  const JUSTIFY &justify_ = ZENI_DEFAULT_JUSTIFY,
825  const int &tab_spaces_ = ZENI_DEFAULT_TAB_SPACES);
826  ~Text_Box();
827 
828 #ifndef ANDROID
829  virtual void on_key(const SDL_Keysym &keysym, const bool &down);
830 #endif
831 
832  virtual void on_mouse_button(const Point2i &pos, const bool &down, const int &button);
833  virtual void on_accept();
834 
835  virtual void on_focus();
836  virtual void on_unfocus();
837  virtual void on_change();
838 
839  inline const String & get_font_name() const;
840  inline const Font & get_Font() const;
841  inline const String & get_text() const;
842  inline const Color & get_text_color() const;
843  inline const JUSTIFY & get_justify() const;
844  inline size_t get_num_lines() const;
845  inline size_t get_max_lines() const;
846 
847  virtual void set_editable(const bool &editable_);
848  virtual void set_upper_left(const Point2f &upper_left_);
849  virtual void set_lower_right(const Point2f &lower_right_);
850  inline void set_font_name(const String &font_name_);
851  inline void set_text(const String &text_);
852  inline void set_text_color(const Color &text_color_);
853  inline void set_justify(const JUSTIFY &justify_);
854  inline void erase_lines(const unsigned int &begin, const unsigned int &end);
855 
856  const int & get_edit_pos() const;
857  int get_cursor_pos() const;
858  int get_max_seek() const;
859  int get_max_cursor_seek() const;
860 
861  void seek(const int &edit_pos);
862  void seek_cursor(const int &cursor_pos);
863  void set_focus(const bool &value);
864 
865  virtual void render_impl() const;
866 
867  inline const Widget_Render_Function * get_BG_Renderer() const;
868  inline void give_BG_Renderer(Widget_Render_Function * const &renderer);
869  inline void lend_BG_Renderer(const Widget_Render_Function * const &renderer);
870  inline void fax_BG_Renderer(const Widget_Render_Function * const &renderer);
871 
872  private:
873  const Widget_Render_Function * get_Renderer() const;
874  void give_Renderer(Widget_Render_Function * const &);
875  void lend_Renderer(const Widget_Render_Function * const &);
876  void fax_Renderer(const Widget_Render_Function * const &);
877 
878  struct ZENI_REST_DLL Word {
879  enum Type {NONSENSE = 0x0, WORD = 0x1, SPACE = 0x2};
880 
881  Word(const Type &type_ = NONSENSE) : unformatted_glyph_sides(1, 0), type(type_), splittable(false), fpsplit(false) {}
882 
883  String unformatted;
884 #ifdef _WINDOWS
885 #pragma warning( push )
886 #pragma warning( disable : 4251 )
887 #endif
888  std::vector<float> unformatted_glyph_sides;
889 #ifdef _WINDOWS
890 #pragma warning( pop )
891 #endif
892  Type type;
893  bool splittable;
894  bool fpsplit; // indicates it has been split already and a '-' should be appended
895  };
896 
897  struct ZENI_REST_DLL Line : public Word {
898  Line() : glyph_top(0), endled(false) {}
899 
900  String formatted;
901  float glyph_top;
902  bool endled;
903  };
904 
905  void format();
906  void append_word(const Word &word);
907 
908  Widget_Render_Function * m_bg_renderer;
909  bool delete_m_bg_renderer;
910  Widget_Renderer_Text m_text;
911 
912  String clean_string(const String &unclean_string) const;
913  String untablinebreak(const String &tabbed_text) const;
914  float get_text_width(const Font &font, const String &text);
915  float max_line_width() const;
916 
917  inline void invalidate_edit_pos();
918 
919 #ifdef _WINDOWS
920 #pragma warning( push )
921 #pragma warning( disable : 4251 )
922 #endif
923  std::vector<Line> m_lines;
924 #ifdef _WINDOWS
925 #pragma warning( pop )
926 #endif
927 
928  int m_edit_pos;
929  Time m_last_seek;
930 
931  JUSTIFY m_justify;
932  int m_tab_spaces;
933 
934  Point2i m_cursor_pos;
935  Point2i m_cursor_index;
936 
937  public:
938  static void reformat_all();
939 
940  private:
941 #ifdef _WINDOWS
942 #pragma warning( push )
943 #pragma warning( disable : 4251 )
944 #endif
945  static class Reinit : public Event::Handler {
946  void operator()() {
948  }
949 
950  Reinit * duplicate() const {
951  return new Reinit;
952  }
953 
954  public:
955  Reinit() {}
956 
957  private:
958  // Undefined
959  Reinit(const Reinit &);
960  Reinit operator=(const Reinit &);
961  } g_reinit;
962 #ifdef _WINDOWS
963 #pragma warning( pop )
964 #endif
965 
966  static std::set<Text_Box *> & get_text_boxes();
967  };
968 
969  class ZENI_REST_DLL Widget_Input_Repeater : public Widget {
971  Widget_Input_Repeater & operator=(const Widget_Input_Repeater &);
972 
973  public:
975  inline Widget_Input_Repeater(Widget &widget_,
976  const int &repeat_delay_ = SDL_DEFAULT_REPEAT_DELAY,
977  const int &repeat_interval_ = SDL_DEFAULT_REPEAT_INTERVAL);
978 
979  inline Widget * const & get_widget() const;
980  inline const int & get_repeat_delay() const;
981  inline const int & get_repeat_interval() const ;
982 
983  inline void set_widget(Widget &widget_);
984  inline void set_repeat_delay(const int &repeat_delay_ = SDL_DEFAULT_REPEAT_DELAY);
985  inline void set_repeat_interval(const int &repeat_interval_ = SDL_DEFAULT_REPEAT_INTERVAL);
986 
987 #ifndef ANDROID
988  virtual void on_key(const SDL_Keysym &keysym, const bool &down);
990 #endif
991 
993  virtual void on_mouse_button(const Point2i &pos, const bool &down, const int &button);
995  virtual void on_mouse_motion(const Point2i &pos);
996 
998  virtual void perform_logic();
999 
1000  // render is simply passed through
1001  virtual void render_impl() const;
1002 
1003  private:
1004  const Widget_Render_Function * get_Renderer() const;
1005  void give_Renderer(Widget_Render_Function * const &);
1006  void lend_Renderer(const Widget_Render_Function * const &);
1007  void fax_Renderer(const Widget_Render_Function * const &);
1008 
1009  Widget * m_widget;
1010  int m_repeat_delay;
1011  int m_repeat_interval;
1012 
1013  Time m_last_repeated;
1014  bool m_active;
1015  bool m_delay_finished;
1016 
1017 #ifndef ANDROID
1018  SDL_Keysym m_keysym;
1019 #endif
1020  bool m_down;
1021  };
1022 
1023  class ZENI_REST_DLL Widgets : public Widget {
1024  Widgets(const Widgets &);
1025  Widgets & operator=(const Widgets &);
1026 
1027  public:
1028  inline Widgets();
1029 
1030  inline void lend_Widget(Widget &widget);
1031  inline void unlend_Widget(Widget &widget);
1032 
1033 #ifndef ANDROID
1034  virtual void on_key(const SDL_Keysym &keysym, const bool &down);
1035 #endif
1036 
1037  virtual void on_mouse_button(const Point2i &pos, const bool &down, const int &button);
1038  virtual void on_mouse_motion(const Point2i &pos);
1039 #if SDL_VERSION_ATLEAST(2,0,0)
1040  virtual void on_mouse_wheel(const Point2i &pos, const int &up);
1041 #endif
1042 
1043  virtual void perform_logic();
1044 
1045  virtual void render_impl() const;
1046 
1047  private:
1048  const Widget_Render_Function * get_Renderer() const;
1049  void give_Renderer(Widget_Render_Function * const &);
1050  void lend_Renderer(const Widget_Render_Function * const &);
1051  void fax_Renderer(const Widget_Render_Function * const &);
1052 
1053 #ifdef _WINDOWS
1054 #pragma warning( push )
1055 #pragma warning( disable : 4251 )
1056 #endif
1057  mutable std::vector<Widget *> m_widgets;
1058 #ifdef _WINDOWS
1059 #pragma warning( pop )
1060 #endif
1061  Widget * m_busy_one;
1062  };
1063 
1064  class ZENI_REST_DLL Widget_Renderer_Wrong_Type : public Error {
1065  public:
1066  Widget_Renderer_Wrong_Type() : Error("Widget_Renderer_Function received an unexpected type") {}
1067  };
1068 
1069 }
1070 
1071 #include <Zeni/Undefine.h>
1072 
1073 #endif
#define ZENI_DEFAULT_TAB_SPACES
Definition: Define.h:64
virtual Widget_Renderer_Pair< T1, T2 > * get_duplicate() const
Definition: Widget.hxx:229
#define ZENI_DEFAULT_JUSTIFY
Definition: Define.h:65
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
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_)
Definition: Widget.hxx:234
A Radio Button.
Definition: Widget.h:558
GLclampf f
Definition: glew.h:3390
A Check Box.
Definition: Widget.h:501
virtual void on_accept()
Called when the cursor is released inside the button.
Definition: Widget.h:484
A Set of Radio Buttons.
Definition: Widget.h:527
GLboolean invert
Definition: glew.h:1408
#define ZENI_DEFAULT_TEXTBOX_EDITABLE
Definition: Define.h:66
const T1 *const & first() const
Definition: Widget.hxx:201
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
static void reformat_all()
Reformat all Text_Box instances.
Definition: Widget.cpp:1397
#define SDL_DEFAULT_REPEAT_DELAY
Definition: SDL.h:6
The SDL keysym structure, used in key events.
Definition: SDL_keyboard.h:47
virtual void render_to(const Widget &widget)
Definition: Widget.hxx:221
virtual void on_unhover()
Called when the cursor leaves the button without clicking.
Definition: Widget.h:474
virtual ~Widget_Rectangle()
Definition: Widget.h:433
JUSTIFY
Definition: Font.h:68
#define ZENI_DEFAULT_SLIDER_POSITION
Definition: Define.h:63
Collision Line Segment.
Definition: Collision.h:233
#define SDL_DEFAULT_REPEAT_INTERVAL
Definition: SDL.h:7
A Text_Box.
Definition: Widget.h:816
GLenum GLint * range
Definition: glew.h:3391
GLuint GLenum option
Definition: glew.h:3180
Keyboard button event structure (event.key.*)
Definition: SDL_events.h:176
An Input Repeater Class.
Definition: Widget.h:969
virtual void on_hover()
Called when the cursor passes over the button.
Definition: Widget.h:472
virtual void on_key(const SDL_Keysym &, const bool &)
Definition: Widget.h:271
The Widget base class.
Definition: Widget.h:243
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl2ext.h:845
The 2D Projector.
Definition: Projector.h:86
Font Abstraction.
Definition: Font.h:70
A Button Widget.
Definition: Widget.h:454
enum State_ State
A Widget Set.
Definition: Widget.h:1023
std::pair< int, int > Range
Definition: Widget.h:629
Mouse wheel event structure (event.wheel.*)
Definition: SDL_events.h:251
const T2 *const & second() const
Definition: Widget.hxx:206
virtual void on_click()
Called when the cursor downclicks the button.
Definition: Widget.h:477
A Text Button Widget.
Definition: Widget.h:492
virtual ~Widget_Renderer_Pair()
Definition: Widget.hxx:193
EGLSurface EGLint void ** value
Definition: eglext.h:301
Mouse motion event structure (event.motion.*)
Definition: SDL_events.h:218
A Slider.
Definition: Widget.h:576
Mouse button event structure (event.button.*)
Definition: SDL_events.h:234
std::vector< String > Options
Definition: Widget.h:715
GLuint GLuint end
Definition: glew.h:1239
virtual void on_stray()
Called when the cursor is dragged off the button after being clicked.
Definition: Widget.h:479
virtual void perform_logic()
Definition: Widget.h:279
The Error Class.
Definition: Error.h:52
virtual void on_unstray()
Called when the cursor is dragged back onto the button without releasing the clicker.
Definition: Widget.h:481
virtual void on_reject()
Called when the cursor is released outside the button.
Definition: Widget.h:486
A 2D Point represented with floats.
Definition: Coordinate.h:98
Widget_Renderer_Pair(const T1 *const &first_, const bool &delete_first_, const T2 *const &second_, const bool &delete_second_)
Definition: Widget.hxx:183
Rectangle positioning.
Definition: Widget.h:430
Color.
Definition: Color.h:41
cl_event event
Definition: glew.h:3556
A Snapshot of the Timer.
Definition: Timer.h:63
A 2D Point represented with integers.
Definition: Coordinate.h:85
virtual ~Widget_Render_Function()
Definition: Widget.h:301