Raspberry Pi Weighting Control System
This project serves as a simple weighting control system, that was realized as a Bachelor Thesis
Macros | Functions | Variables
screen_manager.cpp File Reference
#include "screen_manager.h"
#include <vector>
#include <exception>
#include <spdlog/spdlog.h>
#include "screen_definitions.h"
#include "imgui.h"
#include "imgui_internal.h"
#include "localisation.h"
#include "app_workspace.h"

Go to the source code of this file.

Macros

#define DEBUG_SCREENS   5
 
#define REAL_SCREENS   6
 
#define PATIENT_SCREEN_CNT   4
 
#define EMPLOYEE_SCREEN_CNT   4
 

Functions

void render_nav_bar ()
 called nav bar, render current input mode at the bottom of the screen More...
 
void render_status_bar ()
 
template<typename Base , typename T >
bool instanceof (const T *ptr)
 
void draw_status_circle (ImVec2 center, bool usr_logged, float radius)
 

Variables

float rt_content_width
 
float rt_line_height
 
const uint8_t patient_screens [] = {1, 2, 3, 4}
 
const uint8_t employee_screens [] = {1, 2, 3, 4}
 

Macro Definition Documentation

◆ DEBUG_SCREENS

#define DEBUG_SCREENS   5

Definition at line 16 of file screen_manager.cpp.

◆ EMPLOYEE_SCREEN_CNT

#define EMPLOYEE_SCREEN_CNT   4

Definition at line 24 of file screen_manager.cpp.

◆ PATIENT_SCREEN_CNT

#define PATIENT_SCREEN_CNT   4

Definition at line 23 of file screen_manager.cpp.

◆ REAL_SCREENS

#define REAL_SCREENS   6

Definition at line 17 of file screen_manager.cpp.

Function Documentation

◆ draw_status_circle()

void draw_status_circle ( ImVec2  center,
bool  usr_logged,
float  radius 
)

Definition at line 295 of file screen_manager.cpp.

295  {
296  ImU32 color = usr_logged ? IM_COL32(0, 255, 0, 255) : IM_COL32(255, 0, 0, 255);
297 
298  ImDrawList *wdl = ImGui::GetWindowDrawList();
299  wdl->AddCircleFilled(center, radius, color);
300 }

◆ instanceof()

template<typename Base , typename T >
bool instanceof ( const T *  ptr)
inline

Definition at line 66 of file screen_manager.cpp.

66  {
67  return dynamic_cast<const Base*>(ptr) != nullptr;
68 }

◆ render_nav_bar()

void render_nav_bar ( )

called nav bar, render current input mode at the bottom of the screen

Definition at line 350 of file screen_manager.cpp.

350  {
351  app_workspace *app_wrk = app_workspace::get_instance().get();;
352  app_workspace_ns::kb_input_state *kbins = app_wrk->kb_in_state.get();
353  ImVec2 win_size = ImGui::GetContentRegionMax();
354  char buff[DEF_BUFF_SIZE_BIG] = {0}, in_mod[DEF_BUFF_SIZE_SMALL] = {0};
355  float th = ImGui::GetTextLineHeightWithSpacing(); // text height (with spacing)
356 
357  switch (kbins->current_mode) {
359  strcpy(in_mod, get_localized_text("GT_NAVIGATION"));
360  break;
362  switch (kbins->current_type) {
364  strcpy(in_mod, get_localized_text("GT_INPUT_INT"));
365  break;
367  strcpy(in_mod, get_localized_text("GT_INPUT_FLOAT"));
368  break;
370  strcpy(in_mod, get_localized_text("GT_INPUT_TEXT"));
371  break;
372 
374  default:
375  strcpy(in_mod, get_localized_text("GT_INPUT_ERR"));
376  break;
377  }
378  break;
379  default:
380  strcpy(in_mod, get_localized_text("GT_ERR"));
381  break;
382  }
383 
384  sprintf(buff, "%s: %s\t%s: %s\t%s: %s",
385  get_localized_text("GT_MODE"),
386  in_mod,
387  get_localized_text("GT_CAPS"),
388  app_wrk->get_instance()->capslock_flag ? get_localized_text("GT_YES") : get_localized_text("GT_NO"),
389  get_localized_text("GT_SHIFT"),
390  app_wrk->get_instance()->lshift_flag ? get_localized_text("GT_YES") : get_localized_text("GT_NO"));
391 
392  ImGui::SetCursorPosY(win_size.y - th);
393  ImGui::Text(buff);
394 }
#define DEF_BUFF_SIZE_SMALL
Definition: app_workspace.h:22
#define DEF_BUFF_SIZE_BIG
Definition: app_workspace.h:24
One of the most importat classes in the whole project. Holds variables that define the state of the a...
static std::unique_ptr< app_workspace > & get_instance()
Get the instance app_workspace which is a singleton.
std::unique_ptr< app_workspace_ns::kb_input_state > kb_in_state
Input state holder.
const char * get_localized_text(const char *key)
Get the localized text object.
Structure holding the values of keyboard input mode and input type.
Definition: app_workspace.h:96

