ScummVM API documentation
call_back.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
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 as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_MISC_CALLBACK_H
23 #define NUVIE_MISC_CALLBACK_H
24 
25 #include "ultima/nuvie/core/nuvie_defs.h"
26 
27 namespace Ultima {
28 namespace Nuvie {
29 
30 class CallBack;
31 
32 // general messages
33 typedef enum {
34  CB_TIMED, /* timer fired (data=uint32:time) */
35 
36  ANIM_CB_DONE, /* animation has finished */
37  ANIM_CB_HIT, /* animation hit a MapEntity (data=MapEntity) */
38  ANIM_CB_HIT_WORLD, /* animation hit some other tile on the map (data=MapCoord) */
39 
40  EFFECT_CB_COMPLETE, /* effect has finished */
41 
42  CB_DATA_READY, /* some data is ready to be retrieved (data=char)*/
43  MSGSCROLL_CB_TEXT_READY, /* text is ready to be retrieved (data=Std::string)*/
44  CB_INPUT_CANCELED /* input canceled by user */
45 } CallbackMessage;
46 
47 
48 /* Classes inheriting this can send & receive callback messages.
49  */
50 class CallBack {
51 protected:
52  char *callback_user_data; // data set by Caller
53  CallBack *callback_target; // Caller: default CallBack that message() sends to
54 
55 public:
56  CallBack() {
57  callback_user_data = nullptr;
58  callback_target = nullptr;
59  }
60  virtual ~CallBack() { }
61 
62  // receive message
63  virtual uint16 callback(uint16 msg, CallBack *caller, void *data = nullptr) {
64  DEBUG(0, LEVEL_WARNING, "Unhandled callback. msg (%x)\n", msg);
65  return 0;
66  }
67  // send message
68  uint16 message(uint16 msg, void *msg_data = nullptr, void *my_data = nullptr) {
69  if (my_data)
70  set_user_data(my_data);
71  callback_target->set_user_data(callback_user_data);
72 
73  return (callback_target->callback(msg, this, msg_data));
74  }
75 
76  void set_user_data(void *user_data) {
77  callback_user_data = (char *)user_data;
78  }
79  void set_target(CallBack *t) {
80  callback_target = t;
81  }
82 };
83 
84 } // End of namespace Nuvie
85 } // End of namespace Ultima
86 
87 #endif
Definition: detection.h:27
Definition: call_back.h:50