GUI九宫格的原理是怎么实现的,当缩放时他是如何工作的?


最好有图文和代码的说明。。本人比较菜。。
(注:一般用于客户端的图片背景,非游戏九宫格)

GUI开发 VC as3

三山五岳丸 11 years, 12 months ago

同意 @胡加杰 所描述的。
九宫格示意图

但需要补充一下,当发生大小变换时,一般为了效率和图片质量考虑,都把缩放模式改为平铺。

这是一些示例代码。你可以参考一下

   
  int width_top_left = imagetl_->GetWidth();
  
int width_top_right = imagetr_->GetWidth();
int height_top_left = imagetl_->GetHeight();
int height_top_right = imagetr_->GetHeight();

int width_bottom_left = imagebl_->GetWidth();
int width_bottom_right = imagebr_->GetWidth();
int height_bottom_left = imagebl_->GetHeight();
int height_bottom_right = imagebr_->GetHeight();

int width_left = imagel_->GetWidth();
int width_right = imager_->GetWidth();
int height_top = imaget_->GetHeight();
int height_bottom = imageb_->GetHeight();

int width_center = imagec_->GetWidth();
int height_center = imagec_->GetHeight();

//绘制中间
for(int left = width_left; left < client.right - width_right; left += width_center)
{
for(int top = height_top; top < client.bottom - height_bottom; top += height_center)
{
imagec_->Draw(dc, left, top);
}
}

//绘制上方
int top_width = imaget_->GetWidth();
for(int left = width_top_left; left < client.right - width_top_right; left += top_width)
imaget_->Draw(dc, left, 0);

//绘制下方
int bottom_width = imageb_->GetWidth();
for(int left = width_bottom_left; left < client.right - width_bottom_right; left += bottom_width)
imageb_->Draw(dc, left, client.bottom - height_bottom);

//绘制左方
imagel_->Draw(dc, 0, height_top_left, width_left, client.bottom - height_top_left - height_bottom_left);

//绘制右方
imager_->Draw(dc, client.right - width_right, height_top_right, width_right, client.bottom - height_top_right - height_bottom_right);

//绘制四个角的图片
imagetl_->Draw(dc, 0, 0);
imagetr_->Draw(dc, client.right - width_top_right, 0);
imagebl_->Draw(dc, 0, client.bottom - height_bottom_left);
imagebr_->Draw(dc, client.right - width_bottom_right, client.bottom - height_bottom_right);

Basho answered 11 years, 12 months ago

Your Answer