~qcumber-some/widelands/spice-up-cmake

« back to all changes in this revision

Viewing changes to src/ui_basic/icongrid.h

  • Committer: Jens Beyer (Qcumber-some)
  • Date: 2010-05-28 14:51:37 UTC
  • mfrom: (5149.1.226 trunk)
  • Revision ID: qcumber-some@buerotiger.de-20100528145137-0pyil9qw7szyztsw
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#define UI_ICONGRID_H
22
22
 
23
23
#include "panel.h"
 
24
#include "textarea.h"
24
25
#include "m_signal.h"
25
26
 
26
 
#include "rgbcolor.h"
27
 
 
28
27
#include <vector>
29
28
 
30
29
namespace UI {
32
31
/**
33
32
 * Arranges clickable pictures of common size in a regular grid.
34
33
 *
35
 
 * Arrangement can be horizontal (pictures fill the grid from left to right, top
36
 
 * to bottom) or vertical (pictures fill the grid from top to bottom, then left
37
 
 * to right).
38
 
 *
39
 
 * An Icon_Grid can be persistant, which means that one of the pictures can be
40
 
 * the currently selected picture. This picture is highlighted all the time.
 
34
 * Arrangement is horizontal (pictures fill the grid from left to right, top to
 
35
 * bottom).
41
36
*/
42
37
struct Icon_Grid : public Panel {
43
 
        enum {
44
 
                Grid_Horizontal = 0,
45
 
                Grid_Vertical = 1,
46
 
                Grid_Orientation_Mask = 1,
47
 
 
48
 
                Grid_Persistant = 2,
49
 
        };
50
 
 
51
38
        Icon_Grid
52
39
                (Panel  * parent,
53
40
                 int32_t x, int32_t y, int32_t cellw, int32_t cellh,
54
 
                 uint32_t flags,
55
41
                 int32_t  cols);
56
42
 
57
43
        Signal1<int32_t> clicked;
58
44
        Signal1<int32_t> mouseout;
59
45
        Signal1<int32_t> mousein;
60
46
 
61
 
        bool is_persistant() const {return m_flags & Grid_Persistant;}
62
 
        uint32_t get_orientation() const {return m_flags & Grid_Orientation_Mask;}
63
 
 
64
47
        int32_t add
65
 
                (PictureID           picid,
 
48
                (std::string const & name,
 
49
                 PictureID           picid,
66
50
                 void              * data,
67
51
                 std::string const & descr = std::string());
68
52
        void * get_data(int32_t idx);
69
53
 
70
 
        void set_selection(int32_t idx);
71
 
        int32_t get_selection() const {return m_selected;}
72
 
 
73
 
        void set_selectbox_color(RGBColor clr);
74
 
 
75
 
protected:
76
 
        void draw(RenderTarget &);
77
 
 
78
 
        int32_t index_for_point(int32_t x, int32_t y);
79
 
        void get_cell_position(int32_t idx, uint32_t & px, uint32_t & py);
80
 
        void update_for_index(int32_t idx);
81
 
 
82
 
        void handle_mousein(bool inside);
83
 
        bool handle_mousemove
84
 
                (Uint8 state, int32_t x, int32_t y, int32_t xdiff, int32_t ydiff);
85
 
        bool handle_mousepress  (Uint8 btn, int32_t x, int32_t y);
86
 
        bool handle_mouserelease(Uint8 btn, int32_t x, int32_t y);
87
 
 
88
54
private:
 
55
        void clicked_button(uint32_t);
 
56
 
89
57
        struct Item {
90
 
                PictureID   picid;
91
58
                void      * data;
92
 
                std::string descr;
93
59
        };
94
60
 
95
 
        uint32_t   m_flags;
96
 
 
97
61
        /// max # of columns (or rows, depending on orientation) in the grid
98
62
        int32_t m_columns;
99
 
 
100
 
        ///currently highlight (mouseover) icon idx (-1 = no highlight)
101
 
        int32_t m_highlight;
102
 
 
103
 
        int32_t m_clicked; ///< icon that was clicked (only while LMB is down)
104
 
 
105
 
        ///currently selected (persistant) icon idx (-1 = no selection)
106
 
        int32_t m_selected;
107
 
 
108
 
        int32_t               m_cell_width; ///< size of one cell
109
 
        int32_t               m_cell_height;
110
 
        int32_t               m_font_height;
111
 
 
 
63
        int32_t m_cell_width; ///< size of one cell
 
64
        int32_t m_cell_height;
 
65
 
 
66
        Textarea * m_ta;
112
67
        std::vector<Item> m_items;
113
 
 
114
 
        RGBColor          m_selectbox_color;
115
68
};
116
69
 
117
70
}