-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFil4.cpp
More file actions
132 lines (66 loc) · 1.62 KB
/
Fil4.cpp
File metadata and controls
132 lines (66 loc) · 1.62 KB
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <SDL.h>
using namespace std;
const int WINDOW_WIDTH = 800;
const int WINDOW_HEIGHT = 600;
struct Point {
int x;
int y;
};
struct Line {
Point start;
Point end;
};
void render(SDL_Renderer* renderer) {
// Clear the screen
SDL_RenderClear(renderer);
// Draw the lines
for (Line line : lines) {
SDL_RenderDrawLine(renderer, line.start.x, line.start.y, line.end.x, line.end.y);
}
// Update the screen
SDL_RenderPresent(renderer);
}
void handle_events(SDL_Event* event) {
switch (event->type) {
case SDL_QUIT:
// Quit the application
cout << "Quitting..." << endl;
SDL_Quit();
exit(0);
break;
case SDL_MOUSEBUTTONDOWN:
// Add a new line to the list
Point point;
point.x = event->button.x;
point.y = event->button.y;
lines.push_back({point, point});
break;
}
}
int main() {
// Initialize SDL
SDL_Init(SDL_INIT_VIDEO);
// Create a window
SDL_Window* window = SDL_CreateWindow("Math Problem Solver", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN);
// Create a renderer
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
// Create a list of lines
vector<Line> lines;
// Start the event loop
while (true) {
// Handle events
SDL_Event event;
while (SDL_PollEvent(&event)) {
handle_events(&event);
}
// Render the lines
render(renderer);
}
// Quit SDL
SDL_Quit();
return 0;
}