Apollo  6.0
Open source self driving car software
screen.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 #ifndef TOOLS_CVT_MONITOR_SCREEN_H_
18 #define TOOLS_CVT_MONITOR_SCREEN_H_
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 #ifndef CTRL
25 #define CTRL(c) ((c)&0x1F)
26 #endif
27 
28 class RenderableMessage;
29 
30 class Screen final {
31  public:
32  static const char InteractiveCmdStr[];
33 
34  enum ColorPair { // foreground color - background color
35  INVALID = 0,
41  };
42  static Screen* Instance(void);
43 
44  ~Screen(void);
45 
46  void Init(void);
47  void Run(void);
48  void Resize();
49  void Stop(void) { canRun_ = false; }
50 
51  int Width(void) const;
52  int Height(void) const;
53 
54  void AddStr(int x, int y, ColorPair color, const char* str) const;
55 
56  ColorPair Color(void) const { return current_color_pair_; }
57  void SetCurrentColor(ColorPair color) const;
58  void AddStr(int x, int y, const char* str) const;
59  void AddStr(const char* str) const;
60  void MoveOffsetXY(int offsetX, int offsetY) const;
61  void ClearCurrentColor(void) const;
62 
63  void SetCurrentRenderMessage(RenderableMessage* const render_obj) {
64  if (render_obj) {
65  current_render_obj_ = render_obj;
66  }
67  }
68 
69  private:
70  explicit Screen();
71  Screen(const Screen&) = delete;
72  Screen& operator=(const Screen&) = delete;
73 
74  int SwitchState(int ch);
75  void HighlightLine(int line_no);
76 
77  void ShowInteractiveCmd(int ch);
78  void ShowRenderMessage(int ch);
79 
80  bool IsInit(void) const;
81 
82  enum class State { RenderMessage, RenderInterCmdInfo };
83 
84  mutable ColorPair current_color_pair_;
85  bool canRun_;
86  State current_state_;
87  int highlight_direction_;
88  RenderableMessage* current_render_obj_;
89 };
90 
91 #endif // TOOLS_CVT_MONITOR_SCREEN_H_
ColorPair
Definition: screen.h:34
Definition: screen.h:36
void MoveOffsetXY(int offsetX, int offsetY) const
Definition: screen.h:30
Definition: renderable_message.h:24
static const char InteractiveCmdStr[]
Definition: screen.h:32
Definition: screen.h:37
void Stop(void)
Definition: screen.h:49
void Init(void)
void ClearCurrentColor(void) const
void SetCurrentColor(ColorPair color) const
~Screen(void)
Definition: screen.h:40
void Run(void)
Definition: screen.h:38
Definition: screen.h:39
Definition: screen.h:35
int Height(void) const
void SetCurrentRenderMessage(RenderableMessage *const render_obj)
Definition: screen.h:63
void AddStr(int x, int y, ColorPair color, const char *str) const
static Screen * Instance(void)
void Resize()
ColorPair Color(void) const
Definition: screen.h:56
int Width(void) const