From b409820950a9e165483f887c8a487ac95063b4bd Mon Sep 17 00:00:00 2001 From: Jaromil Date: Sat, 29 Aug 2009 11:49:06 +0200 Subject: [PATCH] Factory is now used also for Screens Screen API changed a bit: now size args are taken from init(w,h) screen implementations should provide an _init(w,h) as well constructors are without arguments (as in the rest of freej) --- scripts/python/DIRPlaylist/DIRPlaylist.py | 8 +++- scripts/python/RSSPlaylist/RSSPlaylist.py | 8 +++- scripts/python/eos_test.py | 13 ++++--- scripts/python/gtkgui/main.py | 4 +- scripts/python/test.py | 3 +- scripts/python/video_test.py | 8 +++- src/context.cpp | 1 + src/freej.cpp | 18 +++++++-- src/gl_screen.cpp | 9 +++-- src/include/gl_screen.h | 12 +++--- src/include/screen.h | 11 +++--- src/include/sdl_screen.h | 10 ++++- src/include/sdlgl_screen.h | 7 +++- src/include/soft_screen.h | 11 ++++-- src/screen.cpp | 43 ++++++++++++--------- src/sdl_screen.cpp | 11 +++--- src/sdlgl_screen.cpp | 9 +++-- src/soft_screen.cpp | 12 ++++-- xcode/CFreej.mm | 3 +- xcode/CVScreen.mm | 47 +++++++++++++++++------ 20 files changed, 164 insertions(+), 84 deletions(-) diff --git a/scripts/python/DIRPlaylist/DIRPlaylist.py b/scripts/python/DIRPlaylist/DIRPlaylist.py index c47b73da..84245512 100644 --- a/scripts/python/DIRPlaylist/DIRPlaylist.py +++ b/scripts/python/DIRPlaylist/DIRPlaylist.py @@ -58,9 +58,13 @@ class DIRPlaylist(object): print("error: no videos found in dir " + dir) exit() +# init context self.cx = freej.Context() - self.scr = freej.SdlScreen( self.width, self.height ) - self.cx.add_screen(self.scr) + self.cx.init() + + self.scr = freej.SdlScreen() + self.scr.init( 400, 300 ); + self.cx.add_screen(scr) self.cx.plugger.refresh(self.cx) self.ctx_thread = threading.Thread(target = self.cx.start, diff --git a/scripts/python/RSSPlaylist/RSSPlaylist.py b/scripts/python/RSSPlaylist/RSSPlaylist.py index b539778c..3664d6f8 100644 --- a/scripts/python/RSSPlaylist/RSSPlaylist.py +++ b/scripts/python/RSSPlaylist/RSSPlaylist.py @@ -77,9 +77,13 @@ class RSSPlaylist(object): self.ctx_thread = None if len(self.rsssucker.list): +# init context self.cx = freej.Context() - self.scr = freej.SdlScreen( self.width, self.height ) - self.cx.add_screen(self.scr) + self.cx.init() + + self.scr = freej.SdlScreen() + self.scr.init( 400, 300 ); + self.cx.add_screen(scr) self.cx.plugger.refresh(self.cx) self.ctx_thread = threading.Thread(target = self.cx.start, diff --git a/scripts/python/eos_test.py b/scripts/python/eos_test.py index 94b2f06e..6f4e5150 100644 --- a/scripts/python/eos_test.py +++ b/scripts/python/eos_test.py @@ -12,12 +12,15 @@ freej.set_debug(3) W = 400 H = 300 + +# init context cx = freej.Context() +cx.init() +# init screen +scr = freej.SdlScreen() +scr.init( 400, 300 ) - -scr = freej.SdlScreen( 400, 300) - -cx.add_screen( scr ) +cx.add_screen(scr) v = freej.VideoLayer() @@ -27,7 +30,7 @@ v.open('/home/jaromil/Movies/TheRevolutionWillNotBeTelevisedGilScottHeron.mp4') v.start() -cx.add_layer( v ) +scr.add_layer( v ) diff --git a/scripts/python/gtkgui/main.py b/scripts/python/gtkgui/main.py index 71bdc6b2..3aec0fa5 100644 --- a/scripts/python/gtkgui/main.py +++ b/scripts/python/gtkgui/main.py @@ -119,11 +119,13 @@ class ContextMenu(gtk.Menu): class FreeJ(object): def __init__(self): - self.scr = freej.SdlScreen( 400, 300) + self.scr = freej.SdlScreen() + self.scr.init( 400 , 300 ) self.init_context() def init_context(self): self.cx = freej.Context() + self.cx.init() self.cx.clear_all = True diff --git a/scripts/python/test.py b/scripts/python/test.py index eebb2717..e8ec60e9 100644 --- a/scripts/python/test.py +++ b/scripts/python/test.py @@ -9,7 +9,8 @@ import sys cx = freej.Context() cx.init() #cx.init(400,300,0,0) -scr = freej.SdlScreen( 400, 300) +scr = freej.SdlScreen() +scr.init( 400, 300 ); cx.add_screen(scr) cx.config_check("keyboard.js") cx.plugger.refresh(cx) diff --git a/scripts/python/video_test.py b/scripts/python/video_test.py index 5c46b8f6..0c7ea81f 100644 --- a/scripts/python/video_test.py +++ b/scripts/python/video_test.py @@ -7,7 +7,13 @@ import sys # init context cx = freej.Context() -cx.init(400,300,0,0) +cx.init() +# init screen +scr = freej.SdlScreen() +scr.init( 400, 300 ) + +cx.add_screen(scr) + cx.config_check("keyboard.js") cx.plugger.refresh(cx) diff --git a/src/context.cpp b/src/context.cpp index b05c49bc..f0d238a0 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -110,6 +110,7 @@ Context::Context() { Factory::set_default_classtype("GeometryLayer", "basic"); Factory::set_default_classtype("KeyboardController", "sdl"); + Factory::set_default_classtype("Screen", "sdl"); assert( init() ); diff --git a/src/freej.cpp b/src/freej.cpp index 3dea2942..ac7f6004 100644 --- a/src/freej.cpp +++ b/src/freej.cpp @@ -283,12 +283,22 @@ int main (int argc, char **argv) { set_debug(debug_level); // create SDL screen by default at selected size -#ifdef WITH_OPENGL + screen = NULL; if(opengl) - screen = new SdlGlScreen(width, height); + screen = Factory::new_instance( "SdlGlScreen" ); else -#endif - screen = new SdlScreen(width, height); + // screen = Factory::new_instance( "SdlScreen" ); + screen = Factory::new_instance( "Screen", "sdl" ); + + screen = new SdlScreen(); + + if(!screen) { + error("no screen can be opened"); + delete freej; + exit(1); + } + + screen->init(width, height); // add the screen to the context freej->add_screen(screen); diff --git a/src/gl_screen.cpp b/src/gl_screen.cpp index 3c36923f..7f07eb95 100644 --- a/src/gl_screen.cpp +++ b/src/gl_screen.cpp @@ -16,9 +16,8 @@ * this source code; if not, write to: * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: $ - * */ + #include #ifdef WITH_OPENGL @@ -30,9 +29,11 @@ #include #include +// our objects are allowed to be created trough the factory engine +FACTORY_REGISTER_INSTANTIATOR(ViewPort, GlScreen, Screen, gl); -GlScreen::GlScreen(int w, int h) - : ViewPort(w, h) { +GlScreen::GlScreen() + : ViewPort() { dbl = false; x_translation = 0; diff --git a/src/include/gl_screen.h b/src/include/gl_screen.h index 5b3304ce..f2afccdb 100644 --- a/src/include/gl_screen.h +++ b/src/include/gl_screen.h @@ -15,8 +15,6 @@ * this source code; if not, write to: * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * "$Id$" - * */ #include @@ -24,9 +22,6 @@ #ifndef __GL_SCREEN_H__ #define __GL_SCREEN_H__ -//#include -//#include - #include #include @@ -40,9 +35,10 @@ struct Vertex class GlScreen : public ViewPort { public: - GlScreen(int w, int h); + GlScreen(); ~GlScreen(); + bool _init(int widt, int height); fourcc get_pixel_format() { return RGBA32; }; void *get_surface(); @@ -70,7 +66,6 @@ class GlScreen : public ViewPort { // bool unlock(); private: - bool init(int widt, int height); int setres(int wx, int hx); bool dbl; uint32_t sdl_flags; @@ -78,6 +73,9 @@ class GlScreen : public ViewPort { // check gl error and print it bool check_opengl_error(); + // allow to use Factory on this class + FACTORY_ALLOWED + }; #endif diff --git a/src/include/screen.h b/src/include/screen.h index 99c494f7..d79eac26 100644 --- a/src/include/screen.h +++ b/src/include/screen.h @@ -1,9 +1,9 @@ /* FreeJ - * (c) Copyright 2001 Denis Roio aka jaromil + * (c) Copyright 2001 - 2009 Denis Roio * * This source code is free software; you can redistribute it and/or * modify it under the terms of the GNU Public License as published - * by the Free Software Foundation; either version 2 of the License, + * by the Free Software Foundation; either version 3 of the License, * or (at your option) any later version. * * This source code is distributed in the hope that it will be useful, @@ -15,8 +15,6 @@ * this source code; if not, write to: * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * "$Id$" - * */ #ifndef __SCREEN_H__ @@ -80,9 +78,12 @@ class VideoEncoder; class ViewPort : public Entry { friend class Layer; public: - ViewPort(int w, int h); + ViewPort(); virtual ~ViewPort(); + bool init(int w, int h); ///< general initialization + + virtual bool _init(int w, int h) = 0; ///< implemented initialization enum fourcc { RGBA32, BGRA32, ARGB32 }; ///< pixel formats understood virtual fourcc get_pixel_format() =0; ///< return the pixel format diff --git a/src/include/sdl_screen.h b/src/include/sdl_screen.h index cdfb2aef..35afcb07 100644 --- a/src/include/sdl_screen.h +++ b/src/include/sdl_screen.h @@ -25,9 +25,11 @@ #include #include +#include + class SdlScreen : public ViewPort { public: - SdlScreen(int w, int h); + SdlScreen(); ~SdlScreen(); @@ -54,7 +56,9 @@ class SdlScreen : public ViewPort { private: - bool init(int width, int height); + + bool _init(int width, int height); + int setres(int wx, int hx); SDL_Surface *emuscr; @@ -72,6 +76,8 @@ class SdlScreen : public ViewPort { uint32_t *scr, *off, *poff, *pastoff, *ppastoff; uint32_t *pscr, *play, *ppast; // generic blit buffer pointers + // allow to use Factory on this class + FACTORY_ALLOWED; }; diff --git a/src/include/sdlgl_screen.h b/src/include/sdlgl_screen.h index b530c286..eb1b51cb 100644 --- a/src/include/sdlgl_screen.h +++ b/src/include/sdlgl_screen.h @@ -38,9 +38,10 @@ class SdlGlScreen : public ViewPort { public: - SdlGlScreen(int w, int h); + SdlGlScreen(); ~SdlGlScreen(); + bool _init(int width, int height); void set_magnification(int algo); void resize(int resize_w, int resize_h); @@ -72,7 +73,6 @@ class SdlGlScreen : public ViewPort { bool unlock(); private: - bool init(int width, int height); int setres(int wx, int hx); SDL_Surface *emuscr; SDL_Surface *screen; @@ -85,6 +85,9 @@ class SdlGlScreen : public ViewPort { // check gl error and print it void check_opengl_error(); + // allow to use Factory on this class + FACTORY_ALLOWED + }; #endif diff --git a/src/include/soft_screen.h b/src/include/soft_screen.h index 7766606d..19ef4849 100644 --- a/src/include/soft_screen.h +++ b/src/include/soft_screen.h @@ -22,18 +22,22 @@ #include +#include + class SoftScreen : public ViewPort { public: - SoftScreen(int w, int h); + SoftScreen(); ~SoftScreen(); + bool _init(int w, int h); fourcc get_pixel_format() { return RGBA32; }; void *get_surface(); + void setup_blits(Layer *); void blit(Layer *src); @@ -44,8 +48,9 @@ class SoftScreen : public ViewPort { uint32_t *pscr, *play; // generic blit buffer pointers - private: - bool init(int w, int h); + // allow to use Factory on this class + FACTORY_ALLOWED + }; diff --git a/src/screen.cpp b/src/screen.cpp index 63a230cf..db52fc89 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -1,21 +1,19 @@ /* FreeJ - * (c) Copyright 2001 Denis Roio aka jaromil + * (c) Copyright 2001 - 2009 Denis Roio * - * This source code is free software; you can redistribute it and/or - * modify it under the terms of the GNU Public License as published - * by the Free Software Foundation; either version 2 of the License, - * or (at your option) any later version. + * This source code is free software; you can redistribute it and/or + * modify it under the terms of the GNU Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. * * This source code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * Please refer to the GNU Public License for more details. + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Please refer + * to the GNU Public License for more details. * - * You should have received a copy of the GNU Public License along with - * this source code; if not, write to: - * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * "$Id$" + * You should have received a copy of the GNU Public License along + * with this source code; if not, write to: Free Software Foundation, + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ @@ -33,7 +31,7 @@ #include -ViewPort::ViewPort(int w, int h) +ViewPort::ViewPort() : Entry() { opengl = false; @@ -42,11 +40,6 @@ ViewPort::ViewPort(int w, int h) magnification = 0; changeres = false; - this->w = w; - this->h = h; - bpp = 32; // we use only RGBA - size = w*h*(bpp>>3); - pitch = w*(bpp>>3); audio = NULL; m_SampleRate=NULL; @@ -82,6 +75,18 @@ ViewPort::~ViewPort() { } +bool ViewPort::init(int w, int h) { + + this->w = w; + this->h = h; + bpp = 32; // we use only RGBA + size = w*h*(bpp>>3); + pitch = w*(bpp>>3); + + return _init(w, h); + +} + bool ViewPort::add_layer(Layer *lay) { func("%s",__PRETTY_FUNCTION__); diff --git a/src/sdl_screen.cpp b/src/sdl_screen.cpp index 5913f126..5e94cf8a 100644 --- a/src/sdl_screen.cpp +++ b/src/sdl_screen.cpp @@ -36,10 +36,11 @@ #include +// our objects are allowed to be created trough the factory engine +FACTORY_REGISTER_INSTANTIATOR(ViewPort, SdlScreen, Screen, sdl); - -SdlScreen::SdlScreen(int w, int h) - : ViewPort(w, h) { +SdlScreen::SdlScreen() + : ViewPort() { sdl_screen = NULL; emuscr = NULL; @@ -55,15 +56,13 @@ SdlScreen::SdlScreen(int w, int h) magnification = 0; switch_fullscreen = false; - // set_name("SDL"); - init(w, h); } SdlScreen::~SdlScreen() { SDL_Quit(); } -bool SdlScreen::init(int width, int height) { +bool SdlScreen::_init(int width, int height) { char temp[120]; /* initialize SDL */ diff --git a/src/sdlgl_screen.cpp b/src/sdlgl_screen.cpp index aa0dce12..9674c6c1 100644 --- a/src/sdlgl_screen.cpp +++ b/src/sdlgl_screen.cpp @@ -15,9 +15,8 @@ * this source code; if not, write to: * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * "$Id$" - * */ + #include #ifdef WITH_OPENGL @@ -30,12 +29,14 @@ #include #include +// our objects are allowed to be created trough the factory engine +FACTORY_REGISTER_INSTANTIATOR(ViewPort, SdlGlScreen, Screen, sdlgl); -SdlGlScreen::SdlGlScreen(int w, int h) - : ViewPort(w, h) { +SdlGlScreen::SdlGlScreen() + : ViewPort() { emuscr = NULL; bpp = 32; diff --git a/src/soft_screen.cpp b/src/soft_screen.cpp index 13be3066..7fa55a62 100644 --- a/src/soft_screen.cpp +++ b/src/soft_screen.cpp @@ -27,16 +27,17 @@ #include #include +// our objects are allowed to be created trough the factory engine +FACTORY_REGISTER_INSTANTIATOR(ViewPort, SoftScreen, Screen, soft); -SoftScreen::SoftScreen(int w, int h) - : ViewPort(w, h) { +SoftScreen::SoftScreen() + : ViewPort() { buffer = NULL; bpp = 32; - init(w, h); // set_name("SOFT"); } @@ -45,8 +46,11 @@ SoftScreen::~SoftScreen() { } +void SoftScreen::setup_blits(Layer *lay) { -bool SoftScreen::init(int w, int h) { +} + +bool SoftScreen::_init(int w, int h) { // test buffer = malloc(size); diff --git a/xcode/CFreej.mm b/xcode/CFreej.mm index bcf4fde2..d9f8446e 100644 --- a/xcode/CFreej.mm +++ b/xcode/CFreej.mm @@ -169,7 +169,8 @@ freej = new Context(); freej->quit = false; NSRect frame = [screenView frame]; - screen = new CVScreen(frame.size.width, frame.size.height); + screen = new CVScreen(); + screen->init(frame.size.width, frame.size.height); freej->add_screen(screen); freej->plugger.refresh(freej); //freej->config_check("keyboard.js"); diff --git a/xcode/CVScreen.mm b/xcode/CVScreen.mm index 2e170a84..47504fb9 100644 --- a/xcode/CVScreen.mm +++ b/xcode/CVScreen.mm @@ -723,11 +723,41 @@ bail: @end -CVScreen::CVScreen(int w, int h) - : ViewPort(w, h) { - init(w, h); +@implementation CVScreenController + +// handle keystrokes +- (void)keyDown:(NSEvent *)event +{ + // NSLog(@"Keypress (%hu, modifier flags: 0x%x) %@\n", [event keyCode], [event modifierFlags], [event charactersIgnoringModifiers]); + NSString *modifier = nil; + switch ([event modifierFlags]) { + case NSShiftKeyMask: + modifier = [NSString stringWithUTF8String:"shift_"]; + break; + case NSControlKeyMask: + modifier = [NSString stringWithUTF8String:"control_"]; + break; + case NSAlternateKeyMask: + modifier = [NSString stringWithUTF8String:"alt_"]; + break; + case NSCommandKeyMask: + modifier = [NSString stringWithUTF8String:"cmd_"]; + break; + case NSFunctionKeyMask: + modifier = [NSString stringWithUTF8String:"fn_"]; + break; + } +} + +@end + +CVScreen::CVScreen() + : ViewPort() { + view = NULL; + Factory::set_default_classtype("KeyboardController", "cocoa"); + } CVScreen::~CVScreen() { @@ -735,14 +765,9 @@ CVScreen::~CVScreen() { } +bool CVScreen::_init(int w, int h) { -bool CVScreen::init(int w, int h) { - - this->w = w; - this->h = h; - bpp = 32; - size = w*h*(bpp>>3); - pitch = w*(bpp>>3); + // do your init here if you need return true; } @@ -807,4 +832,4 @@ void CVScreen::resize(int rw, int rh) w = rw; h = rh; unlock(); -} \ No newline at end of file +}