Commit ba944eb0 authored by Christian Sponfeldner's avatar Christian Sponfeldner

refactor DrawString helper

parent dd4b9ec6
......@@ -28,8 +28,6 @@
#include "../../devices/inc/powermanagement.h"
constexpr float RADS_TO_UMIN = noexcept(60 / (2 * M_TWOPI));
using namespace EMROSCmdType::Basecontroller;
namespace EMROS_GUI
......
......@@ -8,7 +8,7 @@
#include <cmath>
void DrawTacho(int32_t speed, uint16_t pos_x, uint16_t pos_y, uint16_t len, uint8_t no);
void DrawStringBugfix(uint16_t, uint16_t, fonthandle_t, const char*);
void DrawStringWithFont(uint16_t, uint16_t, fonthandle_t, const char*);
void DrawSystemLoad(rectangle_t);
#endif /* NANOTEC_INC_GUI_HELPER_H_ */
......@@ -195,10 +195,10 @@ Error MecanumGUI::HandleLowPrioMsg(os_msg_t & msg)
Graphics::DrawFilledRectangle(410, 218, 50, 20);
Graphics::SelectColor(COLOR_WHITE);
DrawStringBugfix(224, 118, SYSFONT8, vel_fl);
DrawStringBugfix(224, 218, SYSFONT8, vel_rl);
DrawStringBugfix(410, 118, SYSFONT8, vel_fr);
DrawStringBugfix(410, 218, SYSFONT8, vel_rr);
DrawStringWithFont(224, 118, SYSFONT8, vel_fl);
DrawStringWithFont(224, 218, SYSFONT8, vel_rl);
DrawStringWithFont(410, 118, SYSFONT8, vel_fr);
DrawStringWithFont(410, 218, SYSFONT8, vel_rr);
}
//-------------------------------------------------------------------
......@@ -224,7 +224,7 @@ Error MecanumGUI::HandleRTOutput()
Graphics::WaitUntilPreviousOpFinished();
Graphics::SelectColor(COLOR_WHITE);
DrawStringBugfix(uint16_t(mBoxes.RT_box->left + 2), uint16_t(mBoxes.RT_box->top + 2), SYSFONT12, string);
DrawStringWithFont(uint16_t(mBoxes.RT_box->left + 2), uint16_t(mBoxes.RT_box->top + 2), SYSFONT12, string);
//Graphics::DrawString(text_box.left + 2, text_box.top + 2, _TXT string);
DrawSystemLoad(*mBoxes.sys_load);
......@@ -421,8 +421,8 @@ Error DifferentialGUI::HandleLowPrioMsg(os_msg_t & msg)
Graphics::SelectColor(COLOR_WHITE);
DrawStringBugfix(120, 218, SYSFONT12, vel_l);
DrawStringBugfix(300, 218, SYSFONT12, vel_r);
DrawStringWithFont(120, 218, SYSFONT12, vel_l);
DrawStringWithFont(300, 218, SYSFONT12, vel_r);
}
//-------------------------------------------------------------------
......@@ -458,7 +458,7 @@ Error DifferentialGUI::HandleRTOutput()
Graphics::WaitUntilPreviousOpFinished();
Graphics::SelectColor(COLOR_WHITE);
DrawStringBugfix(uint16_t(mBoxes.RT_box->left + 2), uint16_t(mBoxes.RT_box->top + 2), SYSFONT12, string);
DrawStringWithFont(uint16_t(mBoxes.RT_box->left + 2), uint16_t(mBoxes.RT_box->top + 2), SYSFONT12, string);
//Graphics::DrawString(text_box.left + 2, text_box.top + 2, _TXT string);
DrawSystemLoad(*mBoxes.sys_load);
return (Error::NO_ERROR);
......
......@@ -57,57 +57,11 @@ void DrawTacho(int32_t speed, uint16_t pos_x, uint16_t pos_y,
DrawTachoNeedle(x1, y1, x2, y2);
}
void DrawStringBugfix(uint16_t xPos, uint16_t yPos, fonthandle_t font,
void DrawStringWithFont(uint16_t xPos, uint16_t yPos, fonthandle_t font,
const char* string) {
fonthandle_t default_font = Graphics::GetDefaultFont();
Graphics::SelectFont(font);
uint32_t len = std::strlen(string);
char* inStr = new char[len];
if (!inStr) {
DBGBRK(true);
//TODO: error
return;
}
std::strcpy(inStr, string);
uint16_t len_sub_string;
char* pResult;
uint16_t row = 0;
uint16_t offset = 0;
if (inStr[len - 1] == '\n') {
inStr[len - 1] = 0;
}
char* tempStr = new char[len];
while ((pResult = std::strchr(inStr + offset, '\n'))) {
std::memset(tempStr, 0, len);
len_sub_string = uint16_t(pResult - inStr - offset);
if (len_sub_string > 0) {
std::strncpy(tempStr, inStr + offset, len_sub_string);
Graphics::DrawString(xPos,
uint16_t(yPos + row * font->DefaultLineSpacing),
string_t(tempStr), len_sub_string);
offset = uint16_t(offset + len_sub_string + 1);
row++;
}
}
len_sub_string = uint16_t(len - offset);
if (len_sub_string > 0) {
std::memset(tempStr, 0, std::strlen(tempStr));
std::strncpy(tempStr, inStr + offset, len_sub_string);
Graphics::DrawString(xPos,
uint16_t(yPos + row * font->DefaultLineSpacing),
string_t(tempStr), len_sub_string);
}
Graphics::WaitUntilPreviousOpFinished();
Graphics::SelectFont(default_font);
delete[] tempStr;
delete[] inStr;
fonthandle_t prior_font = Graphics::SelectFont(font);
Graphics::DrawString(xPos, yPos, string);
Graphics::SelectFont(prior_font);
}
void DrawSystemLoad(rectangle_t box) {
......@@ -125,11 +79,11 @@ void DrawSystemLoad(rectangle_t box) {
Graphics::SelectColor(COLOR_WHITE);
std::sprintf(system_info_text, "System Info:\nMemory Load:\nSize: %u b\n(%.3f%%)",
(unsigned int) (ptSysIf->DynamicMemUsed), double(_mem_load));
DrawStringBugfix(uint16_t(box.left + offset), uint16_t(box.top + offset),
DrawStringWithFont(uint16_t(box.left + offset), uint16_t(box.top + offset),
font, system_info_text);
std::memset(system_info_text, 0, system_info_text_size_in_bytes);
std::sprintf(system_info_text, "CPU Load:\n%u%%", (unsigned int) (ptSysIf->CpuLoad));
DrawStringBugfix(uint16_t(box.left + offset),
DrawStringWithFont(uint16_t(box.left + offset),
uint16_t(box.top + 5 * font->DefaultLineSpacing + offset), font,
system_info_text);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment