forked from georgiavachon/EC327-SmartList
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEC327-SmartList.cpp
More file actions
911 lines (798 loc) · 31.3 KB
/
Copy pathEC327-SmartList.cpp
File metadata and controls
911 lines (798 loc) · 31.3 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
// Copyright Dasha Smolina 2021 dsmolina@bu.edu
// Copyright Megan Freeman 2021 megfree@bu.edu
// Copyright Ayrton Reulet 2021 reulayrt@bu.edu
// Copyright Georgia Vachon gvachon@bu.edu
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "Algorithm.h"
using std::vector;
using std::cin;
using std::cout;
using std::atoi;
using std::string;
using std::to_string;
int main() {
// creating window
sf::RenderWindow window(sf::VideoMode(1500, 1000), "SmartList");
window.setFramerateLimit(10);
// setting view to scale for DPI
sf::View view(sf::FloatRect(0, 0, 1500, 1000));
view.setViewport(sf::FloatRect(0.f, 0.f, 1.f, 1.f));
window.setView(view);
// creating app elements
sf::RectangleShape background;
background.setSize(sf::Vector2f(1500, 1000));
background.setFillColor(sf::Color::White);
sf::RectangleShape topbanner;
topbanner.setSize(sf::Vector2f(1500, 60));
topbanner.setFillColor(sf::Color(102, 178, 255, 255));
sf::RectangleShape hidescroll;
hidescroll.setSize(sf::Vector2f(1500, 300));
hidescroll.setFillColor(sf::Color::White);
sf::RectangleShape hidescroll2;
hidescroll2.setSize(sf::Vector2f(1500, 110));
hidescroll2.setFillColor(sf::Color::White);
hidescroll2.setPosition(0, 890);
sf::RectangleShape datebox;
datebox.setSize(sf::Vector2f(300, 30));
datebox.setOutlineColor(sf::Color::Black);
datebox.setFillColor(sf::Color(246, 246, 246, 255));
sf::RectangleShape taskbox;
taskbox.setSize(sf::Vector2f(300, 30));
taskbox.setOutlineColor(sf::Color::Black);
taskbox.setFillColor(sf::Color(246, 246, 246, 255));
sf::RectangleShape rankbox;
rankbox.setSize(sf::Vector2f(300, 30));
rankbox.setOutlineColor(sf::Color::Black);
rankbox.setFillColor(sf::Color(246, 246, 246, 255));
sf::RectangleShape add;
add.setSize(sf::Vector2f(150, 50));
add.setOutlineColor(sf::Color::Black);
add.setFillColor(sf::Color(102, 178, 255, 255));
sf::RectangleShape deletebutton;
deletebutton.setSize(sf::Vector2f(250, 50));
deletebutton.setOutlineColor(sf::Color::Black);
deletebutton.setFillColor(sf::Color(102, 178, 255, 255));
sf::RectangleShape clearbutton;
clearbutton.setSize(sf::Vector2f(150, 50));
clearbutton.setOutlineColor(sf::Color::Black);
clearbutton.setFillColor(sf::Color(102, 178, 255, 255));
sf::RectangleShape genbutton;
genbutton.setSize(sf::Vector2f(350, 50));
genbutton.setOutlineColor(sf::Color::Black);
genbutton.setFillColor(sf::Color(102, 178, 255, 255));
// creating string and displayed text objects
sf::Font font;
font.loadFromFile("/usr/share/fonts/truetype/ubuntu/Ubuntu-BI.ttf");
sf::Text bannertxt("SmartList", font);
bannertxt.setCharacterSize(50);
bannertxt.setStyle(sf::Text::Bold);
bannertxt.setFillColor(sf::Color::White);
// Date field
sf::Text datetitle("Due Date (mm/dd)", font);
datetitle.setCharacterSize(25);
datetitle.setFillColor(sf::Color::Black);
sf::String userdInput;
sf::Text userdText("", font, 25);
// Task field
sf::Text tasktitle("Task", font);
tasktitle.setCharacterSize(25);
tasktitle.setFillColor(sf::Color::Black);
sf::String usertInput;
sf::Text usertText("", font, 25);
// Rank field
sf::Text ranktitle("Priority: 1 (low) - 10 (high)", font);
ranktitle.setCharacterSize(25);
ranktitle.setFillColor(sf::Color::Black);
sf::String userrInput;
sf::Text userrText("", font, 25);
// Add button text
sf::Text addtext("ADD", font);
addtext.setCharacterSize(30);
addtext.setFillColor(sf::Color::White);
// Tasks header
sf::Text tasksheader("Tasks:", font);
tasksheader.setCharacterSize(30);
tasksheader.setFillColor(sf::Color::Black);
// Delete last entry button text
sf::Text deletelast("Delete Last Item", font);
deletelast.setCharacterSize(30);
deletelast.setFillColor(sf::Color::White);
// Clear All button text
sf::Text clearall("Clear All", font);
clearall.setCharacterSize(30);
clearall.setFillColor(sf::Color::White);
// Generate my list button text
sf::Text genlist("Generate my SmartList", font);
genlist.setCharacterSize(30);
genlist.setFillColor(sf::Color::White);
// creating app elements
sf::RectangleShape background2;
background2.setSize(sf::Vector2f(1500, 1000));
background2.setFillColor(sf::Color::White);
sf::RectangleShape topbanner2;
topbanner2.setSize(sf::Vector2f(1500, 60));
topbanner2.setFillColor(sf::Color(102, 178, 255, 255));
sf::RectangleShape clickbox;
clickbox.setSize(sf::Vector2f(1400, 60));
clickbox.setFillColor(sf::Color::White);
sf::RectangleShape checkbox;
checkbox.setSize(sf::Vector2f(50, 50));
checkbox.setOutlineColor(sf::Color::Black);
checkbox.setFillColor(sf::Color(sf::Color(246, 246, 246, 255)));
sf::RectangleShape hidescroll3;
hidescroll3.setSize(sf::Vector2f(1500, 300));
hidescroll3.setFillColor(sf::Color::White);
hidescroll3.setPosition(0, 0);
sf::RectangleShape hidescroll4;
hidescroll4.setSize(sf::Vector2f(1500, 50));
hidescroll4.setFillColor(sf::Color::White);
hidescroll4.setPosition(0, 950);
// add text
sf::Text bannertxt2("Your SmartList", font);
bannertxt2.setCharacterSize(50);
bannertxt2.setStyle(sf::Text::Bold);
bannertxt2.setFillColor(sf::Color::White);
// date header
sf::Text datetitle2("Due Date (mm/dd)", font);
datetitle2.setCharacterSize(30);
datetitle2.setFillColor(sf::Color::Black);
// Task header
sf::Text tasktitle2("Task", font);
tasktitle2.setCharacterSize(30);
tasktitle2.setFillColor(sf::Color::Black);
// Completed header
sf::Text donetitle("Complete", font);
donetitle.setCharacterSize(30);
donetitle.setFillColor(sf::Color::Black);
// Instructions list
sf::Text instruct("Click on your task to mark as complete", font);
instruct.setCharacterSize(25);
instruct.setFillColor(sf::Color(54, 120, 231, 255));
// Tasks list
sf::Text tasksheader2("Tasks (in order of priority):", font);
tasksheader2.setCharacterSize(35);
tasksheader2.setFillColor(sf::Color::Black);
// Dates output
sf::Text dated("", font);
dated.setCharacterSize(25);
dated.setFillColor(sf::Color::Black);
// Text output
sf::Text tasked("", font);
tasked.setCharacterSize(25);
tasked.setFillColor(sf::Color::Black);
// Completed output
sf::Text complete("", font);
complete.setCharacterSize(25);
complete.setFillColor(sf::Color(45, 216, 17, 255));
window.display();
// creating blinking cursor
sf::Text cursor("|", font, 25);
cursor.setFillColor(sf::Color::Black);
bool Shown = false;
const int blinkFreq = 10;
int blinkCnt = 0;
bool showcurs = false;
// booleans to tell whether date, task, or rank box have been clicked
bool dateentry = false;
bool taskentry = false;
bool rankentry = false;
// initialzing running display strings
string date_disp = "";
string task_disp = "";
string rank_disp = "";
// creating text that will display user's added input
sf::Text dates("", font);
dates.setCharacterSize(25);
dates.setFillColor(sf::Color::Black);
sf::Text tasks("", font);
tasks.setCharacterSize(25);
tasks.setFillColor(sf::Color::Black);
sf::Text ranks("", font);
ranks.setCharacterSize(25);
ranks.setFillColor(sf::Color::Black);
// initializing vector of vector of strings that will store
// all valid user inputs and will be used when generate
// button is pressed
vector<vector<string>> allinput;
// initializing vector of vector of strings that will store
// tasks marked as completed in window2
vector<vector<string>> done;
// done = {{"06/10", "hello"}, {"04/23", "hey"}};
// second window launched by generate my list button
sf::RenderWindow window2;
// setting initial positions of some elements
tasksheader.setPosition(80, 200);
dates.setPosition(80, 250);
tasks.setPosition(460, 250);
ranks.setPosition(840, 250);
while (window.isOpen() || window2.isOpen()) {
if (window2.isOpen()) {
sf::Event event2;
while (window2.pollEvent(event2)) {
// when window2 is closed, completed tasks are removed from
// vector allinputs and from displayed tasks in window
if (event2.type == sf::Event::Closed)
window2.close();
// creating SmartList Interface elements
sf::RectangleShape background2;
background2.setSize(sf::Vector2f(1500, 1000));
background2.setFillColor(sf::Color::White);
sf::RectangleShape topbanner2;
topbanner2.setSize(sf::Vector2f(1500, 60));
topbanner2.setFillColor(sf::Color(102, 178, 255, 255));
sf::RectangleShape clickbox;
clickbox.setSize(sf::Vector2f(1400, 60));
clickbox.setFillColor(sf::Color::White);
sf::RectangleShape checkbox;
checkbox.setSize(sf::Vector2f(50, 50));
checkbox.setOutlineColor(sf::Color::Black);
checkbox.setFillColor(sf::Color(sf::Color(246, 246, 246, 255)));
sf::RectangleShape hidescroll3;
hidescroll3.setSize(sf::Vector2f(1500, 300));
hidescroll3.setFillColor(sf::Color::White);
hidescroll3.setPosition(0, 0);
sf::RectangleShape hidescroll4;
hidescroll4.setSize(sf::Vector2f(1500, 50));
hidescroll4.setFillColor(sf::Color::White);
hidescroll4.setPosition(0, 950);
// add text
sf::Text bannertxt2("Your SmartList", font);
bannertxt2.setCharacterSize(50);
bannertxt2.setStyle(sf::Text::Bold);
bannertxt2.setFillColor(sf::Color::White);
// date header
sf::Text datetitle2("Due Date (mm/dd)", font);
datetitle2.setCharacterSize(30);
datetitle2.setFillColor(sf::Color::Black);
// Task header
sf::Text tasktitle2("Task", font);
tasktitle2.setCharacterSize(30);
tasktitle2.setFillColor(sf::Color::Black);
// Completed header
sf::Text donetitle("Complete", font);
donetitle.setCharacterSize(30);
donetitle.setFillColor(sf::Color::Black);
// Instructions list
sf::Text instruct("Click on your task to mark as complete", font);
instruct.setCharacterSize(25);
instruct.setFillColor(sf::Color(54, 120, 231, 255));
// Tasks list
sf::Text tasksheader2("Tasks (in order of priority):", font);
tasksheader2.setCharacterSize(35);
tasksheader2.setFillColor(sf::Color::Black);
// Dates output
sf::Text dated("", font);
dated.setCharacterSize(25);
dated.setFillColor(sf::Color::Black);
// Text output
sf::Text tasked("", font);
tasked.setCharacterSize(25);
tasked.setFillColor(sf::Color::Black);
// Completed output
sf::Text complete("", font);
complete.setCharacterSize(25);
complete.setFillColor(sf::Color(45, 216, 17, 255));
// Declaring input/output
string compl_display = "";
// Initialize our output variable, the variable that is displayed
// on our SmartList interface
vector<vector<string>> output;
vector<vector<string>> SmartList;
// running our algorithm
if (allinput.size() != 0) {
SmartList = algorithm(allinput);
for (int i = 0; i < SmartList.size(); i++) {
output.push_back({SmartList.at(i).at(0), SmartList.at(i).at(1)});
}
} else {
output.push_back({"00/00", "No task entered"});
}
int numtask = output.size();
string date_display = "";
string task_display = "";
string temp = "";
for (int i = 0; i < output.size(); i++) {
date_display = date_display + "\n\n" + output.at(i).at(0);
task_display = task_display + "\n\n" + output.at(i).at(1);
compl_display = compl_display + "\n\n ";
}
dated.setPosition(80, 250);
tasked.setPosition(460, 250);
complete.setPosition(900, 250);
clickbox.setPosition(40, 280);
// Window is open
while (window2.isOpen()) {
sf::Event event2;
while (window2.pollEvent(event2)) {
if (event2.type == sf::Event::Closed) {
window2.close();
vector<vector<string>> fixedinput;
for (auto a : allinput) {
bool keep = true;
for (auto d : done) {
if (a.at(0) == d.at(0) && a.at(1) == d.at(1))
keep = false;
}
if (keep)
fixedinput.push_back(a);
}
if (done.size() == 0)
fixedinput = allinput;
allinput = fixedinput;
for (auto d : done) {
string thisdate = d.at(0);
string thistask = d.at(1);
bool rm = false;
int b = 0;
for (int i = 0; i < date_disp.length(); i = i + 7) {
b++;
if (date_disp.substr(i + 2, 5) == thisdate) {
// dates.setString(thisdate);
int lb = 0;
for (int j = 0; j < task_disp.length(); j++) {
if (task_disp.at(j) == '\n') lb++;
if (lb / 2 == b && lb % 2 == 0) {
if (task_disp.substr(j + 1, \
thistask.length()) == thistask) {
date_disp = date_disp.substr(0, i) + \
date_disp.substr(i + 7,
date_disp.length() - (i + 7));
task_disp = task_disp.substr(0, j - 1) + \
task_disp.substr(j + thistask.length() + 1\
, task_disp.length() - (j + 1 + \
thistask.length()));
dates.setString(date_disp);
tasks.setString(task_disp);
rm = true;
break;
}
}
}
if (rm) {
int lb = 0;
for (int j = 0; j < rank_disp.length(); j++) {
if (rank_disp.at(j) == '\n') lb++;
if (lb / 2 == b && lb % 2 == 0) {
string thisrank = rank_disp.substr(j + 1, 2);
int change = 2;
if (thisrank == "10") change += 1;
rank_disp = rank_disp.substr(0, j - 1) + \
rank_disp.substr(j + change, \
rank_disp.length() - (j + change));
ranks.setString(rank_disp);
break;
}
}
}
}
if (rm) break;
}
}
}
int lineh = tasked.getGlobalBounds().height;
// account for the tasks printing with \n\n before the first task
clickbox.setSize(sf::Vector2f(1400, lineh));
int clickpos;
int linesize = (lineh) / numtask;
// user clicked in box
auto mouse_pos = sf::Mouse::getPosition(window2);
auto translated_pos = window2.mapPixelToCoords(mouse_pos);
if (event2.type == sf::Event::MouseButtonPressed) {
if (clickbox.getGlobalBounds().contains(translated_pos)) {
clickpos = translated_pos.y - clickbox.getPosition().y;
// normalize position to box coordinates
clickpos = clickpos / linesize;
char wait = compl_display.at(((clickpos + 1) * 3) - 1);
vector<string> checked;
checked.push_back(output.at(clickpos).at(0));
checked.push_back(output.at(clickpos).at(1));
if (wait == ' ') {
compl_display.at(((clickpos + 1) * 3) - 1) = 'x';
// add to output
done.push_back(checked);
} else if (wait == 'x') {
compl_display.at(((clickpos + 1) * 3) - 1) = ' ';
auto pos = find(done.begin(), done.end(), checked);
done.erase(pos);
}
complete.setString(compl_display);
}
}
if (event2.type == sf::Event::MouseWheelScrolled) {
// allow scrolling if displayed input long enough
int scrolled = event2.mouseWheelScroll.delta;
int datey = dated.getPosition().y;
int dateh = dated.getLocalBounds().height;
int tasky = tasked.getPosition().y;
int compy = complete.getPosition().y;
int boxy = clickbox.getPosition().y;
if (dateh > 600) {
if (scrolled < 0) {
if (dateh + datey >= 900) {
dated.setPosition(80, datey + 10 * scrolled);
tasked.setPosition(460, tasky + 10 * scrolled);
complete.setPosition(900, compy + 10 * scrolled);
clickbox.setPosition(40, boxy + 10 * scrolled);
}
} else if (scrolled > 0) {
if (datey <= 251) {
dated.setPosition(80, datey + 10 * scrolled);
tasked.setPosition(460, tasky + 10 * scrolled);
complete.setPosition(900, compy + 10 * scrolled);
clickbox.setPosition(40, boxy + 10 * scrolled);
}
}
}
}
}
// setting positions of title elements
topbanner2.setPosition(0, 0);
datetitle2.setPosition(80, 250);
tasktitle2.setPosition(460, 250);
donetitle.setPosition(840, 250);
tasksheader2.setPosition(80, 100);
instruct.setPosition(80, 180);
// setting positions of output
dated.setString(date_display);
tasked.setString(task_display);
complete.setString(compl_display);
// dated.setPosition(80, 250);
// tasked.setPosition(460, 250);
// complete.setPosition(900, 250);
// creating clickable box for check marks
window2.draw(background2);
window2.draw(clickbox);
window2.draw(dated);
window2.draw(tasked);
window2.draw(complete);
window2.draw(hidescroll3);
window2.draw(hidescroll4);
window2.draw(topbanner2);
window2.draw(bannertxt2);
window2.draw(instruct);
window2.draw(donetitle);
window2.draw(tasksheader2);
window2.draw(datetitle2);
window2.draw(tasktitle2);
window2.display();
window2.clear();
}
}
}
// setting button fill color in the loop so that it can briefly change
// to darker and back when a user clicks a button
add.setFillColor(sf::Color(102, 178, 255, 255));
deletebutton.setFillColor(sf::Color(102, 178, 255, 255));
clearbutton.setFillColor(sf::Color(102, 178, 255, 255));
genbutton.setFillColor(sf::Color(102, 178, 255, 255));
// finding size of user input to check for valid input
int datelength = userdInput.getSize();
int tasklength = usertInput.getSize();
int ranklength = userrInput.getSize();
bool valid = false;
// setting proper position of blinking cursor if textbox is hot
if (dateentry == true)
cursor.setPosition(85 + userdText.getLocalBounds().width, 125);
if (taskentry == true)
cursor.setPosition(465 + usertText.getLocalBounds().width, 125);
if (rankentry == true)
cursor.setPosition(845 + userrText.getLocalBounds().width, 125);
if (dateentry == false && taskentry\
== false && rankentry == false)
showcurs = false;
else
showcurs = true;
// setting blink rate of cursor
if (++blinkCnt >= blinkFreq) {
Shown = !Shown;
blinkCnt = 0;
}
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
// getting coordinates of mouse to check where user clicks
auto mouse_pos = sf::Mouse::getPosition(window);
auto translated_pos = window.mapPixelToCoords(mouse_pos);
if (event.type == sf::Event::MouseButtonPressed) {
if (datebox.getGlobalBounds().contains(translated_pos)) {
// clicked in datebox
userdText.setFillColor(sf::Color::Black);
dateentry = true;
taskentry = false;
rankentry = false;
} else if (taskbox.getGlobalBounds().contains(translated_pos)) {
// clicked in taskbox
dateentry = false;
taskentry = true;
rankentry = false;
} else if (rankbox.getGlobalBounds().contains(translated_pos)) {
// clicked in rankbox
dateentry = false;
taskentry = false;
rankentry = true;
} else if (add.getGlobalBounds().contains(translated_pos)) {
// clicked add button
add.setFillColor(sf::Color(92, 158, 225, 255));
// only add if input is valid
if (datelength == 5 && tasklength > 0 && ranklength > 0) {
// cursor not blinking anymore
dateentry = false;
taskentry = false;
rankentry = false;
// checking validity of date
string smonth = userdInput.substring(0, 2);
string sday = userdInput.substring(3, 2);
int month = stoi(smonth);
int day = stoi(sday);
if (month > 0 && month < 13) {
if (month == 9 || month == 4 || month == 6 || month == 11) {
if (day > 0 && day <= 30) valid = true;
} else if (month == 2) {
if (day > 0 && day <= 29) valid = true;
} else if (day > 0 && day <= 31) {
valid = true;
}
}
if (valid) {
// add new entry to display and vector and delete text from fields
date_disp = date_disp + "\n\n" + userdInput;
task_disp = task_disp + "\n\n" + usertInput;
rank_disp = rank_disp + "\n\n" + userrInput;
vector<string> input;
input.push_back(userdInput);
input.push_back(usertInput);
input.push_back(userrInput);
allinput.push_back(input);
dates.setString(date_disp);
tasks.setString(task_disp);
ranks.setString(rank_disp);
userdText.setString("");
usertText.setString("");
userrText.setString("");
userdInput.clear();
usertInput.clear();
userrInput.clear();
} else {
// if date invalid
userdText.setFillColor(sf::Color::Red);
}
}
} else if (deletebutton.getGlobalBounds().contains(translated_pos)) {
// delete button clicked
deletebutton.setFillColor(sf::Color(92, 158, 225, 255));
if (allinput.size()>0){
allinput.pop_back();
char check = ' ';
int j;
for (j = date_disp.length() - 1; j >= 0 ; j--) {
check = date_disp.at(j);
if (check == '\n') {
break;
}
}
date_disp = date_disp.substr(0, j + 1);
dates.setString(date_disp);
date_disp = date_disp.substr(0, j - 1);
for (j = task_disp.length() - 1; j >= 0 ; j--) {
check = task_disp.at(j);
if (check == '\n') {
break;
}
}
task_disp = task_disp.substr(0, j + 1);
tasks.setString(task_disp);
task_disp = task_disp.substr(0, j - 1);
for (j = rank_disp.length() - 1; j >= 0 ; j--) {
check = rank_disp.at(j);
if (check == '\n') {
break;
}
}
rank_disp = rank_disp.substr(0, j + 1);
ranks.setString(rank_disp);
rank_disp = rank_disp.substr(0, j - 1);
}
} else if (clearbutton.getGlobalBounds().contains(translated_pos)) {
// clear all button clicked
clearbutton.setFillColor(sf::Color(92, 158, 225, 255));
date_disp = "";
task_disp = "";
rank_disp = "";
dates.setString(date_disp);
tasks.setString(task_disp);
ranks.setString(rank_disp);
allinput = {};
} else if (genbutton.getGlobalBounds().contains(translated_pos)) {
// generate button clicked: open window2
genbutton.setFillColor(sf::Color(92, 158, 225, 255));
if(allinput.size()>0){
window2.create(sf::VideoMode(1000, 1000), "Your SmartList");
window2.setFramerateLimit(10);
window2.setView(view);
window2.display();
}
}
}
if (event.type == sf::Event::TextEntered) {
if (event.text.unicode == 13 && datelength == 5 && \
tasklength > 0 && ranklength > 0) {
// enter key pressed (check validity of input)
string smonth = userdInput.substring(0, 2);
string sday = userdInput.substring(3, 2);
int month = stoi(smonth);
int day = stoi(sday);
if (month > 0 && month < 13) {
if (month == 9 || month == 4 || month == 6 || month == 11) {
if (day > 0 && day <= 30) valid = true;
} else if (month == 2) {
if (day > 0 && day <= 29) valid = true;
} else if (day > 0 && day <= 31) {
valid = true;
}
}
if (valid) {
// cursor not blinking anymore
dateentry = false;
taskentry = false;
rankentry = false;
// add new entry and delete text from fields
date_disp = date_disp + "\n\n" + userdInput;
task_disp = task_disp + "\n\n" + usertInput;
rank_disp = rank_disp + "\n\n" + userrInput;
vector<string> input;
input.push_back(userdInput);
input.push_back(usertInput);
input.push_back(userrInput);
allinput.push_back(input);
dates.setString(date_disp);
tasks.setString(task_disp);
ranks.setString(rank_disp);
userdText.setString("");
usertText.setString("");
userrText.setString("");
userdInput.clear();
usertInput.clear();
userrInput.clear();
} else {
// invalid date
userdText.setFillColor(sf::Color::Red);
}
}
if (dateentry == true) {
// user typing in date box (can only type ##/##)
if (event.text.unicode == '\b' && datelength > 0) {
userdInput.erase(datelength - 1, 1);
} else if (event.text.unicode == 9) {
dateentry = false;
taskentry = true;
break;
} else if (event.text.unicode < 128 && datelength < 5) {
if (datelength == 2 && event.text.unicode == 47)
userdInput += event.text.unicode;
else if (datelength != 2 && event.text.unicode >= 48\
&& event.text.unicode <= 57)
userdInput += event.text.unicode;
}
userdText.setString(userdInput);
userdText.setCharacterSize(25);
userdText.setFillColor(sf::Color::Black);
userdText.setPosition(85, 125);
} else if (taskentry == true) {
// user typing in task box
if (event.text.unicode == '\b' && tasklength > 0) {
usertInput.erase(tasklength - 1, 1);
} else if (event.text.unicode == 9) {
taskentry = false;
rankentry = true;
break;
} else if (event.text.unicode < 128 && \
usertText.getLocalBounds().width < \
taskbox.getLocalBounds().width - 12) {
usertInput += event.text.unicode;
}
usertText.setString(usertInput);
usertText.setCharacterSize(25);
usertText.setFillColor(sf::Color::Black);
usertText.setPosition(465, 125);
} else if (rankentry == true) {
// user typing in rank box (only 1-10)
if (event.text.unicode == '\b' && ranklength > 0) {
userrInput.erase(ranklength - 1, 1);
} else if (event.text.unicode == 9) {
dateentry = true;
rankentry = false;
break;
} else if (event.text.unicode < 58 && \
event.text.unicode > 47 && ranklength < 2) {
if (ranklength == 0 && event.text.unicode != '0')
userrInput += event.text.unicode;
else if (userrInput == "1" && event.text.unicode == '0')
userrInput += event.text.unicode;
}
userrText.setString(userrInput);
userrText.setCharacterSize(25);
userrText.setFillColor(sf::Color::Black);
userrText.setPosition(845, 125);
}
}
if (event.type == sf::Event::MouseWheelScrolled) {
// allow scrolling if displayed input long enough
int scrolled = event.mouseWheelScroll.delta;
int datey = dates.getPosition().y;
int dateh = dates.getLocalBounds().height;
int tasky = tasks.getPosition().y;
int ranky = ranks.getPosition().y;
if (dateh > 600) {
if (scrolled < 0) {
if (dateh + datey >= 850) {
dates.setPosition(80, datey + 10 * scrolled);
tasks.setPosition(460, tasky + 10 * scrolled);
ranks.setPosition(840, ranky + 10 * scrolled);
}
} else if (scrolled > 0) {
if (datey <= 250) {
dates.setPosition(80, datey + 10 * scrolled);
tasks.setPosition(460, tasky + 10 * scrolled);
ranks.setPosition(840, ranky + 10 * scrolled);
}
}
}
}
}
// setting positions of elements
topbanner.setPosition(0, 0);
datebox.setPosition(80, 128);
datetitle.setPosition(80, 100);
taskbox.setPosition(460, 128);
tasktitle.setPosition(460, 100);
rankbox.setPosition(840, 128);
ranktitle.setPosition(840, 100);
add.setPosition(1200, 115);
addtext.setPosition(1240, 120);
deletebutton.setPosition(550, 900);
deletelast.setPosition(560, 905);
clearbutton.setPosition(850, 900);
clearall.setPosition(860, 905);
genbutton.setPosition(1060, 900);
genlist.setPosition(1070, 905);
// draw and display elements in window
window.draw(background);
window.draw(dates);
window.draw(tasks);
window.draw(ranks);
window.draw(hidescroll);
window.draw(hidescroll2);
window.draw(topbanner);
window.draw(bannertxt);
window.draw(datebox);
window.draw(datetitle);
window.draw(userdText);
window.draw(taskbox);
window.draw(tasktitle);
window.draw(usertText);
window.draw(rankbox);
window.draw(ranktitle);
window.draw(userrText);
if (Shown && showcurs == true)
window.draw(cursor);
window.draw(add);
window.draw(addtext);
window.draw(tasksheader);
window.draw(deletebutton);
window.draw(deletelast);
window.draw(clearbutton);
window.draw(clearall);
window.draw(genbutton);
window.draw(genlist);
window.display();
window.clear();
}
return 0;
}