MCPcopy Create free account
hub / github.com/davisking/dlib / draw_button

Method draw_button

dlib/gui_widgets/style.cpp:17–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15// ----------------------------------------------------------------------------------------
16
17 void button_style_default::draw_button (
18 const canvas& c,
19 const rectangle& rect,
20 const bool enabled,
21 const font& mfont,
22 const long ,
23 const long ,
24 const ustring& name,
25 const bool is_depressed
26 ) const
27 {
28 rectangle area = rect.intersect(c);
29 if (area.is_empty())
30 return;
31
32 fill_rect(c,rect,rgb_pixel(212,208,200));
33
34 unsigned char red, green, blue;
35 if (enabled)
36 {
37 red = 0;
38 green = 0;
39 blue = 0;
40 }
41 else
42 {
43 red = 128;
44 green = 128;
45 blue = 128;
46 }
47
48 // compute the name length if it hasn't already been computed
49 if (name_width == 0)
50 {
51 unsigned long height;
52 mfont.compute_size(name,name_width,height);
53 }
54
55 // figure out where the name string should appear
56 rectangle name_rect;
57 const unsigned long width = name_width;
58 const unsigned long height = mfont.height();
59 name_rect.set_left((rect.right() + rect.left() - width)/2);
60 name_rect.set_top((rect.bottom() + rect.top() - height)/2 + 1);
61 name_rect.set_right(name_rect.left()+width-1);
62 name_rect.set_bottom(name_rect.top()+height);
63
64
65 if (is_depressed)
66 {
67 name_rect.set_left(name_rect.left()+1);
68 name_rect.set_right(name_rect.right()+1);
69 name_rect.set_top(name_rect.top()+1);
70 name_rect.set_bottom(name_rect.bottom()+1);
71
72 mfont.draw_string(c,name_rect,name,rgb_pixel(red,green,blue));
73
74 draw_button_down(c,rect);

Callers 1

drawMethod · 0.80

Calls 15

rgb_pixelClass · 0.85
draw_button_downFunction · 0.85
draw_button_upFunction · 0.85
draw_rounded_rectangleFunction · 0.85
rgb_alpha_pixelClass · 0.85
fill_gradient_roundedFunction · 0.85
centered_rectFunction · 0.85
draw_imageFunction · 0.85
compute_sizeMethod · 0.80
set_leftMethod · 0.80
set_topMethod · 0.80
set_rightMethod · 0.80

Tested by

no test coverage detected