Zmeika
простая аркадная игра
 Указатель Классы Пространства имен Файлы Функции Переменные Определения типов Перечисления Страницы
Screen.hpp
См. документацию.
1 /*
2  * This file is part of AV Orchid.
3  * Copyright (c) 2013, Dmitri R. Kuvshinov <evetro.here@gmail.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
25 #pragma once
26 #include <string>
27 
28 
30 
36 void draw_stroke_string(void *font, const std::string &text,
37  float left, float bottom, float right = 0.f, float top = 0.f);
38 
40 
48 void fit_window(float target_width, float target_height);
49 
50 
52 
55 namespace Drawing_area_info
56 {
57  int x();
58  int y();
59  int width();
60  int height();
61  int border_width();
62  int border_height();
63  int screen_width();
64  int screen_height();
65 };
66 
67 
69 
73 class AScreen
74 {
75 public:
77  virtual ~AScreen();
78 
80 
83  void select();
84 
86  static bool has_active();
88  static AScreen& get_active();
89 
90 protected:
92  virtual void on_select() {}
94  virtual void on_deselect() {}
96  virtual void on_idle() {}
98  virtual void on_display() = 0;
100  virtual void on_display_before();
102  virtual void on_display_after();
104 
108  virtual void on_reshape(int width, int height);
110 
114  virtual void on_position(int x, int y) {}
116 
119  virtual void on_visibility(bool visible) {}
121 
127  virtual void on_char(unsigned char code, int mouse_x, int mouse_y) {}
129 
135  virtual void on_char_up(unsigned char code, int mouse_x, int mouse_y) {}
137 
143  virtual void on_special_key(int code, int mouse_x, int mouse_y) {}
145 
151  virtual void on_special_key_up(int code, int mouse_x, int mouse_y) {}
153 
156  virtual void on_entry(bool entered) {}
158 
165  virtual void on_hover(int mouse_x, int mouse_y) {}
167 
174  virtual void on_drag(int mouse_x, int mouse_y) {}
176 
184  virtual void on_mouse(int button, int mouse_x, int mouse_y) {}
186 
192  virtual void on_mouse_up(int button, int mouse_x, int mouse_y) {}
194 
200  virtual void on_mouse_wheel(int wheel_number, int direction, int mouse_x, int mouse_y) {}
201 
202 private:
203  // FreeGlut вызывает нижеперечисленные функции в качестве обработчиков событий.
204  // Static-функции по сути являются "свободными", и могут быть переданы в качестве колбеков FreeGlut'у.
205  // То, что они являются членами AScreen, позволяет им переадресовать вызов
206  // обработчику сообщения, являющимуся методом объекта AScreen (вызвать protected-функцию).
207  static void current_screen_select(AScreen*);
208  static void on_idle_wrapper();
209  static void on_display_wrapper();
210  static void on_reshape_wrapper(int width, int height);
211  static void on_position_wrapper(int x, int y);
212  static void on_visibility_wrapper(int status);
213  static void on_char_wrapper(unsigned char code, int mouse_x, int mouse_y);
214  static void on_char_up_wrapper(unsigned char code, int mouse_x, int mouse_y);
215  static void on_special_key_wrapper(int code, int mouse_x, int mouse_y);
216  static void on_special_key_up_wrapper(int code, int mouse_x, int mouse_y);
217  static void on_entry_wrapper(int status);
218  static void on_hover_wrapper(int mouse_x, int mouse_y);
219  static void on_drag_wrapper(int mouse_x, int mouse_y);
220  static void on_mouse_button_wrapper(int button, int state, int x, int y);
221  static void on_mouse_wheel_wrapper(int wheel, int direction, int x, int y);
222 };