forked from notsecure/uTox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.h
221 lines (169 loc) · 4.61 KB
/
main.h
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#ifndef MAIN_H
#define MAIN_H
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <time.h>
#include <string.h>
#include <tox/tox.h>
#define debug(...) printf(__VA_ARGS__)
#define countof(x) (sizeof(x)/sizeof(*(x)))
#define volatile(x) (*((volatile typeof(x)*)&x))
#define IPV6_ENABLED 0
#define DEFAULT_NAME "Tox User"
#define DEFAULT_STATUS "Toxing on uTox"
#define DEFAULT_ADD_MESSAGE "Please accept this friend request."
typedef struct
{
uint16_t length;
uint8_t id[TOX_CLIENT_ID_SIZE], msg[1];
}FRIENDREQ;
typedef struct
{
uint32_t n, width, height, id;
uint16_t istart, start, iend, end;
void **data;
double scroll;
}MSG_DATA;
typedef struct
{
uint32_t peers;
uint16_t name_length, topic_length, typed_length;
uint8_t name[128], topic[128]; //static sizes for now
uint8_t *typed;
uint8_t *peername[256];
MSG_DATA msg;
}GROUPCHAT;
typedef struct msg_file MSG_FILE;
typedef uint8_t char_t;
#ifdef __WIN32__
#include "win32/main.h"
#else
#include "xlib/main.h"
#endif
#include "tox.h"
#include "dns.h"
#include "friend.h"
#include "ui.h"
#include "svg.h"
#include "list.h"
#include "messages.h"
#include "edit.h"
#include "scrollable.h"
#include "button.h"
#include "text.h"
#include "util.h"
volatile _Bool tox_thread_init, tox_done;
_Bool tox_connected;
//friends and groups
//note: assumes array size will always be large enough
FRIEND friend[256];
GROUPCHAT group[1024];
uint32_t friends, groups;
//window
int width, height;
_Bool maximized;
_Bool hand, overtext;
_Bool mdown;
//fonts
//HFONT font_big, font_big2, font_med, font_med2, font_small, font_msg;
int font_small_lineheight, font_msg_lineheight;
enum
{
FONT_TEXT,
FONT_TITLE,
FONT_MSG,
FONT_MSG_NAME,
FONT_MSG_LINK,
FONT_SELF_NAME,
FONT_STATUS,
FONT_LIST_NAME,
FONT_MISC,
};
//sysmenu icons
enum
{
BM_ONLINE,
BM_AWAY,
BM_BUSY,
BM_OFFLINE,
BM_NMSG,
BM_ADD,
BM_GROUPS,
BM_TRANSFER,
BM_SETTINGS,
BM_LBUTTON,
BM_SBUTTON,
BM_CONTACT,
BM_GROUP,
BM_FILE,
BM_CALL,
BM_FT,
BM_FTM,
BM_FTB1,
BM_FTB2,
BM_NO,
BM_PAUSE,
BM_YES,
BM_SCROLLHALFTOP,
BM_SCROLLHALFBOT,
BM_STATUSAREA,
};
void drawalpha(int bm, int x, int y, int width, int height, uint32_t color);
//me
struct
{
uint8_t status;
uint16_t name_length, statusmsg_length;
char_t *statusmsg, name[TOX_MAX_NAME_LENGTH];
char_t id[TOX_FRIEND_ADDRESS_SIZE * 2];
}self;
//add friend page
uint8_t addfriend_status;
#define BORDER 1
#define CAPTION 26
#define MAIN_WIDTH 800
#define MAIN_HEIGHT 600
#define inrect(x, y, rx, ry, width, height) ((x) >= (rx) && (y) >= (ry) && (x) < ((rx) + (width)) && (y) < ((ry) + (height)))
#define strcmp2(x, y) (memcmp(x, y, sizeof(y) - 1))
#define strcpy2(x, y) (memcpy(x, y, sizeof(y) - 1))
void postmessage(uint32_t msg, uint16_t param1, uint16_t param2, void *data);
/* draw functions*/
void drawtext(int x, int y, uint8_t *str, uint16_t length);
int drawtext_getwidth(int x, int y, uint8_t *str, uint16_t length);
void drawtextwidth(int x, int width, int y, uint8_t *str, uint16_t length);
void drawtextwidth_right(int x, int width, int y, uint8_t *str, uint16_t length);
void drawtextrange(int x, int x2, int y, uint8_t *str, uint16_t length);
void drawtextrangecut(int x, int x2, int y, uint8_t *str, uint16_t length);
int textwidth(uint8_t *str, uint16_t length);
int textfit(uint8_t *str, uint16_t length, int width);
void framerect(int x, int y, int right, int bottom, uint32_t color);
void drawrect(int x, int y, int right, int bottom, uint32_t color);
void drawrectw(int x, int y, int width, int height, uint32_t color);
void drawhline(int x, int y, int x2, uint32_t color);
void drawvline(int x, int y, int y2, uint32_t color);
#define drawpixel(x, y, color) drawvline(x, y, (y) + 1, color)
void setfont(int id);
uint32_t setcolor(uint32_t color);
void pushclip(int x, int y, int width, int height);
void popclip(void);
void enddraw(int x, int y, int width, int height);
/* other */
void thread(void func(void*), void *args);
void yieldcpu(uint32_t ms);
uint64_t get_time(void);
void address_to_clipboard(void);
void editpopup(void);
void listpopup(uint8_t item);
void openurl(char_t *str);
void openfilesend(void);
void savefilerecv(uint32_t fid, MSG_FILE *file);
void sysmexit(void);
void sysmsize(void);
void sysmmini(void);
void setselection(void);
#define drawstr(x, y, str) drawtext(x, y, (uint8_t*)str, sizeof(str) - 1)
#define drawstr_getwidth(x, y, str) drawtext_getwidth(x, y, (uint8_t*)str, sizeof(str) - 1)
#define strwidth(x) textwidth((uint8_t*)x, sizeof(x) - 1)
#endif