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  */
22 #pragma once
23 
24 #include "ViewModelBase.hpp"
25 #include <string>
26 
27 
29 
35 void drawString(void *font, const std::string &text,
36  float left, float bottom, float right = 0.f, float top = 0.f);
37 
39 
44 void fitWindow(float target_width, float target_height);
45 
46 
48 
52 class AScreen
53 {
54 public:
56  virtual ~AScreen();
57 
59 
64  void select();
65 
66 protected:
68  virtual void onSelect() {}
70  virtual void onDeselect() {}
72  virtual void onIdle() {}
74  virtual void onDisplay() = 0;
76  virtual void onDisplayBefore();
78  virtual void onDisplayAfter();
80  virtual void onReshape(int width, int height);
82  virtual void onVisibility(bool visible) {}
84  virtual void onChar(unsigned char code, int mouse_x, int mouse_y) {}
86  virtual void onCharUp(unsigned char code, int mouse_x, int mouse_y) {}
88  virtual void onSpecialKey(int code, int mouse_x, int mouse_y) {}
90  virtual void onSpecialKeyUp(int code, int mouse_x, int mouse_y) {}
92  virtual void onEntry(bool entered) {}
94  virtual void onHover(int mouse_x, int mouse_y) {}
96  virtual void onDrag(int mouse_x, int mouse_y) {}
98  virtual void onMouse(int button, int mouse_x, int mouse_y) {}
100  virtual void onMouseUp(int button, int mouse_x, int mouse_y) {}
102 
106  virtual void onMouseWheel(int wheel_number, int direction, int mouse_x, int mouse_y) {}
107 
108 private:
109  // FreeGlut вызывает нижеперечисленные функции в качестве обработчиков событий.
110  // Static-функции по сути являются "свободными", и могут быть переданы в качестве колбеков FreeGlut'у.
111  // То, что они являются членами AScreen, позволяет им переадресовать вызов
112  // обработчику сообщения, являющимуся методом объекта AScreen (вызвать protected-функцию).
113  static void curScreenSelect(AScreen*);
114  static void onIdleWrapper();
115  static void onDisplayWrapper();
116  static void onReshapeWrapper(int width, int height);
117  static void onVisibilityWrapper(int status);
118  static void onCharWrapper(unsigned char code, int mouse_x, int mouse_y);
119  static void onCharUpWrapper(unsigned char code, int mouse_x, int mouse_y);
120  static void onSpecialKeyWrapper(int code, int mouse_x, int mouse_y);
121  static void onSpecialKeyUpWrapper(int code, int mouse_x, int mouse_y);
122  static void onEntryWrapper(int status);
123  static void onHoverWrapper(int mouse_x, int mouse_y);
124  static void onDragWrapper(int mouse_x, int mouse_y);
125  static void onMouseButtonWrapper(int button, int state, int x, int y);
126  static void onMouseWheelWrapper(int wheel, int direction, int x, int y);
127 };