source: thomson/elec/CrO2/software/gui.cpp@ c7b4218

main
Last change on this file since c7b4218 was c7b4218, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago
  • Move GUI in its own class
  • Design C++ callbacksystem for IUP
  • Load file from menu

git-svn-id: svn://localhost/thomson@13 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/* CrO2 datassette emulator
2 * Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
3 *
4 * Distributed under the terms of the MIT licence.
5 */
6
7#include "gui.h"
8
9#include "device.h"
10#include "k5.h"
11
12#include <stdint.h>
13#include <iup.h>
14#include <iupcontrols.h>
15
16///////////////////////////////////////////////////////////////////////////////
17// Super awesome extended powerful ultimate deluxe C++ IUP callback system ;)
18
19typedef int (Gui::*Callee)();
20
21class Callback
22{
23 public:
24 static int call(Ihandle* that);
25 static int destroy(Ihandle* that);
26 static void create(Ihandle* handle, const char* name, Gui* self, Callee what);
27
28 private:
29 Callback(Gui* self, Callee what);
30 Callback(); // do not use
31
32 Gui* self;
33 Callee what;
34};
35
36void Callback::create(Ihandle* handle,const char* name, Gui* self, Callee what)
37{
38 Callback* cb = new Callback(self, what);
39 IupSetAttribute(handle, "LCALLBACK", (char*)cb);
40 IupSetCallback(handle, name, Callback::call);
41 IupSetCallback(handle, "LDESTROY_CB", Callback::destroy);
42}
43
44Callback::Callback(Gui* self, Callee what)
45{
46 this->self = self;
47 this->what = what;
48}
49
50int Callback::call(Ihandle* that)
51{
52 Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK");
53 return ((call->self)->*(call->what))();
54}
55
56int Callback::destroy(Ihandle* that)
57{
58 Callback* call = (Callback*)IupGetAttribute(that, "LCALLBACK");
59 delete call;
60 return IUP_DEFAULT;
61}
62
63///////////////////////////////////////////////////////////////////////////////
64
65 // Start status poller "thread"
66 int pollStatus(Ihandle* ih)
67 {
68 Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target");
69
70 uint8_t status = Device::getDevice().getStatus();
71 if (status & 8)
72 IupSetAttribute(motoron, "VALUE", "0"); // motor OFF
73 else
74 IupSetAttribute(motoron, "VALUE", "1"); // motor ON
75 return IUP_DEFAULT;
76 }
77
78void startPolling(Ihandle* target) {
79 Ihandle* timer = IupTimer();
80
81 IupSetAttribute(timer, "target", (const char*)target);
82
83 IupSetAttribute(timer, "TIME", "300");
84 IupSetCallback(timer, "ACTION_CB", pollStatus);
85 IupSetAttribute(timer, "RUN", "YES");
86}
87
88/* UI */
89
90int menu_exit(Ihandle* that)
91{
92 return IUP_CLOSE;
93}
94
95
96
97Gui::Gui(int* argc, char*** argv)
98{
99 file = NULL;
100
101 IupOpen(argc, argv);
102// IupControlsOpen();
103
104 IupSetFunction("EXIT", menu_exit);
105
106 Ihandle* menu_open = IupItem("Open", NULL);
107 Callback::create(menu_open, "ACTION", this, &Gui::menu_open);
108
109 Ihandle* menu = IupMenu(
110 IupSubmenu("File",
111 IupMenu(
112 menu_open,
113 IupItem("Exit", "EXIT"),
114 NULL
115 )
116 ),
117 NULL
118 );
119
120
121 // CONTROL
122 Ihandle* motoron = IupProgressBar();
123 IupSetAttribute(motoron, "RASTERSIZE", "16x16");
124
125 // EXPLORE
126 Ihandle* platformlist = IupList(NULL);
127 IupSetAttribute(platformlist, "EXPAND", "HORIZONTAL");
128 IupSetAttribute(platformlist, "DROPDOWN", "YES");
129 IupSetAttribute(platformlist, "1", "MO5");
130 IupSetAttribute(platformlist, "VALUE", "1");
131
132 Ihandle* blocklist = IupTree();
133 IupSetAttribute(blocklist, "EXPAND", "VERTICAL");
134
135 Ihandle* tabs = IupTabs(
136 IupVbox(
137 IupHbox(
138 IupLabel("Motor"),
139 motoron,
140 NULL
141 ),
142 IupHbox(
143 IupToggle("play",NULL),
144 IupToggle("REC",NULL),
145 NULL
146 ),
147 NULL
148 ),
149 IupVbox(
150 IupHbox(
151 IupLabel("Format:"),
152 platformlist,
153 NULL
154 ),
155 IupHbox(
156 blocklist,
157 IupVbox(
158// IupMatrix(NULL),
159 IupLabel("Checksum:"),
160 NULL
161 ),
162 NULL
163 )
164 ),
165 NULL
166 );
167
168 IupSetAttribute(tabs,"TABTITLE0", "Control");
169 IupSetAttribute(tabs,"TABTITLE1", "Explore");
170
171 Ihandle* dialog = IupDialog(tabs);
172 IupSetAttribute(dialog, "TITLE", "CrO2 tape emulator");
173 IupSetAttributeHandle(dialog, "MENU", menu);
174 IupShow(dialog);
175
176 // Run the timer
177 startPolling(motoron);
178
179 IupMainLoop();
180
181 IupClose();
182}
183
184
185Gui::~Gui()
186{
187 delete file;
188}
189
190int Gui::menu_open()
191{
192 char name[65536];
193 name[0] = 0;
194 if (IupGetFile(name) == 0)
195 {
196 // Load file
197 file = new K5(name);
198 }
199 return IUP_DEFAULT;
200}
Note: See TracBrowser for help on using the repository browser.