File: treeview_item_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 (62 lines) | stat: -rw-r--r-- 1,766 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
/*
	$Id: treeview_item_default.cpp,v 1.5 2002/01/16 19:43:06 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 "API/Display/Font/font.h"
#include "treeview_item_default.h"
#include "stylemanager_default_generic.h"

/////////////////////////////////////////////////////////////////////////////
// Construction:

CL_TreeView_Item_Default::CL_TreeView_Item_Default(
	CL_TreeView_Item *treeview_item,
	CL_StyleManager_Default *style)
: CL_ComponentStyle(treeview_item), item(treeview_item)
{
	this->style = style;
	
	resources = style->get_resources();
	font = CL_Font::load("TreeViewItem/font", resources);
		
	slot_paint = item->sig_paint().connect(
		this, &CL_TreeView_Item_Default::on_paint);
	slot_get_preferred_size = item->sig_get_preferred_size().connect(
		this, &CL_TreeView_Item_Default::on_get_preferred_size);
}

CL_TreeView_Item_Default::~CL_TreeView_Item_Default()
{
	delete font;
}

/////////////////////////////////////////////////////////////////////////////
// Callbacks:

void CL_TreeView_Item_Default::on_get_preferred_size(CL_Point &size)
{
	size.x = font->get_text_width(item->get_text()) + 8;
	size.y = font->get_height();
}

void CL_TreeView_Item_Default::on_paint()
{
	int height = item->get_height();
	int width = item->get_width();
	
	if(item->is_highlighted())
		style->fill_rect(0, 0, width, height, GUICOLOR_SELECTION);
	else
		style->fill_rect(0, 0, width, height, GUICOLOR_WINDOW_NORMAL);

	int font_height = font->get_height();
	font->print_left(4, (height - font_height) / 2, item->get_text().c_str());
}