-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtara_funcs.cc
More file actions
161 lines (124 loc) · 3.37 KB
/
tara_funcs.cc
File metadata and controls
161 lines (124 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <string>
#include "TaraDraw/TaraDraw.hh"
#include "PixelStream/curlLib.hh"
#include "app_data.hh"
extern appdata AppData;
extern void Idle(void);
extern void Terminate(int);
extern void HandleMouseMotion(double, double);
extern void HandleMousePress(double, double);
extern void HandleMouseRelease(void);
extern void HandleKeyboard(unsigned char);
static void app_run(void);
static void app_term(void);
void mouse_click(ButtonEvent);
void key_click(KeyboardEvent);
void win_config(ConfigureEvent);
void win_close(WinCloseEvent);
void SwapBuffers(void);
static struct
{
tdWindow id;
tdGLContext *gl_context;
double width;
double height;
} mywin;
void ui_init(const std::string &xdisplay)
{
tdInitialize(xdisplay);
}
void window_init(const std::string &displayId, bool fullscreen, int winOriginX, int winOriginY, int winSizeX, int winSizeY)
{
tdRegion usable;
tdGetScreenData(0x0, &usable);
std::string d = "dcapp";
if (!displayId.empty()) d = displayId;
if (fullscreen)
{
mywin.id = tdOpenFullScreen(d);
mywin.width = usable.width;
mywin.height = usable.height;
}
else
{
mywin.id = tdOpenWindow(d, (float)winOriginX, usable.top - (float)winOriginY, (float)winSizeX, (float)winSizeY, tdAlignLeft | tdAlignTop);
mywin.width = (double)winSizeX;
mywin.height = (double)winSizeY;
}
mywin.gl_context = tdGLCreateContext(mywin.id);
}
void mouse_click(ButtonEvent btn)
{
if (btn.state == tdPressed) HandleMousePress(btn.pos.x/mywin.width, btn.pos.y/mywin.height);
else HandleMouseRelease();
}
void key_click(KeyboardEvent kbd)
{
if (kbd.state == tdPressed && kbd.key) // Ignore if "specialkey" pressed
{
// Pressing 0x1b (escape) toggles fullscreen mode
if (kbd.key == 0x1b) tdToggleFullScreen();
// Change 0x7f (delete) to 0x08 (backspace) for standardization
else if (kbd.key == 0x7f) HandleKeyboard(0x08);
else HandleKeyboard(kbd.key);
}
}
void win_config(ConfigureEvent cfg)
{
AppData.toplevel->reshape(cfg.size.width, cfg.size.height);
mywin.width = cfg.size.width;
mywin.height = cfg.size.height;
tdGLSetContext(mywin.gl_context);
tdGLReshapeContext(0, 0, 0, cfg.size.width, cfg.size.height);
}
void win_close(WinCloseEvent /* wcl */)
{
app_term();
}
static void app_run(void)
{
static unsigned passnum = 0;
tdPosition pos;
std::list<PixelStreamItem *>::iterator psitem;
passnum++;
Idle();
tdGetPointer(nullptr, &pos);
HandleMouseMotion(pos.x/mywin.width, pos.y/mywin.height);
tdProcessEvents(mouse_click, key_click, win_config, win_close);
for (psitem = AppData.pixelstreams.begin(); psitem != AppData.pixelstreams.end(); psitem++)
(*psitem)->psd->updateStatus();
curlLibRun();
AppData.toplevel->updateStreams(passnum);
if (tdNeedsRedraw(mywin.id))
{
AppData.toplevel->draw();
SwapBuffers();
AppData.last_update->restart();
}
}
static void app_term(void)
{
Terminate(0);
}
void ui_terminate(void)
{
tdTerminate();
}
void mainloop(void)
{
tdMainLoop(app_run, app_term);
}
void SetNeedsRedraw(void)
{
tdSetNeedsRedraw(mywin.id);
}
void SwapBuffers(void)
{
tdGLSwapBuffers();
}
void UpdateDisplay(void)
{
AppData.toplevel->setCurrentPanel();
AppData.DisplayLogic();
SetNeedsRedraw();
}