Skip to content

Commit 8dcdff9

Browse files
author
Sebi
authored
Merge pull request #1 from PapeCoding/feature/rework_rendering
Merging feature/rework_rendering
2 parents 2a22a90 + 18c0e65 commit 8dcdff9

File tree

6 files changed

+58
-16
lines changed

6 files changed

+58
-16
lines changed

DasherCore

src/DasherController.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class XmlServerStore;
44

55
DasherController::DasherController(Dasher::CSettingsStore* pSettingsStore): CDashIntfScreenMsgs(pSettingsStore)
66
{
7-
ScreenModule = make_shared<DasherUIScreen>();
7+
ScreenModule = std::make_shared<DasherUIScreen>();
88
CDashIntfScreenMsgs::ChangeScreen(ScreenModule.get());
99
}
1010

@@ -110,11 +110,11 @@ void DasherController::Render(long deltaTime, ImVec2 canvasPos, ImVec2 canvasSiz
110110
//Handle Input
111111
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) && ImGui::IsMouseHoveringRect(canvasPos, canvasPos + canvasSize))
112112
{
113-
KeyDown(Time, 100); //100 is the keycode for LMB
113+
KeyDown(Time, Dasher::Keys::Primary_Input); //100 is the keycode for LMB
114114
}
115115

116116
if(ImGui::IsMouseReleased(ImGuiMouseButton_Left))
117117
{
118-
KeyUp(Time, 100); //100 is the keycode for LMB
118+
KeyUp(Time, Dasher::Keys::Primary_Input); //100 is the keycode for LMB
119119
}
120120
}

src/DasherUIScreen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ DasherUIScreen::DasherUIScreen(): Dasher::CDasherScreen(100,100), CScreenCoordIn
1010

1111
std::pair<Dasher::screenint, Dasher::screenint> DasherUIScreen::TextSize(Label* Label, unsigned iFontSize)
1212
{
13-
const ImVec2 Size = Font->CalcTextSizeA(iFontSize, FLT_MAX, -1, Label->m_strText.c_str());
14-
return {Size.x, Size.y};
13+
const ImVec2 Size = Font->CalcTextSizeA(static_cast<float>(iFontSize), FLT_MAX, -1, Label->m_strText.c_str());
14+
return {static_cast<Dasher::screenint>(Size.x), static_cast<Dasher::screenint>(Size.y)};
1515
}
1616

1717
void DasherUIScreen::DrawString(Label* label, Dasher::screenint x, Dasher::screenint y, unsigned iFontSize, int iColour)

src/MainWindow.cpp

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,56 @@ MainWindow::MainWindow()
1010
{
1111
ImGui::SetCurrentFont(LoadFonts(14.0f));
1212

13-
Settings = make_unique<Dasher::XmlSettingsStore>("Settings.xml", this);
13+
Settings = std::make_unique<Dasher::XmlSettingsStore>("Settings.xml", this);
1414
Settings->Load();
1515
Settings->Save();
1616

17-
Controller = make_unique<DasherController>(Settings.get());
17+
Controller = std::make_unique<DasherController>(Settings.get());
1818
Controller->Initialize();
1919

20-
Controller->GetPermittedValues(SP_ALPHABET_ID, Alphabets);
20+
Controller->GetPermittedValues(Dasher::SP_ALPHABET_ID, Alphabets);
2121

2222
}
2323

