source: Thomson/elec/CrO2/software/gui.cpp @ 14

Revision 14, 2.8 KB checked in by pulkomandy, 16 months ago (diff)

Final version (?) of iup++, which handles callbacks with arguments. Needs C++11.

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 <iupcontrols.h>
14
15        // Start status poller "thread"
16        int pollStatus(Ihandle* ih)
17        {
18                Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target");
19
20                uint8_t status = Device::getDevice().getStatus();
21                if (status & 8)
22                        IupSetAttribute(motoron, "VALUE", "0"); // motor OFF
23                else
24                        IupSetAttribute(motoron, "VALUE", "1"); // motor ON
25                return IUP_DEFAULT;
26        }
27
28void startPolling(Ihandle* target) {
29        Ihandle* timer = IupTimer();
30
31        IupSetAttribute(timer, "target", (const char*)target);
32
33        IupSetAttribute(timer, "TIME", "300");
34        IupSetCallback(timer, "ACTION_CB", pollStatus);
35        IupSetAttribute(timer, "RUN", "YES");
36}
37
38/* UI */
39
40int Gui::menu_exit()
41{
42        return IUP_CLOSE;
43}
44
45Gui::Gui(int* argc, char*** argv)
46{
47        file = NULL;
48
49        IupOpen(argc, argv);
50//      IupControlsOpen();
51
52        Ihandle* menu_open = IupItem("Open", NULL);
53        Ihandle* menu_exit = IupItem("Exit", NULL);
54        Callback<Gui>::create(menu_open, "ACTION", this, &Gui::menu_open);
55        Callback<Gui>::create(menu_exit, "ACTION", this, &Gui::menu_exit);
56
57        Ihandle* menu = IupMenu(
58                IupSubmenu("File",
59                        IupMenu(
60                                menu_open,             
61                                menu_exit,
62                                NULL
63                        )
64                ),
65                NULL
66        );
67
68
69        // CONTROL
70        Ihandle* motoron = IupProgressBar();
71        IupSetAttribute(motoron, "RASTERSIZE", "16x16");
72
73        // EXPLORE
74        Ihandle* platformlist = IupList(NULL);
75        IupSetAttribute(platformlist, "EXPAND", "HORIZONTAL");
76        IupSetAttribute(platformlist, "DROPDOWN", "YES");
77        IupSetAttribute(platformlist, "1", "MO5");
78        IupSetAttribute(platformlist, "VALUE", "1");
79
80        Ihandle* blocklist = IupTree();
81        IupSetAttribute(blocklist, "EXPAND", "VERTICAL");
82
83        Ihandle* tabs = IupTabs(
84                IupVbox(
85                        IupHbox(
86                                IupLabel("Motor"),
87                                motoron,
88                                NULL
89                        ),
90                        IupHbox(
91                                IupToggle("play",NULL),
92                                IupToggle("REC",NULL),
93                                NULL
94                        ),
95                        NULL
96                ),
97                IupVbox(
98                        IupHbox(
99                                IupLabel("Format:"),
100                                platformlist,
101                                NULL
102                        ),
103                        IupHbox(
104                                blocklist,
105                                IupVbox(
106//                                      IupMatrix(NULL),
107                                        IupLabel("Checksum:"),
108                                        NULL
109                                ),
110                                NULL
111                        )
112                ),
113                NULL
114        );
115
116        IupSetAttribute(tabs,"TABTITLE0", "Control");
117        IupSetAttribute(tabs,"TABTITLE1", "Explore");
118
119        Ihandle* dialog = IupDialog(tabs);
120        IupSetAttribute(dialog, "TITLE", "CrO2 tape emulator");
121        IupSetAttributeHandle(dialog, "MENU", menu);
122        IupShow(dialog);
123
124        // Run the timer
125        startPolling(motoron);
126
127        IupMainLoop();
128
129        IupClose();
130}
131
132
133Gui::~Gui()
134{
135        delete file;
136}
137
138int Gui::menu_open()
139{
140        char name[65536];
141        name[0] = 0;
142        if (IupGetFile(name) == 0)
143        {
144                // Load file
145                file = new K5(name);
146        }
147        return IUP_DEFAULT;
148}
Note: See TracBrowser for help on using the repository browser.