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

Method draw_toggle_button

dlib/gui_widgets/style.cpp:409–476  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

407// ----------------------------------------------------------------------------------------
408
409 void toggle_button_style_default::draw_toggle_button (
410 const canvas& c,
411 const rectangle& rect,
412 const bool enabled,
413 const font& mfont,
414 const long ,
415 const long ,
416 const ustring& name,
417 const bool is_depressed,
418 const bool is_checked
419 ) const
420 {
421 rectangle area = rect.intersect(c);
422 if (area.is_empty())
423 return;
424
425 fill_rect(c,rect,rgb_pixel(212,208,200));
426
427 unsigned char red, green, blue;
428 if (enabled)
429 {
430 red = 0;
431 green = 0;
432 blue = 0;
433 }
434 else
435 {
436 red = 128;
437 green = 128;
438 blue = 128;
439 }
440
441 // compute the name length if it hasn't already been computed
442 if (name_width == 0)
443 {
444 unsigned long height;
445 mfont.compute_size(name,name_width,height);
446 }
447
448 // figure out where the name string should appear
449 rectangle name_rect;
450 const unsigned long width = name_width;
451 const unsigned long height = mfont.height();
452 name_rect.set_left((rect.right() + rect.left() - width)/2);
453 name_rect.set_top((rect.bottom() + rect.top() - height)/2 + 1);
454 name_rect.set_right(name_rect.left()+width-1);
455 name_rect.set_bottom(name_rect.top()+height);
456
457 long d = 0;
458 if (is_checked)
459 d = 1;
460
461 if (is_depressed)
462 d = 2;
463
464 name_rect.set_left(name_rect.left()+d);
465 name_rect.set_right(name_rect.right()+d);
466 name_rect.set_top(name_rect.top()+d);

Callers 1

drawMethod · 0.80

Calls 15

rgb_pixelClass · 0.85
draw_button_downFunction · 0.85
draw_button_upFunction · 0.85
draw_sunken_rectangleFunction · 0.85
draw_pixelFunction · 0.85
compute_sizeMethod · 0.80
set_leftMethod · 0.80
set_topMethod · 0.80
set_rightMethod · 0.80
set_bottomMethod · 0.80
draw_stringMethod · 0.80
fill_rectFunction · 0.70

Tested by

no test coverage detected