Mercurial > sdl-ios-xcode
annotate src/video/bwindow/SDL_BWin.h @ 411:8c4999b0ac10
Fix another memory leak
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 13 Jun 2002 16:54:26 +0000 |
parents | f6ffac90895c |
children | b8d311d90021 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
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 | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
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 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #ifndef _SDL_BWin_h | |
29 #define _SDL_BWin_h | |
30 | |
31 #include <stdio.h> | |
32 #include <AppKit.h> | |
33 #include <InterfaceKit.h> | |
34 #include <be/game/DirectWindow.h> | |
35 #ifdef HAVE_OPENGL | |
36 #include <be/opengl/GLView.h> | |
37 #endif | |
38 | |
39 #include "SDL_BeApp.h" | |
40 #include "SDL_events.h" | |
41 #include "SDL_BView.h" | |
42 | |
43 extern "C" { | |
44 #include "SDL_events_c.h" | |
45 }; | |
46 | |
47 class SDL_BWin : public BDirectWindow | |
48 { | |
49 public: | |
50 SDL_BWin(BRect bounds) : | |
51 BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) { | |
52 the_view = NULL; | |
53 #ifdef HAVE_OPENGL | |
54 SDL_GLView = NULL; | |
55 #endif | |
56 SDL_View = NULL; | |
57 Unlock(); | |
58 shown = false; | |
59 inhibit_resize = false; | |
60 } | |
61 virtual ~SDL_BWin() { | |
62 Lock(); | |
63 if ( the_view ) { | |
64 #ifdef HAVE_OPENGL | |
65 if ( the_view == SDL_GLView ) { | |
66 SDL_GLView->UnlockGL(); | |
67 } | |
68 #endif | |
69 RemoveChild(the_view); | |
70 the_view = NULL; | |
71 } | |
72 Unlock(); | |
73 #ifdef HAVE_OPENGL | |
74 if ( SDL_GLView ) { | |
75 delete SDL_GLView; | |
76 } | |
77 #endif | |
78 if ( SDL_View ) { | |
79 delete SDL_View; | |
80 } | |
81 } | |
82 | |
83 /* Override the Show() method so we can tell when we've been shown */ | |
84 virtual void Show(void) { | |
85 BWindow::Show(); | |
86 shown = true; | |
87 } | |
88 virtual bool Shown(void) { | |
89 return (shown); | |
90 } | |
91 /* If called, the next resize event will not be forwarded to SDL. */ | |
92 virtual void InhibitResize(void) { | |
93 inhibit_resize=true; | |
94 } | |
95 /* Handle resizing of the window */ | |
96 virtual void FrameResized(float width, float height) { | |
97 if(inhibit_resize) | |
98 inhibit_resize = false; | |
99 else | |
100 SDL_PrivateResize((int)width, (int)height); | |
101 } | |
102 virtual int CreateView(Uint32 flags) { | |
103 int retval; | |
104 | |
105 retval = 0; | |
106 Lock(); | |
107 if ( flags & SDL_OPENGL ) { | |
108 #ifdef HAVE_OPENGL | |
109 if ( SDL_GLView == NULL ) { | |
110 /* FIXME: choose BGL type via user flags */ | |
111 SDL_GLView = new BGLView(Bounds(), "SDL GLView", | |
112 B_FOLLOW_ALL_SIDES, | |
113 (B_WILL_DRAW|B_FRAME_EVENTS), | |
114 (BGL_RGB|BGL_DOUBLE|BGL_DEPTH)); | |
115 } | |
116 if ( the_view != SDL_GLView ) { | |
117 if ( the_view ) { | |
118 RemoveChild(the_view); | |
119 } | |
120 AddChild(SDL_GLView); | |
121 SDL_GLView->LockGL(); | |
122 the_view = SDL_GLView; | |
123 } | |
124 #else | |
125 SDL_SetError("OpenGL support not enabled"); | |
126 retval = -1; | |
127 #endif | |
128 } else { | |
129 if ( SDL_View == NULL ) { | |
130 SDL_View = new SDL_BView(Bounds()); | |
131 } | |
132 if ( the_view != SDL_View ) { | |
133 if ( the_view ) { | |
134 #ifdef HAVE_OPENGL | |
135 if ( the_view == SDL_GLView ) { | |
136 SDL_GLView->UnlockGL(); | |
137 } | |
138 #endif | |
139 RemoveChild(the_view); | |
140 } | |
141 AddChild(SDL_View); | |
142 the_view = SDL_View; | |
143 } | |
144 } | |
145 Unlock(); | |
146 return(retval); | |
147 } | |
148 virtual void SetBitmap(BBitmap *bitmap) { | |
149 SDL_View->SetBitmap(bitmap); | |
150 } | |
151 virtual void SetXYOffset(int x, int y) { | |
152 #ifdef HAVE_OPENGL | |
153 if ( the_view == SDL_GLView ) { | |
154 return; | |
155 } | |
156 #endif | |
157 SDL_View->SetXYOffset(x, y); | |
158 } | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
159 virtual void GetXYOffset(int &x, int &y) { |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
160 #ifdef HAVE_OPENGL |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
161 if ( the_view == SDL_GLView ) { |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
162 x = 0; |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
163 y = 0; |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
164 return; |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
165 } |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
166 #endif |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
167 SDL_View->GetXYOffset(x, y); |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
168 } |
0 | 169 virtual bool BeginDraw(void) { |
170 return(Lock()); | |
171 } | |
172 virtual void DrawAsync(BRect updateRect) { | |
173 SDL_View->DrawAsync(updateRect); | |
174 } | |
175 virtual void EndDraw(void) { | |
176 SDL_View->Sync(); | |
177 Unlock(); | |
178 } | |
179 #ifdef HAVE_OPENGL | |
180 virtual void SwapBuffers(void) { | |
181 SDL_GLView->UnlockGL(); | |
182 SDL_GLView->LockGL(); | |
183 SDL_GLView->SwapBuffers(); | |
184 } | |
185 #endif | |
186 virtual BView *View(void) { | |
187 return(the_view); | |
188 } | |
189 | |
190 /* Hook functions -- overridden */ | |
191 virtual void Minimize(bool minimize) { | |
192 /* This is only called when mimimized, not when restored */ | |
193 //SDL_PrivateAppActive(minimize, SDL_APPACTIVE); | |
194 BWindow::Minimize(minimize); | |
195 } | |
196 virtual void WindowActivated(bool active) { | |
197 SDL_PrivateAppActive(active, SDL_APPINPUTFOCUS); | |
198 } | |
199 virtual bool QuitRequested(void) { | |
200 if ( SDL_BeAppActive > 0 ) { | |
201 SDL_PrivateQuit(); | |
202 /* We don't ever actually close the window here because | |
203 the application should respond to the quit request, | |
204 or ignore it as desired. | |
205 */ | |
206 return(false); | |
207 } | |
208 return(true); /* Close the app window */ | |
209 } | |
210 | |
211 private: | |
212 #ifdef HAVE_OPENGL | |
213 BGLView *SDL_GLView; | |
214 #endif | |
215 SDL_BView *SDL_View; | |
216 BView *the_view; | |
217 | |
218 bool shown; | |
219 bool inhibit_resize; | |
220 }; | |
221 | |
222 #endif /* _SDL_BWin_h */ |