Ejemplo n.º 1
0
void HKWidgetLabel::SetProperty(const char *pProperty, const char *pValue)
{
	if(!MFString_CaseCmp(pProperty, "text"))
		SetText(pValue);
	else if(!MFString_CaseCmp(pProperty, "text_colour"))
		SetTextColour(HKWidget_GetColourFromString(pValue));
	else if(!MFString_CaseCmp(pProperty, "text_height"))
		SetTextHeight(MFString_AsciiToFloat(pValue));
	else if(!MFString_CaseCmp(pProperty, "text_shadowDepth"))
		SetShadowDepth(MFString_AsciiToFloat(pValue));
	else if(!MFString_CaseCmp(pProperty, "text_font"))
	{
		if(bOwnFont)
			MFFont_Release(pFont);
		pFont = MFFont_Create(pValue);
		bOwnFont = true;

		if(bAutoTextHeight)
			textHeight = MFFont_GetFontHeight(pFont);

		AdjustSize();
	}
	else if(!MFString_CaseCmp(pProperty, "text_align"))
		SetTextJustification((MFFontJustify)HKWidget_GetEnumValue(pValue, sJustifyKeys));
	else
		HKWidget::SetProperty(pProperty, pValue);
}
Ejemplo n.º 2
0
bool HKWidgetRenderer::SetProperty(const char *pProperty, const char *pValue, HKWidget *pWidget)
{
	if(!MFString_CaseCmp(pProperty, "background_image"))
	{
		if(pImage)
			MFMaterial_Destroy(pImage);
		pImage = MFMaterial_Create(pValue);
		if(pImage)
		{
			int texW, texH;
			MFTexture *pTex = MFMaterial_GetParameterT(pImage, MFMatStandard_Texture, MFMatStandard_Tex_DifuseMap);
			MFTexture_GetTextureDimensions(pTex, &texW, &texH);

			texWidth = (float)texW;
			texHeight = (float)texH;

			if(pWidget && (pWidget->bAutoWidth || pWidget->bAutoHeight))
			{
				if(pWidget->bAutoWidth && pWidget->bAutoHeight)
					pWidget->Resize(MakeVector(texWidth, texHeight));
				else if(pWidget->bAutoWidth)
					pWidget->UpdateWidth(texWidth);
				else
					pWidget->UpdateHeight(texHeight);
			}
		}
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "background_align"))
	{
		imageAlignment = (HKWidget::Justification)HKWidget_GetEnumValue(pValue, HKWidget::sJustifyKeys);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "background_colour"))
	{
		colour = HKWidget_GetColourFromString(pValue);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "background_padding"))
	{
		padding = HKWidget_GetVectorFromString(pValue);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "background_9-cell-margin"))
	{
		margin9Cell = MFString_AsciiToFloat(pValue);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "border_width"))
	{
		border = HKWidget_GetVectorFromString(pValue);
		return true;
	}
	else if(!MFString_CaseCmp(pProperty, "border_colour"))
	{
		borderColour = HKWidget_GetColourFromString(pValue);
		return true;
	}
	return false;
}
Ejemplo n.º 3
0
int MFRenderer_CreateDisplay(MFDisplay *pDisplay)
{
#if MF_DISPLAY == MF_DRIVER_X11
	Window window = (Window)MFWindow_GetSystemWindowHandle(pDisplay->settings.pWindow);

	glXWindow = glXCreateWindow(xdisplay, fbConfigs[0], window, NULL);
	if(!glXWindow)
	{
		MFDebug_Error("Unable to associate window with a GLXWindow");
		MFRenderer_DestroyDisplay(pDisplay);
		return 1;
	}

	glXContext = glXCreateNewContext(xdisplay, fbConfigs[0], GLX_RGBA_TYPE, NULL, true);
	if(!glXContext)
	{
		MFDebug_Error("Unable to create GLXContext");
		MFRenderer_DestroyDisplay(pDisplay);
		return 1;
	}

	XFree(fbConfigs);
	fbConfigs = NULL;

	if(!glXMakeContextCurrent(xdisplay, glXWindow, glXWindow, glXContext))
	{
		MFDebug_Error("glXMakeContextCurrent failed");
		MFRenderer_DestroyDisplay(pDisplay);
		return 1;
	}
#elif MF_DISPLAY == MF_DRIVER_WIN32
	HWND hWnd = (HWND)MFWindow_GetSystemWindowHandle(pDisplay->settings.pWindow);

	GLuint pixelFormat;

	PIXELFORMATDESCRIPTOR pfd =
	{
		sizeof(PIXELFORMATDESCRIPTOR),
		1,
		PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
		PFD_TYPE_RGBA,
		32, // colour depth
		0, 0, 0, 0, 0, 0,
		0, // No Alpha Buffer
		0, // Shift Bit Ignored
		0, // No Accumulation Buffer
		0, 0, 0, 0, // Accumulation Bits Ignored
		24, // 16Bit Z-Buffer (Depth Buffer)
		8, // No Stencil Buffer
		0, // No Auxiliary Buffer
		PFD_MAIN_PLANE, // Main Drawing Layer
		0, // Reserved
		0, 0, 0 // Layer Masks Ignored
	};

	pfd.dwFlags |= pDisplay->settings.numBuffers > 1 ? PFD_DOUBLEBUFFER : 0;

	hDC = GetDC(hWnd);
	if(!hDC)
	{
		MFRenderer_DestroyDisplay(pDisplay);
		MessageBoxA(NULL, "Can't Create A GL Device Context.", "ERROR", MB_OK|MB_ICONEXCLAMATION);
		return 1;
	}

	pixelFormat = ChoosePixelFormat(hDC, &pfd);
	if(!pixelFormat)
	{
		MFRenderer_DestroyDisplay(pDisplay);
		MessageBoxA(NULL, "Can't Find A Suitable PixelFormat.", "ERROR", MB_OK|MB_ICONEXCLAMATION);
		return 2;
	}

	if(!SetPixelFormat(hDC, pixelFormat, &pfd))
	{
		MFRenderer_DestroyDisplay(pDisplay);
		MessageBoxA(NULL, "Can't Set The PixelFormat.", "ERROR", MB_OK|MB_ICONEXCLAMATION);
		return 3;
	}

	hRC = wglCreateContext(hDC);
	if(!hRC)
	{
		// *** driver bug ***
		// HACK: do it again...
		SetPixelFormat(hDC, pixelFormat, &pfd);
		hRC = wglCreateContext(hDC);
	}

	if(!hRC)
	{
		MessageBoxA(NULL, MFStr("Failed to create OpenGL context: %s", MFSystemPC_GetLastError()), "ERROR", MB_OK|MB_ICONEXCLAMATION);

		MFRenderer_DestroyDisplay(pDisplay);
		return 4;
	}

	if(!wglMakeCurrent(hDC, hRC))
	{
		MFRenderer_DestroyDisplay(pDisplay);
		MessageBoxA(NULL, "Can't Activate The GL Rendering Context.", "ERROR", MB_OK|MB_ICONEXCLAMATION);
		return 5;
	}
#elif MF_DISPLAY == MF_DRIVER_SDL2
	glContext = SDL_GL_CreateContext((SDL_Window*)MFWindow_GetSystemWindowHandle(pDisplay->settings.pWindow));
#elif MF_DISPLAY == MF_DRIVER_IPHONE
	MFRendererIPhone_MakeCurrent();
#elif MF_DISPLAY == MF_DRIVER_NACL
	// do we need to do anything?
#endif

    // get the opengl version
	const char *pVersion = (const char *)glGetString(GL_VERSION);
	while(pVersion && *pVersion && !MFIsNumeric(*pVersion))
		++pVersion;
	float ver = MFString_AsciiToFloat(pVersion);
	gOpenGLVersion = (int)(ver * 100);

#if !defined(MF_OPENGL_ES)
	// glew wrangles all the horrid extensions...
	GLenum r = glewInit();
	MFDebug_Assert(r == GLEW_OK, "Error loading extensions!");
#endif

#if !defined(MF_OPENGL_ES)
	glEnable(GL_LINE_SMOOTH);

//	glFrontFace(GL_CW);
//	glCullFace(GL_BACK);

	glDisable(GL_LIGHTING);
#endif

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glEnable(GL_TEXTURE_2D);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

#if defined(MF_OPENGL_ES)
	// we need the EGL display apparently...
//	eglSwapInterval(, 1);
#else
#if MF_DISPLAY == MF_DRIVER_X11
//	GLXDrawable drawable = glXGetCurrentDrawable();
//	glXSwapIntervalEXT(xdisplay, drawable, 1);
#elif MF_DISPLAY == MF_DRIVER_WIN32
//	wglSwapInterval(1);
#endif
#endif

	glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint*)&gDefaultRenderTarget);

	MFTextureDesc texDesc = { MFTexType_2D, ImgFmt_A8R8G8B8, pDisplay->settings.width, pDisplay->settings.height, 0, 0, 1, MFTCF_RenderTarget };
	gpDeviceColourTarget = MFTexture_InitTexture(&texDesc, MFRD_OpenGL, 0);
	gpDeviceColourTarget->pName = "Device Colour Target";
	gpDeviceColourTarget->pSurfaces[0].platformData = (uint64)gDefaultRenderTarget;

	texDesc.format = ImgFmt_D24S8;
	gpDeviceZTarget = MFTexture_InitTexture(&texDesc, MFRD_OpenGL, 0);
	gpDeviceZTarget->pName = "Device Depth Stencil";
	gpDeviceZTarget->pSurfaces[0].platformData = 0;

	MFRenderTargetDesc desc;
	desc.pName = "Device Render Target";
	desc.width = pDisplay->settings.width;
	desc.height = pDisplay->settings.height;
	desc.colourTargets[0].pSurface = gpDeviceColourTarget;
	desc.depthStencil.pSurface = gpDeviceZTarget;
	gpDeviceRenderTarget = MFRenderTarget_Create(&desc);

	gCurrentViewport.x = 0.0f;
	gCurrentViewport.y = 0.0f;
	gCurrentViewport.width = (float)pDisplay->settings.width;
	gCurrentViewport.height = (float)pDisplay->settings.height;
	glViewport(0, 0, pDisplay->settings.width, pDisplay->settings.height);

	return 0;
}