| 1 | //============================================================================ |
| 2 | // |
| 3 | // SSSS tt lll lll |
| 4 | // SS SS tt ll ll |
| 5 | // SS tttttt eeee ll ll aaaa |
| 6 | // SSSS tt ee ee ll ll aa |
| 7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
| 8 | // SS SS tt ee ll ll aa aa |
| 9 | // SSSS ttt eeeee llll llll aaaaa |
| 10 | // |
| 11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
| 12 | // and the Stella Team |
| 13 | // |
| 14 | // See the file "License.txt" for information on usage and redistribution of |
| 15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 16 | // |
| 17 | // Based on code from ScummVM - Scumm Interpreter |
| 18 | // Copyright (C) 2002-2004 The ScummVM project |
| 19 | //============================================================================ |
| 20 | |
| 21 | #ifndef COMMAND_HXX |
| 22 | #define COMMAND_HXX |
| 23 | |
| 24 | #include "bspf.hxx" |
| 25 | |
| 26 | /** |
| 27 | Allows base GUI objects to send and receive commands. |
| 28 | |
| 29 | @author Stephen Anthony |
| 30 | */ |
| 31 | class CommandReceiver; |
| 32 | class CommandSender; |
| 33 | |
| 34 | class CommandReceiver |
| 35 | { |
| 36 | friend class CommandSender; |
| 37 | |
| 38 | public: |
| 39 | virtual ~CommandReceiver() = default; |
| 40 | |
| 41 | protected: |
| 42 | virtual void handleCommand(CommandSender* sender, int cmd, int data, int id) { } |
| 43 | }; |
| 44 | |
| 45 | class CommandSender |
| 46 | { |
| 47 | // TODO - allow for multiple targets, i.e. store targets in a list |
| 48 | // and add methods addTarget/removeTarget. |
| 49 | public: |
| 50 | explicit CommandSender(CommandReceiver* target) |
| 51 | : _target(target) { } |
| 52 | |
| 53 | virtual ~CommandSender() = default; |
| 54 | |
| 55 | void setTarget(CommandReceiver* target) { _target = target; } |
| 56 | CommandReceiver* getTarget() const { return _target; } |
| 57 | |
| 58 | virtual void sendCommand(int cmd, int data, int id) |
| 59 | { |
| 60 | if(_target && cmd) |
| 61 | _target->handleCommand(this, cmd, data, id); |
| 62 | } |
| 63 | |
| 64 | protected: |
| 65 | CommandReceiver* _target; |
| 66 | }; |
| 67 | |
| 68 | #endif |
| 69 | |