Mercurial > sdl-ios-xcode
annotate src/video/bwindow/SDL_BWin.h @ 3983:540466e900db SDL-1.2
Removed textrels from hermes code.
Partially fixes Bugzilla #418.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 27 Jun 2007 10:12:49 +0000 |
parents | 678576473849 |
children | 4e29535b821b |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1013
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
1
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifndef _SDL_BWin_h | |
24 #define _SDL_BWin_h | |
25 | |
1367
e440d5c488c1
Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
26 #include "SDL_config.h" |
e440d5c488c1
Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
27 |
0 | 28 #include <stdio.h> |
29 #include <AppKit.h> | |
30 #include <InterfaceKit.h> | |
31 #include <be/game/DirectWindow.h> | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
32 #if SDL_VIDEO_OPENGL |
0 | 33 #include <be/opengl/GLView.h> |
34 #endif | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
35 #include <support/UTF8.h> |
0 | 36 |
1367
e440d5c488c1
Fixes for BeOS and Solaris builds
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
37 #include "../../main/beos/SDL_BeApp.h" |
0 | 38 #include "SDL_events.h" |
39 #include "SDL_BView.h" | |
40 | |
41 extern "C" { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
42 #include "../../events/SDL_events_c.h" |
3878 | 43 |
44 extern int mouse_relative; | |
0 | 45 }; |
46 | |
47 class SDL_BWin : public BDirectWindow | |
48 { | |
49 public: | |
50 SDL_BWin(BRect bounds) : | |
51 BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) { | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
52 last_buttons = 0; |
0 | 53 the_view = NULL; |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
54 #if SDL_VIDEO_OPENGL |
0 | 55 SDL_GLView = NULL; |
56 #endif | |
57 SDL_View = NULL; | |
58 Unlock(); | |
59 shown = false; | |
60 inhibit_resize = false; | |
61 } | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
62 |
0 | 63 virtual ~SDL_BWin() { |
64 Lock(); | |
65 if ( the_view ) { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
66 #if SDL_VIDEO_OPENGL |
0 | 67 if ( the_view == SDL_GLView ) { |
68 SDL_GLView->UnlockGL(); | |
69 } | |
70 #endif | |
71 RemoveChild(the_view); | |
72 the_view = NULL; | |
73 } | |
74 Unlock(); | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
75 #if SDL_VIDEO_OPENGL |
0 | 76 if ( SDL_GLView ) { |
77 delete SDL_GLView; | |
78 } | |
79 #endif | |
80 if ( SDL_View ) { | |
81 delete SDL_View; | |
82 } | |
83 } | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
84 |
0 | 85 |
86 /* Override the Show() method so we can tell when we've been shown */ | |
87 virtual void Show(void) { | |
88 BWindow::Show(); | |
89 shown = true; | |
90 } | |
91 virtual bool Shown(void) { | |
92 return (shown); | |
93 } | |
94 /* If called, the next resize event will not be forwarded to SDL. */ | |
95 virtual void InhibitResize(void) { | |
96 inhibit_resize=true; | |
97 } | |
98 /* Handle resizing of the window */ | |
99 virtual void FrameResized(float width, float height) { | |
100 if(inhibit_resize) | |
101 inhibit_resize = false; | |
102 else | |
103 SDL_PrivateResize((int)width, (int)height); | |
104 } | |
906
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
105 virtual int CreateView(Uint32 flags, Uint32 gl_flags) { |
0 | 106 int retval; |
107 | |
108 retval = 0; | |
109 Lock(); | |
110 if ( flags & SDL_OPENGL ) { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
111 #if SDL_VIDEO_OPENGL |
0 | 112 if ( SDL_GLView == NULL ) { |
113 SDL_GLView = new BGLView(Bounds(), "SDL GLView", | |
906
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
114 B_FOLLOW_ALL_SIDES, (B_WILL_DRAW|B_FRAME_EVENTS), |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
115 gl_flags); |
0 | 116 } |
117 if ( the_view != SDL_GLView ) { | |
118 if ( the_view ) { | |
119 RemoveChild(the_view); | |
120 } | |
121 AddChild(SDL_GLView); | |
122 SDL_GLView->LockGL(); | |
123 the_view = SDL_GLView; | |
124 } | |
125 #else | |
126 SDL_SetError("OpenGL support not enabled"); | |
127 retval = -1; | |
128 #endif | |
129 } else { | |
130 if ( SDL_View == NULL ) { | |
131 SDL_View = new SDL_BView(Bounds()); | |
132 } | |
133 if ( the_view != SDL_View ) { | |
134 if ( the_view ) { | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
135 #if SDL_VIDEO_OPENGL |
0 | 136 if ( the_view == SDL_GLView ) { |
137 SDL_GLView->UnlockGL(); | |
138 } | |
139 #endif | |
140 RemoveChild(the_view); | |
141 } | |
142 AddChild(SDL_View); | |
143 the_view = SDL_View; | |
144 } | |
145 } | |
146 Unlock(); | |
147 return(retval); | |
148 } | |
149 virtual void SetBitmap(BBitmap *bitmap) { | |
150 SDL_View->SetBitmap(bitmap); | |
151 } | |
152 virtual bool BeginDraw(void) { | |
153 return(Lock()); | |
154 } | |
155 virtual void DrawAsync(BRect updateRect) { | |
156 SDL_View->DrawAsync(updateRect); | |
157 } | |
158 virtual void EndDraw(void) { | |
159 SDL_View->Sync(); | |
160 Unlock(); | |
161 } | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
162 #if SDL_VIDEO_OPENGL |
0 | 163 virtual void SwapBuffers(void) { |
164 SDL_GLView->UnlockGL(); | |
165 SDL_GLView->LockGL(); | |
166 SDL_GLView->SwapBuffers(); | |
167 } | |
168 #endif | |
169 virtual BView *View(void) { | |
170 return(the_view); | |
171 } | |
172 | |
173 /* Hook functions -- overridden */ | |
174 virtual void Minimize(bool minimize) { | |
175 /* This is only called when mimimized, not when restored */ | |
176 //SDL_PrivateAppActive(minimize, SDL_APPACTIVE); | |
177 BWindow::Minimize(minimize); | |
178 } | |
179 virtual void WindowActivated(bool active) { | |
180 SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS); | |
181 } | |
182 virtual bool QuitRequested(void) { | |
183 if ( SDL_BeAppActive > 0 ) { | |
184 SDL_PrivateQuit(); | |
185 /* We don't ever actually close the window here because | |
186 the application should respond to the quit request, | |
187 or ignore it as desired. | |
188 */ | |
189 return(false); | |
190 } | |
191 return(true); /* Close the app window */ | |
192 } | |
906
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
193 virtual void Quit() { |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
194 if (!IsLocked()) |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
195 Lock(); |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
196 BDirectWindow::Quit(); |
a48acf6ee48f
Date: Sat, 03 Jul 2004 02:23:48 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
197 } |
0 | 198 |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
199 virtual int16 Translate2Unicode(const char *buf) { |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
200 int32 state, srclen, dstlen; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
201 unsigned char destbuf[2]; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
202 Uint16 unicode = 0; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
203 |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
204 if ((uchar)buf[0] > 127) { |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
205 state = 0; |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
206 srclen = SDL_strlen(buf); |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
207 dstlen = sizeof(destbuf); |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
208 convert_from_utf8(B_UNICODE_CONVERSION, buf, &srclen, (char *)destbuf, &dstlen, &state); |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
209 unicode = destbuf[0]; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
210 unicode <<= 8; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
211 unicode |= destbuf[1]; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
212 } else |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
213 unicode = buf[0]; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
214 |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
215 /* For some reason function keys map to control characters */ |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
216 # define CTRL(X) ((X)-'@') |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
217 switch (unicode) { |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
218 case CTRL('A'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
219 case CTRL('B'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
220 case CTRL('C'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
221 case CTRL('D'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
222 case CTRL('E'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
223 case CTRL('K'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
224 case CTRL('L'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
225 case CTRL('P'): |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
226 if ( ! (SDL_GetModState() & KMOD_CTRL) ) |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
227 unicode = 0; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
228 break; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
229 /* Keyboard input maps newline to carriage return */ |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
230 case '\n': |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
231 unicode = '\r'; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
232 break; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
233 default: |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
234 break; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
235 } |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
236 |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
237 return unicode; |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
238 } |
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
239 |
3878 | 240 virtual void DispatchMessage(BMessage *msg, BHandler *target); |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
241 |
0 | 242 private: |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
243 #if SDL_VIDEO_OPENGL |
0 | 244 BGLView *SDL_GLView; |
245 #endif | |
246 SDL_BView *SDL_View; | |
247 BView *the_view; | |
248 bool shown; | |
249 bool inhibit_resize; | |
907
3bd4d7a1ee04
Date: Mon, 21 Jun 2004 16:52:47 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
906
diff
changeset
|
250 int32 last_buttons; |
0 | 251 }; |
252 | |
253 #endif /* _SDL_BWin_h */ |