Adonthell  0.4
win_event.h
1 /*
2  $Id: win_event.h,v 1.5 2001/12/25 20:06:00 ksterker Exp $
3 
4  (C) Copyright 2000, 2001 Joel Vennin
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details
13 */
14 
15 #ifndef _WIN_EVENT_H_
16 #define _WIN_EVENT_H_
17 
18 #include "Python.h"
19 #include <vector>
20 
21 class py_callback;
22 
23 
24 #include "types.h"
25 #include "callback.h"
26 
27 
28 using namespace std;
29 
30 class win_event
31 {
32  public:
33 
34  win_event(){return_code_=0;}
35 
36  //Use this function to set a callback function
37  void set_return_code (int rc)
38  { return_code_ = rc; }
39 
40 #ifndef SWIG
41  void set_signal_connect (const Functor0 &func, u_int8 signal)
42  { callback_[signal] = func; }
43  void set_callback_destroy (const Functor0wRet<bool> &func)
44  { callback_destroy_ = func; }
45  void set_callback_quit (const Functor1<int> &func)
46  { callback_quit_ = func;}
47 #endif
48 
49  bool update();
50 
51  void py_signal_connect (PyObject *pyfunc, int signal, PyObject *args = NULL);
52 
53  const static u_int8 ACTIVATE =1 ;
54  const static u_int8 UNACTIVATE = 2;
55  const static u_int8 UPDATE = 3;
56  const static u_int8 DRAW = 4;
57  const static u_int8 DRAW_ON_VISIBLE = 5;
58  const static u_int8 ACTIVATE_KEY = 6;
59  const static u_int8 SELECT = 7;
60  const static u_int8 UNSELECT = 8;
61  const static u_int8 KEYBOARD = 9;
62  const static u_int8 SCROLL_UP = 10;
63  const static u_int8 SCROLL_DOWN = 11;
64  const static u_int8 NEXT = 12;
65  const static u_int8 PREVIOUS = 13;
66  const static u_int8 CLOSE = 14;
67  const static u_int8 DESTROY = 15;
68 
69  /*****************************************************/
70  /*****************************************************/
71  //DESTRUCTOR
72  virtual ~win_event();
73 
74  protected:
75  // the python callbacks connected to the window
76  vector<py_callback *> py_callbacks;
77 
78 
79  Functor0 callback_[20];
80  Functor0wRet<bool> callback_destroy_;
81  Functor1<int> callback_quit_;
82 
83 
84  int return_code_;
85 
86  //execute the callback function
87  virtual void on_activate(){ if(callback_[ACTIVATE]) (callback_[ACTIVATE])();}
88  virtual void on_unactivate(){ if(callback_[UNACTIVATE]) (callback_[UNACTIVATE])();}
89 
90  virtual void on_update() { if(callback_[UPDATE]) (callback_[UPDATE])();}
91 
92  virtual void on_draw_visible(){ if(callback_[DRAW_ON_VISIBLE]) (callback_[DRAW_ON_VISIBLE])();}
93  virtual void on_draw(){ if(callback_[DRAW]) (callback_[DRAW])();}
94 
95  virtual void on_activate_key(){ if(callback_[ACTIVATE_KEY]) (callback_[ACTIVATE_KEY])();}
96  virtual void on_select(){ if(callback_[SELECT]) (callback_[SELECT])();}
97  virtual void on_unselect(){ if(callback_[UNSELECT]) (callback_[UNSELECT])();}
98 
99  virtual void on_up(){if(callback_[SCROLL_UP]) (callback_[SCROLL_UP])();}
100  virtual void on_down(){if(callback_[SCROLL_DOWN]) (callback_[SCROLL_DOWN])();}
101 
102  virtual void on_next(){if(callback_[NEXT]) (callback_[NEXT])();}
103  virtual void on_previous(){if(callback_[PREVIOUS]) (callback_[PREVIOUS])();}
104 };
105 
106 
107 
108 #endif
109 
110 
Declares some basic types.
#define u_int8
8 bits long unsigned integer
Definition: types.h:29
Stores the C++ <-> Python callback binding.
Definition: py_callback.h:36