? adonthell.patch Index: src/base/callback.cc =================================================================== RCS file: /cvsroot/adonthell/adonthell/src/base/callback.cc,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 callback.cc --- src/base/callback.cc 18 Jul 2003 15:16:09 -0000 1.1.1.1 +++ src/base/callback.cc 24 Jul 2003 08:40:00 -0000 @@ -24,4 +24,41 @@ #include "callback.h" -using namespace base; +namespace base +{ + functor_base::functor_base() + : func(0), calle(0) + { + } + + functor_base::functor_base(void* c, PFunc f, const void* mf, size_t sz) + : func(0), callee(c) + { + if(callee) + { + memcpy(memFunc, mf, sz); + if(sz < MEM_FUNC_SIZE) + { + memset(memFunc+sz, 0, MEM_FUNC_SIZE-sz); + } + } + else + { + func = f; + } + } + + functor_0::functor_0(Thunk t,const void *c,PFunc f,const void *mf,size_t sz) + : functor_base(c,f,mf,sz), thunk(t) + { + } + + functor_0::functor_0() + { + } + + functor_0::~functor_0() + { + } + +} Index: src/base/callback.h =================================================================== RCS file: /cvsroot/adonthell/adonthell/src/base/callback.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 callback.h --- src/base/callback.h 18 Jul 2003 15:16:09 -0000 1.1.1.1 +++ src/base/callback.h 24 Jul 2003 08:40:04 -0000 @@ -47,17 +47,8 @@ char memFunc[MEM_FUNC_SIZE]; }; void *callee; - functor_base():func(0),callee(0){} - functor_base(const void *c,PFunc f, const void *mf,size_t sz):callee((void *)c) - { - if(c) - { - memcpy(memFunc,mf,sz); - if(szsetup_rects (); ret.move(temp.x() > x ()? temp.x() : x (), temp.y() > y ()? temp.y() : y ()); - + // Precalculated for faster operation. s_int32 xpl = x () + length (); s_int32 txw = temp.x() + temp.length(); @@ -65,17 +66,19 @@ } else - { + { ret = *this; ret.assign_drawing_area(NULL); - } - + } + return ret; - -} - -bool drawing_area::point_belong (s_int16 px, s_int16 py) -{ + + } + + bool drawing_area::point_belong (s_int16 px, s_int16 py) + { return (px >= x () && px <= x () + length () && py >= y () && py <= y () + height ()); + } + } Index: src/gfx/drawing_area.h =================================================================== RCS file: /cvsroot/adonthell/adonthell/src/gfx/drawing_area.h,v retrieving revision 1.2 diff -u -r1.2 drawing_area.h --- src/gfx/drawing_area.h 22 Jul 2003 17:40:39 -0000 1.2 +++ src/gfx/drawing_area.h 24 Jul 2003 08:40:06 -0000 @@ -129,9 +129,9 @@ * by the drawing_area is the intersection of the two. * @param da the drawing_area to assign. */ - void assign_drawing_area (const drawing_area * da) + void assign_drawing_area (drawing_area * da) { - draw_to = (drawing_area *) da; + draw_to = da; } /** Index: src/gfx/gfx.cc =================================================================== RCS file: /cvsroot/adonthell/adonthell/src/gfx/gfx.cc,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 gfx.cc --- src/gfx/gfx.cc 18 Jul 2003 15:16:09 -0000 1.1.1.1 +++ src/gfx/gfx.cc 24 Jul 2003 08:40:07 -0000 @@ -22,11 +22,18 @@ * */ +#include + +#include "gfx/drawing_area.h" +#include "gfx/drawable.h" +#include "gfx/surface.h" +#include "gfx/screen.h" #include "base/paths.h" -#include "gfx/gfx.h" #include "ltdl.h" -#include + +#include "gfx/gfx.h" + /** * The handler of our library file. @@ -50,92 +57,98 @@ * Virtual backend surface creation function. * */ -static gfx::surface * (*create_surface_p)() = 0; +static gfx::surface * (*create_surface_p)() = 0; -bool gfx::init(const std::string & backend_name) +using namespace std; + +namespace gfx { + bool init(const string & backend_name) + { if (lt_dlinit()) - { - std::cerr << lt_dlerror() << std::endl; - std::cerr << "Error initializing liblt!\n"; + { + cerr << lt_dlerror() << endl; + cerr << "Error initializing liblt!\n"; return false; - } - -// dlhandle = lt_dlopenext(libname.c_str()); - dlhandle = base::get_module(std::string("/gfx/") + backend_name); + } + + // dlhandle = lt_dlopenext(libname.c_str()); + dlhandle = base::get_module(string("/gfx/") + backend_name); if (!dlhandle) goto bigerror; - + gfxinit = (bool(*)()) lt_dlsym(dlhandle, "gfx_init"); if (!gfxinit) - { - std::cerr << lt_dlerror() << std::endl; + { + cerr << lt_dlerror() << endl; goto bigerror; - } + } gfxcleanup = (void(*)()) lt_dlsym(dlhandle, "gfx_cleanup"); if (!gfxcleanup) - { - std::cerr << lt_dlerror() << std::endl; + { + cerr << lt_dlerror() << endl; goto bigerror; - } + } screen::set_video_mode_p = (bool(*)(u_int16, u_int16, u_int8)) lt_dlsym(dlhandle, "gfx_screen_set_video_mode"); if (!screen::set_video_mode_p) - { - std::cerr << lt_dlerror() << std::endl; + { + cerr << lt_dlerror() << endl; goto bigerror; - } - + } + screen::update_p = (void(*)()) lt_dlsym(dlhandle, "gfx_screen_update"); if (!screen::update_p) - { - std::cerr << lt_dlerror() << std::endl; + { + cerr << lt_dlerror() << endl; goto bigerror; - } - + } + screen::trans_color_p = (u_int32(*)()) lt_dlsym(dlhandle, "gfx_screen_trans_color"); if (!screen::trans_color_p) - { - std::cerr << lt_dlerror() << std::endl; + { + cerr << lt_dlerror() << endl; goto bigerror; - } - + } + screen::clear_p = (void(*)()) lt_dlsym(dlhandle, "gfx_screen_clear"); if (!screen::clear_p) - { - std::cerr << lt_dlerror() << std::endl; + { + cerr << lt_dlerror() << endl; goto bigerror; - } - - create_surface_p = (gfx::surface *(*)()) lt_dlsym(dlhandle, "gfx_create_surface"); + } + + create_surface_p = (surface *(*)()) lt_dlsym(dlhandle, "gfx_create_surface"); if (!create_surface_p) - { - std::cerr << lt_dlerror() << std::endl; + { + cerr << lt_dlerror() << endl; goto bigerror; - } - + } + goto success; bigerror: if (dlhandle) lt_dlclose(dlhandle); lt_dlexit(); return false; - + success: return gfxinit(); -} + } -void gfx::cleanup() -{ + void cleanup() + { if (gfxcleanup) gfxcleanup(); gfxcleanup = NULL; - + if (dlhandle) lt_dlclose(dlhandle); lt_dlexit(); -} + } -gfx::surface * gfx::create_surface() -{ + surface * create_surface() + { return create_surface_p(); + } + } Index: src/gfx/gfx.h =================================================================== RCS file: /cvsroot/adonthell/adonthell/src/gfx/gfx.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 gfx.h --- src/gfx/gfx.h 18 Jul 2003 15:16:09 -0000 1.1.1.1 +++ src/gfx/gfx.h 24 Jul 2003 08:40:07 -0000 @@ -26,17 +26,14 @@ #include -#include "gfx/drawing_area.h" -#include "gfx/drawable.h" -#include "gfx/surface.h" -#include "gfx/screen.h" - /** * All the low-level graphical tasks are handled by this module. * */ namespace gfx { + class surface; + /** * Initialize the gfx module. This function \e must be called * before doing anything gfx-related. @@ -69,7 +66,7 @@ * @return a new surface (NULL if failed) corresponding to * the current backend. */ - gfx::surface * create_surface(); + surface * create_surface(); } Index: src/gfx/pnm.cc =================================================================== RCS file: /cvsroot/adonthell/adonthell/src/gfx/pnm.cc,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 pnm.cc --- src/gfx/pnm.cc 18 Jul 2003 15:16:09 -0000 1.1.1.1 +++ src/gfx/pnm.cc 24 Jul 2003 08:40:08 -0000 @@ -28,10 +28,13 @@ #include #include -using namespace gfx; +using namespace std; -void * pnm::get (std::ifstream & file, u_int16 & length, u_int16 & height) +namespace gfx { + + void * pnm::get (ifstream & file, u_int16 & length, u_int16 & height) + { char *image; char sign[10]; u_int16 l, h; @@ -73,46 +76,48 @@ if (height) height = h; return (image); -} + } -void pnm::put (std::ofstream & file, const char *image, u_int16 length, u_int16 height) -{ + void pnm::put (ofstream & file, const char *image, u_int16 length, u_int16 height) + { char s[30]; - + sprintf (s, "P6\n%d %d\n255\n", length, height); file.write(s, sizeof (char) * strlen (s)); - + file.write(image, 3 * length * height); -} + } -// Private methods. + // Private methods. -void pnm::pnm_gotonextline (std::ifstream & file) -{ + void pnm::pnm_gotonextline (ifstream & file) + { char buff; - + do file.read(&buff, 1); while (buff != '\n'); -} - -int pnm::pnm_checkforcomment (std::ifstream & file) -{ + } + + int pnm::pnm_checkforcomment (ifstream & file) + { char buff; - + file.read(&buff, 1); if (buff == '#') - { + { pnm_gotonextline (file); return (1); - } + } else - { - file.seekg(-1, std::ios::cur); + { + file.seekg(-1, ios::cur); return (0); - } + } + } + } Index: src/gfx/screen.cc =================================================================== RCS file: /cvsroot/adonthell/adonthell/src/gfx/screen.cc,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 screen.cc --- src/gfx/screen.cc 18 Jul 2003 15:16:09 -0000 1.1.1.1 +++ src/gfx/screen.cc 24 Jul 2003 08:40:08 -0000 @@ -24,27 +24,30 @@ #include "gfx/screen.h" -using namespace gfx; - -u_int16 screen::length_, screen::height_; -u_int8 screen::bytes_per_pixel_; -bool screen::fullscreen_; - -bool (*screen::set_video_mode_p) (u_int16 nl, u_int16 nh, u_int8 depth) = NULL; -void (*screen::update_p)() = NULL; -u_int32 (*screen::trans_color_p)() = NULL; -void (*screen::clear_p)() = NULL; - -bool screen::set_video_mode(u_int16 nl, u_int16 nh, u_int8 depth) +namespace gfx { - bool res = set_video_mode_p(nl, nh, depth); + + u_int16 screen::length_, screen::height_; + u_int8 screen::bytes_per_pixel_; + bool screen::fullscreen_; + + bool (*screen::set_video_mode_p) (u_int16 nl, u_int16 nh, u_int8 depth) = NULL; + void (*screen::update_p)() = NULL; + u_int32 (*screen::trans_color_p)() = NULL; + void (*screen::clear_p)() = NULL; + bool screen::set_video_mode(u_int16 nl, u_int16 nh, u_int8 depth) + { + bool res = set_video_mode_p(nl, nh, depth); + if (res) - { + { length_ = nl; height_ = nh; bytes_per_pixel_ = depth; - } - + } + return res; + } + } Index: src/gfx/surface.cc =================================================================== RCS file: /cvsroot/adonthell/adonthell/src/gfx/surface.cc,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 surface.cc --- src/gfx/surface.cc 18 Jul 2003 15:16:09 -0000 1.1.1.1 +++ src/gfx/surface.cc 24 Jul 2003 08:40:10 -0000 @@ -24,23 +24,25 @@ #include "surface.h" #include "gfx/pnm.h" -using namespace gfx; +using namespace std; -surface::surface() +namespace gfx { - alpha_ = 255; - is_masked_ = false; -} -surface::~surface() -{ -} + surface::surface() + : is_masked_(false), alpha_(255) + { + } -bool surface::get_pnm (std::ifstream & file) -{ + surface::~surface() + { + } + + bool surface::get_pnm (ifstream & file) + { void *rawdata; u_int16 l, h; - + rawdata = pnm::get (file, l, h); if (!rawdata) return false; @@ -51,50 +53,52 @@ * won't be rendered correctly on big-endian machines. */ set_data(rawdata, l, h, 3, 0x0000ff, 0x00ff00, 0xff0000); - + free (rawdata); - + return true; -} + } -bool surface::load_pnm (const std::string & fname) -{ - std::ifstream file(fname.c_str()); + bool surface::load_pnm (const string & fname) + { + ifstream file(fname.c_str()); bool ret = true; - + if (!file.is_open()) - return false; + return false; ret = get_pnm (file); file.close(); return ret; -} + } -bool surface::put_pnm (std::ofstream & file) const -{ + bool surface::put_pnm (ofstream & file) const + { /** * @bug We don't take care of endianness here! * */ void * rawdata = get_data(3, 0x0000ff, 0x00ff00, 0xff0000); - + if (!rawdata) return false; - + pnm::put (file, (const char *)rawdata, length (), height ()); free(rawdata); return true; -} + } -bool surface::save_pnm (const std::string & fname) const -{ - std::ofstream file(fname.c_str()); + bool surface::save_pnm (const string & fname) const + { + ofstream file(fname.c_str()); bool ret = true; if (!file.is_open()) - return false; + return false; ret = put_pnm (file); file.close(); return true; + } + } Index: src/gfx/surface.h =================================================================== RCS file: /cvsroot/adonthell/adonthell/src/gfx/surface.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 surface.h --- src/gfx/surface.h 18 Jul 2003 15:16:09 -0000 1.1.1.1 +++ src/gfx/surface.h 24 Jul 2003 08:40:12 -0000 @@ -61,7 +61,7 @@ * Destructor. * */ - virtual ~surface () = 0; + virtual ~surface (); /** @@ -276,7 +276,7 @@ * @attention Not available from Python. Use copy() from Python instead. * @sa copy () */ - virtual surface& operator = (surface& src) = 0; + virtual surface& operator = (const surface& src) = 0; #endif /** @@ -284,7 +284,7 @@ * * @sa operator = */ - void copy (surface& src) + void copy (const surface& src) { *this = src; } @@ -412,7 +412,7 @@ * Forbid copy construction. * */ - surface (surface & src); + surface (const surface & src); }; }