-
Notifications
You must be signed in to change notification settings - Fork 0
/
Widget.cpp
118 lines (96 loc) · 2.48 KB
/
Widget.cpp
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
#include "Widget.hpp"
#include "Application.hpp"
#include "graphics.hpp"
#include "Colors.hpp"
#include <iostream>
using namespace std;
using namespace genv;
/*** CONSTRUCTOR ***/
Widget::Widget(Application* ap, int x, int y, int sx, int sy)
: AppPointer(ap), coord_x(x), coord_y(y), size_x(sx), size_y(sy)
{
}
/*** FUNCTIONS ***/
bool Widget::GetFocusable()
{
return focusable;
}
bool Widget::GetFocused()
{
return focused;
}
void Widget::DrawFocused()
{
SetColor("focus");
for (int i=-1; i<size_x+2; i++)
{
if(i%2 == 0)
{
gout << move_to(coord_x + i, coord_y-2) << dot;
gout << move_to(coord_x + i, coord_y + size_y + 1) << dot;
}
}
for (int i=-1; i<size_y+2; i++)
{
if(i%2 == 0)
{
gout << move_to(coord_x - 2, coord_y + i) << dot;
gout << move_to(coord_x + size_x + 1, coord_y + i) << dot;
}
}
}
void Widget::SetFocusOn()
{
focused = true;
}
void Widget::SetFocusOff()
{
focused = false;
}
bool Widget::GetOnMe(int x, int y)
{
if (x >= coord_x && x < coord_x + size_x && y >= coord_y && y < coord_y+size_y) return true;
else return false;
}
/*** GRAPHICS FUNCTIONS ***/
void Widget::DrawBorder()
{
gout
<< move_to (coord_x, coord_y)
<< line(size_x, 0)
<< line(0, size_y)
<< line(-size_x, 0)
<< line(0, -size_y);
}
void Widget::SetColor(string ColorName)
{
string color_s;
if(ColorName == "bg") gout << color(BgColorR, BgColorG, BgColorB);
else if(ColorName == "border") gout << color(BorderColorR, BorderColorG, BorderColorB);
else if(ColorName == "focus") gout << color(FocusColorR, FocusColorG, FocusColorB);
else if(ColorName == "text1") gout << color(Text1ColorR, Text1ColorG, Text1ColorB);
else if(ColorName == "text2") gout << color(Text2ColorR, Text2ColorG, Text2ColorB);
else gout << color(255,255,255);
}
void Widget::WriteTextAlignLeft(string value)
{
gout
<< move_to(coord_x + 1, coord_y+(size_y/2)+ gout.cdescent())
<< text(value);
}
void Widget::WriteTextAlignRight(string value)
{
gout
<< move_to(coord_x + size_x - gout.twidth(value), coord_y+(size_y/2)+ gout.cdescent())
<< text(value);
}
void Widget::WriteTextAlignCenter(string value)
{
gout
<< move_to(coord_x + (size_x -gout.twidth(value))/2, coord_y+(size_y/2)+ gout.cdescent())
<< text(value);
}
void Widget::Load(Application* ap)
{
ap->LoadWidget(this);
}