00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "precomp.h"
00010 #include <stdio.h>
00011 #include "API/Display/Display/surface.h"
00012 #include "API/Core/Resources/resource_manager.h"
00013 #include "frame_default.h"
00014
00015 CL_Frame_Default::CL_Frame_Default(
00016 CL_Frame *_frame,
00017 const CL_ComponentOptions &options,
00018 CL_StyleManager_Default *style)
00019 : CL_ComponentStyle(_frame), frame(_frame)
00020 {
00021 this->style = style;
00022
00023 resources = style->get_resources();
00024 sur_surface = NULL;
00025 mode = tile;
00026
00027 if(options.exists("surface"))
00028 {
00029 surface = options.get_value("surface");
00030 sur_surface = CL_Surface::load(surface.c_str(), resources);
00031 }
00032
00033 if (options.exists("mode"))
00034 {
00035 std::string v = options.get_value("mode");
00036
00037 if (v == "center") mode = center;
00038 else if (v == "stretch") mode = stretch;
00039 else if (v == "tile") mode = tile;
00040 else throw CL_Error("unknown frame mode");
00041 }
00042
00043 slot_paint = frame->sig_paint().connect(CL_CreateSlot(this, &CL_Frame_Default::on_paint));
00044 }
00045
00046 CL_Frame_Default::~CL_Frame_Default()
00047 {
00048
00049
00050 }
00051
00052 void CL_Frame_Default::on_paint()
00053 {
00054 int width = frame->get_width();
00055 int height = frame->get_height();
00056
00057 if (sur_surface)
00058 {
00059 switch (mode)
00060 {
00061 case center:
00062 sur_surface->put_screen(
00063 width / 2 - sur_surface->get_width() / 2,
00064 height / 2 - sur_surface->get_height() / 2);
00065 break;
00066
00067 case stretch:
00068 sur_surface->put_screen(0, 0, width, height);
00069 break;
00070
00071 case tile:
00072 {
00073 for (int y = 0; y < height; y += sur_surface->get_height())
00074 for (int x = 0; x < width; x += sur_surface->get_width())
00075 sur_surface->put_screen(x, y);
00076 }
00077 }
00078 }
00079 else
00080 {
00081 style->draw_box(0, 0, width, height, GUICOLOR_DARK_SHADE, GUICOLOR_BRIGHT_SHADE);
00082
00083 }
00084 }