bool OguiButton::SetText(const char *text)
{
	// HACK: optimization, if text is the same as it was before,
	// do nothing...
	if (((orvgui_but *)but)->text != NULL
		&& text != NULL
		&& strcmp(((orvgui_but *)but)->text, text) == 0)
		return false;
	
	if( ( text != NULL && !std::string( text ).empty() ) &&
		( this->text.empty() ||	this->text.size() < strlen( text ) || 
		this->text.substr( 0, strlen( text ) ) != text ) )
	{
		this->text = text;
	}
#ifdef PROJECT_SHADOWGROUNDS
	IOguiFont* temp_font = font;
#else
	IOguiFont* temp_font = GetTheFontCurrentlyInUse();
#endif
	// TODO: check if this is a text button, else abort
	int pixwidth = 0;
	int pixheight = 0;
	int fontwidth = 0;
	int fontheight = 0;
	if (temp_font != NULL && text != NULL)
	{
		OguiStormFont *implFont = (OguiStormFont *) (temp_font);
		IStorm3D_Font *stormFont = implFont->fnt;

		/*
		if(stormFont && stormFont->isUnicode())
		{
			std::wstring unicode;
			frozenbyte::util::convertToWide(text, unicode);

			pixwidth = stormFont->GetCharacterWidth(&unicode[0], unicode.size());
		}
		else
		{
			pixwidth = font->getStringWidth(text);
		}
		*/

		pixwidth = temp_font->getStringWidth(text);
		pixheight = temp_font->getStringHeight(text);
		fontwidth = temp_font->getWidth();
		fontheight = temp_font->getHeight();

	}

	// note, const char * -> char * cast.
	// however, the og_set_text_button should not change that.
	og_set_text_button((orvgui_but *)but, (char *)text, pixwidth, pixheight, 
		fontwidth, fontheight);

	return true;
}
Example #2
0
OguiButton *OguiWindow::CreateNewButton(int x, int y, int sizex, int sizey, 
	IOguiImage *img, IOguiImage *imgdown, IOguiImage *imghigh, IOguiImage *imgdisabled, bool withText, 
	const char *text, int id, const void *argument, IOguiFont *font, bool clipToWindow )
{
	orvgui_but *but;

	// NOTICE: the orvgui button is created here, but deleted in 
	// the OguiButton class destructor

	if (withText)
	{
		IStorm3D_Font *fnt = NULL;
		COL fnt_color;
		if (font != NULL)
		{
			fnt = ((OguiStormFont *)font)->fnt;
			fnt_color = ((OguiStormFont *)font)->color;
		}

		int pixwidth = 0;
		int pixheight = 0;
		int fontwidth = 0;
		int fontheight = 0;
		if (font != NULL && text != NULL)
		{
			pixwidth = font->getStringWidth(text);
			pixheight = font->getStringHeight(text);
			fontwidth = font->getWidth();
			fontheight = font->getHeight();
		}

		but = og_create_button((orvgui_win *)win, OG_BUT_PIC_AND_TEXT, x, y, sizex, sizey, clipToWindow);
		og_set_text_button(but, fnt, fnt_color, OG_H_ALIGN_CENTER, OG_V_ALIGN_MIDDLE, text, pixwidth, pixheight, fontwidth, fontheight);
	} else {
		but = og_create_button((orvgui_win *)win, OG_BUT_PIC, x, y, sizex, sizey, clipToWindow);
	}

	IStorm3D_Material *mat = NULL;
	IStorm3D_Material *matdown = NULL;
	IStorm3D_Material *mathigh = NULL;
	IStorm3D_Material *matdisabled = NULL;
	if (img != NULL) mat = ((OguiStormImage *)img)->mat;
	if (imgdown != NULL) matdown = ((OguiStormImage *)imgdown)->mat;
	if (imghigh != NULL) mathigh = ((OguiStormImage *)imghigh)->mat;
	if (imgdisabled != NULL) matdisabled = ((OguiStormImage *)imgdisabled)->mat;
	og_set_pic_button(but, mat, matdown, matdisabled, mathigh);

	OguiButton *ob = new OguiButton(ogui, id, argument);
	ob->but = but;
	ob->parent = this;
	ob->image = img;
	ob->imageDown = imgdown;
	ob->imageDisabled = NULL;
	ob->imageHighlighted = imghigh;
	ob->imageAutodel = false;
	ob->imageDownAutodel = false;
	ob->imageDisabledAutodel = false;
	ob->imageHighlightedAutodel = false;
	ob->font = font;

	og_set_click_button(but, ogui_button_click_handler, ob);
	og_set_press_button(but, ogui_button_press_handler, ob);
	og_set_out_button(but, ogui_button_out_handler, ob);
	og_set_over_button(but, ogui_button_over_handler, ob);
	og_set_leave_button(but, ogui_button_leave_handler, ob);
	og_set_hold_button(but, ogui_button_hold_handler, ob);

	buttonList->append(ob);

	return ob;
}