File: checkbox_default.cpp

package info (click to toggle)
clanlib 0.5.4-1-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 10,320 kB
  • ctags: 10,893
  • sloc: cpp: 76,056; xml: 3,281; sh: 2,961; perl: 1,204; asm: 837; makefile: 775
file content (81 lines) | stat: -rw-r--r-- 2,371 bytes parent folder | download
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
/*
	$Id: checkbox_default.cpp,v 1.27 2002/01/17 14:38:44 sphair Exp $
	
	ClanGUI, copyrights by various people. Have a look in the CREDITS file.
	
	This sourcecode is distributed using the Library GNU Public Licence,
	version 2 or (at your option) any later version. Please read LICENSE
	for details.
*/

#include "precomp.h"
#include <cstdio>
#include "API/Display/Display/surface.h"
#include "API/Core/Resources/resource_manager.h"
#include "API/Display/Font/font.h"
#include "checkbox_default.h"

CL_CheckBox_Default::CL_CheckBox_Default(
	CL_CheckBox *checkbox,
	CL_StyleManager_Default *style)
: CL_ComponentStyle(checkbox), checkbox(checkbox), style(style)
{
	resources = style->get_resources();

	sur_checked = CL_Surface::load("CheckBox/sur_checked", resources);
	sur_unchecked = CL_Surface::load("CheckBox/sur_unchecked", resources);
	sur_disabled = CL_Surface::load("CheckBox/sur_disabled", resources);
	font = CL_Font::load("CheckBox/font", resources);

	slot_paint = checkbox->sig_paint().connect_virtual(
		this, &CL_CheckBox_Default::on_paint);

	slot_get_preferred_size = checkbox->sig_get_preferred_size().connect(
		this, &CL_CheckBox_Default::on_get_preferred_size);

/*	int width = sur_checked->get_width();
	int height = sur_checked->get_height();
	if (checkbox->get_text().length() > 0)
		width += 4 + font->get_text_width(checkbox->get_text().c_str());
	checkbox->set_width(width);
	checkbox->set_height(height);
*/
}

CL_CheckBox_Default::~CL_CheckBox_Default()
{
	delete font;
	delete sur_checked;
	delete sur_unchecked;
	delete sur_disabled;
}

void CL_CheckBox_Default::on_get_preferred_size(CL_Point &size)
{
	CL_Surface *s = sur_checked;
	size.x = s->get_width() + font->get_text_width(checkbox->get_text()) + 8;
	size.y = font->get_height() + 4;
	if(size.y < s->get_height())
		size.y = s->get_height();
}

void CL_CheckBox_Default::on_paint(CL_SlotParent_v0 &super)
{
	CL_Surface *show_surface = sur_disabled;

	if (checkbox->is_enabled())
	{
		if (checkbox->is_checked())
			show_surface = sur_checked;
		else
			show_surface = sur_unchecked;

		// Focus
		if(checkbox->has_focus())
			style->fill_rect(0, 0, checkbox->get_width(), show_surface->get_height(), GUICOLOR_FOCUS);
	}

	show_surface->put_screen(0, 0);
	if (checkbox->get_text().length() > 0)
		font->print_left(4 + show_surface->get_width(), 0, checkbox->get_text().c_str());
}