-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRayUtils.cpp
54 lines (52 loc) · 2.65 KB
/
RayUtils.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
#include "RayUtils.h"
#include <wx/hyperlink.h>
std::vector<std::string> RayUtils::split(const std::string& str, const std::string& delim) {
std::vector<std::string> tokens;
size_t prev = 0, pos = 0;
do {
pos = str.find(delim, prev);
if (pos == std::string::npos) pos = str.length();
std::string token = str.substr(prev, pos - prev);
if (!token.empty()) tokens.push_back(token);
prev = pos + delim.length();
} while (pos < str.length() && prev < str.length());
return tokens;
}
wxStaticText* RayUtils::CreateText(wxPanel* panel, int id, std::string text, wxPoint point, int textSize, bool bold) {
wxStaticText* textObj = new wxStaticText(panel, id, text, point, wxDefaultSize);
wxSize textObjWidth = GetTextSize(textObj, textSize, bold);
textObj->SetPosition(point);
return textObj;
}
wxStaticText* RayUtils::CreateCenteredText(wxPanel* panel, int id, std::string text, int y_height, int textSize, bool bold, RayUtils::Window window) {
int width = panel->GetMaxWidth();
wxStaticText* textObj = new wxStaticText(panel, id, text, wxDefaultPosition, wxDefaultSize);
wxSize textObjWidth = GetTextSize(textObj, textSize, bold);
textObj->SetPosition(wxPoint(((window == Window::ACCOUNTS ? 420 : window == Window::MAIN ? 560 : 0)/2) - ((textObjWidth.GetWidth()) / 2), y_height));
return textObj;
}
wxSize RayUtils::GetTextSize(wxStaticText* textObj, int size, bool bold) {
wxFont fontObj = wxFont(size, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_SEMIBOLD, false, "Burbank Big Rg Bd");
textObj->SetForegroundColour(wxColour(0xffffff));
textObj->SetFont(fontObj);
wxClientDC dc(textObj);
dc.SetFont(fontObj);
wxSize textObjWidth = dc.GetTextExtent(textObj->GetLabelText());
return textObjWidth;
}
wxSize RayUtils::GetTextSize(wxHyperlinkCtrl* textObj, int size, bool bold) {
wxSize textObjWidth = GetTextSize((wxStaticText*)textObj, size, bold);
return GetTextSize((wxStaticText*)textObj, size, bold);
}
wxHyperlinkCtrl* RayUtils::CreateHyperlink(wxPanel* panel, int id, wxString text, wxString link, wxPoint point, int textSize) {
wxHyperlinkCtrl* linkObj = new wxHyperlinkCtrl(panel, id, text, link, point, wxSize(20, 20));
linkObj->SetSize(GetTextSize(linkObj, textSize, false));
return linkObj;
}
wxHyperlinkCtrl* RayUtils::CreateCenteredLink(wxPanel* panel, int id, wxString text, wxString link, int y_height, int textSize) {
wxHyperlinkCtrl* linkObj = new wxHyperlinkCtrl(panel, id, text, link, wxPoint(0, y_height), wxSize(20, 20));
wxSize textObjWidth = GetTextSize(linkObj, textSize, false);
linkObj->SetPosition(wxPoint((420 / 2) - ((textObjWidth.GetWidth()) / 2), y_height));
linkObj->SetSize(textObjWidth);
return linkObj;
}