CL_Rectf ObjMapSpriteObjectImpl::get_bound_rect() const { CL_Point align = CL_Point(0, 0); CL_Origin origin_e; sprite.get_alignment(origin_e, align.x, align.y); CL_Point origin = calc_origin(origin_e, CL_Size(sprite.get_width(), sprite.get_height())); align.x = -align.x; // FIXME: This looks a bit hacky float scale_x, scale_y; sprite.get_scale(scale_x, scale_y); if (scale_x < 0) align.x += sprite.get_width(); if (scale_y < 0) align.y += sprite.get_height(); // if (scale_x > 1.0f && scale_y > 1.0f) // return CL_Rectf(pos - origin - align, // CL_Sizef(sprite.get_width() * scale_x, sprite.get_height() * scale_y)); // else return CL_Rectf(pos - origin - align, CL_Sizef(sprite.get_width(), sprite.get_height())); }
// verkleinertes Sprite an Ziel-Position zeichnen void Character::drawTarget(CL_Sprite& sprite) { CL_Pointf position = world->getLevel().getCoordinates(targetField); sprite.set_scale(0.5f, 0.5f); sprite.draw(world->get_gc(), position.x - sprite.get_width() / 4, position.y - sprite.get_height() / 4); sprite.set_scale(1.0f, 1.0f); }
void CL_ListViewIcon::draw(CL_GraphicContext &gc, const CL_Rect &rect, CL_ListViewDisplayMode mode, const CL_Colorf &color) { CL_Sprite sp = get_sprite(mode); if (!sp.is_null()) { float scale = 1.0; sp.set_color(color); // if (mode == listview_mode_thumbnails && sp.get_frame_size(0) != rect.get_size()) if (impl->scalable && (sp.get_frame_size(0) != rect.get_size())) { // Scale to max vertically or horizontally. float sx, sy; sx = rect.get_width()/float(sp.get_width()); sy = rect.get_height()/(float)sp.get_height(); if (sx <= 0 || sy <= 0) { return; } scale = cl_min(sx, sy); sp.set_scale(scale,scale); } CL_Rect R = rect; CL_Point offset = get_offset(mode); R.translate(offset); if (!impl->scalable && offset == CL_Point(0,0)) { // center in cell rect. int center_offset_x = int((float)rect.get_center().x - (float)rect.left - scale*(float)sp.get_width()/2.0); int center_offset_y = int((float)rect.get_center().y - (float)rect.top - scale*(float)sp.get_height()/2.0); R.left += center_offset_x; R.top += center_offset_y; } if (!impl->scalable) sp.draw(gc, (float)R.left, (float)R.top); else sp.draw(gc, R); return; } CL_PixelBuffer pb = get_pixel_buffer(mode); if (!pb.is_null()) { float scale = 1.0; float center_offset_x = 0, center_offset_y = 0; // if (mode == listview_mode_thumbnails && pb.get_size() != rect.get_size()) if (impl->scalable && (pb.get_size() != rect.get_size())) { float sx = 1.0, sy = 1.0; // Scale to max vertically or horizontally. sx = rect.get_width()/float(pb.get_width()); sy = rect.get_height()/(float)pb.get_height(); if (sx <= 0 || sy <= 0) { return; } scale = cl_min(sx, sy); // center in the rect. center_offset_x = (float)rect.get_center().x - (float)rect.left - scale*(float)pb.get_width()/2.0f; center_offset_y = (float)rect.get_center().y - (float)rect.top - scale*(float)pb.get_height()/2.0f; } CL_Point offset = get_offset(mode); gc.draw_pixels(rect.left + center_offset_x + offset.x, rect.top + center_offset_y + offset.y, scale, scale, pb, pb.get_size(), color); } }
// Sprite an aktueller Position zeichnen void Character::drawSprite(CL_Sprite& sprite) { sprite.draw(world->get_gc(), position.x - sprite.get_width() / 2, position.y - sprite.get_height() / 2); }