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
|
#include <ClanLib/display.h>
#include <ClanLib/gl.h>
#include "checkbox_opengl.h"
#include "stylemanager_opengl.h"
CL_CheckBox_OpenGL::CL_CheckBox_OpenGL(
CL_CheckBox *checkbox,
CL_StyleManager_OpenGL *style)
:
CL_ComponentStyle(checkbox),
style(style),
checkbox(checkbox)
{
resources = style->get_resources();
font = CL_Font::load("CheckBox/font", resources);
surface_left = new CL_Surface("CheckBox/left", resources);
surface_right = new CL_Surface("CheckBox/right", resources);
surface_ticker = new CL_Surface("CheckBox/ticker", resources);
slot_paint = checkbox->sig_paint().connect_virtual(
this, &CL_CheckBox_OpenGL::on_paint);
slot_get_preferred_size = checkbox->sig_get_preferred_size().connect(
this, &CL_CheckBox_OpenGL::on_get_preferred_size);
}
CL_CheckBox_OpenGL::~CL_CheckBox_OpenGL()
{
}
void CL_CheckBox_OpenGL::on_get_preferred_size(CL_Point &size)
{
size.x = font->get_text_width(checkbox->get_text()) + 28;
size.y = 35;
}
void CL_CheckBox_OpenGL::on_paint(CL_SlotParent_v0 &super)
{
surface_left->put_screen(0, 0);
surface_right->put_screen(16, 0);
int checkbox_width = checkbox->get_width();
int checkbox_height = checkbox->get_height();
if(checkbox->is_down())
surface_ticker->put_screen(-3, -10);
int x_pos = 28;
int text_height = font->get_height();
int y_pos = (checkbox_height - text_height) / 2 - 4;
font->print_left(x_pos, y_pos, checkbox->get_text().c_str());
}
|