/* Copyright (C) 1997, 1998, 1999, 2000 by Alex Pfaffe (Digital Dawn Graphics Inc) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef _ddgViewPort_Class_ #define _ddgViewPort_Class_ #include "util/ddgutil.h" #include "struct/ddgevent.h" #include "render/ddgcamera.h" #include "render/ddguiobj.h" class WEXP ddgViewport : public ddgListNode { friend class ddgViewportSet; int _id; bool _enabled:1; bool _edge:1; bool _slave:1; bool _control:1; ddgCamera *_camera; void (*_update)(void); ddgUIGroup _uigroup; ddgEventHandler *_eventHandler; public: unsigned short int _px, _py, _dx, _dy; ddgViewport( ddgCamera *c, unsigned short x = 5, unsigned short y = 70, unsigned short w = 25, unsigned short h = 25); ~ddgViewport() { } unsigned short int px( int i = -1) { return (i>-1 ? _px = i: _px); } unsigned short int py( int i = -1) { return (i>-1 ? _py = i: _py); } unsigned short int dx( int i = 0) { return (i ? _dx = i : _dx ); } unsigned short int dy( int i = 0) { return (i ? _dy = i : _dy ); } int id( int i = 0) { return (i ? _id = i : _id); } void enabled( bool e ) { _enabled = e; } bool enabled(void) { return _enabled; } void edge(bool edge) { _edge = edge; } bool edge(void) { return _edge; } void slave( bool s ) { _slave = s; } bool slave( void ) { return _slave; } void control( bool c ) { _control = c; } bool control( void ) { return _control; } void camera( ddgCamera *c ) { _camera = c; } ddgCamera* camera(void) { return _camera; } ddgUIGroup *uigroup(void) { return &_uigroup; } void update( void (*u)(void)) { _update = u; } bool update( void ) { return _update ? true : false; } void doUpdate (void ) { _update(); } ddgEventHandler *eventHandler(void) { return _eventHandler; } void eventHandler(ddgEventHandler *eh) { _eventHandler = eh; } }; class WEXP ddgViewportSet : public ddgList { typedef ddgList super; ddgStr _name; ddgViewport *_current; static ddgViewportSet *_viewportset; ddgViewport *hitTest(int x, int y); bool (*_shutdown)(void); bool _fullscreen; unsigned int _fsmode; public: ddgViewportSet( char *n = 0, unsigned int fs = 0) : _current(0), _shutdown(0), _fsmode(fs) { _name.assign(n ? n : "DDG"); _fullscreen = fs ? true:false; } void name( char *n ); char *name( void ) { return _name; } // Initialize all viewports; int init( int argc, char **argv ); void enable(void); static void draw(void); static void reshape( int w, int h ); static void specialKey( int key, int x, int y ); static void key( unsigned char key, int x, int y ); static void mouse( int button, int state, int x, int y ); static void mouseMotion( int x, int y ); static void idle( void ); static void visible( int vis ); ddgViewport *find( int id ) { ddgViewport *v = (ddgViewport*) head(); while (v && v->id() != id) v = (ddgViewport *) v->next(); return v; } // This function will be called at shutdown time to // allow the user to clean up data. // Returns true if shutdown should be aborted. void shutdown( bool (*s)(void)) { _shutdown = s; } bool shutdown( void ) { return _shutdown ? true : false; } void doShutdown ( ddgError *e ); static bool checkForError(void); static char *mode (unsigned int m, char *buf, unsigned int bufsize ); static bool smouse(void *obj, int button, int state, int x, int y); static bool smouseMotion(void *obj, int x, int y); static bool sspecialKey(void *obj, int k, int x, int y); static bool skey(void *obj, unsigned char k, int x, int y); }; class WEXP ddgViewportEventHandler : public ddgEventHandler { public: ddgViewportEventHandler(void); }; #endif