40 #include <InterfaceKit.h>
41 #include <be/game/DirectWindow.h>
43 #include <be/opengl/GLView.h>
46 #include "../../main/beos/SDL_BApp.h"
68 : BDirectWindow(bounds,
"Untitled", look, B_NORMAL_WINDOW_FEEL, flags)
76 _inhibit_resize =
false;
77 _mouse_focused =
false;
81 _connected = _connection_disabled =
false;
82 _buffer_created = _buffer_dirty =
false;
83 _trash_window_buffer =
false;
84 _buffer_locker =
new BLocker();
87 _draw_thread_id = spawn_thread(
BE_DrawThread,
"drawing_thread",
88 B_NORMAL_PRIORITY, (
void*)
this);
89 resume_thread(_draw_thread_id);
96 _connection_disabled =
true;
101 _SDL_GLView->UnlockGL();
102 RemoveChild(_SDL_GLView);
115 _buffer_locker->Lock();
117 wait_for_thread(_draw_thread_id, &result);
120 delete _buffer_locker;
126 virtual BGLView *CreateGLView(
Uint32 gl_flags) {
128 if (_SDL_GLView ==
NULL) {
129 _SDL_GLView =
new BGLView(Bounds(),
"SDL GLView",
131 (B_WILL_DRAW | B_FRAME_EVENTS),
134 AddChild(_SDL_GLView);
135 _SDL_GLView->EnableDirectMode(
true);
136 _SDL_GLView->LockGL();
138 return (_SDL_GLView);
141 virtual void RemoveGLView() {
144 _SDL_GLView->UnlockGL();
145 RemoveChild(_SDL_GLView);
150 virtual void SwapBuffers(
void) {
151 _SDL_GLView->UnlockGL();
152 _SDL_GLView->LockGL();
153 _SDL_GLView->SwapBuffers();
159 if(!_connected && _connection_disabled) {
164 _trash_window_buffer = _trash_window_buffer
165 || ((info->buffer_state & B_BUFFER_RESIZED)
166 || (info->buffer_state & B_BUFFER_RESET)
167 || (info->driver_state == B_MODE_CHANGED));
170 switch(info->buffer_state & B_DIRECT_MODE_MASK) {
174 case B_DIRECT_MODIFY:
180 _num_clips = info->clip_list_count;
181 _clips = (clipping_rect *)
malloc(_num_clips*
sizeof(clipping_rect));
183 memcpy(_clips, info->clip_list,
184 _num_clips*
sizeof(clipping_rect));
186 _bits = (uint8*) info->bits;
187 _row_bytes = info->bytes_per_row;
188 _bounds = info->window_bounds;
189 _bytes_per_px = info->bits_per_pixel / 8;
190 _buffer_dirty =
true;
200 _SDL_GLView->DirectConnected(info);
206 BDirectWindow::DirectConnected(info);
220 msg.AddInt32(
"window-x", (
int)origin.x);
221 msg.AddInt32(
"window-y", (
int)origin.y);
222 _PostWindowEvent(msg);
225 BDirectWindow::FrameMoved(origin);
232 msg.AddInt32(
"window-w", (
int)width + 1);
233 msg.AddInt32(
"window-h", (
int)height + 1);
234 _PostWindowEvent(msg);
237 BDirectWindow::FrameResized(width, height);
242 _PostWindowEvent(msg);
250 _PostWindowEvent(msg);
253 virtual void Zoom(BPoint origin,
257 _PostWindowEvent(msg);
261 _prev_frame =
new BRect(Frame());
264 BDirectWindow::Zoom(origin, width, height);
270 BDirectWindow::Show();
275 _PostWindowEvent(msg);
279 BDirectWindow::Hide();
283 _PostWindowEvent(msg);
287 BDirectWindow::Minimize(minimize);
290 BMessage msg(minState);
291 _PostWindowEvent(msg);
305 if (msg->FindPoint(
"where", &where) == B_OK
306 && msg->FindInt32(
"be:transit", &transit) == B_OK) {
307 _MouseMotionEvent(where, transit);
314 if (msg->FindInt32(
"buttons", &buttons) == B_OK) {
315 _MouseButtonEvent(buttons);
323 if (msg->FindInt32(
"buttons", &buttons) == B_OK) {
324 _MouseButtonEvent(buttons);
328 case B_MOUSE_WHEEL_CHANGED:
330 if (msg->FindFloat(
"be:wheel_delta_x", &x) == B_OK
331 && msg->FindFloat(
"be:wheel_delta_y", &y) == B_OK) {
332 _MouseWheelEvent((
int)x, (
int)y);
337 case B_UNMAPPED_KEY_DOWN:
338 if (msg->FindInt32(
"key", &key) == B_OK) {
344 case B_UNMAPPED_KEY_UP:
345 if (msg->FindInt32(
"key", &key) == B_OK) {
360 BDirectWindow::DispatchMessage(msg, target);
365 switch (message->what) {
377 _SetBordered(message);
395 _SetFullScreen(message);
399 BDirectWindow::MessageReceived(message);
424 BGLView *GetGLView() {
return _SDL_GLView; }
439 void _MouseMotionEvent(BPoint &where, int32 transit) {
440 if(transit == B_EXITED_VIEW) {
443 _MouseFocusEvent(
false);
447 if (!_mouse_focused) {
448 _MouseFocusEvent(
true);
451 msg.AddInt32(
"x", (
int)where.x);
452 msg.AddInt32(
"y", (
int)where.y);
454 _PostWindowEvent(msg);
458 void _MouseFocusEvent(
bool focusGained) {
459 _mouse_focused = focusGained;
461 msg.AddBool(
"focusGained", focusGained);
462 _PostWindowEvent(msg);
469 void _MouseButtonEvent(int32 buttons) {
470 int32 buttonStateChange = buttons ^ _last_buttons;
473 if( !(buttonStateChange) ) {
478 if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
480 B_PRIMARY_MOUSE_BUTTON);
482 if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
484 B_PRIMARY_MOUSE_BUTTON);
486 if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
488 B_PRIMARY_MOUSE_BUTTON);
491 _last_buttons = buttons;
494 void _SendMouseButton(int32 button, int32 state) {
496 msg.AddInt32(
"button-id", button);
497 msg.AddInt32(
"button-state", state);
498 _PostWindowEvent(msg);
501 void _MouseWheelEvent(int32
x, int32
y) {
504 msg.AddInt32(
"xticks", x);
505 msg.AddInt32(
"yticks", y);
506 _PostWindowEvent(msg);
509 void _KeyEvent(int32 keyCode, int32 keyState) {
512 msg.AddInt32(
"key-state", keyState);
513 msg.AddInt32(
"key-scancode", keyCode);
514 be_app->PostMessage(&msg);
518 void _RepaintEvent() {
521 _PostWindowEvent(msg);
523 void _PostWindowEvent(BMessage &msg) {
524 msg.AddInt32(
"window-id", _id);
525 be_app->PostMessage(&msg);
529 void _SetTitle(BMessage *msg) {
532 msg->FindString(
"window-title", &title) != B_OK
539 void _MoveTo(BMessage *msg) {
542 msg->FindInt32(
"window-x", &x) != B_OK ||
543 msg->FindInt32(
"window-y", &y) != B_OK
550 void _ResizeTo(BMessage *msg) {
553 msg->FindInt32(
"window-w", &w) != B_OK ||
554 msg->FindInt32(
"window-h", &h) != B_OK
561 void _SetBordered(BMessage *msg) {
563 if(msg->FindBool(
"window-border", &bEnabled) != B_OK) {
566 SetLook(bEnabled ? B_BORDERED_WINDOW_LOOK : B_NO_BORDER_WINDOW_LOOK);
572 }
else if(IsHidden()) {
574 }
else if(_prev_frame !=
NULL) {
575 MoveTo(_prev_frame->left, _prev_frame->top);
576 ResizeTo(_prev_frame->Width(), _prev_frame->Height());
580 void _SetFullScreen(BMessage *msg) {
583 msg->FindBool(
"fullscreen", &fullscreen) != B_OK
587 SetFullScreen(fullscreen);
592 BGLView * _SDL_GLView;
599 bool _inhibit_resize;
605 _connection_disabled,
608 _trash_window_buffer;
611 clipping_rect _bounds;
612 BLocker *_buffer_locker;
613 clipping_rect *_clips;
616 thread_id _draw_thread_id;
virtual void WindowActivated(bool active)
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLenum GLuint GLuint GLsizei GLchar * message
static void Lock(volatile ALenum *l)
EGLSurface EGLint EGLint EGLint EGLint height
SDL_BWin(BRect bounds, window_look look, uint32 flags)
clipping_rect * GetClips()
void SetBitmap(BBitmap *bitmap)
void SetBufferExists(bool bufferExists)
EGLContext EGLenum target
uint32_t Uint32
An unsigned 32-bit integer type.
EGLSurface EGLint EGLint EGLint width
virtual void DispatchMessage(BMessage *msg, BHandler *target)
virtual void Minimize(bool minimize)
virtual void Zoom(BPoint origin, float width, float height)
virtual void MessageReceived(BMessage *message)
virtual void FrameResized(float width, float height)
#define SDL_BUTTON_MIDDLE
void SetBufferDirty(bool bufferDirty)
virtual void FrameMoved(BPoint origin)
EGLSurface EGLint EGLint y
static void Unlock(volatile ALenum *l)
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
bool CanTrashWindowBuffer()
GLint GLint GLint GLint GLint w
GLsizei GLfixed GLfixed GLfixed GLfixed const GLubyte * bitmap
virtual void DirectConnected(direct_buffer_info *info)
void SetTrashBuffer(bool trash)
int32 BE_DrawThread(void *data)
SDL_Scancode
The SDL keyboard scancode representation.
virtual bool QuitRequested()