예제 #1
0
void CL_Sprite_Impl::draw(CL_GraphicContext &gc, const CL_Rectf &dest)
{
	SpriteFrame &frame = frames[current_frame];

	CL_Surface_DrawParams2 params2;
	params2.srcX = frame.position.left;
	params2.srcY = frame.position.top;
	params2.srcWidth = frame.position.get_width();
	params2.srcHeight = frame.position.get_height();
	params2.destX = dest.left;
	params2.destY = dest.top;
	params2.destZ = 1.0;
	params2.color = color;
	params2.scale_x = dest.get_width()/float(frame.position.get_width());
	params2.scale_y = dest.get_height()/float(frame.position.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);
}
예제 #2
0
ObjMapObject
ObjectLayer::find_object(const CL_Pointf& click_pos)
{
  for(Objects::reverse_iterator i = impl->objects.rbegin(); i != impl->objects.rend(); ++i)
  {
    CL_Rectf rect = (*i).get_bound_rect();

    if (rect.is_inside(CL_Point(click_pos)))
      return *i;
  }
  return ObjMapObject();
}
예제 #3
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;
}
예제 #4
0
CL_Rectf RotateGUIRect(CL_Rectf vRect, CL_Rectf inputRect, float angle, CL_Vec2f destRectSize)
{
	CL_Vec2f vTopLeft =  RotateGUIPoint(vRect.get_top_left(), inputRect, angle, destRectSize);
	CL_Vec2f vBottomRight =  RotateGUIPoint(vRect.get_bottom_right(), inputRect, angle, destRectSize);

	if (angle == 90 ||angle == 270)
	{
		swap(vTopLeft.y, vBottomRight.y);
	}

    CL_Vec2f vTemp = vBottomRight-vTopLeft;
    
	return CL_Rectf(vTopLeft, *(CL_Sizef*)&(vTemp));
}
예제 #5
0
void DialogScene::render()
{
	Renderer::Ref renderer = m_manager->getRenderer();
	CL_Sizef window = renderer->getGCSize();

	// render underlying scene:
	m_topScene->render();

	// fade out a little:
	CL_Rectf rcShadow = m_rcBub; rcShadow.translate(CL_Pointf(5.0f, 5.0f));
	CL_Colorf bubColor = blendColors(getPhraseColor(m_newtype), getPhraseColor(m_oldtype), m_percent);

	CL_Draw::fill(renderer->getGC(), rcShadow, CL_Colorf::black);
	CL_Draw::fill(renderer->getGC(), m_rcBub, bubColor);

	m_layout.draw_layout(renderer->getGC());
}
예제 #6
0
ObjectLayer::Objects
ObjectLayer::get_selection(const CL_Rectf& rect)
{
  Objects selection;

  for(Objects::iterator i = impl->objects.begin(); i != impl->objects.end(); ++i)
  {
    // FIXME:
    if (rect.is_inside((*i).get_pos()))
    {
      selection.push_back(*i);
    }
  }

  return selection;
}
예제 #7
0
void DrawRect(const CL_Rectf &r, uint32 color, float lineWidth)
{
	DrawRect(r.left, r.top, r.get_width(), r.get_height(), color, lineWidth);
}
예제 #8
0
void DrawFilledRect(const CL_Rectf &r, uint32 color)
{
	GenerateFillRect(color, r.left, r.top, r.get_width(), r.get_height());
}
예제 #9
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
}
예제 #10
0
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());
			}
		}
	}
}