aboutsummaryrefslogtreecommitdiff
path: root/src/mandelbrot-zoom.c
blob: f54a2ab08480e034e2996b5b21063d7246cb4997 (plain)
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
/*
 * mandelbrot-zoom.c
 *
 *  Created on: 13.01.2018
 *      Author: Superleo1810
 */

#include "mandelbrot-zoom.h"

int main(int argc, char **argv)
{
	GtkBuilder *builder;
	gtk_init(&argc, &argv);
	glutInit(&argc, argv);
	builder = gtk_builder_new();
	gtk_builder_add_from_file (builder, "glade/settings.glade", NULL); // TODO: Glade-Zeug mit in die exe

	ui_settings.settings = GTK_WINDOW(gtk_builder_get_object(builder, "settings"));
	//gtk_builder_connect_signals(builder, NULL);
	ui_settings.iterationsSp = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "iterationsSp"));
	ui_settings.threadsSp = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "threadsSp"));
	ui_settings.colorFromBtn = GTK_BUTTON(gtk_builder_get_object(builder, "colorFromBtn"));
	ui_settings.colorToBtn = GTK_BUTTON(gtk_builder_get_object(builder, "colorToBtn"));
	ui_settings.zoomToXEntry = GTK_ENTRY(gtk_builder_get_object(builder, "zoomToXEntry"));
	ui_settings.zoomToYEntry = GTK_ENTRY(gtk_builder_get_object(builder, "zoomToYEntry"));
	ui_settings.speedEntry = GTK_ENTRY(gtk_builder_get_object(builder, "speedEntry"));
	ui_settings.modeCPURd = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "modeCPURd"));
	ui_settings.modeGPURd = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "modeGPURd"));
	ui_settings.exportCb = GTK_CHECK_BUTTON(gtk_builder_get_object(builder, "exportCb"));
	ui_settings.gifRd = GTK_RADIO_BUTTON(gtk_builder_get_object(builder, "gifRd"));
	ui_settings.widthSp = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "widthSp"));
	ui_settings.heightSp = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "heightSp"));
	ui_settings.fpsRenderSp = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "fpsRenderSp"));
	ui_settings.fpsVideoSp = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "fpsVideoSp"));
	ui_settings.bitrateSp = GTK_SPIN_BUTTON(gtk_builder_get_object(builder, "bitrateSp"));
	ui_settings.exportTf = GTK_ENTRY(gtk_builder_get_object(builder, "exportTf"));
	ui_settings.startBtn = GTK_BUTTON(gtk_builder_get_object(builder, "startBtn"));
	ui_settings.exitBtn = GTK_BUTTON(gtk_builder_get_object(builder, "exitBtn"));
	ui_settings.colorDialog = GTK_COLOR_SELECTION_DIALOG(gtk_builder_get_object(builder, "colorDialog"));

	gtk_spin_button_set_increments(ui_settings.iterationsSp, 1, 2);
	gtk_spin_button_set_increments(ui_settings.threadsSp, 1, 2);
	gtk_spin_button_set_increments(ui_settings.widthSp, 1, 2);
	gtk_spin_button_set_increments(ui_settings.heightSp, 1, 2);
	gtk_spin_button_set_increments(ui_settings.fpsRenderSp, 1, 2);
	gtk_spin_button_set_increments(ui_settings.fpsVideoSp, 1, 2);
	gtk_spin_button_set_increments(ui_settings.bitrateSp, 1, 2);

	gtk_spin_button_set_value(ui_settings.iterationsSp, 1000);
	gtk_spin_button_set_value(ui_settings.threadsSp, 4);
	gtk_spin_button_set_value(ui_settings.widthSp, 1920);
	gtk_spin_button_set_value(ui_settings.heightSp, 1080);
	gtk_spin_button_set_value(ui_settings.fpsRenderSp, 30);
	gtk_spin_button_set_value(ui_settings.fpsVideoSp, 30);
	gtk_spin_button_set_value(ui_settings.bitrateSp, 1000);

	gtk_spin_button_set_range(ui_settings.iterationsSp, 1, 16777215); // 3 bytes á 8 bit = 24 bit
	gtk_spin_button_set_range(ui_settings.threadsSp, 1, 255);
	gtk_spin_button_set_range(ui_settings.widthSp, 1, 1920);
	gtk_spin_button_set_range(ui_settings.heightSp, 1, 1080);
	gtk_spin_button_set_range(ui_settings.fpsRenderSp, 1, 60);
	gtk_spin_button_set_range(ui_settings.fpsVideoSp, 1, 60);
	gtk_spin_button_set_range(ui_settings.bitrateSp, 1, 65535);

	g_signal_connect(ui_settings.iterationsSp, "value-changed", G_CALLBACK(on_iterationsSp_valueChanged), NULL);
	g_signal_connect(ui_settings.threadsSp, "value-changed", G_CALLBACK(on_threadsSp_valueChanged), NULL);
	g_signal_connect(ui_settings.colorFromBtn, "clicked", G_CALLBACK(on_colorFromBtn_clicked), NULL);
	g_signal_connect(ui_settings.colorToBtn, "clicked", G_CALLBACK(on_colorToBtn_clicked), NULL);
	g_signal_connect(ui_settings.exportCb, "toggled", G_CALLBACK(on_exportCb_toggled), NULL);
	g_signal_connect(ui_settings.widthSp, "value-changed", G_CALLBACK(on_widthSp_valueChanged), NULL);
	g_signal_connect(ui_settings.heightSp, "value-changed", G_CALLBACK(on_heightSp_valueChanged), NULL);
	g_signal_connect(ui_settings.fpsRenderSp, "value-changed", G_CALLBACK(on_fpsRenderSp_valueChanged), NULL);
	g_signal_connect(ui_settings.fpsVideoSp, "value-changed", G_CALLBACK(on_fpsVideoSp_valueChanged), NULL);
	g_signal_connect(ui_settings.bitrateSp, "value-changed", G_CALLBACK(on_bitrateSp_valueChanged), NULL);
	g_signal_connect(ui_settings.exportTf, "changed", G_CALLBACK(on_exportTf_changed), NULL);
	g_signal_connect(ui_settings.startBtn, "clicked", G_CALLBACK(on_startBtn_clicked), NULL);
	g_signal_connect(ui_settings.exitBtn, "clicked", G_CALLBACK(on_exitBtn_clicked), NULL);

	g_object_unref(builder);
	gtk_widget_show(GTK_WIDGET(ui_settings.settings));
	gtk_main();
	return 0;
}

