blob: 906bf3b299f37001bc9c7de93b279ad16cd30e25 [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:
15 explicit CairoRender(cairo_t *cr) : cr_(cr) {}
16 virtual ~CairoRender() {}
17
18 void Translate(double x, double y) override { cairo_translate(cr_, x, y); }
19
20 void SetSourceRGB(double r, double g, double b) override {
21 cairo_set_source_rgb(cr_, r, g, b);
22 }
23
24 void MoveTo(double x, double y) override { cairo_move_to(cr_, x, y); }
25
26 void LineTo(double x, double y) override { cairo_line_to(cr_, x, y); }
27
28 void Circle(double x, double y, double r) override {
29 cairo_arc(cr_, x, y, r, 0.0, 2 * M_PI);
30 }
31
32 void Stroke() override { cairo_stroke(cr_); }
33
34 void Text(int x, int y, int text_x, int text_y,
35 const std::string &text) override;
36
37 private:
38 cairo_t *cr_;
39};
40
41// Simple debug view window.
Parker Schuhef47dbf2017-03-04 16:59:30 -080042class DebugWindow {
Parker Schuh2cd173d2017-01-28 00:12:01 -080043 public:
44 struct Internals;
Parker Schuhef47dbf2017-03-04 16:59:30 -080045 explicit DebugWindow(bool flip);
46 ~DebugWindow();
Parker Schuh2cd173d2017-01-28 00:12:01 -080047 // Explicit redraw queuing (Will not double-queue).
48 void Redraw();
49
50 // This will resize the window as well as updating to draw from the
51 // (not owned) ptr. When you change ptr, you should call Redraw();
52 void UpdateImage(ImagePtr ptr);
53
54 // Sets up the window to draw a list of overlays.
55 // See overlay.h for more info.
56 void SetOverlays(std::vector<OverlayBase *> *overlay);
57
58 // Resizes the window.
59 void SetScale(double scale_factor);
60
61 // Move window.
62 void MoveTo(int x, int y);
63
64 // Set to change the key_press behaviour.
65 // The argument type is a constant that looks like: GDK_KEY_#{key_val_name}
66 std::function<void(uint32_t)> key_press_event;
67
68 private:
Parker Schuh309dd722017-02-25 11:31:18 -080069 bool shown_yet_ = false;
Parker Schuh2cd173d2017-01-28 00:12:01 -080070 double scale_factor = 1.0;
71 int window_width_ = 100;
72 int window_height_ = 100;
73 std::unique_ptr<Internals> self;
74};
75
76} // namespace vision
77} // namespace aos
78
Parker Schuhef47dbf2017-03-04 16:59:30 -080079#endif // AOS_VISION_DEBUG_DEBUG_WINDOW_H_