Rise
The Vieneo Province
Component.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Condition.h"
4 
5 class Component
6 {
7  Bus* bus = nullptr;
8  Logger* logger = nullptr;
9  DeviceObject* pDevice = nullptr;
10 
11 public:
12  //std::string guid; // not supporting real sensors
13 
14  std::string busval;
15 
16  float* ptrValue = nullptr;
17  char* chrValue = nullptr;
18 
19  //Systems::Fault* ptrFault = nullptr; // not supporting fault flags
20 
21  float bias = 0.0f;
22  float modulate = 1.0f;
23  bool abs = false;
24  std::vector<Condition> conditions;
25 
26  Component(Bus* prmBus, Logger* prmLogger, DeviceObject* prmDevice);
27  void Update();
28  void Render();
29 };
30 
31 inline Component::Component(Bus* prmBus, Logger* prmLogger, DeviceObject* prmDevice)
32 {
33  logger = prmLogger;
34  logger->AddToCallStack("Component::ctor");
35  bus = prmBus;
36  pDevice = prmDevice;
37 }
38 
39 inline void Component::Update()
40 {
41  logger->AddToCallStack("Component::Update");
42 
43  for (UINT j = 0; j < conditions.size(); j++)
44  {
45  // Draw all the sprites
46  for (UINT k = 0; k < conditions.at(j).sprites.size(); k++)
47  {
48  conditions.at(j).sprites.at(k).Update();
49  }
50  }
51 }
52 
53 inline void Component::Render()
54 {
55  logger->AddToCallStack("Component::Render");
56 
57  for (UINT j = 0; j < conditions.size(); j++)
58  {
59  if (!ptrValue || conditions.at(j).MeetsCondition(*ptrValue))
60  {
61  // Draw all the sprites
62  for (UINT k = 0; k < conditions.at(j).sprites.size(); k++)
63  {
64  conditions.at(j).sprites.at(k).Draw();
65  }
66 
67  // Draw all the text
68  for (UINT k = 0; k < conditions.at(j).text.size(); k++)
69  {
70  WCHAR format[99];
71  swprintf_s(format, 99, L"%S", conditions.at(j).text.at(k).formattedText.c_str());
72  if (conditions.at(j).text.at(k).formattedText.find('%') != std::string::npos)
73  {
74  WCHAR str[99];
75  if (ptrValue)
76  {
77  if (!abs)
78  swprintf_s(str, 99, format, *ptrValue * modulate + bias);
79  else
80  swprintf_s(str, 99, format, fabsf(*ptrValue * modulate + bias));
81  conditions.at(j).text.at(k).Draw(str);
82  }
83  else if (chrValue)
84  {
85  swprintf_s(str, 99, format, chrValue);
86  conditions.at(j).text.at(k).Draw(str);
87  }
88  else
89  {
90  conditions.at(j).text.at(k).Draw(format);
91  }
92  }
93  else
94  {
95  conditions.at(j).text.at(k).Draw(format);
96  }
97  }
98  break;
99  }
100  }
101 }
char * chrValue
Definition: Component.h:17
Bus * bus
Definition: Component.h:7
float * ptrValue
Definition: Component.h:16
Definition: Logger.h:9
DeviceObject * pDevice
Definition: Component.h:9
Definition: Bus.h:16
void Render()
Definition: Component.h:53
Component(Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice)
Definition: Component.h:31
float modulate
Definition: Component.h:22
std::string busval
Definition: Component.h:14
std::vector< Condition > conditions
Definition: Component.h:24
Logger * logger
Definition: Component.h:8
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86
void Update()
Definition: Component.h:39
bool abs
Definition: Component.h:23
float bias
Definition: Component.h:21