[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash/gui sdl.cpp sdlsup.h
From: |
Vitaly Alexeev |
Subject: |
[Gnash-commit] gnash/gui sdl.cpp sdlsup.h |
Date: |
Thu, 10 Aug 2006 19:05:14 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Vitaly Alexeev <alexeev> 06/08/10 19:05:14
Modified files:
gui : sdl.cpp sdlsup.h
Log message:
added key events handler & removed showlogo(useless)
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/sdl.cpp?cvsroot=gnash&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/sdlsup.h?cvsroot=gnash&r1=1.9&r2=1.10
Patches:
Index: sdl.cpp
===================================================================
RCS file: /sources/gnash/gnash/gui/sdl.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- sdl.cpp 10 Aug 2006 11:48:12 -0000 1.13
+++ sdl.cpp 10 Aug 2006 19:05:14 -0000 1.14
@@ -44,12 +44,6 @@
#include "log.h"
#include "sdlsup.h"
-// for progress bar
-#define H_BAR 0.05f
-#define MARGIN_BAR 0.0f
-#define Y_BAR 0.0f
-#include "render.h"
-
#ifdef RENDERER_OPENGL
#if defined(_WIN32) || defined(WIN32)
@@ -84,8 +78,6 @@
namespace gnash
{
-bitmap_info* SDLGui::mlogo = NULL;
-
SDLGui::SDLGui(unsigned long xid, float scale, bool loop, unsigned int depth)
: Gui(xid, scale, loop, depth),
_timeout(0),
@@ -99,8 +91,6 @@
{
GNASH_REPORT_FUNCTION;
- logo_delete();
-
#ifdef RENDERER_CAIRO
cairo_surface_destroy(_cairo_surface);
cairo_destroy (_cairo_handle);
@@ -126,7 +116,10 @@
if ( _func ) _func(this);
for (unsigned int i=0; i < _interval; i++) {
- SDL_PollEvent(&event);
+ if (SDL_PollEvent(&event) == 0)
+ {
+ break;
+ }
switch (event.type) {
case SDL_MOUSEMOTION:
@@ -153,14 +146,25 @@
break;
}
case SDL_KEYDOWN:
+ {
if (event.key.keysym.sym == SDLK_ESCAPE)
+ {
return true;
+ }
+ key_event(event.key.keysym.sym, true);
+ break;
+ }
+ case SDL_KEYUP:
+ {
+ SDLKey key = event.key.keysym.sym;
+ key_event(key, false);
break;
+ }
case SDL_QUIT:
return true;
break;
}
- SDL_Delay(1);
+ SDL_Delay(10);
}
}
@@ -288,9 +292,6 @@
#elif defined (RENDERER_OPENGL)
_renderer = create_render_handler_ogl();
- gnash::register_progress_callback(progress_bar_callback);
-// logo_create("c:\\gnash_logo.jpg");
-
# ifdef FIX_I810_LOD_BIAS
glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT,
_tex_lod_bias);
# endif
@@ -300,7 +301,6 @@
return false;
}
-
void
SDLGui::disableCoreTrap()
{
@@ -352,112 +352,57 @@
return false;
}
-// create logo from jpeg_file
-void SDLGui::logo_create(const char* jpeg_file)
+void SDLGui::key_event(SDLKey key, bool down)
+// For forwarding SDL key events.
{
- if (mlogo == NULL)
- {
- if (_renderer)
- {
- image::rgb* im = image::read_jpeg(jpeg_file);
- if (im != NULL)
- {
- mlogo = _renderer->create_bitmap_info_rgb(im);
- }
+ gnash::key::code c(gnash::key::INVALID);
+
+ if (key >= SDLK_0 && key <= SDLK_9) {
+ c = (gnash::key::code) ((key - SDLK_0) + gnash::key::_0);
+ } else if (key >= SDLK_a && key <= SDLK_z) {
+ c = (gnash::key::code) ((key - SDLK_a) + gnash::key::A);
+ } else if (key >= SDLK_F1 && key <= SDLK_F15) {
+ c = (gnash::key::code) ((key - SDLK_F1) + gnash::key::F1);
+ } else if (key >= SDLK_KP0 && key <= SDLK_KP9) {
+ c = (gnash::key::code) ((key - SDLK_KP0) + gnash::key::KP_0);
+ } else {
+ // many keys don't correlate, so just use a look-up table.
+ struct {
+ SDLKey sdlk;
+ gnash::key::code gs;
+ } table[] = {
+ { SDLK_SPACE, gnash::key::SPACE },
+ { SDLK_PAGEDOWN, gnash::key::PGDN },
+ { SDLK_PAGEUP, gnash::key::PGUP },
+ { SDLK_HOME, gnash::key::HOME },
+ { SDLK_END, gnash::key::END },
+ { SDLK_INSERT, gnash::key::INSERT },
+ { SDLK_DELETE, gnash::key::DELETEKEY },
+ { SDLK_BACKSPACE, gnash::key::BACKSPACE },
+ { SDLK_TAB, gnash::key::TAB },
+ { SDLK_RETURN, gnash::key::ENTER },
+ { SDLK_ESCAPE, gnash::key::ESCAPE },
+ { SDLK_LEFT, gnash::key::LEFT },
+ { SDLK_UP, gnash::key::UP },
+ { SDLK_RIGHT, gnash::key::RIGHT },
+ { SDLK_DOWN, gnash::key::DOWN },
+ // @@ TODO fill this out some more
+ { SDLK_UNKNOWN, gnash::key::INVALID }
+ };
+
+ for (int i = 0; table[i].sdlk != SDLK_UNKNOWN; i++) {
+ if (key == table[i].sdlk) {
+ c = table[i].gs;
+ break;
}
}
-}
-
-void SDLGui::logo_delete()
-{
- // delete logo bitmap info
- if (mlogo)
- {
- delete mlogo;
- mlogo = NULL;
}
-}
-
-void SDLGui::show_logo()
-{
-#if defined (RENDERER_OPENGL)
-// default full window
-// glViewport(0, 0, width, height);
- if (mlogo)
- {
- gnash::matrix m;
- gnash::rect coords;
- gnash::rect uv_coords;
- gnash::rgba color;
-
- m.set_identity();
-
- coords.m_x_min = -1.0f;
- coords.m_x_max = 1.0f;
- coords.m_y_min = -1.0f;
- coords.m_y_max = 1.0f;
-
- uv_coords.m_x_min = 0.0f;
- uv_coords.m_x_max = 1.0f;
- uv_coords.m_y_min = 0.0f;
- uv_coords.m_y_max = 1.0f;
-
- color.m_a = 255;
- color.m_r = 255;
- color.m_g = 255;
- color.m_b = 255;
- gnash::get_render_handler()->draw_bitmap(m, mlogo, coords,
uv_coords, color);
- glDisable(GL_TEXTURE_2D);
+ if (c != gnash::key::INVALID) {
+ gnash::notify_key_event(c, down);
}
- else
- {
- glBegin(GL_QUADS);
- glColor4ub(0, 0, 255, 255);
- glVertex2f(-1.0, -1.0);
- glVertex2f(1.0, -1.0);
- glColor4ub(0, 0, 0, 255);
- glVertex2f(1.0, 1.0);
- glVertex2f(-1.0, 1.0);
- glEnd();
- }
-#endif
}
-void SDLGui::progress_bar_callback(unsigned int loaded_tags, unsigned int
total_tags)
-// Callback function. This show loading progress.
-{
-#if defined (RENDERER_OPENGL)
- float p = (float)loaded_tags / (float)total_tags * 2.0f * (1.0f -
MARGIN_BAR);
-
- glDisable(GL_DEPTH_TEST); // Disable depth testing.
- glDrawBuffer(GL_BACK);
- glDisable(GL_TEXTURE_2D);
-
- // show background
- show_logo();
-
- // show progress bar
- glBegin(GL_QUADS);
- glColor3ub(255, 255, 255);
- glVertex2f(-1.0f + MARGIN_BAR, 1.0f - Y_BAR - H_BAR);
- glVertex2f(1.0f - MARGIN_BAR, 1.0f - Y_BAR - H_BAR);
- glVertex2f(1.0f - MARGIN_BAR, 1.0f - Y_BAR);
- glVertex2f(-1.0f + MARGIN_BAR, 1.0f - Y_BAR);
- glEnd();
-
- // show progress %
- glBegin(GL_QUADS);
- glColor4ub(255, 0, 0, 255);
- glVertex2f(-1.0f + MARGIN_BAR, 1.0f - Y_BAR - H_BAR);
- glVertex2f(-1.0f + MARGIN_BAR + p, 1.0f - Y_BAR - H_BAR);
- glVertex2f(-1.0f + MARGIN_BAR + p, 1.0f - Y_BAR);
- glVertex2f(-1.0f + MARGIN_BAR, 1.0f - Y_BAR);
- glEnd();
-
- SDL_GL_SwapBuffers();
-}
-#endif
} // namespace gnash
Index: sdlsup.h
===================================================================
RCS file: /sources/gnash/gnash/gui/sdlsup.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- sdlsup.h 10 Aug 2006 11:48:12 -0000 1.9
+++ sdlsup.h 10 Aug 2006 19:05:14 -0000 1.10
@@ -72,17 +72,12 @@
virtual void disableCoreTrap();
virtual void setTimeout(unsigned int timeout);
- // for progress bar
- void logo_create(const char* jpeg_file);
- static void show_logo();
- void logo_delete();
- static void progress_bar_callback(unsigned int loaded_tags,
unsigned int total_tags);
+ void key_event(SDLKey key, bool down);
private:
unsigned int _interval, _timeout;
callback_t _func;
SDL_Surface *_screen;
- static bitmap_info* mlogo;
#ifdef RENDERER_CAIRO
cairo_surface_t *_cairo_surface;
cairo_t *_cairo_handle;