File: frame_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 (92 lines) | stat: -rw-r--r-- 2,196 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
/*
	$Id: frame_default.cpp,v 1.35 2002/01/16 18:58:13 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 "frame_default.h"

CL_Frame_Default::CL_Frame_Default(
	CL_Frame *_frame,
	CL_StyleManager_Default *style) 
: CL_ComponentStyle(_frame), frame(_frame)
{
	this->style = style;

	resources = style->get_resources();
	sur_surface = NULL;
	mode = tile;

	slot_set_options = frame->sig_set_options().connect(
		this, &CL_Frame_Default::on_set_options);
	slot_paint = frame->sig_paint().connect(
		this, &CL_Frame_Default::on_paint);
}

CL_Frame_Default::~CL_Frame_Default()
{
	if(sur_surface)
		delete sur_surface;
}

void CL_Frame_Default::on_set_options(const CL_ComponentOptions &options)
{
	if(options.exists("surface"))
	{
		std::string surface = options.get_value("surface");
		sur_surface = CL_Surface::load(surface.c_str(), resources);
	}
	
	if (options.exists("mode"))
	{
		std::string v = options.get_value("mode");
		
		if (v == "center") mode = center;
		else if (v == "stretch") mode = stretch;
		else if (v == "tile") mode = tile;
		else throw CL_Error("unknown frame mode");
	}
}

void CL_Frame_Default::on_paint()
{
	int width = frame->get_width();
	int height = frame->get_height();

	if (sur_surface)
	{
		switch (mode)
		{
		case center:
			sur_surface->put_screen(
				width / 2 - sur_surface->get_width() / 2,
				height / 2 - sur_surface->get_height() / 2);
			break;
			
		case stretch:
			sur_surface->put_screen(0, 0, width, height);
			break;

		case tile:
			{
			for (int y = 0; y < height; y += sur_surface->get_height())
				for (int x = 0; x < width; x += sur_surface->get_width())
					sur_surface->put_screen(x, y);
			}
		}
	}
	else
	{
		style->draw_box(0, 0, width, height, GUICOLOR_DARK_SHADE, GUICOLOR_BRIGHT_SHADE);
		if(frame->is_fill_enabled())
			style->fill_rect(1, 1, width - 1, height -1, GUICOLOR_MEDIUM_SHADE);
	}
}