◆ render_status_bar()

void render_status_bar ( )

Definition at line 302 of file screen_manager.cpp.

302  {
303  app_workspace *app_wrk = app_workspace::get_instance().get();
304  screen_manager *scr_mgr = app_wrk->get_scr_mgr();
305  ImVec2 win_pos = ImGui::GetWindowPos();
306  ImVec2 win_size = ImGui::GetContentRegionMax();
307  ImVec2 cur_pos;
308  ImVec2 padding = ImGui::GetStyle().WindowPadding;
309  char usr_buff[DEF_BUFF_SIZE] = {0};
310  float radius = 8;
311 
312  sprintf(usr_buff, "%s: %s", get_localized_text("GT_USER"),
313  app_wrk->has_user() ? app_wrk->userspace->get_username().c_str() :
314  get_localized_text("GT_USER_NO_LOGIN"));
315 
316  cur_pos = ImGui::GetCursorPos();
317  ImVec2 usr_center(win_pos.x + cur_pos.x + radius, win_pos.y + cur_pos.y + (radius / 2));
318 
319  // print username and draw status circle
320  draw_status_circle(usr_center, app_wrk->user_logged, radius);
321  ImGui::SetCursorPosX(padding.x + (radius * 2) + padding.x);
322  ImGui::Text(usr_buff);
323 
324  // print time
325  time_t now = time(0);
326  tm *ltm = localtime(&now);
327  char time[DEF_BUFF_SIZE_V_SMALL];
328  sprintf(time, "%.2d:%.2d:%.2d", ltm->tm_hour, ltm->tm_min, ltm->tm_sec);
329  ImVec2 tts = ImGui::CalcTextSize(time); // time text size
330  ImGui::SameLine();
331  float time_x = win_size.x - padding.x - tts.x - 2;
332  ImGui::SetCursorPosX(time_x);
333  ImGui::Text(time);
334 
335  // print selected screen
336  // FIXME centered in previous version, moved more to right because i haven't decided yet on usr: usr_name length
337  ImGui::SameLine();
338  //ImGui::SetCursorPosX((win_size.x / 2) - padding.x - 2);
339  ImGui::SetCursorPosX(time_x - 100);
340  ImGui::TextColored(ImColor(IM_COL32(0, 180, 0, 255)), "%d", scr_mgr->get_selected_screen());
341 
342  // "extra" empty line after status bar (as padding)
343  ImGui::NewLine();
344 }
#define DEF_BUFF_SIZE
Definition: app_workspace.h:23
#define DEF_BUFF_SIZE_V_SMALL
Definition: app_workspace.h:21
bool has_user()
Checks if user is logged in. This is determined by user_space being initialized and having the user_l...
screen_manager * get_scr_mgr()
Get the screen manager instance. This instance is kind of singleton. Is initalized only once on start...
bool user_logged
Flag to indicate if a user is logged in.
std::unique_ptr< user_workspace > userspace
User's workspace. Serves similar function as app_workspace but for user data.
uint8_t get_selected_screen()
void draw_status_circle(ImVec2 center, bool usr_logged, float radius)

Variable Documentation

◆ employee_screens

const uint8_t employee_screens[] = {1, 2, 3, 4}

Definition at line 27 of file screen_manager.cpp.

◆ patient_screens

const uint8_t patient_screens[] = {1, 2, 3, 4}

Definition at line 26 of file screen_manager.cpp.

◆ rt_content_width

float rt_content_width

Definition at line 20 of file screen_manager.cpp.

◆ rt_line_height

float rt_line_height

Definition at line 21 of file screen_manager.cpp.