File: label.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 (104 lines) | stat: -rw-r--r-- 2,019 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
	$Id: label.cpp,v 1.42 2002/01/16 19:02:12 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/GUI/label.h"
#include "API/GUI/component_options.h"
#include "API/GUI/stylemanager.h"
#include "label_generic.h"
#include "component_generic.h"

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

CL_Label::CL_Label(
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Component(parent, style), impl(NULL)
{
	init("");
}

CL_Label::CL_Label(
	const CL_Point &pos,
	const std::string &text,
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Component(CL_Rect(pos.x, pos.y), parent, style), impl(NULL)
{
	init(text);
	find_preferred_size();
}

CL_Label::CL_Label(
	const CL_Rect &pos,
	const std::string &text,
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Component(pos, parent, style), impl(NULL)
{
	init(text);
}

void CL_Label::init(const std::string &text)
{
	impl = new CL_Label_Generic(this, text);
	get_style_manager()->connect_styles("label", this);
}

CL_Label::~CL_Label()
{
	delete impl;
}

/////////////////////////////////////////////////////////////////////////////
// Attributes:

const std::string &CL_Label::get_text() const
{
	return impl->text;
}

int CL_Label::get_alignment() const
{
	return impl->alignment;
}

/////////////////////////////////////////////////////////////////////////////
// Operations:

void CL_Label::set_text(const std::string &text)
{
	impl->text = text;
}

void CL_Label::set_text(int number)
{
	char buf[20];
	sprintf(buf, "%d", number);
	impl->text = buf;
}

void CL_Label::set_text(double number)
{
	char buf[20];
	sprintf(buf, "%f", number);
	impl->text = buf;
}

void CL_Label::clear()
{
	impl->text = "";
}

void CL_Label::set_alignment(int alignment)
{
	impl->alignment = alignment;
}