File: Fl_Gl_Image_Widget.hh

package info (click to toggle)
gl-image-display 0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 256 kB
  • sloc: ansic: 1,003; cpp: 794; makefile: 102; python: 47
file content (136 lines) | stat: -rw-r--r-- 5,233 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#pragma once

extern "C"
{
#include "GL_image_display.h"
}

#include <FL/Fl_Gl_Window.H>

class Fl_Gl_Image_Widget : public Fl_Gl_Window
{
protected:
    GL_image_display_context_t m_ctx;
    int                        m_last_drag_update_xy[2];

    struct DeferredInitCache
    {
        DeferredInitCache();
        ~DeferredInitCache();
        void dealloc_update_image(void);
        void dealloc_set_lines   (void);

        bool save_update_image( int         _decimation_level,
                                bool        _flip_x,
                                bool        _flip_y,
                                const char* _image_filename,
                                const char* _image_data,
                                int         _image_width,
                                int         _image_height,
                                int         _image_bpp,
                                int         _image_pitch);
        bool save_set_lines(const GL_image_display_line_segments_t* _line_segment_sets,
                            int _Nline_segment_sets);
        bool apply(Fl_Gl_Image_Widget* w);

        // update_image
        int   decimation_level;
        bool  flip_x;
        bool  flip_y;
        char* image_filename;
        char* image_data;
        int   image_width;
        int   image_height;
        int   image_bpp;
        int   image_pitch;

        // set_lines
        GL_image_display_line_segments_t* line_segment_sets;
        int Nline_segment_sets;
    } m_deferred_init_cache;


public:
    Fl_Gl_Image_Widget(int x, int y, int w, int h,
                       // On some hardware (i915 for instance) double-buffering
                       // causes redrawing bugs (the window sometimes is never
                       // updated), so disabling double-buffering is a good
                       // workaround. In general, single-buffering causes redraw
                       // flicker, so double-buffering is recommended where
                       // possible
                       bool double_buffered = true);

    virtual ~Fl_Gl_Image_Widget();

    void draw(void);

    virtual int handle(int event);

    /////// C API wrappers
    ///////
    /////// these directly wrap the GL_image_display.h C API. The arguments and
    /////// function names are the same, except for the leading context: we pass
    /////// &m_ctx
    bool update_image2(int  decimation_level        = 0,
                       bool flip_x                  = false,
                       bool flip_y                  = false,
                       // Either this should be given
                       const char* image_filename   = NULL,
                       // Or these should be given
                       const char* image_data       = NULL,
                       int         image_width      = 0,
                       int         image_height     = 0,
                       int         image_bpp        = 0,
                       int         image_pitch      = 0);
    // For legacy compatibility. Calls update_image2() with flip_x, flip_y = false
    bool update_image( int  decimation_level        = 0,
                       // Either this should be given
                       const char* image_filename   = NULL,
                       // Or these should be given
                       const char* image_data       = NULL,
                       int         image_width      = 0,
                       int         image_height     = 0,
                       int         image_bpp        = 0,
                       int         image_pitch      = 0);

    // This is virtual, so a subclass could override the implementation
    virtual
    bool set_panzoom(double x_centerpixel, double y_centerpixel,
                     double visible_width_pixels);

    bool map_pixel_viewport_from_image(double* xout, double* yout,
                                       double x, double y);

    bool map_pixel_image_from_viewport(double* xout, double* yout,
                                       double x, double y);

    bool set_lines(const GL_image_display_line_segments_t* line_segment_sets,
                   int Nline_segment_sets);

    // internals of the interactive pan/zoom operations. Used primarily to
    // connect multiple Fl_Gl_Image_Widget together in interactive operations
    virtual
    bool process_mousewheel_zoom(double dy,
                                 double event_x,
                                 double event_y,
                                 double viewport_width,
                                 double viewport_height);
    virtual
    bool process_mousewheel_pan(double dx,
                                double dy,
                                double viewport_width,
                                double viewport_height);
    virtual
    bool process_mousedrag_pan(double dx,
                               double dy,
                               double viewport_width,
                               double viewport_height);

    // Old name for process_keyboard_panzoom(). For backwards compatibility only
    virtual
    bool process_keyboard_panzoom_orig(void);

    virtual
    bool process_keyboard_panzoom(void);

};