blob: aa31a8c64b22f69e76a13b4ef414aea4d71d4e8a [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>
5#include <functional>
6#include "aos/vision/debug/overlay.h"
7#include "aos/vision/image/image_types.h"
8
9namespace aos {
10namespace vision {
11
12// Implement Cairo version of RenderInterface.
13class CairoRender : public RenderInterface {
14 public:
Parker Schuhcd258b82017-04-09 16:28:29 -070015 explicit CairoRender(cairo_t *cr, double text_scale)
16 : cr_(cr), text_scale_(text_scale) {}
Parker Schuh2cd173d2017-01-28 00:12:01 -080017 virtual ~CairoRender() {}
18
19 void Translate(double x, double y) override { cairo_translate(cr_, x, y); }
20
21 void SetSourceRGB(double r, double g, double b) override {
22 cairo_set_source_rgb(cr_, r, g, b);
23 }
24
25 void MoveTo(double x, double y) override { cairo_move_to(cr_, x, y); }
26
27 void LineTo(double x, double y) override { cairo_line_to(cr_, x, y); }
28
29 void Circle(double x, double y, double r) override {
30 cairo_arc(cr_, x, y, r, 0.0, 2 * M_PI);
31 }
32
33 void Stroke() override { cairo_stroke(cr_); }
34
35 void Text(int x, int y, int text_x, int text_y,
36 const std::string &text) override;
37
38 private:
39 cairo_t *cr_;
Parker Schuhcd258b82017-04-09 16:28:29 -070040 double text_scale_ = 1.0;
Parker Schuh2cd173d2017-01-28 00:12:01 -080041};
42
43// Simple debug view window.
Parker Schuhef47dbf2017-03-04 16:59:30 -080044class DebugWindow {
Parker Schuh2cd173d2017-01-28 00:12:01 -080045 public:
46 struct Internals;
Parker Schuhef47dbf2017-03-04 16:59:30 -080047 explicit DebugWindow(bool flip);
48 ~DebugWindow();
Parker Schuh2cd173d2017-01-28 00:12:01 -080049 // Explicit redraw queuing (Will not double-queue).
50 void Redraw();
51
52 // This will resize the window as well as updating to draw from the
53 // (not owned) ptr. When you change ptr, you should call Redraw();
54 void UpdateImage(ImagePtr ptr);
55
56 // Sets up the window to draw a list of overlays.
57 // See overlay.h for more info.
58 void SetOverlays(std::vector<OverlayBase *> *overlay);
59
Parker Schuhcd258b82017-04-09 16:28:29 -070060 void AddOverlay(OverlayBase *overlay);
61 void AddOverlays(const std::vector<OverlayBase *> &overlays) {
62 for (auto *overlay : overlays) {
63 AddOverlay(overlay);
64 }
65 }
66
Parker Schuh2cd173d2017-01-28 00:12:01 -080067 // Resizes the window.
68 void SetScale(double scale_factor);
69
70 // Move window.
71 void MoveTo(int x, int y);
72
73 // Set to change the key_press behaviour.
74 // The argument type is a constant that looks like: GDK_KEY_#{key_val_name}
75 std::function<void(uint32_t)> key_press_event;
76
77 private:
Parker Schuh309dd722017-02-25 11:31:18 -080078 bool shown_yet_ = false;
Parker Schuh2cd173d2017-01-28 00:12:01 -080079 double scale_factor = 1.0;
80 int window_width_ = 100;
81 int window_height_ = 100;
82 std::unique_ptr<Internals> self;
83};
84
85} // namespace vision
86} // namespace aos
87
Parker Schuhef47dbf2017-03-04 16:59:30 -080088#endif // AOS_VISION_DEBUG_DEBUG_WINDOW_H_