aboutsummaryrefslogtreecommitdiff
path: root/src/mandelbrot-zoom.c
blob: 53f22ebd5ac375c4c5de9a9842fc01eba1c7f9ba (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
/*
 * 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);
	builder = gtk_builder_new();
	gtk_builder_add_from_file (builder, "C:/Users/JanNiklas/Desktop/Git/Project/mandelbrot-zoom/glade/settings.glade", NULL); // gtk = zu behindert für relative pfade

	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.colorFromBtn = GTK_BUTTON(gtk_builder_get_object(builder, "colorFromBtn"));
	ui_settings.colorToBtn = GTK_BUTTON(gtk_builder_get_object(builder, "colorToBtn"));
	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.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.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.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.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.iterations = gtk_spin_button_get_value(ui_settings.iterationsSp);
}

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);
}

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

void on_fpsRenderSp_valueChanged()
{
	config.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()
{
	printf("config {\n\t.iterations = %u\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, config.video, 0, config.width, config.height, config.renderFPS, config.videoFPS, config.bitrate, config.path);
	render_init(&config, mandelbrot_r);
	render_show();
}

void on_exitBtn_clicked()
{
	gtk_main_quit();
}