Esempio n. 1
0
void CL_Sprite_Impl::draw(CL_GraphicContext &gc, const CL_Rectf &src, const CL_Rectf &dest)
{
	SpriteFrame &frame = frames[current_frame];

	CL_Surface_DrawParams2 params2;
	params2.srcX = frame.position.left + src.left;
	params2.srcY = frame.position.top + src.top;
	params2.srcWidth = src.get_width();
	params2.srcHeight = src.get_height();
	params2.destX = dest.left;
	params2.destY = dest.top;
	params2.destZ = 1.0;
	params2.color = color;
	params2.scale_x = dest.get_width() / src.get_width();
	params2.scale_y = dest.get_height() / src.get_height();
	params2.translate_origin = translation_origin;
	params2.translate_x = translation_hotspot.x + frame.offset.x;
	params2.translate_y = translation_hotspot.y + frame.offset.y;
	params2.rotate_angle = angle - base_angle;
	params2.rotate_pitch = angle_pitch;
	params2.rotate_yaw = angle_yaw;
	params2.rotate_origin = rotation_origin;
	params2.rotate_x = rotation_hotspot.x + frame.offset.x;
	params2.rotate_y = rotation_hotspot.y + frame.offset.y;
	params2.sub_pixel_accuracy = true;
	draw(gc, params2);
}
Esempio n. 2
0
void ClipRectManager::clamp(const CL_Vec2f& topleftBase, const CL_Size& sizeBase) {
    if (forceRepaint_) {
        CL_Rectf rect(topleftBase.x, topleftBase.y, CL_Sizef(sizeBase.width, sizeBase.height));
        rectangles_.clear();
        rectangles_.push_back(rect);
    } else if (rectangles_.empty()) {
        return;
    }
    
    std::vector<CL_Rectf> clamped;
    
    CL_Rectf clampRect(topleftBase.x, topleftBase.y, CL_Sizef(sizeBase.width, sizeBase.height));
    
    std::vector<CL_Rectf>::iterator iter = rectangles_.begin();
    std::vector<CL_Rectf>::iterator end = rectangles_.end();
    
    for (; iter != end; ++iter) {
        if (clampRect.is_overlapped(*iter)) {
            
            bool addedWithExpand = false;
            CL_Rectf curClamped = iter->clip(clampRect);
            
            float curClampedArea = curClamped.get_width() * curClamped.get_height();
            
            // check for overlaps to keep number of rectangles as small as possible
            std::vector<CL_Rectf>::iterator mergeIter = clamped.begin();
            std::vector<CL_Rectf>::iterator mergeEnd = clamped.end();
            
            for (; mergeIter != mergeEnd; ++mergeIter) {
                if (mergeIter->is_overlapped(curClamped)) {
                    CL_Rectf bounding = CL_Rectf(*mergeIter).bounding_rect(curClamped);
                    CL_Rectf overlap = CL_Rectf(*mergeIter).overlap(curClamped);
                    
                    // area of the bounding rectangle should not be too big. keep the rects seperate if joining them does not give a significant advantage
                    float unnecessaryIncluded = 
                            (bounding.get_width() * bounding.get_height())
                            - (mergeIter->get_width() * mergeIter->get_height() + curClampedArea)
                            + (overlap.get_width() * overlap.get_height());
                            
                    if (unnecessaryIncluded <= curClampedArea * 3) {
                                
                        mergeIter->bounding_rect(curClamped);
                        addedWithExpand = true;
                        break;
                    }
                }
            }
            
            if (!addedWithExpand) {
                clamped.push_back(curClamped);
            }
        }
    }
    
    rectangles_ = clamped;
}
Esempio n. 3
0
void DrawRect(const CL_Rectf &r, uint32 color, float lineWidth)
{
	DrawRect(r.left, r.top, r.get_width(), r.get_height(), color, lineWidth);
}
Esempio n. 4
0
void DrawFilledRect(const CL_Rectf &r, uint32 color)
{
	GenerateFillRect(color, r.left, r.top, r.get_width(), r.get_height());
}
Esempio n. 5
0
CL_Vec2f RotateGUIPoint(CL_Vec2f vPos, CL_Rectf r, float angle, CL_Vec2f destRectSize)
{
#ifndef _CONSOLE

	if (destRectSize.x == 0 && destRectSize.y == 0)
	{
		//set to default, for compatibility with older stuff
		destRectSize = GetScreenSize();
	}
	CL_Vec2f destSize = destRectSize;

	assert(angle >=0 && angle < 360);
	if (angle == 90 || angle == 270) 
	{
		swap(destSize.x, destSize.y);
	}

	switch (int(angle))
	{

	case 0:
		break;

	case 180:
		vPos.y = destSize.y-vPos.y;
		vPos.x = destSize.x-vPos.x;
		break;

	case 270:
		swap(vPos.x, vPos.y);
		vPos.y = destSize.y-vPos.y;
		break;

	case 90:
		vPos.y = destSize.x-vPos.y;
		swap(vPos.x, vPos.y);
		break;

	}

	float xRatio = r.get_width()/ destRectSize.x;
	float yRatio = r.get_height()/ destRectSize.y;

	if (destSize.x != GetScreenSizeXf())
	{
		//need to apply a new aspect ratio
		yRatio *= (destSize.x / destRectSize.x);
		xRatio *= (destSize.y / destRectSize.y);
	} 


	//shrink it to its real screen size
	vPos.x *= xRatio;
	vPos.y *= yRatio;

	//move it the offset required
	vPos.x += r.left;
	vPos.y += r.top;

	return vPos;
#else
	assert(!"Can't use this in console mode, there is no concept of a screen");
	return CL_Vec2f(0,0);
#endif
}
void CL_Button_Silver::on_paint()
{
	int text_width = 0;
	int text_height = 0;

	if(font)
	{
		text_width = font->get_width(button->get_text().c_str());
		text_height = font->get_height();
	}

	CL_Rectf rect = button->get_screen_rect();

	int font_xpos = static_cast<int>(rect.left + (rect.right - rect.left - text_width) / 2);
	int font_ypos = static_cast<int>(rect.top + (rect.bottom - rect.top - text_height) / 2);

	if(button->is_enabled() == false)
	{
		if(draw_only_surfaces == false || sur_disabled == NULL)
		{
			CL_Display::draw_rect(rect, CL_Color(203, 209, 216));
		}
		if(sur_disabled)
		{
			sur_disabled->draw(rect.left + (rect.get_width() - sur_disabled->get_width()) / 2, rect.top + (rect.get_height() - sur_disabled->get_height()) / 2);
		}

		if(font_disabled)
		{
			font_disabled->draw(font_xpos, font_ypos, button->get_text());
		}
		else if(font)
		{
			font->draw(font_xpos, font_ypos, button->get_text());
		}
	}
	else 
	{
		if(button->is_drawn_down())
		{
			if(draw_only_surfaces == false || sur_down == NULL)
			{
				// Main border
				CL_Display::draw_rect(
					rect, 
					CL_Color(128, 142, 159));

				// Dark inner border
				CL_Display::draw_rect(
					CL_Rectf(rect.left + 1, rect.top + 1, rect.right - 1, rect.bottom - 1),
					CL_Color(73, 94, 120));

				// Outer gradient
				CL_Display::fill_rect(
					CL_Rectf(rect.left + 2, rect.top + 2, rect.right - 1, rect.bottom - 1),
					CL_Gradient(CL_Color::white, CL_Color::white, CL_Color(230, 235, 240), CL_Color(230, 235, 240)));

				// Inner fill
				CL_Display::fill_rect(
					CL_Rectf(rect.left + 4, rect.top + 4, rect.right - 1, rect.bottom - 1),
					CL_Color(240, 242, 244));
			}

			if(sur_down)
			{
				sur_down->draw(rect.left + (rect.get_width() - sur_down->get_width()) / 2, rect.top + (rect.get_height() - sur_down->get_height()) / 2);
			}

			if(font)
			{
				font->draw(font_xpos + 1, font_ypos + 1, button->get_text());
			}
		}
		else
		{
			bool need_highlight = false;
			if (button->has_mouse_over())
			{
				if (!button->get_gui_manager() || (!button->get_gui_manager()->get_modal_component() ||	button->has_modal_parent()))
				{
					need_highlight = true;
				}
			}

			CL_Surface *sur = NULL;
			if(sur_highlighted && need_highlight)
			{
				sur = sur_highlighted;
			}
			else if(sur_up)
			{
				sur = sur_up;
			}

			if(draw_only_surfaces == false || sur == NULL)
			{
				// Highlight
				if(need_highlight)
				{
					// Main border
					CL_Display::draw_rect(
						rect, 
						CL_Color(209, 149, 32));

					// Highlight
					CL_Display::draw_rect(
						CL_Rectf(rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1),
						CL_Color(250, 236, 204));

					// Outer gradient
					CL_Display::fill_rect(
						CL_Rectf(rect.left + 1, rect.top + 1, rect.right - 1, rect.bottom - 1),
						CL_Gradient(CL_Color::white, CL_Color::white, CL_Color(230, 235, 240), CL_Color(230, 235, 240)));

					// Inner fill
					CL_Display::fill_rect(
						CL_Rectf(rect.left + 3, rect.top + 3, rect.right - 3, rect.bottom - 3),
						CL_Color(240, 242, 244));
				}
				// Focus
				else if(button->has_focus())
				{
					// Main border
					CL_Display::draw_rect(
						rect, 
						CL_Color(119, 138, 187));

					// Highlight
					CL_Display::draw_rect(
						CL_Rectf(rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1),
						CL_Color(206, 220, 233));

					// Outer gradient
					CL_Display::fill_rect(
						CL_Rectf(rect.left + 1, rect.top + 1, rect.right - 1, rect.bottom - 1),
						CL_Gradient(CL_Color::white, CL_Color::white, CL_Color(230, 235, 240), CL_Color(230, 235, 240)));

					// Inner fill
					CL_Display::fill_rect(
						CL_Rectf(rect.left + 3, rect.top + 3, rect.right - 3, rect.bottom - 3),
						CL_Color(240, 242, 244));
				}
				// Normal
				else
				{
					// Main border
					CL_Display::draw_rect(
						rect, 
						CL_Color(128, 142, 159));

					// Outer gradient
					CL_Display::fill_rect(
						CL_Rectf(rect.left + 1, rect.top + 1, rect.right - 1, rect.bottom - 1),
						CL_Gradient(CL_Color::white, CL_Color::white, CL_Color(230, 235, 240), CL_Color(230, 235, 240)));

					// Inner fill
					CL_Display::fill_rect(
						CL_Rectf(rect.left + 3, rect.top + 3, rect.right - 3, rect.bottom - 3),
						CL_Color(240, 242, 244));
				}
			}

			if(sur)
			{
				sur->draw(rect.left + (rect.get_width() - sur->get_width()) / 2, rect.top + (rect.get_height() - sur->get_height()) / 2);
			}

			if(font)
			{
				font->draw(font_xpos, font_ypos, button->get_text());
			}
		}
	}
}