-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.cpp
More file actions
285 lines (229 loc) · 9.5 KB
/
window.cpp
File metadata and controls
285 lines (229 loc) · 9.5 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
Developed by: Francisco Passos | Frank Steps
Developed in: 25/09/2025
Modifield in: 24/12/2025
[PT-BR]
Este programa é um teste de capacidade dso uso de C++ e raylib. Com exceção das fontes,
este projeto é 100% autoral. A interface apenas foi inspirada no visual antigo do windows.
O projeto consiste em uma calculadora simples que realiza operações básicas
[EN-US]
This program is a capacity test for using C++ and Raylib. This project is 100% original.
The interface was inspired by the old Windows visual style and consists of a simple
calculator that performs basic operations.
*/
// --------------------------------- libraries ---------------------------------
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <unistd.h>
namespace ray {
#include <raylib.h>
}
// --------------------------------- visuals ---------------------------------
const int num_row = 4;
const int num_col = 4;
const int num_buttons = num_row * num_col;
std::vector<ray::Rectangle> controlButton(3);
std::vector<ray::Rectangle> bnt_up(4);
std::vector<ray::Rectangle> bnt_sh(4);
std::vector<ray::Rectangle> bnt_br(4);
std::vector<ray::Rectangle> button(num_buttons);
std::vector<ray::Rectangle> shadow(num_buttons);
std::vector<ray::Rectangle> bright(num_buttons);
ray::Vector2 pos_textButtons[num_buttons + 7] = {
{10,7},{70,7},{150,7},
{31,45},{173,45},{246,45},
{36,162},{110,162},{183,162},{258,162},
{36,230},{110,230},{183,230},{258,234},
{36,295},{110,295},{183,295},{260,296},
{36,360},{144,360},{144,360},{256,360},
{14,424}
};
std::string textButtons[num_buttons + 6] = {
"Main", "Settings", "About",
"---->", "Copy", "Clear",
"7", "8", "9", "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"0", "=", "=", "+"
};
// define colors
ray::Color background = {224, 224, 224, 255};
ray::Color background_Alt = {240, 240, 240, 255};
ray::Color border_c = {0, 0, 0, 155};
ray::Color shadow_c = {148, 148, 148, 70};
ray::Color bright_c = ray::WHITE;
ray::Color inactive = {0, 0, 0, 70};
ray::Color active = ray::BLACK;
ray::Color translucid = {0, 0, 0, 0};
// --------------------------------- state buttons ---------------------------------
enum class ButtonState {
Disabled,
Enabled,
};
std::vector<ButtonState> buttonState = {
ButtonState::Disabled,
ButtonState::Disabled,
ButtonState::Enabled
};
ray::Color returnColor(ButtonState state){
return (state == ButtonState::Enabled)? active : inactive;
}
// --------------------------------- error ---------------------------------
enum class Messenger {
Void, Inactive, Copied, Cleared, Div
};
std::string messenger(Messenger message){
switch(message){
case Messenger::Void: return " ";
case Messenger::Inactive: return "Error or inactive";
case Messenger::Copied: return "Copied!";
case Messenger::Cleared: return "Cleared!";
case Messenger::Div: return "Infinity!";
}
return "Unknown error";
}
// --------------------------------- main function ---------------------------------
int main() {
ray::InitWindow(310, 450, "Neon Calculator");
std::string messengerText = messenger(Messenger::Void);
float timer = 0.0f;
// icon
ray::Image icon = ray::LoadImage("images/neon.png");
ray::SetWindowIcon(icon);
// fonts
ray::Font ms_sans = ray::LoadFont("fonts/ms-sans-serif.otf");
ray::Font tahoma = ray::LoadFont("fonts/tahomabd.ttf");
// menu bar
ray::Rectangle menuBar = {0, 0, 310, 30};
//visor
ray::Rectangle visor = {10, 80, 290, 60};
// control buttons generator
for(int i = 0; i < 3; i++){
controlButton[i] = {10.0f + i*(68+6), 0, 50, 20};
}
// command buttons generator
for(int i = 0; i < 4; i++){
bnt_up[i] = {10.0f + i*(68+6), 40, 68, 30};
bnt_sh[i] = {10.0f + i*(68+6), 40 + 26, 68, 4};
bnt_br[i] = {10.0f + i*(68+6), 40, 68, 4};
}
bnt_up.erase(bnt_up.begin() + 1);
bnt_sh.erase(bnt_sh.begin() + 1);
bnt_br.erase(bnt_br.begin() + 1);
// number buttons and operation buttons generator
int vector_i = 0;
float actual_row = 150.0f;
for(int i = 0; i < num_row; i++){
for(int j = 0; j < num_col; j++){
button[vector_i] = {10.0f + j*(68+6), actual_row, 68, 60};
shadow[vector_i] = {10.0f + j*(68+6), actual_row + 56, 68, 4};
bright[vector_i] = {10.0f + j*(68+6), actual_row, 68, 4};
vector_i++;
}
actual_row += 66.0f;
}
// jury-rig button :/ (Gambiarra) -> Junction
ray::Rectangle Jury_rig = {84, 348, 142, 60};
ray::Rectangle Jury_rig_sh = {84, 404, 142, 4};
ray::Rectangle Jury_rig_br = {84, 348, 142, 4};
//output
ray::Rectangle output = {10, 420, 290, 25};
ray::Rectangle output_sh = {10, 420, 290, 3};
ray::Vector2 pos_button = {0.0f, 0.0f};
while (!ray::WindowShouldClose()) {
ray::Vector2 mousepos = ray::GetMousePosition();
timer += ray::GetFrameTime();
ray::BeginDrawing();
ray::ClearBackground(background);
// menu bar interface
ray::DrawRectangleRec(menuBar, background_Alt);
// render command buttons
for(int i = 0; i < 3; i++){
ray::DrawRectangleRec(bnt_up[i], background_Alt);
ray::DrawRectangleRec(bnt_sh[i], shadow_c);
ray::DrawRectangleRec(bnt_br[i], bright_c);
ray::DrawRectangleLinesEx(bnt_up[i], 1, border_c);
// colision to commands buttons
if (ray::CheckCollisionPointRec(mousepos, bnt_up[i]) && ray::IsMouseButtonPressed(ray::MOUSE_BUTTON_LEFT)){
std::cout << "Command button pressed: " << textButtons[i + 3] << std::endl;
if(textButtons[i + 3] == "Copy"){
ray::SetClipboardText("I love you, my Frank <3"); // bruh haha. Send it to me: franksteps.contato@gmail.com
messengerText = messenger(Messenger::Copied);
}else if(textButtons[i + 3] == "Clear"){
messengerText = messenger(Messenger::Cleared);
} else {
// nothing yet...
}
}
}
// visor
ray::DrawRectangleRec(visor, ray::WHITE);
ray::DrawRectangleLinesEx(visor, 1, border_c);
// render arithmetic buttons
for(int i = 0; i < num_buttons; i++){
ray::DrawRectangleRec(button[i], background_Alt);
ray::DrawRectangleRec(shadow[i], shadow_c);
ray::DrawRectangleRec(bright[i], bright_c);
ray::DrawRectangleLinesEx(button[i], 1, border_c);
// colision to arithmetic buttons -> logic to calculator here
if (ray::CheckCollisionPointRec(mousepos, button[i]) && ray::IsMouseButtonPressed(ray::MOUSE_BUTTON_LEFT)){
std::cout << "Arithmetic button pressed: " << textButtons[i+6] << std::endl;
// here
}
}
// junction
ray::DrawRectangleRec(Jury_rig, background_Alt);
ray::DrawRectangleRec(Jury_rig_sh, shadow_c);
ray::DrawRectangleRec(Jury_rig_br, bright_c);
ray::DrawRectangleLinesEx(Jury_rig, 1, border_c);
// draw control buttons and command buttons text
for(int i = 0; i < 3; i++){
ray::DrawTextEx(ms_sans, textButtons[i].c_str(), pos_textButtons[i], 17, 1, returnColor(buttonState[i]));
ray::DrawTextEx(ms_sans, textButtons[i+3].c_str(), pos_textButtons[i+3], 17, 1, ray::BLACK);
}
// draw arithmetic buttons text
for(int i = 0; i < num_buttons; i++){
ray::DrawTextEx(tahoma, textButtons[i+6].c_str(), pos_textButtons[i+6], 32, 1, ray::BLACK);
}
// control buttons colision
for(int i = 0; i < 3; i++){
ray::DrawRectangleRec(controlButton[i], translucid);
if(ray::CheckCollisionPointRec(mousepos, controlButton[i]) && ray::IsMouseButtonPressed(ray::MOUSE_BUTTON_LEFT)){
bool buttonEnabled = buttonState[i] == ButtonState::Enabled;
if(textButtons[i] == "Main" && buttonEnabled){
messengerText = messenger(Messenger::Void);
//
} else if(textButtons[i] == "Settings" && buttonEnabled) {
messengerText = messenger(Messenger::Void);
//
} else if(textButtons[i] == "About" && buttonEnabled) {
// Opens the "About" window for Neon Calc
messengerText = messenger(Messenger::Void);
if (fork() == 0) {
execl("./about", "./about", nullptr); // a beautiful code...
}
} else {
messengerText = messenger(Messenger::Inactive);
}
}
}
// output
ray::DrawRectangleLinesEx(output, 1, border_c);
ray::DrawRectangleRec(output_sh, shadow_c);
ray::DrawTextEx(ms_sans, messengerText.c_str(), pos_textButtons[22], 17, 1, ray::RED);
// clear output message
if(timer >= 3.0f){
messengerText = messenger(Messenger::Void);
timer = 0.0f;
}
ray::EndDrawing();
}
// end
ray::UnloadImage(icon);
ray::UnloadFont(ms_sans);
ray::UnloadFont(tahoma);
ray::CloseWindow();
return EXIT_SUCCESS;
}