blob: 573cef5059a0435d3c115213a17b6a314ac4f955 [file] [log] [blame]
Parker Schuhef47dbf2017-03-04 16:59:30 -08001#ifndef AOS_VISION_DEBUG_DEBUG_WINDOW_H_
2#define AOS_VISION_DEBUG_DEBUG_WINDOW_H_
Parker Schuh2cd173d2017-01-28 00:12:01 -08003
4#include <cairo.h>
Austin Schuh60e77942022-05-16 17:48:24 -07005
Parker Schuh2cd173d2017-01-28 00:12:01 -08006#include <functional>
Austin Schuh60e77942022-05-16 17:48:24 -07007
Parker Schuh2cd173d2017-01-28 00:12:01 -08008#include "aos/vision/debug/overlay.h"
9#include "aos/vision/image/image_types.h"
10
11namespace aos {
12namespace vision {
13
14// Implement Cairo version of RenderInterface.
15class CairoRender : public RenderInterface {
16 public:
Parker Schuhcd258b82017-04-09 16:28:29 -070017 explicit CairoRender(cairo_t *cr, double text_scale)
18 : cr_(cr), text_scale_(text_scale) {}
Parker Schuh2cd173d2017-01-28 00:12:01 -080019 virtual ~CairoRender() {}
20
21 void Translate(double x, double y) override { cairo_translate(cr_, x, y); }
22
23 void SetSourceRGB(double r, double g, double b) override {
24 cairo_set_source_rgb(cr_, r, g, b);
25 }
26
27 void MoveTo(double x, double y) override { cairo_move_to(cr_, x, y); }
28
29 void LineTo(double x, double y) override { cairo_line_to(cr_, x, y); }
30
31 void Circle(double x, double y, double r) override {
32 cairo_arc(cr_, x, y, r, 0.0, 2 * M_PI);
33 }
34
35 void Stroke() override { cairo_stroke(cr_); }
36
37 void Text(int x, int y, int text_x, int text_y,
38 const std::string &text) override;
39
40 private:
41 cairo_t *cr_;
Parker Schuhcd258b82017-04-09 16:28:29 -070042 double text_scale_ = 1.0;
Parker Schuh2cd173d2017-01-28 00:12:01 -080043};
44
45// Simple debug view window.
Parker Schuhef47dbf2017-03-04 16:59:30 -080046class DebugWindow {
Parker Schuh2cd173d2017-01-28 00:12:01 -080047 public:
48 struct Internals;
Parker Schuhef47dbf2017-03-04 16:59:30 -080049 explicit DebugWindow(bool flip);
50 ~DebugWindow();
Parker Schuh2cd173d2017-01-28 00:12:01 -080051 // Explicit redraw queuing (Will not double-queue).
52 void Redraw();
53
54 // This will resize the window as well as updating to draw from the
55 // (not owned) ptr. When you change ptr, you should call Redraw();
56 void UpdateImage(ImagePtr ptr);
57
58 // Sets up the window to draw a list of overlays.
59 // See overlay.h for more info.
60 void SetOverlays(std::vector<OverlayBase *> *overlay);
61
Parker Schuhcd258b82017-04-09 16:28:29 -070062 void AddOverlay(OverlayBase *overlay);
63 void AddOverlays(const std::vector<OverlayBase *> &overlays) {
64 for (auto *overlay : overlays) {
65 AddOverlay(overlay);
66 }
67 }
68
Parker Schuh2cd173d2017-01-28 00:12:01 -080069 // Resizes the window.
70 void SetScale(double scale_factor);
71
72 // Move window.
73 void MoveTo(int x, int y);
74
75 // Set to change the key_press behaviour.
76 // The argument type is a constant that looks like: GDK_KEY_#{key_val_name}
77 std::function<void(uint32_t)> key_press_event;
78
79 private:
Parker Schuh309dd722017-02-25 11:31:18 -080080 bool shown_yet_ = false;
Parker Schuh2cd173d2017-01-28 00:12:01 -080081 double scale_factor = 1.0;
82 int window_width_ = 100;
83 int window_height_ = 100;
84 std::unique_ptr<Internals> self;
85};
86
87} // namespace vision
88} // namespace aos
89
Parker Schuhef47dbf2017-03-04 16:59:30 -080090#endif // AOS_VISION_DEBUG_DEBUG_WINDOW_H_