-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.c
165 lines (125 loc) · 3.43 KB
/
tools.c
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
#include <gtk/gtk.h>
#include <string.h>
#include <stdlib.h>
#include "SDL/SDL_ttf.h"
#include "tools.h"
int less(int a, int b)
{
return a < b ? a : b;
}
int great(int a, int b)
{
return a > b ? a : b;
}
int abs(int a)
{
return a < 0 ? a * -1 : a;
}
double greatf(double a, double b)
{
return a > b ? a : b;
}
window_info_t emptyWindow()
{
window_info_t winfo = {-10, 10, 0, 0, 0, NO, 600, 400, NULL, NO, 0, 0, NO, NO, {50, 50, 255}, {0, 0, 0}, {0, 255, 255}, NO, NO, NO};
return winfo;
}
int label_id = 0;
label_t emptyLabel()
{
label_t label = {NULL, 13, {255, 0, 255}, 0, 0, label_id++};
return label;
}
label_t *label_with_id(list_t *list, int idx)
{
node_t *node;
for(node = list->head; node; node = node->right)
{
if(((label_t *)node->obj)->label_id == idx)
return (label_t *)node->obj;
}
return NULL;
}
color_t makeColor(unsigned char r, unsigned char g, unsigned char b)
{
color_t col = {r, g, b};
return col;
}
SDL_Surface *createSurface(int width, int height)
{
return SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);
}
void copySurface(SDL_Surface *source, SDL_Surface *dest)
{
SDL_BlitSurface(source, NULL, dest, NULL);
}
void blit(SDL_Surface *source, SDL_Surface *dest, int x, int y)
{
SDL_Rect dstr = {x, y, 0, 0};
SDL_BlitSurface(source, NULL, dest, &dstr);
}
void draw_label(void *obj, void *data)
{
label_t *label = (label_t *)obj;
SDL_Surface *screen = (SDL_Surface *)data;
TTF_Font *font = TTF_OpenFont("AnonPro.ttf", label->fontsize);
SDL_Color col = {label->text_col.r, label->text_col.g, label->text_col.b};
SDL_Surface *surf = TTF_RenderText_Blended(font, label->txt, col);
blit(surf, screen, label->x, label->y);
TTF_CloseFont(font);
SDL_FreeSurface(surf);
}
void drawLabels(label_t labels[], int labelcount, SDL_Surface *screen)
{
int i;
for(i = 0; i < labelcount; i++)
{
label_t label = labels[i];
TTF_Font *font = TTF_OpenFont("AnonPro.ttf", label.fontsize);
SDL_Color col = {label.text_col.r, label.text_col.g, label.text_col.b};
SDL_Surface *surf = TTF_RenderText_Blended(font, label.txt, col);
blit(surf, screen, label.x, label.y);
TTF_CloseFont(font);
SDL_FreeSurface(surf);
}
}
void print_debug_coords(SDL_Surface *screen, TTF_Font *font, int x, int y)
{
char frmt[20];
sprintf(frmt, "(%d, %d)", x, y);
SDL_Color col = {0, 255, 0};
SDL_Surface *surf = TTF_RenderText_Solid(font, frmt, col);
blit(surf, screen, 10, 10);
SDL_FreeSurface(surf);
}
gboolean test(gpointer data)
{
char **file = (char **)data;
GtkWidget *dialog;
GtkFileFilter *filter;
filter = gtk_file_filter_new();
gtk_file_filter_add_pattern(filter, "*.bmp");
gtk_file_filter_set_name(filter, "Bitmap images");
dialog = gtk_file_chooser_dialog_new("Save Snapshot", NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
*file = NULL;
char *filename = NULL;
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
*file = malloc(strlen(filename) + 1);
strcpy(*file, filename);
g_free(filename);
}
gtk_widget_destroy(dialog);
gtk_main_quit();
return FALSE;
}
char *get_filename()
{
char *filename;
g_timeout_add(1, test, (gpointer)&filename);
gtk_main();
return filename;
}