ScummVM API documentation
atari-cursor.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_GRAPHICS_ATARI_CURSOR_H
23 #define BACKENDS_GRAPHICS_ATARI_CURSOR_H
24 
25 #include "graphics/surface.h"
26 
27 class AtariSurface;
28 
29 // Global state consists of:
30 // - palette (used for the overlay only atm)
31 // - shape (surface, dimensions, hotspot, keycolor)
32 // - visibility
33 // These always get updates by ScummVM, no need to differentiate between engines and the overlay.
34 
35 struct Cursor {
36  ~Cursor();
37 
38  void reset(AtariSurface* screenSurf, const Graphics::Surface *boundingSurf) {
39  _screenSurf = screenSurf;
40  _boundingSurf = boundingSurf;
41 
42  _positionChanged = true;
43  _surfaceChanged = true;
44  _visibilityChanged = false;
45 
46  _savedRect = _alignedDstRect = Common::Rect();
47  }
48 
49  // updates outOfScreen OR srcRect/dstRect (only if visible/needed)
50  void update();
51 
52  // visibility
53  bool setVisible(bool visible) {
54  if (_visible == visible) {
55  return _visible;
56  }
57 
58  bool last = _visible;
59 
60  _visible = visible;
61 
62  _visibilityChanged = true;
63 
64  return last;
65  }
66  void setSurfaceChanged() {
67  _surfaceChanged = true;
68  }
69 
70  // position
71  Common::Point getPosition() const {
72  return Common::Point(_x, _y);
73  }
74  void setPosition(int x, int y) {
75  //atari_debug("Cursor::setPosition: %d, %d", x, y);
76 
77  if (_x == x && _y == y)
78  return;
79 
80  _x = x;
81  _y = y;
82 
83  _positionChanged = true;
84  }
85  void updatePosition(int deltaX, int deltaY);
86 
87  // surface
88  static void setSurface(const void *buf, int w, int h, int hotspotX, int hotspotY, uint32 keycolor);
89  static void setPalette(const byte *colors, uint start, uint num);
90 
91  bool isVisible() const {
92  return !_outOfScreen && _visible;
93  }
94  bool isChanged() const {
95  return _positionChanged || _surfaceChanged || _visibilityChanged;
96  }
97 
98  Common::Rect flushBackground(const Common::Rect &alignedRect, bool directRendering);
99  void saveBackground();
100  void draw();
101 
102 private:
103  static void convertSurfaceTo(const Graphics::PixelFormat &format);
104  void restoreBackground();
105 
106  AtariSurface *_screenSurf;
107  const Graphics::Surface *_boundingSurf = nullptr;
108 
109  bool _positionChanged = false;
110  bool _surfaceChanged = false;
111  bool _visibilityChanged = false;
112 
113  bool _visible = false;
114  int _x = 0;
115  int _y = 0;
116  bool _outOfScreen = true;
117  Common::Rect _srcRect;
118  Common::Rect _dstRect;
119 
120  Graphics::Surface _savedBackground;
121  Common::Rect _savedRect;
122  Common::Rect _alignedDstRect;
123 
124  // related to 'surface'
125  static bool _globalSurfaceChanged;
126 
127  static byte _palette[256*3];
128 
129  static const byte *_buf;
130  static int _width;
131  static int _height;
132  static int _hotspotX;
133  static int _hotspotY;
134  static uint32 _keycolor;
135 
136  static Graphics::Surface _surface;
137  static Graphics::Surface _surfaceMask;
138 };
139 
140 #endif // BACKENDS_GRAPHICS_ATARI_CURSOR_H
Definition: surface.h:67
Definition: pixelformat.h:138
Definition: rect.h:524
Definition: atari-surface.h:33
Definition: atari-cursor.h:35
Definition: rect.h:144