void on_iterationsSp_valueChanged()
{
	config.config_cpu.iterations = gtk_spin_button_get_value(ui_settings.iterationsSp);
	config.config_opencl.iterations = gtk_spin_button_get_value(ui_settings.iterationsSp);
}

void on_threadsSp_valueChanged()
{
	config.config_cpu.threads = gtk_spin_button_get_value(ui_settings.threadsSp);
}

void on_colorFromBtn_clicked()
{
	currentColor = COLOR_FROM;
	gtk_dialog_run(ui_settings.colorDialog);
}

void on_colorToBtn_clicked()
{
	currentColor = COLOR_TO;
	gtk_dialog_run(ui_settings.colorDialog);
}

void on_exportCb_toggled()
{
	config.video = gtk_toggle_button_get_active(ui_settings.exportCb);
}

void on_exportTf_changed()
{
	config.path = CHAR_PTR(gtk_entry_get_text(ui_settings.exportTf));
}

void on_widthSp_valueChanged()
{
	config.width = gtk_spin_button_get_value(ui_settings.widthSp);
	config.config_cpu.width = gtk_spin_button_get_value(ui_settings.widthSp);
	config.config_opencl.width = gtk_spin_button_get_value(ui_settings.widthSp);
}

void on_heightSp_valueChanged()
{
	config.height = gtk_spin_button_get_value(ui_settings.heightSp);
	config.config_cpu.height = gtk_spin_button_get_value(ui_settings.heightSp);
	config.config_opencl.height = gtk_spin_button_get_value(ui_settings.heightSp);
}

void on_fpsRenderSp_valueChanged()
{
	config.config_cpu.renderFPS = gtk_spin_button_get_value(ui_settings.fpsRenderSp);
	config.config_opencl.renderFPS = gtk_spin_button_get_value(ui_settings.fpsRenderSp);
}

void on_fpsVideoSp_valueChanged()
{
	config.videoFPS = gtk_spin_button_get_value(ui_settings.fpsVideoSp);
}

void on_bitrateSp_valueChanged()
{
	config.bitrate = gtk_spin_button_get_value(ui_settings.bitrateSp);
}

void on_startBtn_clicked()
{
	double x, y, speed;
	sscanf(gtk_entry_get_text(ui_settings.zoomToXEntry), "%lf", &x);
	sscanf(gtk_entry_get_text(ui_settings.zoomToYEntry), "%lf", &y);
	sscanf(gtk_entry_get_text(ui_settings.speedEntry), "%lf", &speed);
	config.config_cpu.to_x = x;
	config.config_cpu.to_y = y;
	config.config_cpu.speed = speed;
	config.config_opencl.to_x = x;
	config.config_opencl.to_y = y;
	config.config_opencl.speed = speed;
	//printf("config {\n\t.iterations = %u\n\t.tox = %f\n\t.toy = %f\n\t.video = %u\n\t.filetype = %u\n\t.width = %u\n\t.height = %u\n\t.renderFPS = %u\n\t.videoFPS = %u\n\t.bitrate = %u\n\t.path = %s\n}\n", config.iterations, x, y, config.video, 0, config.width, config.height, config.renderFPS, config.videoFPS, config.bitrate, config.path);

	// TODO: implement selection of sets correctly
	config.config_cpu.set_func = mandelbrot_r;
	config.config_opencl.set_func = mandelbrot_r;

	// TODO: implement selection of render mode correctly
	config.mode = MODE_CPU;

	init_render(&config);
	show_render();
}

void on_exitBtn_clicked()
{
	gtk_main_quit();
}