-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDasherController.cpp
More file actions
123 lines (99 loc) · 3.1 KB
/
DasherController.cpp
File metadata and controls
123 lines (99 loc) · 3.1 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
#include "DasherController.h"
#include <iostream>
class XmlServerStore;
DasherController::DasherController(Dasher::CSettingsStore* pSettingsStore): CDashIntfScreenMsgs(pSettingsStore)
{
ScreenModule = std::make_shared<DasherUIScreen>();
CDashIntfScreenMsgs::ChangeScreen(ScreenModule.get());
OSOutputModule = std::make_unique<OSOutput>();
}
void DasherController::editOutput(const std::string& strText, Dasher::CDasherNode* pNode) {
if (Buffer.capacity() < strText.length() + Buffer.size()) {
Buffer.reserve((strText.length() + Buffer.size()) * 2);
}
Buffer.append(strText);
Cursor += static_cast<unsigned int>(strText.length());
OSOutputModule->outputCharacter(strText);
CDasherInterfaceBase::editOutput(strText, pNode);
}
void DasherController::editDelete(const std::string& strText, Dasher::CDasherNode* pNode) {
if(0 == Buffer.compare(Buffer.length() - strText.length(), strText.length(), strText))
{
Buffer.erase(Buffer.length() - strText.length(), strText.length());
OSOutputModule->deleteCharacter();
}
CDasherInterfaceBase::editDelete(strText, pNode);
}
unsigned DasherController::ctrlMove(bool bForwards, Dasher::EditDistance dist)
{
if (dist == Dasher::EditDistance::EDIT_CHAR) {
if (bForwards) Cursor++;
else Cursor--;
}
return Cursor;
}
unsigned DasherController::ctrlDelete(bool bForwards, Dasher::EditDistance dist)
{
if(dist == Dasher::EditDistance::EDIT_CHAR) {
Buffer.erase(Cursor - (bForwards ? 0 : 1), 1);
}
if(!bForwards) Cursor--;
return Cursor;
}
std::string DasherController::GetContext(unsigned iStart, unsigned iLength)
{
return Buffer.substr(iStart, iLength);
}
std::string DasherController::GetAllContext()
{
std::string CurrentBuffer = Buffer;
SetBuffer(0);
return CurrentBuffer;
}
std::string DasherController::GetTextAroundCursor(Dasher::EditDistance iDist) {
if (Buffer.length() > Cursor && Buffer.length() >= 2) {
if (iDist == Dasher::EditDistance::EDIT_CHAR) {
return Buffer.substr(Cursor - 1, 2);
}
std::cerr << "tried to get more than just a char" << std::endl;
return "";
}
std::cerr << "Cursor out of bounds" << std::endl;
return "";
}
//TODO: Some day fix typo in function name
int DasherController::GetAllContextLenght()
{
return static_cast<int>(Buffer.length());
}
void DasherController::Initialize()
{
Realize(0);
}
void DasherController::CreateModules()
{
CDashIntfScreenMsgs::CreateModules();
GetModuleManager()->RegisterInputDeviceModule(ScreenModule.get(), true);
}
void DasherController::CopyToClipboard(const std::string& text)
{
ImGui::SetClipboardText(text.c_str());
}
void DasherController::Render(long deltaTime, ImVec2 canvasPos, ImVec2 canvasSize)
{
Time += deltaTime;
NewFrame(Time, true);
if(ScreenModule->SetCanvasSize(canvasPos, canvasSize))
{
ScreenResized(ScreenModule.get());
}
//Handle Input
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsMouseHoveringRect(canvasPos, canvasPos + canvasSize))
{
KeyDown(Time, Dasher::Keys::Primary_Input); //100 is the keycode for LMB
}
if(ImGui::IsMouseReleased(ImGuiMouseButton_Left))
{
KeyUp(Time, Dasher::Keys::Primary_Input); //100 is the keycode for LMB
}
}