File: progressbar_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 (50 lines) | stat: -rw-r--r-- 1,405 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
/*
	$Id: progressbar_default.cpp,v 1.8 2001/12/28 00:04:31 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 "progressbar_default.h"
#include "button_default.h"
#include "API/Display/Display/surface.h"
#include "API/Core/Resources/resource_manager.h"

CL_ProgressBar_Default::CL_ProgressBar_Default(
	CL_ProgressBar *_progressbar,
	CL_StyleManager_Default *style)
:
	CL_ComponentStyle(_progressbar),
	progressbar(_progressbar)
{
	this->style = style;

	slot_paint = progressbar->sig_paint().connect(
		this, &CL_ProgressBar_Default::on_paint);
}

void CL_ProgressBar_Default::on_paint()
{
	int width = progressbar->get_width();
	int height = progressbar->get_height();
	float percent = progressbar->get_percentage();

	// Outline
	style->draw_rect(0, 0, width, height, GUICOLOR_DARK_OUTLINE);

	// Shade box
	style->draw_box(1, 1, width - 1 , height - 1, GUICOLOR_DARK_SHADE, GUICOLOR_BRIGHT_SHADE);

	// Fill
	int length = (int) ((width - 4) * percent);

	style->fill_rect(2, 2, 2 + length, height - 2, GUICOLOR_PROGRESSBAR_FILLED);
	style->fill_rect(2 + length, 2, width - 2, height - 2, GUICOLOR_PROGRESSBAR);

	// TODO: Write percentage in text
//	font->print_left(...);
}