Adonthell  0.4
win_event.h
00001 /*
00002    $Id: win_event.h,v 1.5 2001/12/25 20:06:00 ksterker Exp $
00003 
00004    (C) Copyright 2000, 2001 Joel Vennin
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details
00013 */
00014 
00015 #ifndef _WIN_EVENT_H_
00016 #define _WIN_EVENT_H_
00017 
00018 #include "Python.h"
00019 #include <vector>
00020 
00021 class py_callback;
00022 
00023 
00024 #include "types.h"
00025 #include "callback.h"
00026 
00027 
00028 using namespace std; 
00029 
00030 class win_event
00031 {
00032  public:
00033   
00034   win_event(){return_code_=0;}
00035 
00036   //Use this function to set a callback function
00037   void set_return_code (int rc) 
00038     { return_code_ = rc; }
00039 
00040 #ifndef SWIG
00041   void set_signal_connect (const Functor0 &func, u_int8 signal)
00042     { callback_[signal] = func; } 
00043   void set_callback_destroy (const Functor0wRet<bool> &func)
00044     { callback_destroy_ = func; }
00045   void set_callback_quit (const Functor1<int> &func)
00046     { callback_quit_ = func;}
00047 #endif
00048   
00049   bool update();
00050   
00051   void py_signal_connect (PyObject *pyfunc, int signal, PyObject *args = NULL); 
00052   
00053   const static u_int8 ACTIVATE =1 ;
00054   const static u_int8 UNACTIVATE = 2;
00055   const static u_int8 UPDATE = 3;
00056   const static u_int8 DRAW = 4;
00057   const static u_int8 DRAW_ON_VISIBLE = 5;
00058   const static u_int8 ACTIVATE_KEY = 6;
00059   const static u_int8 SELECT = 7;
00060   const static u_int8 UNSELECT = 8;
00061   const static u_int8 KEYBOARD = 9;
00062   const static u_int8 SCROLL_UP = 10;
00063   const static u_int8 SCROLL_DOWN = 11;
00064   const static u_int8 NEXT = 12;
00065   const static u_int8 PREVIOUS = 13;
00066   const static u_int8 CLOSE = 14;
00067   const static u_int8 DESTROY = 15;
00068 
00069   /*****************************************************/
00070   /*****************************************************/
00071   //DESTRUCTOR
00072   virtual ~win_event();
00073   
00074  protected:
00075   // the python callbacks connected to the window
00076   vector<py_callback *> py_callbacks;   
00077   
00078   
00079   Functor0 callback_[20];
00080   Functor0wRet<bool> callback_destroy_;
00081   Functor1<int> callback_quit_;
00082   
00083   
00084   int return_code_;
00085   
00086   //execute the callback function
00087   virtual void on_activate(){ if(callback_[ACTIVATE]) (callback_[ACTIVATE])();}
00088   virtual void on_unactivate(){ if(callback_[UNACTIVATE]) (callback_[UNACTIVATE])();}
00089   
00090   virtual void on_update() { if(callback_[UPDATE]) (callback_[UPDATE])();}
00091   
00092   virtual void on_draw_visible(){ if(callback_[DRAW_ON_VISIBLE]) (callback_[DRAW_ON_VISIBLE])();}
00093   virtual void on_draw(){ if(callback_[DRAW]) (callback_[DRAW])();}
00094   
00095   virtual void on_activate_key(){ if(callback_[ACTIVATE_KEY]) (callback_[ACTIVATE_KEY])();}
00096   virtual void on_select(){ if(callback_[SELECT]) (callback_[SELECT])();}
00097   virtual void on_unselect(){ if(callback_[UNSELECT]) (callback_[UNSELECT])();}
00098   
00099   virtual void on_up(){if(callback_[SCROLL_UP]) (callback_[SCROLL_UP])();}
00100   virtual void on_down(){if(callback_[SCROLL_DOWN]) (callback_[SCROLL_DOWN])();}
00101   
00102   virtual void on_next(){if(callback_[NEXT]) (callback_[NEXT])();}
00103   virtual void on_previous(){if(callback_[PREVIOUS]) (callback_[PREVIOUS])();}
00104 };
00105 
00106 
00107 
00108 #endif
00109 
00110