Ejemplo n.º 1
0
void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) {

	if (p_image.is_null() || p_image->empty())
		return;

	begin_frame(0.0);

	int window_w = OS::get_singleton()->get_video_mode(0).width;
	int window_h = OS::get_singleton()->get_video_mode(0).height;

	glBindFramebuffer(GL_FRAMEBUFFER, RasterizerStorageGLES3::system_fbo);
	glViewport(0, 0, window_w, window_h);
	glDisable(GL_BLEND);
	glDepthMask(GL_FALSE);
	if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) {
		glClearColor(0.0, 0.0, 0.0, 0.0);
	} else {
		glClearColor(p_color.r, p_color.g, p_color.b, 1.0);
	}
	glClear(GL_COLOR_BUFFER_BIT);
	canvas->canvas_begin();

	RID texture = storage->texture_create();
	storage->texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, VS::TEXTURE_FLAG_FILTER);
	storage->texture_set_data(texture, p_image);

	Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
	Rect2 screenrect;
	if (p_scale) {

		if (window_w > window_h) {
			//scale horizontally
			screenrect.size.y = window_h;
			screenrect.size.x = imgrect.size.x * window_h / imgrect.size.y;
			screenrect.position.x = (window_w - screenrect.size.x) / 2;

		} else {
			//scale vertically
			screenrect.size.x = window_w;
			screenrect.size.y = imgrect.size.y * window_w / imgrect.size.x;
			screenrect.position.y = (window_h - screenrect.size.y) / 2;
		}
	} else {

		screenrect = imgrect;
		screenrect.position += ((Size2(window_w, window_h) - screenrect.size) / 2.0).floor();
	}

	RasterizerStorageGLES3::Texture *t = storage->texture_owner.get(texture);
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, t->tex_id);
	canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1));
	glBindTexture(GL_TEXTURE_2D, 0);
	canvas->canvas_end();

	storage->free(texture); // free since it's only one frame that stays there

	end_frame(true);
}
Ejemplo n.º 2
0
void GUIInventoryMenu::drawList(const ListDrawSpec &s)
{
	video::IVideoDriver* driver = Environment->getVideoDriver();

	// Get font
	gui::IGUIFont *font = NULL;
	gui::IGUISkin* skin = Environment->getSkin();
	if (skin)
		font = skin->getFont();
	
	Inventory *inv = m_invmgr->getInventory(m_c, s.inventoryname);
	assert(inv);
	InventoryList *ilist = inv->getList(s.listname);
	
	core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
	
	for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
	{
		s32 x = (i%s.geom.X) * spacing.X;
		s32 y = (i/s.geom.X) * spacing.Y;
		v2s32 p(x,y);
		core::rect<s32> rect = imgrect + s.pos + p;
		InventoryItem *item = NULL;
		if(ilist)
			item = ilist->getItem(i);

		if(m_selected_item != NULL && m_selected_item->listname == s.listname
				&& m_selected_item->i == i)
		{
			/*s32 border = imgsize.X/12;
			driver->draw2DRectangle(video::SColor(255,192,192,192),
					core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*border,
							rect.LowerRightCorner + v2s32(1,1)*border),
					NULL);
			driver->draw2DRectangle(video::SColor(255,0,0,0),
					core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*((border+1)/2),
							rect.LowerRightCorner + v2s32(1,1)*((border+1)/2)),
					NULL);*/
			s32 border = 2;
			driver->draw2DRectangle(video::SColor(255,255,0,0),
					core::rect<s32>(rect.UpperLeftCorner - v2s32(1,1)*border,
							rect.LowerRightCorner + v2s32(1,1)*border),
					&AbsoluteClippingRect);
		}

		video::SColor bgcolor(255,128,128,128);
		driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);

		if(item)
		{
			drawInventoryItem(driver, font, item,
					rect, &AbsoluteClippingRect);
		}

	}
}
Ejemplo n.º 3
0
void nuiCoverFlow::DrawCard(nuiDrawContext* pContext, int32 index, float start, float end)
{
  NGL_ASSERT(index < mImages.size());
  nuiTexture* pTex = mImages[index];
  // Draw the selected image:
  float imgw = pTex->GetWidth();
  float imgh = pTex->GetHeight();
  float s = MAX(imgw, imgh);
  float ratiow = imgw / s;
  float ratioh = imgh / s;
  nuiRect imgrect(0.0f, 0.0f, ratiow, ratioh);
  nuiRect r(-.5, 0.0f, 1.0f, 1.0f);
  imgrect.SetPosition(nuiTop, r);
  float tw = imgw;
  float th = imgh;
  pTex->ImageToTextureCoord(tw, th);
  
  float vx0 = imgrect.Left();
  float vy0 = imgrect.Top();
  float vx1 = imgrect.Right();
  float vy1 = imgrect.Bottom();
  float vw = imgrect.GetWidth();
  float vh = imgrect.GetHeight();
  
  nuiColor blank(1.0f, 1.0f, 1.0f, 1.0f);
  
  nuiRenderArray* pArray = new nuiRenderArray(GL_TRIANGLE_STRIP);
  pArray->EnableArray(nuiRenderArray::eColor, true);
  pArray->EnableArray(nuiRenderArray::eTexCoord, true);
  nuiColor c0(mBackground);
  c0.Mix(blank, 1.0-start);
  pArray->SetColor(c0);
  pArray->SetVertex(vx0, vy0);
  pArray->SetTexCoords(0, th);
  pArray->PushVertex();
  
  pArray->SetVertex(vx1, vy0);
  pArray->SetTexCoords(tw, th);
  pArray->PushVertex();
  
  nuiColor c1(mBackground);
  c1.Mix(blank, 1.0-end);
  pArray->SetColor(c1);
  pArray->SetVertex(vx0, vy1);
  pArray->SetTexCoords(0, 0);
  pArray->PushVertex();
  
  pArray->SetVertex(vx1, vy1);
  pArray->SetTexCoords(tw, 0);
  pArray->PushVertex();
  
  pContext->EnableTexturing(true);
  pContext->SetTexture(pTex);
  pContext->DrawArray(pArray);  
}
Ejemplo n.º 4
0
////////////////////////////////////////////////////////////////////////////////////////////////////////
//safe rect
cv::Mat safeRect(const cv::Mat & img, const cv::Rect & rect, cv::Rect & safe)
{
	cv::Rect imgrect(0,0,img.cols,img.rows);
	safe = rect & imgrect;

	if (safe.width < 1 || safe.height < 1)
	{
		return cv::Mat();
	}
	else
	{
		return img(safe);
	}
}
GUIInventoryMenu::ItemSpec GUIInventoryMenu::getItemAtPos(v2s32 p) const
{
	core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);

	for(u32 i=0; i<m_draw_spec.size(); i++)
	{
		const ListDrawSpec &s = m_draw_spec[i];

		for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
		{
			s32 x = (i%s.geom.X) * spacing.X;
			s32 y = (i/s.geom.X) * spacing.Y;
			v2s32 p0(x,y);
			core::rect<s32> rect = imgrect + s.pos + p0;
			if(rect.isPointInside(p))
			{
				return ItemSpec(s.inventoryname, s.listname, i);
			}
		}
	}

	return ItemSpec("", "", -1);
}
void GUIFormSpecMenu::drawSelectedItem()
{
	if(!m_selected_item)
		return;

	video::IVideoDriver* driver = Environment->getVideoDriver();

	// Get font
	gui::IGUIFont *font = NULL;
	gui::IGUISkin* skin = Environment->getSkin();
	if (skin)
		font = skin->getFont();
	
	Inventory *inv = m_invmgr->getInventory(m_selected_item->inventoryloc);
	assert(inv);
	InventoryList *list = inv->getList(m_selected_item->listname);
	assert(list);
	ItemStack stack = list->getItem(m_selected_item->i);
	stack.count = m_selected_amount;

	core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
	core::rect<s32> rect = imgrect + (m_pointer - imgrect.getCenter());
	drawItemStack(driver, font, stack, rect, NULL, m_gamedef);
}
GUIFormSpecMenu::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
{
	core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
	
	for(u32 i=0; i<m_inventorylists.size(); i++)
	{
		const ListDrawSpec &s = m_inventorylists[i];

		for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
		{
			s32 item_i = i + s.start_item_i;
			s32 x = (i%s.geom.X) * spacing.X;
			s32 y = (i/s.geom.X) * spacing.Y;
			v2s32 p0(x,y);
			core::rect<s32> rect = imgrect + s.pos + p0;
			if(rect.isPointInside(p))
			{
				return ItemSpec(s.inventoryloc, s.listname, item_i);
			}
		}
	}

	return ItemSpec(InventoryLocation(), "", -1);
}
Ejemplo n.º 8
0
//NOTE: selectitem = 0 -> no selected; selectitem 1-based
void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
		InventoryList *mainlist, u16 selectitem, u16 direction)
{
#ifdef HAVE_TOUCHSCREENGUI
	if ( (g_touchscreengui) && (offset == 0))
		g_touchscreengui->resetHud();
#endif

	s32 height  = m_hotbar_imagesize + m_padding * 2;
	s32 width   = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2);

	if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) {
		width  = m_hotbar_imagesize + m_padding * 2;
		height = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2);
	}

	// Position of upper left corner of bar
	v2s32 pos = upperleftpos;

	if (hotbar_image != player->hotbar_image) {
		hotbar_image = player->hotbar_image;
		if (hotbar_image != "")
			use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image);
		else
			use_hotbar_image = false;
	}

	if (hotbar_selected_image != player->hotbar_selected_image) {
		hotbar_selected_image = player->hotbar_selected_image;
		if (hotbar_selected_image != "")
			use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image);
		else
			use_hotbar_selected_image = false;
	}

	/* draw customized item background */
	if (use_hotbar_image) {
		core::rect<s32> imgrect2(-m_padding/2, -m_padding/2,
				width+m_padding/2, height+m_padding/2);
		core::rect<s32> rect2 = imgrect2 + pos;
		video::ITexture *texture = tsrc->getTexture(hotbar_image);
		core::dimension2di imgsize(texture->getOriginalSize());
		driver->draw2DImage(texture, rect2,
			core::rect<s32>(core::position2d<s32>(0,0), imgsize),
			NULL, hbar_colors, true);
	}

	for (s32 i = offset; i < itemcount && (size_t)i < mainlist->getSize(); i++)
	{
		v2s32 steppos;
		s32 fullimglen = m_hotbar_imagesize + m_padding * 2;

		core::rect<s32> imgrect(0, 0, m_hotbar_imagesize, m_hotbar_imagesize);

		switch (direction) {
			case HUD_DIR_RIGHT_LEFT:
				steppos = v2s32(-(m_padding + (i - offset) * fullimglen), m_padding);
				break;
			case HUD_DIR_TOP_BOTTOM:
				steppos = v2s32(m_padding, m_padding + (i - offset) * fullimglen);
				break;
			case HUD_DIR_BOTTOM_TOP:
				steppos = v2s32(m_padding, -(m_padding + (i - offset) * fullimglen));
				break;
			default:
				steppos = v2s32(m_padding + (i - offset) * fullimglen, m_padding);
				break;
		}

		drawItem(mainlist->getItem(i), (imgrect + pos + steppos), (i +1) == selectitem );

#ifdef HAVE_TOUCHSCREENGUI
		if (g_touchscreengui)
			g_touchscreengui->registerHudItem(i, (imgrect + pos + steppos));
#endif
	}
}
Ejemplo n.º 9
0
void DisplayView::MakeScreenshot()
{
    // find out the rectangle
    int	minx = 10000000;
    int	miny = 10000000;
    int maxx = 0;
    int maxy = 0;

    for (int i=0; i<graph.filters.GetCount(); i++) {
        Filter	*filter = graph.filters[i];
        if (filter->posx < minx) minx = filter->posx;
        if (filter->posy < miny) miny = filter->posy;
        if (filter->posx + filter->width > maxx) maxx = filter->posx+filter->width;
        if (filter->posy + filter->height > maxy) maxy = filter->posy+filter->height;
    }

    minx = minx &~ 0x07;
    minx -= 8;
    if (minx < 0) minx = 0;
    miny = miny &~ 0x07;
    miny -= 8;
    if (miny < 0) miny = 0;
    maxx = (maxx+7) &~ 0x07;
    maxx += 8;
    maxy = (maxy+7) &~ 0x07;
    maxy += 8;

    // now copy the bitmap
    int	cx = (maxx-minx);
    int cy = (maxy-miny);

    if (cx == 0 || cy == 0) {
        OpenClipboard();
        EmptyClipboard();
        CloseClipboard();
        return ;
    }

    CRect		imgrect(minx, miny, maxx, maxy);
    CRect		bufrect(0, 0, back_width, back_height);
    CDC			tempdc;
    CBitmap		tempbitmap;

    CRect		area=imgrect;
    area.IntersectRect(&imgrect, &bufrect);

    tempdc.CreateCompatibleDC(&memDC);
    tempbitmap.CreateBitmap(area.Width(), area.Height(), 1, 32, NULL);
    CBitmap *old = tempdc.SelectObject(&tempbitmap);
    tempdc.BitBlt(0, 0, area.Width(), area.Height(), &memDC, area.left, area.top, SRCCOPY);

    OpenClipboard();
    EmptyClipboard();
    SetClipboardData(CF_BITMAP, tempbitmap.GetSafeHandle());
    CloseClipboard();

    tempdc.SelectObject(old);
    tempbitmap.DeleteObject();
    tempdc.DeleteDC();

}
Ejemplo n.º 10
0
void CExampleDemoDlg::OnPaint()
{
	CDialogEx::OnPaint();
	//DrawRects();
	if (m_pOrignImage == NULL)
	{
		return;
	}

	Graphics gsClient(this->GetSafeHwnd());
	gsClient.SetSmoothingMode(SmoothingModeHighQuality);
	gsClient.SetInterpolationMode(InterpolationModeNearestNeighbor);


//1、创建可以绘制的rect区域
	CRect dialog_rect;
	GetClientRect(dialog_rect);
	int top = 50;
	int bottom = 50;
	int left = 50;
	int right = 50;
	float drawwidth = dialog_rect.Width() - left - right;
	float drawheight = dialog_rect.Height()- top - bottom;
	Rect draw_rect(left,top,drawwidth,drawheight);


//2、根据m_imagepercent计算图片绘制区域
	int mx = draw_rect.X + draw_rect.Width*(1 - m_imagepercent)*0.5;
	Rect imgrect(mx, draw_rect.Y+50, m_imagepercent*draw_rect.Width, m_imagepercent*draw_rect.Width);
	int tiaoshiw = m_pOrignImage->GetWidth();
	int tiaoshih = m_pOrignImage->GetHeight();
	gsClient.DrawImage(m_pOrignImage, imgrect, 0, 0, m_pOrignImage->GetWidth(), m_pOrignImage->GetHeight(), UnitPixel);


//3、左侧模板绘制
	int button_w = 100;
	int button_h = 30;
	float scalewh = 0.6667;
	int ne = 5;



	//绘制左侧第一排

	int tw_left1 = imgrect.Width*0.33;
	int th_left1 = tw_left1*scalewh;
	int tx_left1 = imgrect.X - 20 - 2 * tw_left1;
	Rect tempplate_rect_left1(tx_left1, draw_rect.Y, tw_left1, th_left1);

	for (int i = 0; i < ne ; i++)
	{
		int iy = (i - 0)*(tempplate_rect_left1.Height + 45);
		Rect tempplate_recti(tempplate_rect_left1.X, tempplate_rect_left1.Y + iy, tempplate_rect_left1.Width, tempplate_rect_left1.Height);
		gsClient.DrawImage(m_tempplate[i], tempplate_recti, 0, 0, m_tempplate[i]->GetWidth(), m_tempplate[i]->GetHeight(), UnitPixel);

		//ResizeBitmap(&m_tempplate[i], tempplate_recti.Width, tempplate_recti.Height);


		int newy = tempplate_recti.Y + tempplate_recti.Height + 7;
		int newx = tempplate_recti.X + tempplate_recti.Width / 3.;

		CButton *pButton = m_radioList[i];
		((CButton *)pButton)->MoveWindow(newx, newy, button_w, button_h, 1);
		((CButton *)pButton)->ShowWindow(SW_SHOW);
	}

//左侧第二排
	int tw_left = imgrect.Width*0.33;
	int th_left = tw_left*scalewh;
	int tx_left = imgrect.X-10- tw_left;
	Rect tempplate_rect_left(tx_left, draw_rect.Y, tw_left, th_left);
	
	for (int i = ne; i < ne * 2; i++)
	{
		int iy = (i - ne)*(tempplate_rect_left1.Height + 45);
		Rect tempplate_recti(tempplate_rect_left.X, tempplate_rect_left.Y+iy, tempplate_rect_left.Width, tempplate_rect_left.Height);
		gsClient.DrawImage(m_tempplate[i], tempplate_recti, 0, 0, m_tempplate[i]->GetWidth(), m_tempplate[i]->GetHeight(), UnitPixel);

		//ResizeBitmap(&m_tempplate[i], tempplate_recti.Width, tempplate_recti.Height);


		int newy = tempplate_recti.Y + tempplate_recti.Height+7;
		int newx = tempplate_recti.X+ tempplate_recti.Width/3.;

		CButton *pButton = m_radioList[i];
		((CButton *)pButton)->MoveWindow(newx, newy, button_w, button_h, 1);
		((CButton *)pButton)->ShowWindow(SW_SHOW);
	}








//4、绘制右侧模板

	int tw_right = imgrect.Width*0.33;
	int th_right = tw_right*scalewh;
	int tx_right = imgrect.X + imgrect.Width+10;
	Rect tempplate_rect_right(tx_right, draw_rect.Y, tw_right, th_right);
	int nright = 5;
	for (int i = ne*2; i <ne*3; i++)
	{
		if (i>m_tempplate.size()-1)
		{
			break;
		}
		int iy = (i- ne * 2)*(tempplate_rect_right.Height + 45);
		Rect tempplate_recti(tempplate_rect_right.X, tempplate_rect_right.Y + iy, tempplate_rect_right.Width, tempplate_rect_right.Height);
		gsClient.DrawImage(m_tempplate[i], tempplate_recti, 0, 0, m_tempplate[i]->GetWidth(), m_tempplate[i]->GetHeight(), UnitPixel);

		//ResizeBitmap(&m_tempplate[i], tempplate_recti.Width, tempplate_recti.Height);


		int newy = tempplate_recti.Y + tempplate_recti.Height + 7;
		int newx = tempplate_recti.X + tempplate_recti.Width / 3.;

		CButton *pButton = m_radioList[i];
		((CButton *)pButton)->MoveWindow(newx, newy, button_w, button_h, 1);
		((CButton *)pButton)->ShowWindow(SW_SHOW);
	}


	int tw_right1 = imgrect.Width*0.33;
	int th_right1 = tw_right1*scalewh;
	int tx_right1 = imgrect.X + (imgrect.Width + 10)+10+ tw_right1;
	Rect tempplate_rect_right1(tx_right1, draw_rect.Y, tw_right1, th_right1);
	for (int i = ne * 3; i < ne * 4; i++)
	{
		if (i > m_tempplate.size() - 1)
		{
			break;
		}
		int iy = (i - ne * 3)*(tempplate_rect_right1.Height + 45);
		Rect tempplate_recti(tempplate_rect_right1.X, tempplate_rect_right1.Y + iy, tempplate_rect_right1.Width, tempplate_rect_right1.Height);
		gsClient.DrawImage(m_tempplate[i], tempplate_recti, 0, 0, m_tempplate[i]->GetWidth(), m_tempplate[i]->GetHeight(), UnitPixel);

		//ResizeBitmap(&m_tempplate[i], tempplate_recti.Width, tempplate_recti.Height);


		int newy = tempplate_recti.Y + tempplate_recti.Height + 7;
		int newx = tempplate_recti.X + tempplate_recti.Width / 3.;

		CButton *pButton = m_radioList[i];
		((CButton *)pButton)->MoveWindow(newx, newy, button_w, button_h, 1);
		((CButton *)pButton)->ShowWindow(SW_SHOW);
	}









//5、绘制底侧"下一张"按钮
	int bbnx = imgrect.X + imgrect.Width/2.2;
	int bbny= imgrect.Y+ imgrect.Height+30;
	((CButton *)m_nextimageb)->MoveWindow(bbnx, bbny, button_w, button_h, 1);
	((CButton *)m_nextimageb)->ShowWindow(SW_SHOW);

}
void GUIFormSpecMenu::drawMenu()
{
	if(m_form_src){
		std::string newform = m_form_src->getForm();
		if(newform != m_formspec_string){
			m_formspec_string = newform;
			regenerateGui(m_screensize_old);
		}
	}

	updateSelectedItem();

	gui::IGUISkin* skin = Environment->getSkin();
	if (!skin)
		return;
	video::IVideoDriver* driver = Environment->getVideoDriver();
	
	video::SColor bgcolor(140,0,0,0);
	driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);

	m_tooltip_element->setVisible(false);

	/*
		Draw items
		Phase 0: Item slot rectangles
		Phase 1: Item images; prepare tooltip
	*/
	
	for(int phase=0; phase<=1; phase++)
	for(u32 i=0; i<m_inventorylists.size(); i++)
	{
		drawList(m_inventorylists[i], phase);
	}

	for(u32 i=0; i<m_images.size(); i++)
	{
		const ImageDrawSpec &spec = m_images[i];
		video::ITexture *texture =
				m_gamedef->tsrc()->getTextureRaw(spec.name);
		// Image size on screen
		core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
		// Image rectangle on screen
		core::rect<s32> rect = imgrect + spec.pos;
		const video::SColor color(255,255,255,255);
		const video::SColor colors[] = {color,color,color,color};
		driver->draw2DImage(texture, rect,
			core::rect<s32>(core::position2d<s32>(0,0),
					core::dimension2di(texture->getOriginalSize())),
			NULL/*&AbsoluteClippingRect*/, colors, true);
	}

	/*
		Draw dragged item stack
	*/
	drawSelectedItem();

	/*
		Call base class
	*/
	gui::IGUIElement::draw();
}
void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int phase)
{
	video::IVideoDriver* driver = Environment->getVideoDriver();

	// Get font
	gui::IGUIFont *font = NULL;
	gui::IGUISkin* skin = Environment->getSkin();
	if (skin)
		font = skin->getFont();
	
	Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
	if(!inv){
		infostream<<"GUIFormSpecMenu::drawList(): WARNING: "
				<<"The inventory location "
				<<"\""<<s.inventoryloc.dump()<<"\" doesn't exist"
				<<std::endl;
		return;
	}
	InventoryList *ilist = inv->getList(s.listname);
	if(!ilist){
		infostream<<"GUIFormSpecMenu::drawList(): WARNING: "
				<<"The inventory list \""<<s.listname<<"\" @ \""
				<<s.inventoryloc.dump()<<"\" doesn't exist"
				<<std::endl;
		return;
	}
	
	core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
	
	for(s32 i=0; i<s.geom.X*s.geom.Y; i++)
	{
		u32 item_i = i + s.start_item_i;
		if(item_i >= ilist->getSize())
			break;
		s32 x = (i%s.geom.X) * spacing.X;
		s32 y = (i/s.geom.X) * spacing.Y;
		v2s32 p(x,y);
		core::rect<s32> rect = imgrect + s.pos + p;
		ItemStack item;
		if(ilist)
			item = ilist->getItem(item_i);

		bool selected = m_selected_item
			&& m_invmgr->getInventory(m_selected_item->inventoryloc) == inv
			&& m_selected_item->listname == s.listname
			&& m_selected_item->i == i;
		bool hovering = rect.isPointInside(m_pointer);

		if(phase == 0)
		{
			if(hovering && m_selected_item)
			{
				video::SColor bgcolor(255,192,192,192);
				driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
			}
			else
			{
				video::SColor bgcolor(255,128,128,128);
				driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
			}
		}

		if(phase == 1)
		{
			// Draw item stack
			if(selected)
			{
				item.takeItem(m_selected_amount);
			}
			if(!item.empty())
			{
				drawItemStack(driver, font, item,
						rect, &AbsoluteClippingRect, m_gamedef);
			}

			// Draw tooltip
			std::string tooltip_text = "";
			if(hovering && !m_selected_item)
				tooltip_text = item.getDefinition(m_gamedef->idef()).description;
			if(tooltip_text != "")
			{
				m_tooltip_element->setVisible(true);
				this->bringToFront(m_tooltip_element);
				m_tooltip_element->setText(narrow_to_wide(tooltip_text).c_str());
				s32 tooltip_x = m_pointer.X + 15;
				s32 tooltip_y = m_pointer.Y + 15;
				s32 tooltip_width = m_tooltip_element->getTextWidth() + 15;
				s32 tooltip_height = m_tooltip_element->getTextHeight() + 5;
				m_tooltip_element->setRelativePosition(core::rect<s32>(
						core::position2d<s32>(tooltip_x, tooltip_y),
						core::dimension2d<s32>(tooltip_width, tooltip_height)));
			}
		}
	}
}
Ejemplo n.º 13
0
//NOTE: selectitem = 0 -> no selected; selectitem 1-based
void Hud::drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount,
		InventoryList *mainlist, u16 selectitem, u16 direction)
{
	s32 padding = imgsize / 12;
	s32 height  = imgsize + padding * 2;
	s32 width   = itemcount * (imgsize + padding * 2);
	if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) {
		width  = imgsize + padding * 2;
		height = itemcount * (imgsize + padding * 2);
	}
	s32 fullimglen = imgsize + padding * 2;

	// Position of upper left corner of bar
	v2s32 pos = upperleftpos;

	// Draw background color
	/*core::rect<s32> barrect(0,0,width,height);
	barrect += pos;
	video::SColor bgcolor(255,128,128,128);
	driver->draw2DRectangle(bgcolor, barrect, NULL);*/

	core::rect<s32> imgrect(0, 0, imgsize, imgsize);
	const video::SColor hbar_color(255, 255, 255, 255);
	const video::SColor hbar_colors[] = {hbar_color, hbar_color, hbar_color, hbar_color};

	if (hotbar_image != player->hotbar_image) {
		hotbar_image = player->hotbar_image;
		if (hotbar_image != "")
			use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image);
		else
			use_hotbar_image = false;
	}

	if (hotbar_selected_image != player->hotbar_selected_image) {
		hotbar_selected_image = player->hotbar_selected_image;
		if (hotbar_selected_image != "")
			use_hotbar_selected_image = tsrc->isKnownSourceImage(hotbar_selected_image);
		else
			use_hotbar_selected_image = false;
	}

	if (use_hotbar_image) {
		core::rect<s32> imgrect2(-padding/2, -padding/2, width+padding/2, height+padding/2);
		core::rect<s32> rect2 = imgrect2 + pos;
		video::ITexture *texture = tsrc->getTexture(hotbar_image);
		core::dimension2di imgsize(texture->getOriginalSize());
		driver->draw2DImage(texture, rect2,
			core::rect<s32>(core::position2d<s32>(0,0), imgsize),
			NULL, hbar_colors, true);
	}

	for (s32 i = 0; i < itemcount; i++)
	{
		const ItemStack &item = mainlist->getItem(i);

		v2s32 steppos;
		switch (direction) {
			case HUD_DIR_RIGHT_LEFT:
				steppos = v2s32(-(padding + i * fullimglen), padding);
				break;
			case HUD_DIR_TOP_BOTTOM:
				steppos = v2s32(padding, padding + i * fullimglen);
				break;
			case HUD_DIR_BOTTOM_TOP:
				steppos = v2s32(padding, -(padding + i * fullimglen));
				break;
			default:
				steppos = v2s32(padding + i * fullimglen, padding);
		}
			
		core::rect<s32> rect = imgrect + pos + steppos;

		if (selectitem == i + 1) {
			if (use_hotbar_selected_image) {
				core::rect<s32> imgrect2(-padding*2, -padding*2, height, height);
				rect = imgrect2 + pos + steppos;
				video::ITexture *texture = tsrc->getTexture(hotbar_selected_image);
				core::dimension2di imgsize(texture->getOriginalSize());
				driver->draw2DImage(texture, rect,
					core::rect<s32>(core::position2d<s32>(0,0), imgsize),
					NULL, hbar_colors, true);
				rect = imgrect + pos + steppos;
			} else {
				rect = imgrect + pos + steppos;
				video::SColor c_outside(255,255,0,0);
				//video::SColor c_outside(255,0,0,0);
				//video::SColor c_inside(255,192,192,192);
				s32 x1 = rect.UpperLeftCorner.X;
				s32 y1 = rect.UpperLeftCorner.Y;
				s32 x2 = rect.LowerRightCorner.X;
				s32 y2 = rect.LowerRightCorner.Y;
				// Black base borders
				driver->draw2DRectangle(c_outside,
					core::rect<s32>(
						v2s32(x1 - padding, y1 - padding),
						v2s32(x2 + padding, y1)
					), NULL);
				driver->draw2DRectangle(c_outside,
					core::rect<s32>(
						v2s32(x1 - padding, y2),
						v2s32(x2 + padding, y2 + padding)
					), NULL);
				driver->draw2DRectangle(c_outside,
					core::rect<s32>(
						v2s32(x1 - padding, y1),
						v2s32(x1, y2)
					), NULL);
				driver->draw2DRectangle(c_outside,
					core::rect<s32>(
						v2s32(x2, y1),
						v2s32(x2 + padding, y2)
					), NULL);
				/*// Light inside borders
				driver->draw2DRectangle(c_inside,
					core::rect<s32>(
						v2s32(x1 - padding/2, y1 - padding/2),
						v2s32(x2 + padding/2, y1)
					), NULL);
				driver->draw2DRectangle(c_inside,
					core::rect<s32>(
						v2s32(x1 - padding/2, y2),
						v2s32(x2 + padding/2, y2 + padding/2)
					), NULL);
				driver->draw2DRectangle(c_inside,
					core::rect<s32>(
						v2s32(x1 - padding/2, y1),
						v2s32(x1, y2)
					), NULL);
				driver->draw2DRectangle(c_inside,
					core::rect<s32>(
						v2s32(x2, y1),
						v2s32(x2 + padding/2, y2)
					), NULL);
				*/
			}
		}

		video::SColor bgcolor2(128, 0, 0, 0);
		if (!use_hotbar_image)
			driver->draw2DRectangle(bgcolor2, rect, NULL);
		drawItemStack(driver, font, item, rect, NULL, gamedef);
	}
}