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 drawString(void *font, const std::string &text,
37  float left, float bottom, float right = 0.f, float top = 0.f);
38 
40 
48 void fitWindow(float target_width, float target_height);
49 
50 
52 
56 {
57  static int x();
58  static int y();
59  static int width();
60  static int height();
61  static int border_width();
62  static int border_height();
63  static int screen_width();
64  static 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 onSelect() {}
94  virtual void onDeselect() {}
96  virtual void onIdle() {}
98  virtual void onDisplay() = 0;
100  virtual void onDisplayBefore();
102  virtual void onDisplayAfter();
104 
108  virtual void onReshape(int width, int height);
110 
114  virtual void onPosition(int x, int y) {}
116 
119  virtual void onVisibility(bool visible) {}
121 
127  virtual void onChar(unsigned char code, int mouse_x, int mouse_y) {}
129 
135  virtual void onCharUp(unsigned char code, int mouse_x, int mouse_y) {}
137 
143  virtual void onSpecialKey(int code, int mouse_x, int mouse_y) {}
145 
151  virtual void onSpecialKeyUp(int code, int mouse_x, int mouse_y) {}
153 
156  virtual void onEntry(bool entered) {}
158 
165  virtual void onHover(int mouse_x, int mouse_y) {}
167 
174  virtual void onDrag(int mouse_x, int mouse_y) {}
176 
184  virtual void onMouse(int button, int mouse_x, int mouse_y) {}
186 
192  virtual void onMouseUp(int button, int mouse_x, int mouse_y) {}
194 
200  virtual void onMouseWheel(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 curScreenSelect(AScreen*);
208  static void onIdleWrapper();
209  static void onDisplayWrapper();
210  static void onReshapeWrapper(int width, int height);
211  static void onPositionWrapper(int x, int y);
212  static void onVisibilityWrapper(int status);
213  static void onCharWrapper(unsigned char code, int mouse_x, int mouse_y);
214  static void onCharUpWrapper(unsigned char code, int mouse_x, int mouse_y);
215  static void onSpecialKeyWrapper(int code, int mouse_x, int mouse_y);
216  static void onSpecialKeyUpWrapper(int code, int mouse_x, int mouse_y);
217  static void onEntryWrapper(int status);
218  static void onHoverWrapper(int mouse_x, int mouse_y);
219  static void onDragWrapper(int mouse_x, int mouse_y);
220  static void onMouseButtonWrapper(int button, int state, int x, int y);
221  static void onMouseWheelWrapper(int wheel, int direction, int x, int y);
222 };