summaryrefslogtreecommitdiff
path: root/MainWindow.h
blob: e99f7ce7f38da741b329ee9e49338311c1f569be (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
/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <fx.h>
#include <FXScrollArea.h>
#include <FXMessageBox.h>
#include <time.h>
#include <vector>
#include <algorithm>
#include <memory>
#include <string>
#include <fxkeys.h>
#include "Gate.h"
#include "icons.h"

class MainWindow : public FXMainWindow
{
	FXDECLARE(MainWindow)

	public:
		explicit MainWindow(FXApp* a);
		~MainWindow();
		virtual void create();

		/* Event system */
		// Messages for our class
		enum {
			ID_CANVAS       = FXMainWindow::ID_LAST,
			ID_BUTTON_INPUT,
			ID_BUTTON_OUTPUT,
			ID_BUTTON_AND,
			ID_BUTTON_OR,
			ID_BUTTON_NOT,
		};

		/* Event handlers */
		long on_paint(FXObject*,FXSelector,void* ptr);
		long on_left_mouse_down(FXObject*,FXSelector,void* ptr);
		long on_left_mouse_up(FXObject*,FXSelector,void* ptr);
		long on_right_mouse_down(FXObject*,FXSelector,void* ptr);
		long on_key_press(FXObject*,FXSelector,void* ptr);
		long on_key_release(FXObject*,FXSelector,void* ptr);
		long on_mouse_move(FXObject*,FXSelector,void* ptr);
		/* toolbox */
		long input_button_press(FXObject*,FXSelector,void* ptr);
		long output_button_press(FXObject*,FXSelector,void* ptr);
		long and_button_press(FXObject*,FXSelector,void* ptr);
		long or_button_press(FXObject*,FXSelector,void* ptr);
		long not_button_press(FXObject*,FXSelector,void* ptr);
		
		/* selected gate */
		Gate *selected_gate = nullptr;

		FXApp *get_app(){ return app; };


	protected:
		MainWindow(){}

	private:
		void create_ui();
		void draw();
		Gate *find_gate_at(int x, int y);
		Gate *find_gate_by_id(int id);

		FXHorizontalFrame *contents;
		FXVerticalFrame   *canvasFrame;
		FXVerticalFrame   *toolsFrame;
		FXScrollWindow 	*scroll_area;
		FXCanvas *canvas;
		FXBMPImage *canvas_image;
		FXApp *app;

		/* icons */
		FXGIFIcon *INPUT_icon;
		FXGIFIcon *OUTPUT_icon;
		FXGIFIcon *AND_icon;
		FXGIFIcon *OR_icon;
		FXGIFIcon *NOT_icon;

		/* buttons */
		FXButton *INPUT_button;
		FXButton *OUTPUT_button;
		FXButton *AND_button;
		FXButton *OR_button;
		FXButton *NOT_button;

		Gate::GATE_TYPE selected_gate_type = Gate::NONE; // the type of gate we will place

		/* mouse */
		bool lmouse_down = false;
		bool rmouse_down = false;
		bool dragging_link = false;
		int mouse_x;
		int mouse_y;

		/* keyboard */
		bool lshift_down = false;

		/* general */
		std::vector<std::unique_ptr<Gate>> gates;
};

#endif // MAINWINDOW_H