diff options
Diffstat (limited to 'src/lib/FL/Fl_Image_Button.cxx')
-rw-r--r-- | src/lib/FL/Fl_Image_Button.cxx | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/lib/FL/Fl_Image_Button.cxx b/src/lib/FL/Fl_Image_Button.cxx new file mode 100644 index 0000000..f169396 --- /dev/null +++ b/src/lib/FL/Fl_Image_Button.cxx | |||
@@ -0,0 +1,110 @@ | |||
1 | #include <FL/Fl_Image_Button.H> | ||
2 | #include <FL/Fl_Image.H> | ||
3 | #include <FL/fl_draw.H> | ||
4 | #ifndef NULL | ||
5 | #define NULL 0 | ||
6 | #endif | ||
7 | void Fl_Image_Button::up_image(Fl_Image* p_upimage) | ||
8 | { | ||
9 | upimage=p_upimage; | ||
10 | } | ||
11 | |||
12 | void Fl_Image_Button::down_image(Fl_Image* p_downimage) | ||
13 | { | ||
14 | downimage=p_downimage; | ||
15 | } | ||
16 | |||
17 | Fl_Image* Fl_Image_Button::up_image() | ||
18 | { | ||
19 | return upimage; | ||
20 | } | ||
21 | |||
22 | Fl_Image* Fl_Image_Button::down_image() | ||
23 | { | ||
24 | return downimage; | ||
25 | } | ||
26 | |||
27 | Fl_Image_Button::Fl_Image_Button(int a,int b,int c,int d,const char* e):Fl_Button(a,b,c,d,e) | ||
28 | { | ||
29 | upimage=NULL; | ||
30 | downimage=NULL; | ||
31 | Fl_Button::clear_visible_focus(); | ||
32 | } | ||
33 | Fl_Image_Button::Fl_Image_Button(int a,int b,int c,int d):Fl_Button(a,b,c,d) | ||
34 | { | ||
35 | upimage=NULL; | ||
36 | downimage=NULL; | ||
37 | Fl_Button::clear_visible_focus(); | ||
38 | } | ||
39 | |||
40 | /*void Fl_Image_Button::draw() { | ||
41 | if (value()==0) | ||
42 | { | ||
43 | if (upimage!=NULL) { | ||
44 | this->image(upimage); | ||
45 | } | ||
46 | } else { | ||
47 | if (this->value()==1) | ||
48 | { | ||
49 | if (downimage!=NULL) { | ||
50 | this->image(downimage); | ||
51 | } | ||
52 | } | ||
53 | } | ||
54 | Fl_Button::draw(); | ||
55 | } | ||
56 | |||
57 | */ | ||
58 | |||
59 | |||
60 | void Fl_Image_Button::draw() | ||
61 | { | ||
62 | // begin - Fl_Button::draw() (box section) | ||
63 | if (type() == FL_HIDDEN_BUTTON) return; | ||
64 | Fl_Color col = value() ? selection_color() : color(); | ||
65 | |||
66 | |||
67 | draw_box(value() ? (down_box()?down_box():fl_down(box())) : box(), col); | ||
68 | // end - Fl_Button::draw() (box section) | ||
69 | |||
70 | // begin - modification to render up/down image | ||
71 | Fl_Boxtype box_; | ||
72 | Fl_Image* pic_; | ||
73 | |||
74 | if(value()) | ||
75 | { | ||
76 | box_ = (down_box())? down_box() : fl_down(box()); | ||
77 | pic_ = downimage; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | box_ = box(); | ||
82 | pic_ = upimage; | ||
83 | } | ||
84 | |||
85 | if(pic_) | ||
86 | { | ||
87 | int xx = x() + Fl::box_dx(box_); | ||
88 | int yy = y() + Fl::box_dy(box_); | ||
89 | int ww = w() - Fl::box_dw(box_); | ||
90 | int hh = h() - Fl::box_dh(box_); | ||
91 | int xpos = (ww - pic_->w()) / 2; | ||
92 | int ypos = (hh - pic_->h()) / 2; | ||
93 | |||
94 | fl_push_clip(xx, yy, ww, hh); | ||
95 | pic_->draw(xx + xpos, yy + ypos); | ||
96 | fl_pop_clip(); | ||
97 | } | ||
98 | // end- modification to render up/down image | ||
99 | |||
100 | // begin - Fl_Button::draw() (label section) | ||
101 | if (labeltype() == FL_NORMAL_LABEL && value()) { | ||
102 | Fl_Color c = labelcolor(); | ||
103 | labelcolor(fl_contrast(c, col)); | ||
104 | draw_label(); | ||
105 | labelcolor(c); | ||
106 | } else draw_label(); | ||
107 | if (Fl::focus() == this) draw_focus(); | ||
108 | // end - Fl_Button::draw() (label section) | ||
109 | } | ||
110 | |||