| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078 |
- #include "BsBuiltinResources.h"
- #include "BsGUIElementStyle.h"
- #include "BsGUILabel.h"
- #include "BsGUIButton.h"
- #include "BsGUIInputBox.h"
- #include "BsGUIToggle.h"
- #include "BsGUIDropDownContent.h"
- #include "BsTextSprite.h"
- #include "BsSpriteTexture.h"
- #include "BsFont.h"
- #include "BsFontImportOptions.h"
- #include "BsImporter.h"
- #include "BsResources.h"
- #include "BsGpuProgram.h"
- #include "BsShader.h"
- #include "BsShaderInclude.h"
- #include "BsTechnique.h"
- #include "BsPass.h"
- #include "BsMaterial.h"
- #include "BsBlendState.h"
- #include "BsDepthStencilState.h"
- #include "BsRTTIType.h"
- #include "BsFileSystem.h"
- #include "BsCoreApplication.h"
- #include "BsCoreThread.h"
- #include "BsApplication.h"
- #include "BsDataStream.h"
- #include "BsTime.h"
- #include "BsResourceManifest.h"
- #include "BsVertexDataDesc.h"
- #include "BsShapeMeshes3D.h"
- #include "BsMesh.h"
- namespace BansheeEngine
- {
- const WString BuiltinResources::DefaultFontFilename = L"arial.ttf";
- const UINT32 BuiltinResources::DefaultFontSize = 11;
- const Color BuiltinResources::TextNormalColor = Color(0.7f, 0.7f, 0.7f);
- const Color BuiltinResources::TextActiveColor = Color(0.0f, 0.0f, 0.0f);
- const WString BuiltinResources::GUISkinFile = L"GUISkin";
- const Path BuiltinResources::CursorFolder = L"Cursors\\";
- const Path BuiltinResources::ShaderFolder = L"Shaders\\";
- const Path BuiltinResources::SkinFolder = L"Skin\\";
- const Path BuiltinResources::ShaderIncludeFolder = L"Includes\\";
- const Path BuiltinResources::MeshFolder = L"Meshes\\";
- const Path BuiltinResources::BuiltinRawDataFolder = RUNTIME_DATA_PATH + L"Raw\\Engine\\";
- const Path BuiltinResources::EngineRawSkinFolder = BuiltinRawDataFolder + SkinFolder;
- const Path BuiltinResources::EngineRawCursorFolder = BuiltinRawDataFolder + CursorFolder;
- const Path BuiltinResources::EngineRawShaderFolder = BuiltinRawDataFolder + ShaderFolder;
- const Path BuiltinResources::EngineRawShaderIncludeFolder = BuiltinRawDataFolder + ShaderIncludeFolder;
- const Path BuiltinResources::BuiltinDataFolder = RUNTIME_DATA_PATH + L"Engine\\";
- const Path BuiltinResources::EngineSkinFolder = BuiltinDataFolder + SkinFolder;
- const Path BuiltinResources::EngineCursorFolder = BuiltinDataFolder + CursorFolder;
- const Path BuiltinResources::EngineShaderFolder = BuiltinDataFolder + ShaderFolder;
- const Path BuiltinResources::EngineShaderIncludeFolder = BuiltinDataFolder + ShaderIncludeFolder;
- const Path BuiltinResources::EngineMeshFolder = BuiltinDataFolder + MeshFolder;
- const Path BuiltinResources::ResourceManifestPath = BuiltinDataFolder + "ResourceManifest.asset";
- /************************************************************************/
- /* GUI TEXTURES */
- /************************************************************************/
- const WString BuiltinResources::WhiteTex = L"White.psd";
- const WString BuiltinResources::ButtonNormalTex = L"ButtonNormal.png";
- const WString BuiltinResources::ButtonHoverTex = L"ButtonHover.png";
- const WString BuiltinResources::ButtonActiveTex = L"ButtonActive.png";
- const WString BuiltinResources::ToggleNormalTex = L"ToggleNormal.png";
- const WString BuiltinResources::ToggleHoverTex = L"ToggleHover.png";
- const WString BuiltinResources::ToggleNormalOnTex = L"ToggleNormalOn.png";
- const WString BuiltinResources::ToggleHoverOnTex = L"ToggleHoverOn.png";
- const WString BuiltinResources::InputBoxNormalTex = L"InputBoxNormal.png";
- const WString BuiltinResources::InputBoxHoverTex = L"InputBoxHover.png";
- const WString BuiltinResources::InputBoxFocusedTex = L"InputBoxActive.png";
- const WString BuiltinResources::ScrollBarUpNormalTex = L"ScrollArrowUpNormal.png";
- const WString BuiltinResources::ScrollBarUpHoverTex = L"ScrollArrowUpHover.png";
- const WString BuiltinResources::ScrollBarUpActiveTex = L"ScrollArrowUpActive.png";
- const WString BuiltinResources::ScrollBarDownNormalTex = L"ScrollArrowDownNormal.png";
- const WString BuiltinResources::ScrollBarDownHoverTex = L"ScrollArrowDownHover.png";
- const WString BuiltinResources::ScrollBarDownActiveTex = L"ScrollArrowDownActive.png";
- const WString BuiltinResources::ScrollBarLeftNormalTex = L"ScrollArrowLeftNormal.png";
- const WString BuiltinResources::ScrollBarLeftHoverTex = L"ScrollArrowLeftHover.png";
- const WString BuiltinResources::ScrollBarLeftActiveTex = L"ScrollArrowLeftActive.png";
- const WString BuiltinResources::ScrollBarRightNormalTex = L"ScrollArrowRightNormal.png";
- const WString BuiltinResources::ScrollBarRightHoverTex = L"ScrollArrowRightHover.png";
- const WString BuiltinResources::ScrollBarRightActiveTex = L"ScrollArrowRightActive.png";
- const WString BuiltinResources::ScrollBarHandleHorzNormalTex = L"ScrollBarHHandleNormal.png";
- const WString BuiltinResources::ScrollBarHandleHorzHoverTex = L"ScrollBarHHandleHover.png";
- const WString BuiltinResources::ScrollBarHandleHorzActiveTex = L"ScrollBarHHandleActive.png";
- const WString BuiltinResources::ScrollBarHandleVertNormalTex = L"ScrollBarVHandleNormal.png";
- const WString BuiltinResources::ScrollBarHandleVertHoverTex = L"ScrollBarVHandleHover.png";
- const WString BuiltinResources::ScrollBarHandleVertActiveTex = L"ScrollBarVHandleActive.png";
- const WString BuiltinResources::ScrollBarHBgTex = L"ScrollBarHBackground.png";
- const WString BuiltinResources::ScrollBarVBgTex = L"ScrollBarVBackground.png";
- const WString BuiltinResources::DropDownBtnNormalTex = L"DropDownButtonNormal.png";
- const WString BuiltinResources::DropDownBtnHoverTex = L"DropDownButtonHover.png";
- const WString BuiltinResources::DropDownBtnActiveTex = L"DropDownButtonActive.png";
- const WString BuiltinResources::DropDownBoxBgTex = L"DropDownBoxBg.png";
- const WString BuiltinResources::DropDownBoxSideBgTex = L"DropDownBoxSideBg.png";
- const WString BuiltinResources::DropDownBoxHandleTex = L"DropDownBoxScrollHandle.png";
- const WString BuiltinResources::DropDownBoxEntryNormalTex = L"DropDownBoxEntryNormal.png";
- const WString BuiltinResources::DropDownBoxEntryHoverTex = L"DropDownBoxEntryHover.png";
- const WString BuiltinResources::DropDownBoxBtnUpNormalTex = L"DropDownBoxArrowUpNormal.png";
- const WString BuiltinResources::DropDownBoxBtnUpHoverTex = L"DropDownBoxArrowUpHover.png";
- const WString BuiltinResources::DropDownBoxBtnDownNormalTex = L"DropDownBoxArrowDownNormal.png";
- const WString BuiltinResources::DropDownBoxBtnDownHoverTex = L"DropDownBoxArrowDownHover.png";
- const WString BuiltinResources::DropDownBoxEntryExpNormalTex = L"DropDownBoxExpandBtnNormal.png";
- const WString BuiltinResources::DropDownBoxEntryExpHoverTex = L"DropDownBoxExpandBtnHover.png";
- const WString BuiltinResources::DropDownSeparatorTex = L"DropDownBoxSeparator.png";
- /************************************************************************/
- /* CURSOR TEXTURES */
- /************************************************************************/
- const WString BuiltinResources::CursorArrowTex = L"Arrow.psd";
- const WString BuiltinResources::CursorArrowDragTex = L"ArrowDrag.psd";
- const WString BuiltinResources::CursorArrowLeftRightTex = L"ArrowLeftRight.psd";
- const WString BuiltinResources::CursorIBeamTex = L"IBeam.psd";
- const WString BuiltinResources::CursorDenyTex = L"Deny.psd";
- const WString BuiltinResources::CursorWaitTex = L"Wait.psd";
- const WString BuiltinResources::CursorSizeNESWTex = L"SizeNESW.psd";
- const WString BuiltinResources::CursorSizeNSTex = L"SizeNS.psd";
- const WString BuiltinResources::CursorSizeNWSETex = L"SizeNWSE.psd";
- const WString BuiltinResources::CursorSizeWETex = L"SizeWE.psd";
- const Vector2I BuiltinResources::CursorArrowHotspot = Vector2I(11, 8);
- const Vector2I BuiltinResources::CursorArrowDragHotspot = Vector2I(11, 8);
- const Vector2I BuiltinResources::CursorArrowLeftRightHotspot = Vector2I(9, 4);
- const Vector2I BuiltinResources::CursorIBeamHotspot = Vector2I(15, 15);
- const Vector2I BuiltinResources::CursorDenyHotspot = Vector2I(15, 15);
- const Vector2I BuiltinResources::CursorWaitHotspot = Vector2I(15, 15);
- const Vector2I BuiltinResources::CursorSizeNESWHotspot = Vector2I(15, 15);
- const Vector2I BuiltinResources::CursorSizeNSHotspot = Vector2I(15, 15);
- const Vector2I BuiltinResources::CursorSizeNWSEHotspot = Vector2I(15, 15);
- const Vector2I BuiltinResources::CursorSizeWEHotspot = Vector2I(15, 15);
- /************************************************************************/
- /* SHADERS */
- /************************************************************************/
- const WString BuiltinResources::ShaderSpriteTextFile = L"SpriteText.bsl";
- const WString BuiltinResources::ShaderSpriteImageAlphaFile = L"SpriteImageAlpha.bsl";
- const WString BuiltinResources::ShaderSpriteImageNoAlphaFile = L"SpriteImageNoAlpha.bsl";
- const WString BuiltinResources::ShaderDiffuseFile = L"Diffuse.bsl";
- const WString BuiltinResources::ShaderDummyFile = L"Dummy.bsl";
- /************************************************************************/
- /* MESHES */
- /************************************************************************/
- const WString BuiltinResources::MeshSphereFile = L"Sphere.asset";
- const WString BuiltinResources::MeshBoxFile = L"Box.asset";
- const WString BuiltinResources::MeshConeFile = L"Cone.asset";
- const WString BuiltinResources::MeshQuadFile = L"Quad.asset";
- const WString BuiltinResources::MeshDiscFile = L"Disc.asset";
- BuiltinResources::~BuiltinResources()
- {
- mCursorArrow = nullptr;
- mCursorArrowDrag = nullptr;
- mCursorArrowLeftRight = nullptr;
- mCursorIBeam = nullptr;
- mCursorDeny = nullptr;
- mCursorWait = nullptr;
- mCursorSizeNESW = nullptr;
- mCursorSizeNS = nullptr;
- mCursorSizeNWSE = nullptr;
- mCursorSizeWE = nullptr;
- }
- BuiltinResources::BuiltinResources()
- {
- Path absoluteDataPath = FileSystem::getWorkingDirectoryPath();
- absoluteDataPath.append(BuiltinDataFolder);
- if (FileSystem::exists(ResourceManifestPath))
- mResourceManifest = ResourceManifest::load(ResourceManifestPath, absoluteDataPath);
- if (mResourceManifest == nullptr)
- mResourceManifest = ResourceManifest::create("BuiltinResources");
- gResources().registerResourceManifest(mResourceManifest);
- #if BS_DEBUG_MODE
- if (BuiltinResourcesHelper::checkForModifications(BuiltinRawDataFolder, BuiltinDataFolder + L"Timestamp.asset"))
- {
- preprocess();
- BuiltinResourcesHelper::writeTimestamp(BuiltinDataFolder + L"Timestamp.asset");
- Path absoluteDataPath = FileSystem::getWorkingDirectoryPath();
- absoluteDataPath.append(BuiltinDataFolder);
- ResourceManifest::save(mResourceManifest, ResourceManifestPath, absoluteDataPath);
- }
- #endif
-
- mShaderSpriteText = getShader(ShaderSpriteTextFile);
- mShaderSpriteImage = getShader(ShaderSpriteImageAlphaFile);
- mShaderSpriteNonAlphaImage = getShader(ShaderSpriteImageNoAlphaFile);
- mShaderDiffuse = getShader(ShaderDiffuseFile);
- mShaderDummy = getShader(ShaderDummyFile);
- mWhiteSpriteTexture = getSkinTexture(WhiteTex);
- mSkin = gResources().load<GUISkin>(BuiltinDataFolder + (GUISkinFile + L".asset"));
- /************************************************************************/
- /* CURSOR */
- /************************************************************************/
- HTexture cursorArrowTex = getCursorTexture(CursorArrowTex);
- HTexture cursorArrowDragTex = getCursorTexture(CursorArrowDragTex);
- HTexture cursorArrowLeftRightTex = getCursorTexture(CursorArrowLeftRightTex);
- HTexture cursorIBeamTex = getCursorTexture(CursorIBeamTex);
- HTexture cursorDenyTex = getCursorTexture(CursorDenyTex);
- HTexture cursorWaitTex = getCursorTexture(CursorWaitTex);
- HTexture cursorSizeNESWTex = getCursorTexture(CursorSizeNESWTex);
- HTexture cursorSizeNSTex = getCursorTexture(CursorSizeNSTex);
- HTexture cursorSizeNWSETex = getCursorTexture(CursorSizeNWSETex);
- HTexture cursorSizeWETex = getCursorTexture(CursorSizeWETex);
- mCursorArrow = cursorArrowTex->getProperties().allocateSubresourceBuffer(0);
- cursorArrowTex->readSubresource(gCoreAccessor(), 0, mCursorArrow);
- mCursorArrowDrag = cursorArrowDragTex->getProperties().allocateSubresourceBuffer(0);
- cursorArrowDragTex->readSubresource(gCoreAccessor(), 0, mCursorArrowDrag);
- mCursorArrowLeftRight = cursorArrowLeftRightTex->getProperties().allocateSubresourceBuffer(0);
- cursorArrowLeftRightTex->readSubresource(gCoreAccessor(), 0, mCursorArrowLeftRight);
- mCursorIBeam = cursorIBeamTex->getProperties().allocateSubresourceBuffer(0);
- cursorIBeamTex->readSubresource(gCoreAccessor(), 0, mCursorIBeam);
- mCursorDeny = cursorDenyTex->getProperties().allocateSubresourceBuffer(0);
- cursorDenyTex->readSubresource(gCoreAccessor(), 0, mCursorDeny);
- mCursorWait = cursorWaitTex->getProperties().allocateSubresourceBuffer(0);
- cursorWaitTex->readSubresource(gCoreAccessor(), 0, mCursorWait);
- mCursorSizeNESW = cursorSizeNESWTex->getProperties().allocateSubresourceBuffer(0);
- cursorSizeNESWTex->readSubresource(gCoreAccessor(), 0, mCursorSizeNESW);
- mCursorSizeNS = cursorSizeNSTex->getProperties().allocateSubresourceBuffer(0);
- cursorSizeNSTex->readSubresource(gCoreAccessor(), 0, mCursorSizeNS);
- mCursorSizeNWSE = cursorSizeNWSETex->getProperties().allocateSubresourceBuffer(0);
- cursorSizeNWSETex->readSubresource(gCoreAccessor(), 0, mCursorSizeNWSE);
- mCursorSizeWE = cursorSizeWETex->getProperties().allocateSubresourceBuffer(0);
- cursorSizeWETex->readSubresource(gCoreAccessor(), 0, mCursorSizeWE);
- gCoreAccessor().submitToCoreThread(true);
- }
- void BuiltinResources::preprocess()
- {
- FileSystem::remove(EngineCursorFolder);
- FileSystem::remove(EngineShaderIncludeFolder);
- FileSystem::remove(EngineShaderFolder);
- FileSystem::remove(EngineSkinFolder);
- FileSystem::remove(EngineMeshFolder);
- BuiltinResourcesHelper::importAssets(EngineRawCursorFolder, EngineCursorFolder, mResourceManifest);
- BuiltinResourcesHelper::importAssets(EngineRawShaderIncludeFolder, EngineShaderIncludeFolder, mResourceManifest); // Hidden dependency: Includes must be imported before shaders
- BuiltinResourcesHelper::importAssets(EngineRawShaderFolder, EngineShaderFolder, mResourceManifest);
- BuiltinResourcesHelper::importAssets(EngineRawSkinFolder, EngineSkinFolder, mResourceManifest);
- // Import font
- BuiltinResourcesHelper::importFont(BuiltinRawDataFolder + DefaultFontFilename, BuiltinDataFolder, DefaultFontSize, false, mResourceManifest);
- // Generate & save GUI sprite textures
- BuiltinResourcesHelper::generateSpriteTextures(EngineSkinFolder, mResourceManifest);
- // Generate & save GUI skin
- {
- HGUISkin skin = generateGUISkin();
- Path outputPath = FileSystem::getWorkingDirectoryPath() + BuiltinDataFolder + (GUISkinFile + L".asset");
- Resources::instance().save(skin, outputPath, true);
- mResourceManifest->registerResource(skin.getUUID(), outputPath);
- }
- // Generate & save meshes
- generateMeshes();
-
- Resources::instance().unloadAllUnused();
- }
- HGUISkin BuiltinResources::generateGUISkin()
- {
- Path fontPath = FileSystem::getWorkingDirectoryPath();
- fontPath.append(BuiltinDataFolder);
- fontPath.append(DefaultFontFilename + L".asset");
- HFont font = Resources::instance().load<Font>(fontPath);
- HGUISkin skin = GUISkin::create();
- // Label
- GUIElementStyle labelStyle;
- labelStyle.font = font;
- labelStyle.fontSize = DefaultFontSize;
- labelStyle.normal.textColor = TextNormalColor;
- labelStyle.fixedWidth = false;
- labelStyle.fixedHeight = true;
- labelStyle.height = 14;
- labelStyle.minWidth = 10;
- skin->setStyle(GUILabel::getGUITypeName(), labelStyle);
- // Button
- GUIElementStyle buttonStyle;
- buttonStyle.normal.texture = getSkinTexture(ButtonNormalTex);
- buttonStyle.hover.texture = getSkinTexture(ButtonHoverTex);
- buttonStyle.active.texture = getSkinTexture(ButtonActiveTex);
- buttonStyle.normalOn.texture = getSkinTexture(ButtonActiveTex);
- buttonStyle.hoverOn.texture = getSkinTexture(ButtonActiveTex);
- buttonStyle.activeOn.texture = getSkinTexture(ButtonActiveTex);
- buttonStyle.normal.textColor = TextNormalColor;
- buttonStyle.hover.textColor = TextNormalColor;
- buttonStyle.active.textColor = TextActiveColor;
- buttonStyle.normalOn.textColor = TextActiveColor;
- buttonStyle.hoverOn.textColor = TextActiveColor;
- buttonStyle.activeOn.textColor = TextActiveColor;
- buttonStyle.border.left = 2;
- buttonStyle.border.right = 2;
- buttonStyle.border.top = 2;
- buttonStyle.border.bottom = 4;
- buttonStyle.contentOffset.top = 2;
- buttonStyle.contentOffset.left = 3;
- buttonStyle.contentOffset.right = 3;
- buttonStyle.margins.bottom = 2;
- buttonStyle.fixedHeight = true;
- buttonStyle.height = 21;
- buttonStyle.minWidth = 20;
- buttonStyle.font = font;
- buttonStyle.fontSize = DefaultFontSize;
- buttonStyle.textHorzAlign = THA_Center;
- buttonStyle.textVertAlign = TVA_Center;
- skin->setStyle(GUIButton::getGUITypeName(), buttonStyle);
- // Toggle
- GUIElementStyle toggleStyle;
- toggleStyle.normal.texture = getSkinTexture(ToggleNormalTex);
- toggleStyle.hover.texture = getSkinTexture(ToggleHoverTex);
- toggleStyle.active.texture = toggleStyle.hover.texture;
- toggleStyle.normalOn.texture = getSkinTexture(ToggleNormalOnTex);
- toggleStyle.hoverOn.texture = getSkinTexture(ToggleHoverOnTex);
- toggleStyle.activeOn.texture = toggleStyle.hoverOn.texture;
- toggleStyle.fixedHeight = true;
- toggleStyle.fixedWidth = true;
- toggleStyle.margins.bottom = 2;
- toggleStyle.height = 15;
- toggleStyle.width = 13;
- skin->setStyle(GUIToggle::getGUITypeName(), toggleStyle);
- // Input box
- GUIElementStyle inputBoxStyle;
- inputBoxStyle.normal.texture = getSkinTexture(InputBoxNormalTex);
- inputBoxStyle.hover.texture = getSkinTexture(InputBoxHoverTex);
- inputBoxStyle.focused.texture = getSkinTexture(InputBoxFocusedTex);
- inputBoxStyle.active.texture = inputBoxStyle.normal.texture;
- inputBoxStyle.normal.textColor = TextNormalColor;
- inputBoxStyle.hover.textColor = TextNormalColor;
- inputBoxStyle.focused.textColor = TextNormalColor;
- inputBoxStyle.active.textColor = TextNormalColor;
- inputBoxStyle.border.left = 4;
- inputBoxStyle.border.right = 4;
- inputBoxStyle.border.top = 4;
- inputBoxStyle.border.bottom = 6;
- inputBoxStyle.contentOffset.left = 4;
- inputBoxStyle.contentOffset.right = 4;
- inputBoxStyle.contentOffset.top = 4;
- inputBoxStyle.contentOffset.bottom = 4;
- inputBoxStyle.margins.bottom = 2;
- inputBoxStyle.fixedHeight = true;
- inputBoxStyle.height = 21;
- inputBoxStyle.minWidth = 10;
- inputBoxStyle.font = font;
- inputBoxStyle.fontSize = DefaultFontSize;
- inputBoxStyle.textHorzAlign = THA_Left;
- inputBoxStyle.textVertAlign = TVA_Top;
- skin->setStyle(GUIInputBox::getGUITypeName(), inputBoxStyle);
- /************************************************************************/
- /* SCROLL BAR */
- /************************************************************************/
- // Up button
- GUIElementStyle scrollUpBtnStyle;
- scrollUpBtnStyle.normal.texture = getSkinTexture(ScrollBarUpNormalTex);
- scrollUpBtnStyle.hover.texture = getSkinTexture(ScrollBarUpHoverTex);
- scrollUpBtnStyle.active.texture = getSkinTexture(ScrollBarUpActiveTex);
- scrollUpBtnStyle.fixedHeight = true;
- scrollUpBtnStyle.fixedWidth = true;
- scrollUpBtnStyle.height = 11;
- scrollUpBtnStyle.width = 13;
- skin->setStyle("ScrollUpBtn", scrollUpBtnStyle);
- // Down button
- GUIElementStyle scrollDownBtnStyle;
- scrollDownBtnStyle.normal.texture = getSkinTexture(ScrollBarDownNormalTex);
- scrollDownBtnStyle.hover.texture = getSkinTexture(ScrollBarDownHoverTex);
- scrollDownBtnStyle.active.texture = getSkinTexture(ScrollBarDownActiveTex);
- scrollDownBtnStyle.fixedHeight = true;
- scrollDownBtnStyle.fixedWidth = true;
- scrollDownBtnStyle.height = 11;
- scrollDownBtnStyle.width = 13;
- skin->setStyle("ScrollDownBtn", scrollDownBtnStyle);
- // Left button
- GUIElementStyle scrollLeftBtnStyle;
- scrollLeftBtnStyle.normal.texture = getSkinTexture(ScrollBarLeftNormalTex);
- scrollLeftBtnStyle.hover.texture = getSkinTexture(ScrollBarLeftHoverTex);
- scrollLeftBtnStyle.active.texture = getSkinTexture(ScrollBarLeftActiveTex);
- scrollLeftBtnStyle.fixedHeight = true;
- scrollLeftBtnStyle.fixedWidth = true;
- scrollLeftBtnStyle.height = 13;
- scrollLeftBtnStyle.width = 11;
- skin->setStyle("ScrollLeftBtn", scrollLeftBtnStyle);
- // Right button
- GUIElementStyle scrollRightBtnStyle;
- scrollRightBtnStyle.normal.texture = getSkinTexture(ScrollBarRightNormalTex);
- scrollRightBtnStyle.hover.texture = getSkinTexture(ScrollBarRightHoverTex);
- scrollRightBtnStyle.active.texture = getSkinTexture(ScrollBarRightActiveTex);
- scrollRightBtnStyle.fixedHeight = true;
- scrollRightBtnStyle.fixedWidth = true;
- scrollRightBtnStyle.height = 13;
- scrollRightBtnStyle.width = 11;
- skin->setStyle("ScrollRightBtn", scrollRightBtnStyle);
- // Horizontal handle
- GUIElementStyle scrollBarHorzBtnStyle;
- scrollBarHorzBtnStyle.normal.texture = getSkinTexture(ScrollBarHandleHorzNormalTex);
- scrollBarHorzBtnStyle.hover.texture = getSkinTexture(ScrollBarHandleHorzHoverTex);
- scrollBarHorzBtnStyle.active.texture = getSkinTexture(ScrollBarHandleHorzActiveTex);
- scrollBarHorzBtnStyle.fixedHeight = true;
- scrollBarHorzBtnStyle.fixedWidth = false;
- scrollBarHorzBtnStyle.width = 10;
- scrollBarHorzBtnStyle.height = 13;
- scrollBarHorzBtnStyle.border.left = 4;
- scrollBarHorzBtnStyle.border.right = 4;
- skin->setStyle("ScrollBarHorzBtn", scrollBarHorzBtnStyle);
- // Vertical handle
- GUIElementStyle scrollBarVertBtnStyle;
- scrollBarVertBtnStyle.normal.texture = getSkinTexture(ScrollBarHandleVertNormalTex);
- scrollBarVertBtnStyle.hover.texture = getSkinTexture(ScrollBarHandleVertHoverTex);
- scrollBarVertBtnStyle.active.texture = getSkinTexture(ScrollBarHandleVertActiveTex);
- scrollBarVertBtnStyle.fixedHeight = false;
- scrollBarVertBtnStyle.fixedWidth = true;
- scrollBarVertBtnStyle.width = 13;
- scrollBarVertBtnStyle.height = 10;
- scrollBarVertBtnStyle.border.top = 4;
- scrollBarVertBtnStyle.border.bottom = 4;
- skin->setStyle("ScrollBarVertBtn", scrollBarVertBtnStyle);
- // Vertical scroll bar
- GUIElementStyle vertScrollBarStyle;
- vertScrollBarStyle.normal.texture = getSkinTexture(ScrollBarVBgTex);
- vertScrollBarStyle.hover.texture = vertScrollBarStyle.normal.texture;
- vertScrollBarStyle.active.texture = vertScrollBarStyle.normal.texture;
- vertScrollBarStyle.fixedHeight = false;
- vertScrollBarStyle.fixedWidth = true;
- vertScrollBarStyle.minHeight = 8;
- vertScrollBarStyle.width = 16;
- skin->setStyle("ScrollBarVert", vertScrollBarStyle);
- // Horizontal scroll bar
- GUIElementStyle horzScrollBarStyle;
- horzScrollBarStyle.normal.texture = getSkinTexture(ScrollBarHBgTex);
- horzScrollBarStyle.hover.texture = horzScrollBarStyle.normal.texture;
- horzScrollBarStyle.active.texture = horzScrollBarStyle.normal.texture;
- horzScrollBarStyle.fixedHeight = true;
- horzScrollBarStyle.fixedWidth = false;
- horzScrollBarStyle.minWidth = 8;
- horzScrollBarStyle.height = 16;
- skin->setStyle("ScrollBarHorz", horzScrollBarStyle);
- /************************************************************************/
- /* DROP DOWN BOX */
- /************************************************************************/
- // ListBox button
- GUIElementStyle dropDownListStyle;
- dropDownListStyle.normal.texture = getSkinTexture(DropDownBtnNormalTex);
- dropDownListStyle.hover.texture = getSkinTexture(DropDownBtnHoverTex);
- dropDownListStyle.active.texture = getSkinTexture(DropDownBtnActiveTex);
- dropDownListStyle.normalOn.texture = dropDownListStyle.active.texture;
- dropDownListStyle.hoverOn.texture = dropDownListStyle.active.texture;
- dropDownListStyle.activeOn.texture = dropDownListStyle.active.texture;
- dropDownListStyle.normal.textColor = TextNormalColor;
- dropDownListStyle.hover.textColor = TextNormalColor;
- dropDownListStyle.active.textColor = TextNormalColor;
- dropDownListStyle.normalOn.textColor = TextNormalColor;
- dropDownListStyle.hoverOn.textColor = TextNormalColor;
- dropDownListStyle.activeOn.textColor = TextNormalColor;
- dropDownListStyle.fixedHeight = true;
- dropDownListStyle.fixedWidth = false;
- dropDownListStyle.height = 21;
- dropDownListStyle.minWidth = 20;
- dropDownListStyle.contentOffset.left = 3;
- dropDownListStyle.contentOffset.right = 18;
- dropDownListStyle.contentOffset.top = 2;
- dropDownListStyle.contentOffset.bottom = 2;
- dropDownListStyle.border.left = 2;
- dropDownListStyle.border.right = 16;
- dropDownListStyle.border.top = 2;
- dropDownListStyle.border.bottom = 4;
- dropDownListStyle.margins.bottom = 2;
- dropDownListStyle.font = font;
- dropDownListStyle.fontSize = DefaultFontSize;
- dropDownListStyle.textHorzAlign = THA_Left;
- dropDownListStyle.textVertAlign = TVA_Center;
- skin->setStyle("ListBox", dropDownListStyle);
- // DropDown scroll up button
- GUIElementStyle dropDownScrollUpBtnStyle;
- dropDownScrollUpBtnStyle.normal.texture = getSkinTexture(DropDownBoxBtnUpNormalTex);
- dropDownScrollUpBtnStyle.hover.texture = getSkinTexture(DropDownBoxBtnUpHoverTex);
- dropDownScrollUpBtnStyle.active.texture = dropDownScrollUpBtnStyle.hover.texture;
- dropDownScrollUpBtnStyle.fixedHeight = true;
- dropDownScrollUpBtnStyle.fixedWidth = true;
- dropDownScrollUpBtnStyle.width = 8;
- dropDownScrollUpBtnStyle.height = 12;
- skin->setStyle("ListBoxScrollUpBtn", dropDownScrollUpBtnStyle);
- skin->setStyle("MenuBarScrollUpBtn", dropDownScrollUpBtnStyle);
- skin->setStyle("ContextMenuScrollUpBtn", dropDownScrollUpBtnStyle);
- // DropDown scroll down button
- GUIElementStyle dropDownScrollDownBtnStyle;
- dropDownScrollDownBtnStyle.normal.texture = getSkinTexture(DropDownBoxBtnDownNormalTex);
- dropDownScrollDownBtnStyle.hover.texture = getSkinTexture(DropDownBoxBtnDownHoverTex);
- dropDownScrollDownBtnStyle.active.texture = dropDownScrollDownBtnStyle.hover.texture;
- dropDownScrollDownBtnStyle.fixedHeight = true;
- dropDownScrollDownBtnStyle.fixedWidth = true;
- dropDownScrollDownBtnStyle.width = 8;
- dropDownScrollDownBtnStyle.height = 12;
- skin->setStyle("ListBoxScrollDownBtn", dropDownScrollDownBtnStyle);
- skin->setStyle("MenuBarScrollDownBtn", dropDownScrollDownBtnStyle);
- skin->setStyle("ContextMenuScrollDownBtn", dropDownScrollDownBtnStyle);
- // DropDown handle
- GUIElementStyle dropDownScrollHandleStyle;
- dropDownScrollHandleStyle.normal.texture = getSkinTexture(DropDownBoxHandleTex);
- dropDownScrollHandleStyle.fixedHeight = false;
- dropDownScrollHandleStyle.fixedWidth = true;
- dropDownScrollHandleStyle.height = 8;
- dropDownScrollHandleStyle.width = 8;
- skin->setStyle("ListBoxHandle", dropDownScrollHandleStyle);
- skin->setStyle("MenuBarHandle", dropDownScrollHandleStyle);
- skin->setStyle("ContextMenuHandle", dropDownScrollHandleStyle);
- // DropDown sidebar background
- GUIElementStyle dropDownSidebarBg;
- dropDownSidebarBg.normal.texture = getSkinTexture(DropDownBoxSideBgTex);
- dropDownSidebarBg.fixedHeight = false;
- dropDownSidebarBg.fixedWidth = true;
- dropDownSidebarBg.height = 8;
- dropDownSidebarBg.width = 9;
- dropDownSidebarBg.border.left = 1;
- dropDownSidebarBg.border.top = 1;
- dropDownSidebarBg.border.bottom = 1;
- skin->setStyle("ListBoxSidebarBg", dropDownSidebarBg);
- skin->setStyle("MenuBarSidebarBg", dropDownSidebarBg);
- skin->setStyle("ContextMenuSidebarBg", dropDownSidebarBg);
- // DropDown entry button
- GUIElementStyle dropDownEntryBtnStyle;
- dropDownEntryBtnStyle.normal.texture = getSkinTexture(DropDownBoxEntryNormalTex);
- dropDownEntryBtnStyle.hover.texture = getSkinTexture(DropDownBoxEntryHoverTex);
- dropDownEntryBtnStyle.active.texture = dropDownEntryBtnStyle.hover.texture;
- dropDownEntryBtnStyle.normalOn.texture = dropDownEntryBtnStyle.hover.texture;
- dropDownEntryBtnStyle.hoverOn.texture = dropDownEntryBtnStyle.hover.texture;
- dropDownEntryBtnStyle.activeOn.texture = dropDownEntryBtnStyle.hover.texture;
- dropDownEntryBtnStyle.normal.textColor = TextNormalColor;
- dropDownEntryBtnStyle.hover.textColor = TextNormalColor;
- dropDownEntryBtnStyle.active.textColor = TextNormalColor;
- dropDownEntryBtnStyle.normalOn.textColor = TextNormalColor;
- dropDownEntryBtnStyle.hoverOn.textColor = TextNormalColor;
- dropDownEntryBtnStyle.activeOn.textColor = TextNormalColor;
- dropDownEntryBtnStyle.fixedHeight = true;
- dropDownEntryBtnStyle.fixedWidth = false;
- dropDownEntryBtnStyle.height = 16;
- dropDownEntryBtnStyle.width = 30;
- dropDownEntryBtnStyle.font = font;
- dropDownEntryBtnStyle.fontSize = DefaultFontSize;
- dropDownEntryBtnStyle.textHorzAlign = THA_Left;
- dropDownEntryBtnStyle.textVertAlign = TVA_Center;
- skin->setStyle(GUIDropDownContent::ENTRY_STYLE_TYPE, dropDownEntryBtnStyle);
- // DropDown entry button with expand
- GUIElementStyle dropDownEntryExpBtnStyle;
- dropDownEntryExpBtnStyle.normal.texture = getSkinTexture(DropDownBoxEntryExpNormalTex);
- dropDownEntryExpBtnStyle.hover.texture = getSkinTexture(DropDownBoxEntryExpHoverTex);
- dropDownEntryExpBtnStyle.active.texture = dropDownEntryExpBtnStyle.hover.texture;
- dropDownEntryExpBtnStyle.normalOn.texture = dropDownEntryExpBtnStyle.hover.texture;
- dropDownEntryExpBtnStyle.hoverOn.texture = dropDownEntryExpBtnStyle.hover.texture;
- dropDownEntryExpBtnStyle.activeOn.texture = dropDownEntryExpBtnStyle.hover.texture;
- dropDownEntryExpBtnStyle.normal.textColor = TextNormalColor;
- dropDownEntryExpBtnStyle.hover.textColor = TextNormalColor;
- dropDownEntryExpBtnStyle.active.textColor = TextNormalColor;
- dropDownEntryExpBtnStyle.normalOn.textColor = TextNormalColor;
- dropDownEntryExpBtnStyle.hoverOn.textColor = TextNormalColor;
- dropDownEntryExpBtnStyle.activeOn.textColor = TextNormalColor;
- dropDownEntryExpBtnStyle.fixedHeight = true;
- dropDownEntryExpBtnStyle.fixedWidth = false;
- dropDownEntryExpBtnStyle.height = 16;
- dropDownEntryExpBtnStyle.width = 30;
- dropDownEntryExpBtnStyle.border.right = 13;
- dropDownEntryExpBtnStyle.font = font;
- dropDownEntryExpBtnStyle.fontSize = DefaultFontSize;
- dropDownEntryExpBtnStyle.textHorzAlign = THA_Left;
- dropDownEntryExpBtnStyle.textVertAlign = TVA_Center;
- skin->setStyle(GUIDropDownContent::ENTRY_EXP_STYLE_TYPE, dropDownEntryExpBtnStyle);
- // Drop down separator
- GUIElementStyle dropDownSeparatorStyle;
- dropDownSeparatorStyle.normal.texture = getSkinTexture(DropDownSeparatorTex);
- dropDownSeparatorStyle.fixedHeight = true;
- dropDownSeparatorStyle.fixedWidth = false;
- dropDownSeparatorStyle.height = 3;
- dropDownSeparatorStyle.width = 30;
- skin->setStyle(GUIDropDownContent::SEPARATOR_STYLE_TYPE, dropDownSeparatorStyle);
- // Drop down content
- GUIElementStyle dropDownContentStyle;
- dropDownContentStyle.minWidth = 50;
- dropDownContentStyle.minHeight = 20;
- dropDownContentStyle.subStyles[GUIDropDownContent::ENTRY_STYLE_TYPE] = GUIDropDownContent::ENTRY_STYLE_TYPE;
- dropDownContentStyle.subStyles[GUIDropDownContent::ENTRY_EXP_STYLE_TYPE] = GUIDropDownContent::ENTRY_EXP_STYLE_TYPE;
- dropDownContentStyle.subStyles[GUIDropDownContent::SEPARATOR_STYLE_TYPE] = GUIDropDownContent::SEPARATOR_STYLE_TYPE;
- skin->setStyle("ListBoxContent", dropDownContentStyle);
- skin->setStyle("MenuBarContent", dropDownContentStyle);
- skin->setStyle("ContextMenuContent", dropDownContentStyle);
- // DropDown box frame
- GUIElementStyle dropDownBoxStyle;
- dropDownBoxStyle.normal.texture = getSkinTexture(DropDownBoxBgTex);
- dropDownBoxStyle.hover.texture = dropDownBoxStyle.normal.texture;
- dropDownBoxStyle.active.texture = dropDownBoxStyle.hover.texture;
- dropDownBoxStyle.fixedHeight = false;
- dropDownBoxStyle.fixedWidth = false;
- dropDownBoxStyle.border.left = 2;
- dropDownBoxStyle.border.right = 2;
- dropDownBoxStyle.border.top = 2;
- dropDownBoxStyle.border.bottom = 4;
- dropDownBoxStyle.margins.left = 6;
- dropDownBoxStyle.margins.right = 6;
- dropDownBoxStyle.margins.top = 4;
- dropDownBoxStyle.margins.bottom = 6;
- skin->setStyle("ListBoxFrame", dropDownBoxStyle);
- skin->setStyle("MenuBarFrame", dropDownBoxStyle);
- skin->setStyle("ContextMenuFrame", dropDownBoxStyle);
- /************************************************************************/
- /* OTHER */
- /************************************************************************/
- // Right-aligned label
- GUIElementStyle rightAlignedLabelStyle;
- rightAlignedLabelStyle.font = font;
- rightAlignedLabelStyle.fontSize = DefaultFontSize;
- rightAlignedLabelStyle.fixedWidth = false;
- rightAlignedLabelStyle.fixedHeight = true;
- rightAlignedLabelStyle.height = 11;
- rightAlignedLabelStyle.minWidth = 10;
- rightAlignedLabelStyle.textHorzAlign = THA_Right;
- rightAlignedLabelStyle.normal.textColor = TextNormalColor;
- skin->setStyle("RightAlignedLabel", rightAlignedLabelStyle);
- return skin;
- }
- void BuiltinResources::generateMeshes()
- {
- VertexDataDescPtr vertexDesc = bs_shared_ptr_new<VertexDataDesc>();
- vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
- vertexDesc->addVertElem(VET_FLOAT3, VES_NORMAL);
- vertexDesc->addVertElem(VET_COLOR, VES_COLOR);
- UINT32 boxNumVertices = 0;
- UINT32 boxNumIndices = 0;
- ShapeMeshes3D::getNumElementsAABox(boxNumVertices, boxNumIndices);
- MeshDataPtr boxMeshData = bs_shared_ptr_new<MeshData>(boxNumVertices, boxNumIndices, vertexDesc);
- AABox box(Vector3(-0.5f, -0.5f, -0.5f), Vector3(0.5f, 0.5f, 0.5f));
- ShapeMeshes3D::solidAABox(box, boxMeshData, 0, 0);
- HMesh boxMesh = Mesh::create(boxMeshData);
- UINT32 sphereNumVertices = 0;
- UINT32 sphereNumIndices = 0;
- ShapeMeshes3D::getNumElementsSphere(1, sphereNumVertices, sphereNumIndices);
- MeshDataPtr sphereMeshData = bs_shared_ptr_new<MeshData>(sphereNumVertices, sphereNumIndices, vertexDesc);
- ShapeMeshes3D::solidSphere(Sphere(Vector3::ZERO, 0.0f), sphereMeshData, 0, 0);
- HMesh sphereMesh = Mesh::create(sphereMeshData);
- UINT32 coneNumVertices = 0;
- UINT32 coneNumIndices = 0;
- ShapeMeshes3D::getNumElementsCone(10, coneNumVertices, coneNumIndices);
- MeshDataPtr coneMeshData = bs_shared_ptr_new<MeshData>(coneNumVertices, coneNumIndices, vertexDesc);
- ShapeMeshes3D::solidCone(Vector3::ZERO, Vector3::UNIT_Y, 1.0f, 1.0f, coneMeshData, 0, 0);
- HMesh coneMesh = Mesh::create(coneMeshData);
- UINT32 quadNumVertices = 8;
- UINT32 quadNumIndices = 12;
- ShapeMeshes3D::getNumElementsQuad(quadNumVertices, quadNumIndices);
- MeshDataPtr quadMeshData = bs_shared_ptr_new<MeshData>(quadNumVertices, quadNumIndices, vertexDesc);
- std::array<Vector3, 2> axes = { Vector3::UNIT_X, Vector3::UNIT_Y };
- std::array<float, 2> sizes = { 1.0f, 1.0f };
- Rect3 rect(Vector3::ZERO, axes, sizes);
- ShapeMeshes3D::solidQuad(rect, quadMeshData, 0, 0);
- HMesh quadMesh = Mesh::create(quadMeshData);
- UINT32 discNumVertices = 0;
- UINT32 discNumIndices = 0;
- ShapeMeshes3D::getNumElementsDisc(10, discNumVertices, discNumIndices);
- MeshDataPtr discMeshData = bs_shared_ptr_new<MeshData>(discNumVertices, discNumIndices, vertexDesc);
- ShapeMeshes3D::solidDisc(Vector3::ZERO, 1.0f, Vector3::UNIT_Y, discMeshData, 0, 0);
- HMesh discMesh = Mesh::create(discMeshData);
- // Save all meshes
- Path outputDir = FileSystem::getWorkingDirectoryPath() + EngineMeshFolder;
- Path meshPath = outputDir + MeshBoxFile;
- Resources::instance().save(boxMesh, meshPath, true);
- mResourceManifest->registerResource(boxMesh.getUUID(), meshPath);
- Path spherePath = outputDir + MeshSphereFile;
- Resources::instance().save(sphereMesh, spherePath, true);
- mResourceManifest->registerResource(sphereMesh.getUUID(), spherePath);
- Path conePath = outputDir + MeshConeFile;
- Resources::instance().save(coneMesh, conePath, true);
- mResourceManifest->registerResource(coneMesh.getUUID(), conePath);
- Path quadPath = outputDir + MeshQuadFile;
- Resources::instance().save(quadMesh, quadPath, true);
- mResourceManifest->registerResource(quadMesh.getUUID(), quadPath);
- Path discPath = outputDir + MeshDiscFile;
- Resources::instance().save(discMesh, discPath, true);
- mResourceManifest->registerResource(discMesh.getUUID(), discPath);
- }
- HSpriteTexture BuiltinResources::getSkinTexture(const WString& name)
- {
- Path texturePath = FileSystem::getWorkingDirectoryPath();
- texturePath.append(EngineSkinFolder);
- texturePath.append(L"sprite_" + name + L".asset");
- return Resources::instance().load<SpriteTexture>(texturePath);
- }
- HShader BuiltinResources::getShader(const WString& name)
- {
- Path programPath = EngineShaderFolder;
- programPath.append(name + L".asset");
- return gResources().load<Shader>(programPath);
- }
- HTexture BuiltinResources::getCursorTexture(const WString& name)
- {
- Path cursorPath = FileSystem::getWorkingDirectoryPath();
- cursorPath.append(EngineCursorFolder);
- cursorPath.append(name + L".asset");
- return Resources::instance().load<Texture>(cursorPath);
- }
- const PixelData& BuiltinResources::getCursorArrow(Vector2I& hotSpot)
- {
- hotSpot = CursorArrowHotspot;
- return *mCursorArrow.get();
- }
- const PixelData& BuiltinResources::getCursorArrowDrag(Vector2I& hotSpot)
- {
- hotSpot = CursorArrowDragHotspot;
- return *mCursorArrowDrag.get();
- }
- const PixelData& BuiltinResources::getCursorWait(Vector2I& hotSpot)
- {
- hotSpot = CursorWaitHotspot;
- return *mCursorWait.get();
- }
- const PixelData& BuiltinResources::getCursorIBeam(Vector2I& hotSpot)
- {
- hotSpot = CursorIBeamHotspot;
- return *mCursorIBeam.get();
- }
- const PixelData& BuiltinResources::getCursorSizeNESW(Vector2I& hotSpot)
- {
- hotSpot = CursorSizeNESWHotspot;
- return *mCursorSizeNESW.get();
- }
- const PixelData& BuiltinResources::getCursorSizeNS(Vector2I& hotSpot)
- {
- hotSpot = CursorSizeNSHotspot;
- return *mCursorSizeNS.get();
- }
- const PixelData& BuiltinResources::getCursorSizeNWSE(Vector2I& hotSpot)
- {
- hotSpot = CursorSizeNWSEHotspot;
- return *mCursorSizeNWSE.get();
- }
- const PixelData& BuiltinResources::getCursorSizeWE(Vector2I& hotSpot)
- {
- hotSpot = CursorSizeWEHotspot;
- return *mCursorSizeWE.get();
- }
- const PixelData& BuiltinResources::getCursorDeny(Vector2I& hotSpot)
- {
- hotSpot = CursorDenyHotspot;
- return *mCursorDeny.get();
- }
- const PixelData& BuiltinResources::getCursorMoveLeftRight(Vector2I& hotSpot)
- {
- hotSpot = CursorArrowLeftRightHotspot;
- return *mCursorArrowLeftRight.get();
- }
- HMesh BuiltinResources::getMesh(BuiltinMesh mesh) const
- {
- Path meshPath = FileSystem::getWorkingDirectoryPath();
- meshPath.append(EngineMeshFolder);
- switch (mesh)
- {
- case BuiltinMesh::Box:
- meshPath.append(MeshBoxFile);
- break;
- case BuiltinMesh::Sphere:
- meshPath.append(MeshSphereFile);
- break;
- case BuiltinMesh::Cone:
- meshPath.append(MeshConeFile);
- break;
- case BuiltinMesh::Quad:
- meshPath.append(MeshQuadFile);
- break;
- case BuiltinMesh::Disc:
- meshPath.append(MeshDiscFile);
- break;
- }
- return Resources::instance().load<Mesh>(meshPath);
- }
- GUIMaterialInfo BuiltinResources::createSpriteTextMaterial() const
- {
- GUIMaterialInfo info;
- info.material = Material::create(mShaderSpriteText);
- info.mainTexture = info.material->getParamTexture("mainTexture");
- info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
- info.tint = info.material->getParamVec4("tint");
- return info;
- }
- GUIMaterialInfo BuiltinResources::createSpriteImageMaterial() const
- {
- GUIMaterialInfo info;
- info.material = Material::create(mShaderSpriteImage);
- info.mainTexture = info.material->getParamTexture("mainTexture");
- info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
- info.tint = info.material->getParamVec4("tint");
- return info;
- }
- GUIMaterialInfo BuiltinResources::createSpriteNonAlphaImageMaterial() const
- {
- GUIMaterialInfo info;
- info.material = Material::create(mShaderSpriteNonAlphaImage);
- info.mainTexture = info.material->getParamTexture("mainTexture");
- info.mainTexSampler = info.material->getParamSamplerState("mainTexSamp");
- info.tint = info.material->getParamVec4("tint");
- return info;
- }
- HMaterial BuiltinResources::createDummyMaterial() const
- {
- return Material::create(mShaderDummy);
- }
- void BuiltinResourcesHelper::importAssets(const Path& inputFolder, const Path& outputFolder, const ResourceManifestPtr& manifest)
- {
- if (!FileSystem::exists(inputFolder))
- return;
- auto importResource = [&](const Path& filePath)
- {
- Path relativePath = filePath.getRelative(inputFolder);
- Path outputPath = FileSystem::getWorkingDirectoryPath() + outputFolder + relativePath;
- outputPath.setFilename(outputPath.getWFilename() + L".asset");
- HResource resource = Importer::instance().import(filePath);
- if (resource != nullptr)
- {
- Resources::instance().save(resource, outputPath, true);
- manifest->registerResource(resource.getUUID(), outputPath);
- }
- return true;
- };
- FileSystem::iterate(inputFolder, importResource);
- }
- void BuiltinResourcesHelper::importFont(const Path& inputFile, const Path& outputFolder,
- UINT32 size, bool antialiasing, const ResourceManifestPtr& manifest)
- {
- ImportOptionsPtr fontImportOptions = Importer::instance().createImportOptions(inputFile);
- if (rtti_is_of_type<FontImportOptions>(fontImportOptions))
- {
- FontImportOptions* importOptions = static_cast<FontImportOptions*>(fontImportOptions.get());
- Vector<UINT32> fontSizes;
- fontSizes.push_back(size);
- importOptions->setFontSizes(fontSizes);
- importOptions->setAntialiasing(antialiasing);
- }
- else
- return;
- HFont font = Importer::instance().import<Font>(inputFile, fontImportOptions);
- WString fontName = inputFile.getWFilename();
- Path outputPath = FileSystem::getWorkingDirectoryPath() + outputFolder + fontName;
- outputPath.setFilename(outputPath.getWFilename() + L".asset");
- Resources::instance().save(font, outputPath, true);
- manifest->registerResource(font.getUUID(), outputPath);
- // Save font texture pages as well. TODO - Later maybe figure out a more automatic way to do this
- const FontData* fontData = font->getFontDataForSize(size);
- Path texPageOutputPath = FileSystem::getWorkingDirectoryPath() + outputFolder;
- UINT32 pageIdx = 0;
- for (auto tex : fontData->texturePages)
- {
- texPageOutputPath.setFilename(fontName + L"_texpage_" + toWString(pageIdx) + L".asset");
- Resources::instance().save(tex, texPageOutputPath, true);
- manifest->registerResource(tex.getUUID(), texPageOutputPath);
- }
- }
- void BuiltinResourcesHelper::generateSpriteTextures(const Path& folder, const ResourceManifestPtr& manifest)
- {
- if (!FileSystem::exists(folder))
- return;
- Vector<Path> filesToProcess;
- auto gather = [&](const Path& filePath)
- {
- filesToProcess.push_back(filePath);
- return true;
- };
- FileSystem::iterate(folder, gather);
- for (auto& filePath : filesToProcess)
- {
- Path outputPath = FileSystem::getWorkingDirectoryPath() + filePath;
- outputPath.setFilename(L"sprite_" + outputPath.getWFilename());
- HTexture source = gResources().load<Texture>(filePath);
- if (source != nullptr)
- {
- HSpriteTexture spriteTex = SpriteTexture::create(source);
- Resources::instance().save(spriteTex, outputPath, true);
- manifest->registerResource(spriteTex.getUUID(), outputPath);
- }
- }
- }
- void BuiltinResourcesHelper::writeTimestamp(const Path& file)
- {
- DataStreamPtr fileStream = FileSystem::createAndOpenFile(file);
- time_t currentTime = std::time(nullptr);
- fileStream->write(¤tTime, sizeof(currentTime));
- fileStream->close();
- }
- bool BuiltinResourcesHelper::checkForModifications(const Path& folder, const Path& timeStampFile)
- {
- if (!FileSystem::exists(timeStampFile))
- return true;
- DataStreamPtr fileStream = FileSystem::openFile(timeStampFile);
- time_t lastUpdateTime = 0;
- fileStream->read(&lastUpdateTime, sizeof(lastUpdateTime));
- fileStream->close();
- bool upToDate = true;
- auto checkUpToDate = [&](const Path& filePath)
- {
- time_t fileLastModified = FileSystem::getLastModifiedTime(filePath);
- if (fileLastModified > lastUpdateTime)
- {
- upToDate = false;
- return false;
- }
- return true;
- };
- FileSystem::iterate(folder, checkUpToDate, checkUpToDate);
- return !upToDate;
- }
- }
|