Parker Schuh | 2cd173d | 2017-01-28 00:12:01 -0800 | [diff] [blame] | 1 | #ifndef AOS_VISION_DEBUG_DEBUG_VIEWER_H_ |
| 2 | #define AOS_VISION_DEBUG_DEBUG_VIEWER_H_ |
| 3 | |
| 4 | #include <cairo.h> |
| 5 | #include <functional> |
| 6 | #include "aos/vision/debug/overlay.h" |
| 7 | #include "aos/vision/image/image_types.h" |
| 8 | |
| 9 | namespace aos { |
| 10 | namespace vision { |
| 11 | |
| 12 | // Implement Cairo version of RenderInterface. |
| 13 | class 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. |
| 42 | class DebugViewer { |
| 43 | public: |
| 44 | struct Internals; |
| 45 | explicit DebugViewer(bool flip); |
| 46 | ~DebugViewer(); |
| 47 | // 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: |
| 69 | double scale_factor = 1.0; |
| 70 | int window_width_ = 100; |
| 71 | int window_height_ = 100; |
| 72 | std::unique_ptr<Internals> self; |
| 73 | }; |
| 74 | |
| 75 | } // namespace vision |
| 76 | } // namespace aos |
| 77 | |
| 78 | #endif // AOS_VISION_DEBUG_DEBUG_VIEWER_H_ |