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 "common/rect.h"
26 #include "common/scummsys.h"
27 #include "graphics/surface.h"
28 
30 struct Screen;
31 
32 // Global state consists of:
33 // - palette (used for the overlay only atm)
34 // - shape (surface, dimensions, hotspot, keycolor)
35 // - visibility
36 // These always get updates by ScummVM, no need to differentiate between engines and the overlay.
37 
38 struct Cursor {
39  Cursor(AtariGraphicsManager *manager, Screen *screen)
40  : _manager(manager)
41  , _parentScreen(screen) {
42  }
43 
44  void reset() {
45  _positionChanged = true;
46  _surfaceChanged = true;
47  _visibilityChanged = false;
48 
49  _savedRect = Common::Rect();
50  }
51 
52  // updates outOfScreen OR srcRect/dstRect (only if visible/needed)
53  void update();
54 
55  // visibility
56  bool setVisible(bool visible) {
57  if (_visible == visible) {
58  return _visible;
59  }
60 
61  bool last = _visible;
62 
63  _visible = visible;
64 
65  _visibilityChanged = true;
66 
67  return last;
68  }
69 
70  // position
71  Common::Point getPosition() const {
72  return Common::Point(_x, _y);
73  }
74  void setPosition(int x, int y) {
75  if (_x == x && _y == y)
76  return;
77 
78  _x = x;
79  _y = y;
80 
81  _positionChanged = true;
82  }
83  void updatePosition(int deltaX, int deltaY);
84 
85  // surface
86  void setSurface(const void *buf, int w, int h, int hotspotX, int hotspotY, uint32 keycolor);
87  void setPalette(const byte *colors, uint start, uint num);
88  void convertTo(const Graphics::PixelFormat &format);
89 
90  bool isVisible() const {
91  return !_outOfScreen && _visible;
92  }
93  bool isChanged() const {
94  return _positionChanged || _surfaceChanged || _visibilityChanged;
95  }
96 
97  bool intersects(const Common::Rect &rect) const {
98  return rect.intersects(_dstRect);
99  }
100 
101  void flushBackground(const Graphics::Surface &srcSurface, const Common::Rect &rect);
102  bool restoreBackground(const Graphics::Surface &srcSurface, bool force);
103  bool draw(bool directRendering, bool force);
104 
105 private:
106  static byte _palette[256*3];
107 
108  AtariGraphicsManager *_manager;
109  Screen *_parentScreen;
110 
111  bool _positionChanged = true;
112  bool _surfaceChanged = true;
113  bool _visibilityChanged = false;
114 
115  bool _visible = false;
116  int _x = -1, _y = -1;
117  bool _outOfScreen = true;
118  Common::Rect _srcRect;
119  Common::Rect _dstRect;
120 
121  Graphics::Surface _savedBackground; // used by direct rendering
122  Common::Rect _savedRect;
123 
124  // related to 'surface'
125  const byte *_buf = nullptr;
126  int _width;
127  int _height;
128  int _hotspotX;
129  int _hotspotY;
130  uint32 _keycolor;
131 
132  Graphics::Surface _surface;
133  Graphics::Surface _surfaceMask;
134  int _rShift, _gShift, _bShift;
135  int _rMask, _gMask, _bMask;
136 };
137 
138 #endif // BACKENDS_GRAPHICS_ATARI_CURSOR_H
Definition: surface.h:67
Definition: pixelformat.h:138
Definition: rect.h:144
Definition: atari-screen.h:60
Definition: atari-cursor.h:38
Definition: rect.h:45
bool intersects(const Rect &r) const
Definition: rect.h:255
Definition: atari-graphics.h:39