24+
#define FORWARD_KEY(ImGui_Key, DasherKey) { \
25+
if(ImGui::IsKeyPressed(ImGui_Key, false)) Controller->KeyDown(time, DasherKey); \
26+
if(ImGui::IsKeyReleased(ImGui_Key, false)) Controller->KeyUp(time, DasherKey); \
27+
}
28+
void MainWindow::HandleInput(const std::unique_ptr<DasherController>& controller, long time)
29+
{
30+
// Space
31+
FORWARD_KEY(ImGuiKey_Space, Dasher::Keys::Big_Start_Stop_Key)
32+
33+
// Button 1
34+
FORWARD_KEY(ImGuiKey_LeftArrow, Dasher::Keys::Button_1)
35+
FORWARD_KEY(ImGuiKey_Keypad4, Dasher::Keys::Button_1)
36+
FORWARD_KEY(ImGuiKey_A, Dasher::Keys::Button_1)
37+
FORWARD_KEY(ImGuiKey_J, Dasher::Keys::Button_1)
38+
FORWARD_KEY(ImGuiKey_1, Dasher::Keys::Button_1)
39+
40+
// Button 2
41+
FORWARD_KEY(ImGuiKey_UpArrow, Dasher::Keys::Button_2)
42+
FORWARD_KEY(ImGuiKey_Keypad8, Dasher::Keys::Button_2)
43+
FORWARD_KEY(ImGuiKey_W, Dasher::Keys::Button_2)
44+
FORWARD_KEY(ImGuiKey_I, Dasher::Keys::Button_2)
45+
FORWARD_KEY(ImGuiKey_2, Dasher::Keys::Button_2)
46+
47+
// Button 3
48+
FORWARD_KEY(ImGuiKey_RightArrow, Dasher::Keys::Button_3)
49+
FORWARD_KEY(ImGuiKey_Keypad6, Dasher::Keys::Button_3)
50+
FORWARD_KEY(ImGuiKey_S, Dasher::Keys::Button_3)
51+
FORWARD_KEY(ImGuiKey_K, Dasher::Keys::Button_3)
52+
FORWARD_KEY(ImGuiKey_3, Dasher::Keys::Button_3)
53+
54+
// Button 4
55+
FORWARD_KEY(ImGuiKey_DownArrow, Dasher::Keys::Button_4)
56+
FORWARD_KEY(ImGuiKey_Keypad2, Dasher::Keys::Button_4)
57+
FORWARD_KEY(ImGuiKey_Z, Dasher::Keys::Button_4)
58+
FORWARD_KEY(ImGuiKey_M, Dasher::Keys::Button_4)
59+
FORWARD_KEY(ImGuiKey_4, Dasher::Keys::Button_4)
60+
}
61+
#undef FORWARD_KEY
62+
2463
bool MainWindow::render(float DeltaTime)
2564
{
2665
static ImGuiWindowFlags flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBackground ;
@@ -29,7 +68,7 @@ bool MainWindow::render(float DeltaTime)
2968
const ImVec2 spacing = ImGui::GetStyle().ItemSpacing;
3069
ImGui::SetNextWindowPos(viewport->WorkPos);
3170
ImGui::SetNextWindowSize(viewport->WorkSize);
32-
71+
3372
if (ImGui::Begin("MainWindow", nullptr, flags))
3473
{
3574
if(ImGui::BeginMainMenuBar())
@@ -61,16 +100,16 @@ bool MainWindow::render(float DeltaTime)
61100
{
62101
ClearBuffer();
63102
}
64-
int speed = Controller->GetLongParameter(LP_MAX_BITRATE);
103+
int speed = Controller->GetLongParameter(Dasher::LP_MAX_BITRATE);
65104
if(ImGui::SliderInt ("Speed", &speed, 1, 2000))
66105
{
67-
Controller->SetLongParameter(LP_MAX_BITRATE, speed);
106+
Controller->SetLongParameter(Dasher::LP_MAX_BITRATE, speed);
68107
}
69108

70109
static int item_current = 0;
71110
if(ImGui::Combo("Alphabet", &item_current, [](void* data, int idx, const char** out_text) { *out_text = static_cast<const std::vector<std::string>*>(data)->at(idx).c_str(); return true; }, (void*)&Alphabets, static_cast<int>(Alphabets.size()), 10))
72111
{
73-
Controller->SetStringParameter(SP_ALPHABET_ID, Alphabets[item_current]);
112+
Controller->SetStringParameter(Dasher::SP_ALPHABET_ID, Alphabets[item_current]);
74113
}
75114

76115
ImGui::EndMenu();
@@ -105,7 +144,7 @@ bool MainWindow::render(float DeltaTime)
105144
}
106145
ImGui::EndGroup();
107146

108-
const ImVec2 canvasPos = ImGui::GetCursorScreenPos();
147+
const ImVec2 canvasPos = ImGui::GetCursorScreenPos();
109148
const ImVec2 canvasSize = ImGui::GetContentRegionAvail();
110149

111150
ImGui::PushClipRect(canvasPos, canvasPos + canvasSize, false);
@@ -117,9 +156,11 @@ bool MainWindow::render(float DeltaTime)
117156
ImGui::ColorConvertFloat4ToU32({0,1,0,1})
118157
);
119158

120-
Controller->Render(DeltaTime * 1000.0f, canvasPos, canvasSize); //convert to millis
159+
Controller->Render(static_cast<long>(DeltaTime * 1000.0f), canvasPos, canvasSize); //convert to millis
121160

122161
ImGui::PopClipRect();
162+
163+
HandleInput(Controller, static_cast<long>(DeltaTime * 1000.0f));
123164
}
124165
ImGui::End();
125166

src/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class MainWindow : public Dasher::CommandlineErrorDisplay
1414
MainWindow();
1515
~MainWindow() = default;
1616

17+
void HandleInput(const std::unique_ptr<DasherController>& controller, long time);
1718
bool render(float DeltaTime);
1819

1920
void CopyTextToClipboard(const std::string& text) const;

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int main(int, char**)
7676
IMGUI_CHECKVERSION();
7777
ImGui::CreateContext();
7878
ImGuiIO& io = ImGui::GetIO(); (void)io;
79-
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
79+
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
8080
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
8181

8282
// Setup Dear ImGui style

0 commit comments

Comments
 (0)