Mercurial > fife-parpg
comparison engine/core/video/cursor.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE Team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 | |
24 // 3rd party library includes | |
25 | |
26 // FIFE includes | |
27 // These includes are split up in two parts, separated by one empty line | |
28 // First block: files included from the FIFE root src directory | |
29 // Second block: files included from the same folder | |
30 #include "util/structures/rect.h" | |
31 #include "util/time/timemanager.h" | |
32 | |
33 #include "imagepool.h" | |
34 #include "animationpool.h" | |
35 #include "animation.h" | |
36 #include "image.h" | |
37 #include "renderbackend.h" | |
38 #include "cursor.h" | |
39 | |
40 namespace FIFE { | |
41 | |
42 Cursor::Cursor(ImagePool* imgpool, AnimationPool* animpool, RenderBackend* renderbackend): | |
43 m_cursor_id(0), | |
44 m_drag_id(0), | |
45 m_cursor_type(CURSOR_NATIVE), | |
46 m_drag_type(CURSOR_NONE), | |
47 m_renderbackend(renderbackend), | |
48 m_imgpool(imgpool), | |
49 m_animpool(animpool), | |
50 m_animtime(0), | |
51 m_drag_animtime(0), | |
52 m_drag_offset_x(0), | |
53 m_drag_offset_y(0), | |
54 m_timemanager(TimeManager::instance()) { | |
55 assert(m_timemanager); | |
56 } | |
57 | |
58 void Cursor::set(MouseCursorType ctype, unsigned int cursor_id) { | |
59 m_cursor_id = cursor_id; | |
60 m_cursor_type = ctype; | |
61 if (ctype == CURSOR_NATIVE) { | |
62 SDL_ShowCursor(1); | |
63 } else { | |
64 SDL_ShowCursor(0); | |
65 if (ctype == CURSOR_ANIMATION) { | |
66 m_animtime = m_timemanager->getTime(); | |
67 } | |
68 } | |
69 } | |
70 | |
71 void Cursor::setDrag(MouseCursorType ctype, unsigned int drag_id, int drag_offset_x, int drag_offset_y) { | |
72 m_drag_type = ctype; | |
73 m_drag_id = drag_id; | |
74 m_drag_offset_x = drag_offset_x; | |
75 m_drag_offset_y = drag_offset_y; | |
76 if (ctype != CURSOR_NONE) { | |
77 if (ctype == CURSOR_ANIMATION) { | |
78 m_drag_animtime = m_timemanager->getTime(); | |
79 } | |
80 } | |
81 } | |
82 | |
83 void Cursor::draw() { | |
84 int mx = 0; | |
85 int my = 0; | |
86 if ((m_cursor_type == CURSOR_NATIVE) && (m_drag_type == CURSOR_NONE)) { | |
87 return; | |
88 } | |
89 SDL_GetMouseState(&mx, &my); | |
90 | |
91 // render possible drag image | |
92 Image* img = NULL; | |
93 if (m_drag_type == CURSOR_IMAGE) { | |
94 img = &m_imgpool->getImage(m_drag_id); | |
95 } else if (m_drag_type == CURSOR_ANIMATION) { | |
96 Animation& anim = m_animpool->getAnimation(m_drag_id); | |
97 int animtime = (m_timemanager->getTime() - m_drag_animtime) % anim.getDuration(); | |
98 img = anim.getFrameByTimestamp(animtime); | |
99 } | |
100 if (img) { | |
101 Rect area(mx + m_drag_offset_x, my + m_drag_offset_y, img->getWidth(), img->getHeight()); | |
102 m_renderbackend->pushClipArea(area, false); | |
103 img->render(area); | |
104 m_renderbackend->popClipArea(); | |
105 } | |
106 | |
107 // render possible cursor image | |
108 img = NULL; | |
109 if (m_cursor_type == CURSOR_IMAGE) { | |
110 img = &m_imgpool->getImage(m_cursor_id); | |
111 } else if (m_cursor_type == CURSOR_ANIMATION) { | |
112 Animation& anim = m_animpool->getAnimation(m_cursor_id); | |
113 int animtime = (m_timemanager->getTime() - m_animtime) % anim.getDuration(); | |
114 img = anim.getFrameByTimestamp(animtime); | |
115 } | |
116 if (img) { | |
117 Rect area(mx, my, img->getWidth(), img->getHeight()); | |
118 m_renderbackend->pushClipArea(area, false); | |
119 img->render(area); | |
120 m_renderbackend->popClipArea(); | |
121 } | |
122 } | |
123 } |