Initial commit
This commit is contained in:
608
engines/hpl1/engine/gui/Gui.cpp
Normal file
608
engines/hpl1/engine/gui/Gui.cpp
Normal file
@@ -0,0 +1,608 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
|
||||
#include "hpl1/engine/graphics/Graphics.h"
|
||||
#include "hpl1/engine/sound/Sound.h"
|
||||
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
#include "hpl1/engine/resources/FileSearcher.h"
|
||||
#include "hpl1/engine/resources/FrameBitmap.h"
|
||||
#include "hpl1/engine/resources/ImageManager.h"
|
||||
#include "hpl1/engine/resources/ResourceImage.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
|
||||
#include "hpl1/engine/gui/GuiMaterialBasicTypes.h"
|
||||
#include "common/multimap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGui::cGui() : iUpdateable("HPL_Gui") {
|
||||
mpSetInFocus = NULL;
|
||||
|
||||
mlLastRenderTime = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGui::~cGui() {
|
||||
Log("Exiting Gui Module\n");
|
||||
Log("--------------------------------------------------------\n");
|
||||
|
||||
STLMapDeleteAll(m_mapSets);
|
||||
STLMapDeleteAll(m_mapSkins);
|
||||
|
||||
STLDeleteAll(mlstGfxElements);
|
||||
|
||||
for (int i = 0; i < eGuiMaterial_LastEnum; ++i) {
|
||||
if (mvMaterials[i])
|
||||
hplDelete(mvMaterials[i]);
|
||||
}
|
||||
|
||||
Log("--------------------------------------------------------\n\n");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGui::Init(cResources *apResources, cGraphics *apGraphics,
|
||||
cSound *apSound, cScene *apScene) {
|
||||
mpResources = apResources;
|
||||
mpGraphics = apGraphics;
|
||||
mpSound = apSound;
|
||||
mpScene = apScene;
|
||||
|
||||
//////////////////////////////
|
||||
// Create materials
|
||||
for (int i = 0; i < eGuiMaterial_LastEnum; ++i)
|
||||
mvMaterials[i] = NULL;
|
||||
|
||||
mvMaterials[eGuiMaterial_Diffuse] = hplNew(cGuiMaterial_Diffuse, (mpGraphics->GetLowLevel()));
|
||||
mvMaterials[eGuiMaterial_Alpha] = hplNew(cGuiMaterial_Alpha, (mpGraphics->GetLowLevel()));
|
||||
mvMaterials[eGuiMaterial_FontNormal] = hplNew(cGuiMaterial_FontNormal, (mpGraphics->GetLowLevel()));
|
||||
mvMaterials[eGuiMaterial_Additive] = hplNew(cGuiMaterial_Additive, (mpGraphics->GetLowLevel()));
|
||||
mvMaterials[eGuiMaterial_Modulative] = hplNew(cGuiMaterial_Modulative, (mpGraphics->GetLowLevel()));
|
||||
|
||||
//////////////////////////////
|
||||
// Skin setup
|
||||
GenerateSkinTypeStrings();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGui::Update(float afTimeStep) {
|
||||
////////////////////////////////////
|
||||
// Update Sets
|
||||
tGuiSetMapIt it = m_mapSets.begin();
|
||||
for (; it != m_mapSets.end(); ++it) {
|
||||
cGuiSet *pSet = it->second;
|
||||
pSet->Update(afTimeStep);
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Update gfx elements
|
||||
tGuiGfxElementListIt gfxIt = mlstGfxElements.begin();
|
||||
for (; gfxIt != mlstGfxElements.end(); ++gfxIt) {
|
||||
cGuiGfxElement *pGfx = *gfxIt;
|
||||
pGfx->Update(afTimeStep);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGui::OnPostSceneDraw() {
|
||||
///////////////////////////////////////
|
||||
// Calculate time since last render
|
||||
unsigned long lCurrentTime = GetApplicationTime();
|
||||
if (mlLastRenderTime > lCurrentTime)
|
||||
mlLastRenderTime = lCurrentTime;
|
||||
|
||||
float fTimeStep = (float)(lCurrentTime - mlLastRenderTime) / 1000.0f;
|
||||
mlLastRenderTime = lCurrentTime;
|
||||
|
||||
////////////////////////////////////
|
||||
// Draw all sets
|
||||
tGuiSetMapIt setIt = m_mapSets.begin();
|
||||
for (; setIt != m_mapSets.end(); ++setIt) {
|
||||
cGuiSet *pSet = setIt->second;
|
||||
pSet->DrawAll(fTimeStep);
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// Render sets that are project to world
|
||||
|
||||
////////////////////////////////////
|
||||
// Render sets that are project to screen
|
||||
setIt = m_mapSets.begin();
|
||||
for (; setIt != m_mapSets.end(); ++setIt) {
|
||||
cGuiSet *pSet = setIt->second;
|
||||
if (pSet->Is3D())
|
||||
pSet->Render();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGui::OnPostGUIDraw() {
|
||||
typedef Common::MultiMap<int, cGuiSet *> tPrioMap;
|
||||
tPrioMap mapSortedSets;
|
||||
|
||||
tGuiSetMapIt it = m_mapSets.begin();
|
||||
for (; it != m_mapSets.end(); ++it) {
|
||||
cGuiSet *pSet = it->second;
|
||||
|
||||
mapSortedSets.insert(tPrioMap::value_type(pSet->GetDrawPriority(), pSet));
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// Render sets that are project to screen
|
||||
tPrioMap::iterator SortIt = mapSortedSets.begin();
|
||||
for (; SortIt != mapSortedSets.end(); ++SortIt) {
|
||||
cGuiSet *pSet = SortIt->second;
|
||||
if (pSet->Is3D() == false)
|
||||
pSet->Render();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGuiMaterial *cGui::GetMaterial(eGuiMaterial aType) {
|
||||
return mvMaterials[aType];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiSkin *cGui::CreateSkin(const tString &asFile) {
|
||||
tString sName = cString::SetFileExt(asFile, "");
|
||||
cGuiSkin *pSkin = hplNew(cGuiSkin, (sName, this));
|
||||
|
||||
tString sPath = mpResources->GetFileSearcher()->GetFilePath(asFile);
|
||||
|
||||
if (pSkin->LoadFromFile(sPath) == false) {
|
||||
hplDelete(pSkin);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
m_mapSkins.insert(tGuiSkinMap::value_type(sName, pSkin));
|
||||
return pSkin;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
eGuiSkinGfx cGui::GetSkinGfxFromString(const tString &asType) {
|
||||
tGuiSkinGfxMapIt it = m_mapSkinGfxStrings.find(asType);
|
||||
if (it == m_mapSkinGfxStrings.end()) {
|
||||
Warning("Skin gfx type '%s' does not exist!\n", asType.c_str());
|
||||
return eGuiSkinGfx_LastEnum;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
eGuiSkinFont cGui::GetSkinFontFromString(const tString &asType) {
|
||||
tGuiSkinFontMapIt it = m_mapSkinFontStrings.find(asType);
|
||||
if (it == m_mapSkinFontStrings.end()) {
|
||||
Warning("Skin Font type '%s' does not exist!\n", asType.c_str());
|
||||
return eGuiSkinFont_LastEnum;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
eGuiSkinAttribute cGui::GetSkinAttributeFromString(const tString &asType) {
|
||||
tGuiSkinAttributeMapIt it = m_mapSkinAttributeStrings.find(asType);
|
||||
if (it == m_mapSkinAttributeStrings.end()) {
|
||||
Warning("Skin Attribute type '%s' does not exist!\n", asType.c_str());
|
||||
return eGuiSkinAttribute_LastEnum;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiSet *cGui::CreateSet(const tString &asName, cGuiSkin *apSkin) {
|
||||
cGuiSet *pSet = hplNew(cGuiSet, (asName, this, apSkin, mpResources, mpGraphics, mpSound, mpScene));
|
||||
|
||||
m_mapSets.insert(tGuiSetMap::value_type(asName, pSet));
|
||||
|
||||
return pSet;
|
||||
}
|
||||
|
||||
cGuiSet *cGui::GetSetFromName(const tString &asName) {
|
||||
tGuiSetMapIt it = m_mapSets.find(asName);
|
||||
if (it == m_mapSets.end())
|
||||
return NULL;
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void cGui::SetFocus(cGuiSet *apSet) {
|
||||
if (mpSetInFocus == apSet)
|
||||
return;
|
||||
|
||||
// TODO: Call lost focus or stuff
|
||||
|
||||
mpSetInFocus = apSet;
|
||||
}
|
||||
|
||||
void cGui::SetFocusByName(const tString &asSetName) {
|
||||
cGuiSet *pSet = GetSetFromName(asSetName);
|
||||
if (pSet)
|
||||
SetFocus(pSet);
|
||||
}
|
||||
|
||||
void cGui::DestroySet(cGuiSet *apSet) {
|
||||
if (apSet == NULL)
|
||||
return;
|
||||
|
||||
tGuiSetMapIt it = m_mapSets.begin();
|
||||
for (; it != m_mapSets.end();) {
|
||||
if (apSet == it->second) {
|
||||
hplDelete(apSet);
|
||||
m_mapSets.erase(it++);
|
||||
break;
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiGfxElement *cGui::CreateGfxFilledRect(const cColor &aColor, eGuiMaterial aMaterial, bool abAddToList) {
|
||||
cGuiGfxElement *pGfxElem = hplNew(cGuiGfxElement, (this));
|
||||
|
||||
pGfxElem->SetColor(aColor);
|
||||
pGfxElem->SetMaterial(GetMaterial(aMaterial));
|
||||
|
||||
if (abAddToList)
|
||||
mlstGfxElements.push_back(pGfxElem);
|
||||
|
||||
return pGfxElem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiGfxElement *cGui::CreateGfxImage(const tString &asFile, eGuiMaterial aMaterial,
|
||||
const cColor &aColor, bool abAddToList) {
|
||||
////////////////////////////
|
||||
// Load image
|
||||
cResourceImage *pImage = mpResources->GetImageManager()->CreateImage(asFile);
|
||||
if (pImage == NULL) {
|
||||
Error("Could not load image '%s'!\n", asFile.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Create element
|
||||
cGuiGfxElement *pGfxElem = hplNew(cGuiGfxElement, (this));
|
||||
|
||||
pGfxElem->SetColor(aColor);
|
||||
pGfxElem->SetMaterial(GetMaterial(aMaterial));
|
||||
pGfxElem->AddImage(pImage);
|
||||
|
||||
if (abAddToList)
|
||||
mlstGfxElements.push_back(pGfxElem);
|
||||
|
||||
return pGfxElem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiGfxElement *cGui::CreateGfxTexture(const tString &asFile, eGuiMaterial aMaterial,
|
||||
const cColor &aColor, bool abMipMaps, bool abAddToList) {
|
||||
///////////////////
|
||||
// Load texture
|
||||
iTexture *pTexture = mpResources->GetTextureManager()->Create2D(asFile, abMipMaps, false);
|
||||
if (pTexture == NULL) {
|
||||
Error("Could not load texture '%s'!\n", asFile.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Create element
|
||||
cGuiGfxElement *pGfxElem = hplNew(cGuiGfxElement, (this));
|
||||
|
||||
pGfxElem->SetColor(aColor);
|
||||
pGfxElem->SetMaterial(GetMaterial(aMaterial));
|
||||
pGfxElem->AddTexture(pTexture);
|
||||
|
||||
if (abAddToList)
|
||||
mlstGfxElements.push_back(pGfxElem);
|
||||
|
||||
return pGfxElem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiGfxElement *cGui::CreateGfxImageBuffer(const tString &asFile, eGuiMaterial aMaterial,
|
||||
bool abCreateAnimation,
|
||||
const cColor &aColor, bool abAddToList) {
|
||||
////////////////////////////
|
||||
// Load images
|
||||
tString sName = cString::SetFileExt(asFile, "");
|
||||
tString sExt = cString::GetFileExt(asFile);
|
||||
|
||||
Common::Array<cResourceImage *> vImages;
|
||||
|
||||
int lFileNum = 0;
|
||||
while (true) {
|
||||
tString sNum = lFileNum <= 9 ? "0" + cString::ToString(lFileNum) : cString::ToString(lFileNum);
|
||||
tString sFile = sName + sNum + "." + sExt;
|
||||
|
||||
if (mpResources->GetFileSearcher()->GetFilePath(sFile) == "")
|
||||
break;
|
||||
|
||||
cResourceImage *pImage = mpResources->GetImageManager()->CreateImage(sFile);
|
||||
vImages.push_back(pImage);
|
||||
++lFileNum;
|
||||
}
|
||||
|
||||
if (vImages.empty()) {
|
||||
Error("Could not load any images with '%s' as base!\n", asFile.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Create element
|
||||
cGuiGfxElement *pGfxElem = hplNew(cGuiGfxElement, (this));
|
||||
|
||||
pGfxElem->SetColor(aColor);
|
||||
pGfxElem->SetMaterial(GetMaterial(aMaterial));
|
||||
|
||||
for (size_t i = 0; i < vImages.size(); ++i) {
|
||||
if (i == 0)
|
||||
pGfxElem->AddImage(vImages[i]);
|
||||
pGfxElem->AddImageToBuffer(vImages[i]);
|
||||
}
|
||||
|
||||
if (abAddToList)
|
||||
mlstGfxElements.push_back(pGfxElem);
|
||||
|
||||
///////////////////////////////
|
||||
// Create animation
|
||||
if (abCreateAnimation) {
|
||||
cGuiGfxAnimation *pAnim = pGfxElem->CreateAnimtion("Default");
|
||||
for (size_t i = 0; i < vImages.size(); ++i) {
|
||||
pAnim->AddFrame((int)i);
|
||||
}
|
||||
}
|
||||
|
||||
return pGfxElem;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGui::DestroyGfx(cGuiGfxElement *apGfx) {
|
||||
STLFindAndDelete(mlstGfxElements, apGfx);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cGui::SendMousePos(const cVector2f &avPos, const cVector2f &avRel) {
|
||||
if (mpSetInFocus == NULL)
|
||||
return false;
|
||||
|
||||
cGuiMessageData data = cGuiMessageData(avPos, avRel);
|
||||
return mpSetInFocus->SendMessage(eGuiMessage_MouseMove, data);
|
||||
}
|
||||
|
||||
bool cGui::SendMouseClickDown(eGuiMouseButton aButton) {
|
||||
if (mpSetInFocus == NULL)
|
||||
return false;
|
||||
|
||||
cGuiMessageData data = cGuiMessageData(aButton);
|
||||
return mpSetInFocus->SendMessage(eGuiMessage_MouseDown, data);
|
||||
}
|
||||
|
||||
bool cGui::SendMouseClickUp(eGuiMouseButton aButton) {
|
||||
if (mpSetInFocus == NULL)
|
||||
return false;
|
||||
|
||||
cGuiMessageData data = cGuiMessageData(aButton);
|
||||
return mpSetInFocus->SendMessage(eGuiMessage_MouseUp, data);
|
||||
}
|
||||
|
||||
bool cGui::SendMouseDoubleClick(eGuiMouseButton aButton) {
|
||||
if (mpSetInFocus == NULL)
|
||||
return false;
|
||||
|
||||
cGuiMessageData data = cGuiMessageData(aButton);
|
||||
return mpSetInFocus->SendMessage(eGuiMessage_MouseDoubleClick, data);
|
||||
}
|
||||
|
||||
bool cGui::SendKeyPress(Common::KeyState keyPress) {
|
||||
if (mpSetInFocus == NULL)
|
||||
return false;
|
||||
|
||||
cGuiMessageData data = cGuiMessageData(keyPress);
|
||||
return mpSetInFocus->SendMessage(eGuiMessage_KeyPress, data);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
/*bool cGui::SentArrowKey(eGuiArrowKey aDir)
|
||||
{
|
||||
if(mpSetInFocus==NULL)return false;
|
||||
|
||||
return false;
|
||||
}*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#define AddFont(name) m_mapSkinFontStrings.insert(tGuiSkinFontMap::value_type(#name, eGuiSkinFont_##name))
|
||||
#define AddAttribute(name) m_mapSkinAttributeStrings.insert(tGuiSkinAttributeMap::value_type(#name, eGuiSkinAttribute_##name))
|
||||
#define AddGfx(name) m_mapSkinGfxStrings.insert(tGuiSkinGfxMap::value_type(#name, eGuiSkinGfx_##name))
|
||||
void cGui::GenerateSkinTypeStrings() {
|
||||
///////////////////////
|
||||
// Fonts
|
||||
AddFont(Default);
|
||||
AddFont(Disabled);
|
||||
AddFont(WindowLabel);
|
||||
|
||||
///////////////////////
|
||||
// Attributes
|
||||
AddAttribute(WindowLabelTextOffset);
|
||||
|
||||
AddAttribute(ButtonPressedContentOffset);
|
||||
|
||||
AddAttribute(SliderButtonSize);
|
||||
|
||||
AddAttribute(ListBoxSliderWidth);
|
||||
|
||||
AddAttribute(ComboBoxButtonWidth);
|
||||
AddAttribute(ComboBoxSliderWidth);
|
||||
|
||||
///////////////////////
|
||||
// Pointer Graphics
|
||||
AddGfx(PointerNormal);
|
||||
AddGfx(PointerText);
|
||||
|
||||
///////////////////////
|
||||
// Window Graphics
|
||||
AddGfx(WindowBorderRight);
|
||||
AddGfx(WindowBorderLeft);
|
||||
AddGfx(WindowBorderUp);
|
||||
AddGfx(WindowBorderDown);
|
||||
|
||||
AddGfx(WindowCornerLU);
|
||||
AddGfx(WindowCornerRU);
|
||||
AddGfx(WindowCornerRD);
|
||||
AddGfx(WindowCornerLD);
|
||||
|
||||
AddGfx(WindowLabel);
|
||||
AddGfx(WindowBackground);
|
||||
|
||||
///////////////////////////////////
|
||||
// Frame Graphics
|
||||
AddGfx(FrameBorderRight);
|
||||
AddGfx(FrameBorderLeft);
|
||||
AddGfx(FrameBorderUp);
|
||||
AddGfx(FrameBorderDown);
|
||||
|
||||
AddGfx(FrameCornerLU);
|
||||
AddGfx(FrameCornerRU);
|
||||
AddGfx(FrameCornerRD);
|
||||
AddGfx(FrameCornerLD);
|
||||
|
||||
AddGfx(FrameBackground);
|
||||
|
||||
///////////////////////////////////
|
||||
// Check box Graphics
|
||||
AddGfx(CheckBoxEnabledUnchecked);
|
||||
AddGfx(CheckBoxEnabledChecked);
|
||||
AddGfx(CheckBoxDisabledUnchecked);
|
||||
AddGfx(CheckBoxDisabledChecked);
|
||||
|
||||
///////////////////////////////////
|
||||
// Text box Graphics
|
||||
AddGfx(TextBoxBackground);
|
||||
AddGfx(TextBoxSelectedTextBack);
|
||||
AddGfx(TextBoxMarker);
|
||||
|
||||
///////////////////////////////////
|
||||
// List box Graphics
|
||||
AddGfx(ListBoxBackground);
|
||||
|
||||
///////////////////////////////////
|
||||
// List box Graphics
|
||||
AddGfx(ComboBoxButtonIcon);
|
||||
|
||||
AddGfx(ComboBoxBorderRight);
|
||||
AddGfx(ComboBoxBorderLeft);
|
||||
AddGfx(ComboBoxBorderUp);
|
||||
AddGfx(ComboBoxBorderDown);
|
||||
|
||||
AddGfx(ComboBoxCornerLU);
|
||||
AddGfx(ComboBoxCornerRU);
|
||||
AddGfx(ComboBoxCornerRD);
|
||||
AddGfx(ComboBoxCornerLD);
|
||||
|
||||
AddGfx(ComboBoxBackground);
|
||||
|
||||
///////////////////////////////////
|
||||
// Slider Graphics
|
||||
AddGfx(SliderVertArrowUp);
|
||||
AddGfx(SliderVertArrowDown);
|
||||
AddGfx(SliderVertBackground);
|
||||
|
||||
AddGfx(SliderHoriArrowUp);
|
||||
AddGfx(SliderHoriArrowDown);
|
||||
AddGfx(SliderHoriBackground);
|
||||
|
||||
///////////////////////
|
||||
// Button Graphics
|
||||
AddGfx(ButtonUpBorderRight);
|
||||
AddGfx(ButtonUpBorderLeft);
|
||||
AddGfx(ButtonUpBorderUp);
|
||||
AddGfx(ButtonUpBorderDown);
|
||||
|
||||
AddGfx(ButtonUpCornerLU);
|
||||
AddGfx(ButtonUpCornerRU);
|
||||
AddGfx(ButtonUpCornerRD);
|
||||
AddGfx(ButtonUpCornerLD);
|
||||
|
||||
AddGfx(ButtonUpBackground);
|
||||
|
||||
AddGfx(ButtonDownBorderRight);
|
||||
AddGfx(ButtonDownBorderLeft);
|
||||
AddGfx(ButtonDownBorderUp);
|
||||
AddGfx(ButtonDownBorderDown);
|
||||
|
||||
AddGfx(ButtonDownCornerLU);
|
||||
AddGfx(ButtonDownCornerRU);
|
||||
AddGfx(ButtonDownCornerRD);
|
||||
AddGfx(ButtonDownCornerLD);
|
||||
|
||||
AddGfx(ButtonDownBackground);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
165
engines/hpl1/engine/gui/Gui.h
Normal file
165
engines/hpl1/engine/gui/Gui.h
Normal file
@@ -0,0 +1,165 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GUI_H
|
||||
#define HPL_GUI_H
|
||||
|
||||
#include "hpl1/engine/game/Updateable.h"
|
||||
|
||||
#include "hpl1/engine/gui/GuiTypes.h"
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cResources;
|
||||
class cGraphics;
|
||||
class cSound;
|
||||
class cScene;
|
||||
|
||||
class cGuiSet;
|
||||
class cGuiSkin;
|
||||
class cGuiGfxElement;
|
||||
|
||||
class iGuiMaterial;
|
||||
|
||||
//------------------------------------------------
|
||||
|
||||
typedef Common::StableMap<tString, cGuiSet *> tGuiSetMap;
|
||||
typedef tGuiSetMap::iterator tGuiSetMapIt;
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
typedef Common::StableMap<tString, cGuiSkin *> tGuiSkinMap;
|
||||
typedef tGuiSkinMap::iterator tGuiSkinMapIt;
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
typedef Common::StableMap<tString, eGuiSkinGfx> tGuiSkinGfxMap;
|
||||
typedef tGuiSkinGfxMap::iterator tGuiSkinGfxMapIt;
|
||||
|
||||
typedef Common::StableMap<tString, eGuiSkinFont> tGuiSkinFontMap;
|
||||
typedef tGuiSkinFontMap::iterator tGuiSkinFontMapIt;
|
||||
|
||||
typedef Common::StableMap<tString, eGuiSkinAttribute> tGuiSkinAttributeMap;
|
||||
typedef tGuiSkinAttributeMap::iterator tGuiSkinAttributeMapIt;
|
||||
|
||||
//------------------------------------------------
|
||||
|
||||
class cGui : public iUpdateable {
|
||||
public:
|
||||
cGui();
|
||||
~cGui();
|
||||
|
||||
///////////////////////////////
|
||||
// General
|
||||
|
||||
void Init(cResources *apResources, cGraphics *apGraphics,
|
||||
cSound *apSound, cScene *apScene);
|
||||
|
||||
void Update(float afTimeStep);
|
||||
|
||||
void OnPostSceneDraw();
|
||||
void OnPostGUIDraw();
|
||||
|
||||
iGuiMaterial *GetMaterial(eGuiMaterial aType);
|
||||
|
||||
///////////////////////////////
|
||||
// Skins
|
||||
cGuiSkin *CreateSkin(const tString &asFile);
|
||||
|
||||
eGuiSkinGfx GetSkinGfxFromString(const tString &asType);
|
||||
eGuiSkinFont GetSkinFontFromString(const tString &asType);
|
||||
eGuiSkinAttribute GetSkinAttributeFromString(const tString &asType);
|
||||
|
||||
///////////////////////////////
|
||||
// Sets
|
||||
cGuiSet *CreateSet(const tString &asName, cGuiSkin *apSkin);
|
||||
cGuiSet *GetSetFromName(const tString &asName);
|
||||
void SetFocus(cGuiSet *apSet);
|
||||
void SetFocusByName(const tString &asSetName);
|
||||
cGuiSet *GetFocusedSet() { return mpSetInFocus; }
|
||||
void DestroySet(cGuiSet *apSet);
|
||||
|
||||
///////////////////////////////
|
||||
// Graphics creation
|
||||
cGuiGfxElement *CreateGfxFilledRect(const cColor &aColor, eGuiMaterial aMaterial, bool abAddToList = true);
|
||||
cGuiGfxElement *CreateGfxImage(const tString &asFile, eGuiMaterial aMaterial,
|
||||
const cColor &aColor = cColor(1, 1), bool abAddToList = true);
|
||||
cGuiGfxElement *CreateGfxTexture(const tString &asFile, eGuiMaterial aMaterial,
|
||||
const cColor &aColor = cColor(1, 1), bool abMipMaps = false,
|
||||
bool abAddToList = true);
|
||||
// Loads several images asFile+00, etc. Used for animations.
|
||||
// Must have extension!
|
||||
cGuiGfxElement *CreateGfxImageBuffer(const tString &asFile, eGuiMaterial aMaterial,
|
||||
bool abCreateAnimation = true,
|
||||
const cColor &aColor = cColor(1, 1), bool abAddToList = true);
|
||||
|
||||
void DestroyGfx(cGuiGfxElement *apGfx);
|
||||
|
||||
///////////////////////////////
|
||||
// Input sending
|
||||
bool SendMousePos(const cVector2f &avPos, const cVector2f &avRel);
|
||||
bool SendMouseClickDown(eGuiMouseButton aButton);
|
||||
bool SendMouseClickUp(eGuiMouseButton aButton);
|
||||
bool SendMouseDoubleClick(eGuiMouseButton aButton);
|
||||
|
||||
bool SendKeyPress(Common::KeyState keyPress);
|
||||
|
||||
// bool SentArrowKey(eGuiArrowKey aDir);
|
||||
|
||||
///////////////////////////////
|
||||
// Properties
|
||||
cResources *GetResources() { return mpResources; }
|
||||
|
||||
private:
|
||||
void GenerateSkinTypeStrings();
|
||||
|
||||
cResources *mpResources;
|
||||
cGraphics *mpGraphics;
|
||||
cSound *mpSound;
|
||||
cScene *mpScene;
|
||||
|
||||
cGuiSet *mpSetInFocus;
|
||||
|
||||
tGuiSetMap m_mapSets;
|
||||
tGuiSkinMap m_mapSkins;
|
||||
|
||||
iGuiMaterial *mvMaterials[eGuiMaterial_LastEnum];
|
||||
|
||||
tGuiGfxElementList mlstGfxElements;
|
||||
|
||||
tGuiSkinGfxMap m_mapSkinGfxStrings;
|
||||
tGuiSkinFontMap m_mapSkinFontStrings;
|
||||
tGuiSkinAttributeMap m_mapSkinAttributeStrings;
|
||||
|
||||
unsigned long mlLastRenderTime;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GUI_H
|
||||
344
engines/hpl1/engine/gui/GuiGfxElement.cpp
Normal file
344
engines/hpl1/engine/gui/GuiGfxElement.cpp
Normal file
@@ -0,0 +1,344 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/resources/FrameBitmap.h"
|
||||
#include "hpl1/engine/resources/ImageManager.h"
|
||||
#include "hpl1/engine/resources/ResourceImage.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
#include "hpl1/engine/resources/TextureManager.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// ANIMATION
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiGfxAnimation::AddFrame(int alNum) {
|
||||
mvFrames.push_back(alNum);
|
||||
}
|
||||
void cGuiGfxAnimation::SetType(eGuiGfxAnimationType aType) {
|
||||
mType = aType;
|
||||
}
|
||||
void cGuiGfxAnimation::SetFrameLength(float afLength) {
|
||||
mfFrameLength = afLength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiGfxElement::cGuiGfxElement(cGui *apGui) {
|
||||
mpGui = apGui;
|
||||
|
||||
/////////////////////////////
|
||||
// Set up vertices
|
||||
mvVtx.resize(4);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
mvVtx[i].pos = 0;
|
||||
mvVtx[i].tex = 0;
|
||||
mvVtx[i].col = cColor(1, 1);
|
||||
}
|
||||
|
||||
// Position
|
||||
mvVtx[1].pos.x = 1;
|
||||
mvVtx[2].pos.x = 1;
|
||||
mvVtx[2].pos.y = 1;
|
||||
mvVtx[3].pos.y = 1;
|
||||
|
||||
// Texture coordinate
|
||||
mvVtx[1].tex.x = 1;
|
||||
mvVtx[2].tex.x = 1;
|
||||
mvVtx[2].tex.y = 1;
|
||||
mvVtx[3].tex.y = 1;
|
||||
|
||||
mvImageSize = 0;
|
||||
|
||||
mvOffset = 0;
|
||||
mvActiveSize = 0;
|
||||
|
||||
////////////////////////////
|
||||
// Set up textures
|
||||
for (int i = 0; i < kMaxGuiTextures; ++i) {
|
||||
mvTextures[i] = NULL;
|
||||
mvImages[i] = NULL;
|
||||
}
|
||||
|
||||
mlTextureNum = 0;
|
||||
mlCurrentAnimation = 0;
|
||||
mfCurrentFrame = 0;
|
||||
mbForwardAnim = true;
|
||||
mlActiveImage = 0;
|
||||
mbAnimationPaused = false;
|
||||
|
||||
mbFlushed = false;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
cGuiGfxElement::~cGuiGfxElement() {
|
||||
STLDeleteAll(mvAnimations);
|
||||
|
||||
////////////////////////////////
|
||||
// Delete all textures / Images
|
||||
if (mvImageBufferVec.size() > 0) {
|
||||
for (int i = 0; i < (int)mvImageBufferVec.size(); ++i) {
|
||||
// Skip for now, memory might be go haywire..
|
||||
// mpGui->GetResources()->GetImageManager()->Destroy(mvImageBufferVec[i]);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < mlTextureNum; ++i) {
|
||||
if (mvImages[i]) {
|
||||
// Skip for now, memory might go haywire..
|
||||
// mpGui->GetResources()->GetImageManager()->Destroy(mvImages[i]);
|
||||
} else if (mvTextures[i]) {
|
||||
mpGui->GetResources()->GetTextureManager()->Destroy(mvTextures[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiGfxElement::Update(float afTimeStep) {
|
||||
|
||||
//////////////////////////////////////
|
||||
// Update image animations
|
||||
if (mvAnimations.empty() || mbAnimationPaused)
|
||||
return;
|
||||
if (mlCurrentAnimation >= (int)mvAnimations.size())
|
||||
return;
|
||||
|
||||
cGuiGfxAnimation *pAnim = mvAnimations[mlCurrentAnimation];
|
||||
|
||||
int lFrame = 0;
|
||||
//////////////////////////////////
|
||||
// Non random animation update
|
||||
if (pAnim->mType != eGuiGfxAnimationType_Random) {
|
||||
mfCurrentFrame += afTimeStep * (1.0f / pAnim->mfFrameLength);
|
||||
lFrame = (int)mfCurrentFrame;
|
||||
if (lFrame >= (int)mvImageBufferVec.size()) {
|
||||
// Log("Over max!\n");
|
||||
// Stop at end
|
||||
if (pAnim->mType == eGuiGfxAnimationType_StopAtEnd) {
|
||||
lFrame = (int)mvImageBufferVec.size() - 1;
|
||||
mfCurrentFrame = (float)lFrame;
|
||||
}
|
||||
// Loop
|
||||
else if (pAnim->mType == eGuiGfxAnimationType_Loop) {
|
||||
lFrame = 0;
|
||||
mfCurrentFrame = 0;
|
||||
}
|
||||
// Oscillate
|
||||
else if (pAnim->mType == eGuiGfxAnimationType_Oscillate) {
|
||||
lFrame = 1;
|
||||
mfCurrentFrame = 1;
|
||||
mbForwardAnim = !mbForwardAnim;
|
||||
}
|
||||
}
|
||||
// Log("Frame %d %f actual_frame: %d size: %d\n",lFrame,mfCurrentFrame,((int)mvImageBufferVec.size()-1) - lFrame,mvImageBufferVec.size());
|
||||
|
||||
// Oscillate fix
|
||||
if (mbForwardAnim == false && pAnim->mType == eGuiGfxAnimationType_Oscillate) {
|
||||
lFrame = ((int)mvImageBufferVec.size() - 1) - lFrame;
|
||||
}
|
||||
}
|
||||
//////////////////////////////////
|
||||
// Random animation update
|
||||
else if (mvImageBufferVec.size() > 1) {
|
||||
float fPrev = mfCurrentFrame;
|
||||
mfCurrentFrame += afTimeStep * (1.0f / pAnim->mfFrameLength);
|
||||
lFrame = (int)mfCurrentFrame;
|
||||
if ((int)mfCurrentFrame != (int)fPrev) {
|
||||
int lPrev = (int)fPrev;
|
||||
do {
|
||||
lFrame = cMath::RandRectl(0, (int)mvImageBufferVec.size() - 1);
|
||||
} while (lFrame == lPrev);
|
||||
|
||||
mfCurrentFrame = (float)lFrame;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
// Set new image
|
||||
if (lFrame != mlActiveImage) {
|
||||
mlActiveImage = lFrame;
|
||||
SetImage(mvImageBufferVec[mlActiveImage], 0);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiGfxElement::AddImage(cResourceImage *apImage) {
|
||||
SetImage(apImage, mlTextureNum);
|
||||
|
||||
mvActiveSize = GetImageSize();
|
||||
|
||||
++mlTextureNum;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
void cGuiGfxElement::AddTexture(iTexture *apTexture) {
|
||||
mvTextures[mlTextureNum] = apTexture;
|
||||
|
||||
if (mlTextureNum == 0) {
|
||||
mvImageSize.x = (float)apTexture->getWidth();
|
||||
mvImageSize.y = (float)apTexture->getHeight();
|
||||
}
|
||||
|
||||
mvActiveSize = GetImageSize();
|
||||
|
||||
++mlTextureNum;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
void cGuiGfxElement::AddImageToBuffer(cResourceImage *apImage) {
|
||||
if (mvImageBufferVec.size() == 0) {
|
||||
SetImage(apImage, 0);
|
||||
}
|
||||
|
||||
mvImageBufferVec.push_back(apImage);
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
cGuiGfxAnimation *cGuiGfxElement::CreateAnimtion(const tString &asName) {
|
||||
cGuiGfxAnimation *pAnimation = hplNew(cGuiGfxAnimation, ());
|
||||
pAnimation->msName = asName;
|
||||
|
||||
mvAnimations.push_back(pAnimation);
|
||||
|
||||
return pAnimation;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
void cGuiGfxElement::PlayAnimation(int alNum) {
|
||||
if (mlCurrentAnimation == alNum)
|
||||
return;
|
||||
|
||||
mlCurrentAnimation = alNum;
|
||||
|
||||
mfCurrentFrame = 0;
|
||||
mbForwardAnim = true;
|
||||
mlActiveImage = 0;
|
||||
SetImage(mvImageBufferVec[mlActiveImage], 0);
|
||||
}
|
||||
|
||||
void cGuiGfxElement::SetAnimationTime(float afTime) {
|
||||
if (mlCurrentAnimation >= 0)
|
||||
mfCurrentFrame = afTime / mvAnimations[mlCurrentAnimation]->mfFrameLength;
|
||||
else
|
||||
mfCurrentFrame = afTime;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
void cGuiGfxElement::SetMaterial(iGuiMaterial *apMat) {
|
||||
mpMaterial = apMat;
|
||||
}
|
||||
|
||||
//---------------------------------------------------
|
||||
|
||||
void cGuiGfxElement::SetColor(const cColor &aColor) {
|
||||
for (int i = 0; i < 4; ++i)
|
||||
mvVtx[i].col = aColor;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2f cGuiGfxElement::GetImageSize() {
|
||||
return mvImageSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiGfxElement::Flush() {
|
||||
if (mbFlushed)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < mlTextureNum; ++i) {
|
||||
if (mvImages[i])
|
||||
mvImages[i]->GetFrameBitmap()->FlushToTexture();
|
||||
}
|
||||
for (size_t i = 0; i < mvImageBufferVec.size(); ++i) {
|
||||
if (mvImageBufferVec[i])
|
||||
mvImageBufferVec[i]->GetFrameBitmap()->FlushToTexture();
|
||||
}
|
||||
|
||||
mbFlushed = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiGfxElement::SetImage(cResourceImage *apImage, int alNum) {
|
||||
// Set image and texture (for sorting)
|
||||
mvImages[alNum] = apImage;
|
||||
mvTextures[alNum] = apImage->GetTexture();
|
||||
|
||||
// Get texture coords
|
||||
const tVertexVec &vImageVtx = apImage->GetVertexVec();
|
||||
for (int i = 0; i < 4; ++i)
|
||||
mvVtx[i].tex = vImageVtx[i].tex;
|
||||
|
||||
if (alNum == 0) {
|
||||
mvImageSize.x = (float)apImage->GetWidth();
|
||||
mvImageSize.y = (float)apImage->GetHeight();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
139
engines/hpl1/engine/gui/GuiGfxElement.h
Normal file
139
engines/hpl1/engine/gui/GuiGfxElement.h
Normal file
@@ -0,0 +1,139 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GUI_GFX_ELEMENT_H
|
||||
#define HPL_GUI_GFX_ELEMENT_H
|
||||
|
||||
#include "hpl1/engine/gui/GuiTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class iGuiMaterial;
|
||||
class iTexture;
|
||||
class cResourceImage;
|
||||
|
||||
class cGui;
|
||||
|
||||
#define kMaxGuiTextures (4)
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
enum eGuiGfxAnimationType {
|
||||
eGuiGfxAnimationType_Loop,
|
||||
eGuiGfxAnimationType_StopAtEnd,
|
||||
eGuiGfxAnimationType_Oscillate,
|
||||
eGuiGfxAnimationType_Random,
|
||||
eGuiGfxAnimationType_LastEnum
|
||||
};
|
||||
|
||||
class cGuiGfxAnimation {
|
||||
friend class cGuiGfxElement;
|
||||
|
||||
public:
|
||||
cGuiGfxAnimation() : mfFrameLength(1), mType(eGuiGfxAnimationType_Loop) {}
|
||||
|
||||
void AddFrame(int alNum);
|
||||
void SetType(eGuiGfxAnimationType aType);
|
||||
void SetFrameLength(float afLength);
|
||||
|
||||
private:
|
||||
tString msName;
|
||||
Common::Array<int> mvFrames;
|
||||
float mfFrameLength;
|
||||
eGuiGfxAnimationType mType;
|
||||
};
|
||||
|
||||
//------------------------------------------
|
||||
|
||||
class cGuiGfxElement {
|
||||
friend class cGuiSet;
|
||||
friend class cGuiRenderObjectCompare;
|
||||
|
||||
public:
|
||||
cGuiGfxElement(cGui *apGui);
|
||||
~cGuiGfxElement();
|
||||
|
||||
void Update(float afTimeStep);
|
||||
|
||||
void AddImage(cResourceImage *apImage);
|
||||
void AddTexture(iTexture *apTexture);
|
||||
|
||||
void AddImageToBuffer(cResourceImage *apImage);
|
||||
|
||||
void SetOffset(const cVector3f &avOffset) { mvOffset = avOffset; }
|
||||
const cVector3f &GetOffset() const { return mvOffset; }
|
||||
|
||||
void SetActiveSize(const cVector2f &avSize) { mvActiveSize = avSize; }
|
||||
const cVector2f &GetActiveSize() { return mvActiveSize; }
|
||||
|
||||
cGuiGfxAnimation *CreateAnimtion(const tString &asName);
|
||||
void PlayAnimation(int alNum);
|
||||
cGuiGfxAnimation *GetAnimation(int alIdx) { return mvAnimations[alIdx]; }
|
||||
void SetAnimationTime(float afTime);
|
||||
|
||||
void SetAnimationPaused(bool abX) { mbAnimationPaused = abX; }
|
||||
bool GSetAnimationPaused() { return mbAnimationPaused; }
|
||||
|
||||
void SetMaterial(iGuiMaterial *apMat);
|
||||
|
||||
void SetColor(const cColor &aColor);
|
||||
|
||||
cVector2f GetImageSize();
|
||||
|
||||
void Flush();
|
||||
|
||||
private:
|
||||
void SetImage(cResourceImage *apImage, int alNum);
|
||||
|
||||
cVector2f mvImageSize;
|
||||
cGui *mpGui;
|
||||
tVertexVec mvVtx;
|
||||
|
||||
cVector3f mvOffset;
|
||||
cVector2f mvActiveSize;
|
||||
|
||||
iGuiMaterial *mpMaterial;
|
||||
iTexture *mvTextures[kMaxGuiTextures];
|
||||
cResourceImage *mvImages[kMaxGuiTextures];
|
||||
|
||||
Common::Array<cResourceImage *> mvImageBufferVec;
|
||||
|
||||
Common::Array<cGuiGfxAnimation *> mvAnimations;
|
||||
int mlCurrentAnimation;
|
||||
float mfCurrentFrame;
|
||||
int mlActiveImage;
|
||||
bool mbForwardAnim;
|
||||
bool mbAnimationPaused;
|
||||
|
||||
int mlTextureNum;
|
||||
|
||||
bool mbFlushed;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GUI_GFX_ELEMENT_H
|
||||
53
engines/hpl1/engine/gui/GuiMaterial.h
Normal file
53
engines/hpl1/engine/gui/GuiMaterial.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GUI_MATERIAL_H
|
||||
#define HPL_GUI_MATERIAL_H
|
||||
|
||||
#include "hpl1/engine/system/SystemTypes.h"
|
||||
namespace hpl {
|
||||
|
||||
class iLowLevelGraphics;
|
||||
|
||||
class iGuiMaterial {
|
||||
public:
|
||||
iGuiMaterial(const tString &asName, iLowLevelGraphics *apLowLevelGraphics) : msName(asName), mpLowLevelGraphics(apLowLevelGraphics) {}
|
||||
virtual ~iGuiMaterial() {}
|
||||
|
||||
virtual void BeforeRender() = 0;
|
||||
virtual void AfterRender() = 0;
|
||||
|
||||
const tString &GetName() const { return msName; }
|
||||
|
||||
protected:
|
||||
tString msName;
|
||||
iLowLevelGraphics *mpLowLevelGraphics;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GUI_MATERIAL_H
|
||||
132
engines/hpl1/engine/gui/GuiMaterialBasicTypes.cpp
Normal file
132
engines/hpl1/engine/gui/GuiMaterialBasicTypes.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/GuiMaterialBasicTypes.h"
|
||||
|
||||
#include "hpl1/engine/graphics/LowLevelGraphics.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// DIFFUSE
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_Diffuse::BeforeRender() {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_One, eBlendFunc_Zero);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_Diffuse::AfterRender() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// ALPHA
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_Alpha::BeforeRender() {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_SrcAlpha, eBlendFunc_OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_Alpha::AfterRender() {
|
||||
// Not needed right?
|
||||
// mpLowLevelGraphics->SetBlendFunc(eBlendFunc_One, eBlendFunc_OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// FONT NORMAL
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_FontNormal::BeforeRender() {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_SrcAlpha, eBlendFunc_OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_FontNormal::AfterRender() {
|
||||
// Not needed right?
|
||||
// mpLowLevelGraphics->SetBlendFunc(eBlendFunc_One, eBlendFunc_OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// ADDITIVE
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_Additive::BeforeRender() {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_One, eBlendFunc_One);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_Additive::AfterRender() {
|
||||
// Not needed right?
|
||||
// mpLowLevelGraphics->SetBlendFunc(eBlendFunc_One, eBlendFunc_OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// MODULATIVE
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_Modulative::BeforeRender() {
|
||||
mpLowLevelGraphics->SetBlendActive(true);
|
||||
mpLowLevelGraphics->SetBlendFunc(eBlendFunc_DestColor, eBlendFunc_Zero);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cGuiMaterial_Modulative::AfterRender() {
|
||||
// Not needed right?
|
||||
// mpLowLevelGraphics->SetBlendFunc(eBlendFunc_One, eBlendFunc_OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
94
engines/hpl1/engine/gui/GuiMaterialBasicTypes.h
Normal file
94
engines/hpl1/engine/gui/GuiMaterialBasicTypes.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GUI_MATERIAL_BASIC_TYPES_H
|
||||
#define HPL_GUI_MATERIAL_BASIC_TYPES_H
|
||||
|
||||
#include "hpl1/engine/gui/GuiMaterial.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
class cGuiMaterial_Diffuse : public iGuiMaterial {
|
||||
public:
|
||||
cGuiMaterial_Diffuse(iLowLevelGraphics *apLowLevelGraphics) : iGuiMaterial("Diffuse", apLowLevelGraphics) {}
|
||||
~cGuiMaterial_Diffuse() {}
|
||||
|
||||
void BeforeRender();
|
||||
void AfterRender();
|
||||
};
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
class cGuiMaterial_Alpha : public iGuiMaterial {
|
||||
public:
|
||||
cGuiMaterial_Alpha(iLowLevelGraphics *apLowLevelGraphics) : iGuiMaterial("Alpha", apLowLevelGraphics) {}
|
||||
~cGuiMaterial_Alpha() {}
|
||||
|
||||
void BeforeRender();
|
||||
void AfterRender();
|
||||
};
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
class cGuiMaterial_FontNormal : public iGuiMaterial {
|
||||
public:
|
||||
cGuiMaterial_FontNormal(iLowLevelGraphics *apLowLevelGraphics) : iGuiMaterial("FontNormal", apLowLevelGraphics) {}
|
||||
~cGuiMaterial_FontNormal() {}
|
||||
|
||||
void BeforeRender();
|
||||
void AfterRender();
|
||||
};
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
class cGuiMaterial_Additive : public iGuiMaterial {
|
||||
public:
|
||||
cGuiMaterial_Additive(iLowLevelGraphics *apLowLevelGraphics) : iGuiMaterial("Additive", apLowLevelGraphics) {}
|
||||
~cGuiMaterial_Additive() {}
|
||||
|
||||
void BeforeRender();
|
||||
void AfterRender();
|
||||
};
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
class cGuiMaterial_Modulative : public iGuiMaterial {
|
||||
public:
|
||||
cGuiMaterial_Modulative(iLowLevelGraphics *apLowLevelGraphics) : iGuiMaterial("Modulative", apLowLevelGraphics) {}
|
||||
~cGuiMaterial_Modulative() {}
|
||||
|
||||
void BeforeRender();
|
||||
void AfterRender();
|
||||
};
|
||||
|
||||
//-----------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GUI_MATERIAL_BASIC_TYPES_H
|
||||
77
engines/hpl1/engine/gui/GuiPopUp.cpp
Normal file
77
engines/hpl1/engine/gui/GuiPopUp.cpp
Normal file
@@ -0,0 +1,77 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/GuiPopUp.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGuiPopUp::iGuiPopUp(cGuiSet *apSet) {
|
||||
mpSet = apSet;
|
||||
mpSkin = mpSet->GetSkin();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iGuiPopUp::~iGuiPopUp() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iGuiPopUp::SelfDestruct() {
|
||||
mpSet->DestroyPopUp(this);
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
52
engines/hpl1/engine/gui/GuiPopUp.h
Normal file
52
engines/hpl1/engine/gui/GuiPopUp.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GUI_POP_UP_H
|
||||
#define HPL_GUI_POP_UP_H
|
||||
|
||||
#include "hpl1/engine/gui/GuiTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSet;
|
||||
class cGuiSkin;
|
||||
|
||||
class iGuiPopUp {
|
||||
public:
|
||||
iGuiPopUp(cGuiSet *apSet);
|
||||
virtual ~iGuiPopUp();
|
||||
|
||||
protected:
|
||||
void SelfDestruct();
|
||||
|
||||
cGuiSet *mpSet;
|
||||
cGuiSkin *mpSkin;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_FRAME_H
|
||||
158
engines/hpl1/engine/gui/GuiPopUpMessageBox.cpp
Normal file
158
engines/hpl1/engine/gui/GuiPopUpMessageBox.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/GuiPopUpMessageBox.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/graphics/font_data.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
#include "hpl1/engine/gui/WidgetButton.h"
|
||||
#include "hpl1/engine/gui/WidgetLabel.h"
|
||||
#include "hpl1/engine/gui/WidgetWindow.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiPopUpMessageBox::cGuiPopUpMessageBox(cGuiSet *apSet,
|
||||
const tWString &asLabel, const tWString &asText,
|
||||
const tWString &asButton1, const tWString &asButton2,
|
||||
void *apCallbackObject, tGuiCallbackFunc apCallback)
|
||||
: iGuiPopUp(apSet) {
|
||||
//////////////////////////
|
||||
// Set up variables
|
||||
mpCallback = apCallback;
|
||||
mpCallbackObject = apCallbackObject;
|
||||
|
||||
cGuiSkinFont *pFont = mpSkin->GetFont(eGuiSkinFont_Default);
|
||||
|
||||
float fWindowMinLength = pFont->mpFont->getLength(pFont->mvSize, asLabel.c_str());
|
||||
float fTextLength = pFont->mpFont->getLength(pFont->mvSize, asText.c_str());
|
||||
|
||||
if (fTextLength > fWindowMinLength)
|
||||
fWindowMinLength = fTextLength;
|
||||
|
||||
float fWindowWidth = fWindowMinLength + 40 > 200 ? fWindowMinLength + 40 : 200;
|
||||
|
||||
cVector2f vVirtSize = mpSet->GetVirtualSize();
|
||||
|
||||
float fWindowHeight = 90 + pFont->mvSize.y;
|
||||
|
||||
//////////////////////////
|
||||
// Window
|
||||
cVector3f vPos = cVector3f(vVirtSize.x / 2 - fWindowWidth / 2, vVirtSize.y / 2 - fWindowHeight / 2, 18);
|
||||
mpWindow = mpSet->CreateWidgetWindow(vPos, cVector2f(fWindowWidth, fWindowHeight), asLabel, NULL);
|
||||
|
||||
//////////////////////////
|
||||
// Buttons
|
||||
if (asButton2 == _W("")) {
|
||||
vPos = cVector3f(fWindowWidth / 2 - 40, 50 + pFont->mvSize.y, 1);
|
||||
mvButtons[0] = mpSet->CreateWidgetButton(vPos, cVector2f(80, 30), asButton1, mpWindow);
|
||||
mvButtons[0]->AddCallback(eGuiMessage_ButtonPressed, this, kGuiCallback(ButtonPress));
|
||||
|
||||
mvButtons[1] = NULL;
|
||||
} else {
|
||||
vPos = cVector3f(fWindowWidth / 2 - (80 * 2 + 20) / 2, 50 + pFont->mvSize.y, 1);
|
||||
mvButtons[0] = mpSet->CreateWidgetButton(vPos, cVector2f(80, 30), asButton1, mpWindow);
|
||||
mvButtons[0]->AddCallback(eGuiMessage_ButtonPressed, this, kGuiCallback(ButtonPress));
|
||||
|
||||
vPos.x += 80 + 20;
|
||||
mvButtons[1] = mpSet->CreateWidgetButton(vPos, cVector2f(80, 30), asButton2, mpWindow);
|
||||
mvButtons[1]->AddCallback(eGuiMessage_ButtonPressed, this, kGuiCallback(ButtonPress));
|
||||
}
|
||||
|
||||
//////////////////////////
|
||||
// Label
|
||||
vPos = cVector3f(20, 30, 1);
|
||||
mpLabel = mpSet->CreateWidgetLabel(vPos, cVector2f(fWindowWidth - 10, pFont->mvSize.y),
|
||||
asText, mpWindow);
|
||||
|
||||
//////////////////////////
|
||||
// Attention
|
||||
mpPrevAttention = mpSet->GetAttentionWidget();
|
||||
mpSet->SetAttentionWidget(mpWindow);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiPopUpMessageBox::~cGuiPopUpMessageBox() {
|
||||
if (mpWindow)
|
||||
mpSet->DestroyWidget(mpWindow);
|
||||
if (mvButtons[0])
|
||||
mpSet->DestroyWidget(mvButtons[0]);
|
||||
if (mvButtons[1])
|
||||
mpSet->DestroyWidget(mvButtons[1]);
|
||||
if (mpLabel)
|
||||
mpSet->DestroyWidget(mpLabel);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cGuiPopUpMessageBox::ButtonPress(iWidget *apWidget, cGuiMessageData &aData) {
|
||||
int lButton = apWidget == mvButtons[0] ? 0 : 1;
|
||||
|
||||
mpSet->SetAttentionWidget(mpPrevAttention);
|
||||
|
||||
if (mpCallback && mpCallbackObject) {
|
||||
cGuiMessageData data = cGuiMessageData(lButton);
|
||||
mpCallback(mpCallbackObject, apWidget, data);
|
||||
}
|
||||
|
||||
SelfDestruct();
|
||||
|
||||
return true;
|
||||
}
|
||||
kGuiCalllbackDeclaredFuncEnd(cGuiPopUpMessageBox, ButtonPress)
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
63
engines/hpl1/engine/gui/GuiPopUpMessageBox.h
Normal file
63
engines/hpl1/engine/gui/GuiPopUpMessageBox.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GUI_POP_UP_MESSAGE_BOX_H
|
||||
#define HPL_GUI_POP_UP_MESSAGE_BOX_H
|
||||
|
||||
#include "hpl1/engine/gui/GuiPopUp.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cWidgetWindow;
|
||||
class cWidgetLabel;
|
||||
class cWidgetButton;
|
||||
|
||||
class cGuiPopUpMessageBox : public iGuiPopUp {
|
||||
public:
|
||||
cGuiPopUpMessageBox(cGuiSet *apSet,
|
||||
const tWString &asLabel, const tWString &asText,
|
||||
const tWString &asButton1, const tWString &asButton2,
|
||||
void *apCallbackObject, tGuiCallbackFunc apCallback);
|
||||
virtual ~cGuiPopUpMessageBox();
|
||||
|
||||
protected:
|
||||
bool ButtonPress(iWidget *apWidget, cGuiMessageData &aData);
|
||||
kGuiCalllbackDeclarationEnd(ButtonPress);
|
||||
|
||||
cWidgetWindow *mpWindow;
|
||||
cWidgetButton *mvButtons[2];
|
||||
cWidgetLabel *mpLabel;
|
||||
|
||||
iWidget *mpPrevAttention;
|
||||
|
||||
void *mpCallbackObject;
|
||||
tGuiCallbackFunc mpCallback;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GUI_POP_UP_MESSAGE_BOX_H
|
||||
1183
engines/hpl1/engine/gui/GuiSet.cpp
Normal file
1183
engines/hpl1/engine/gui/GuiSet.cpp
Normal file
File diff suppressed because it is too large
Load Diff
338
engines/hpl1/engine/gui/GuiSet.h
Normal file
338
engines/hpl1/engine/gui/GuiSet.h
Normal file
@@ -0,0 +1,338 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GUI_SET_H
|
||||
#define HPL_GUI_SET_H
|
||||
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/gui/GuiTypes.h"
|
||||
#include "hpl1/std/multiset.h"
|
||||
#include "hpl1/std/set.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
class cResources;
|
||||
class cGraphics;
|
||||
class cSound;
|
||||
class cScene;
|
||||
|
||||
class FontData;
|
||||
|
||||
class cGui;
|
||||
class cGuiSkin;
|
||||
class iGuiMaterial;
|
||||
class iGuiPopUp;
|
||||
class iWidget;
|
||||
|
||||
class cWidgetWindow;
|
||||
class cWidgetFrame;
|
||||
class cWidgetButton;
|
||||
class cWidgetLabel;
|
||||
class cWidgetSlider;
|
||||
class cWidgetTextBox;
|
||||
class cWidgetCheckBox;
|
||||
class cWidgetImage;
|
||||
class cWidgetListBox;
|
||||
class cWidgetComboBox;
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
typedef Common::List<iGuiPopUp *> tGuiPopUpList;
|
||||
typedef tGuiPopUpList::iterator tGuiPopUpListIt;
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
class cGuiClipRegion;
|
||||
class cGuiRenderObject {
|
||||
public:
|
||||
cGuiGfxElement *mpGfx;
|
||||
cVector3f mvPos;
|
||||
cVector2f mvSize;
|
||||
cColor mColor;
|
||||
iGuiMaterial *mpCustomMaterial;
|
||||
cGuiClipRegion *mpClipRegion;
|
||||
};
|
||||
|
||||
class cGuiRenderObjectCompare {
|
||||
public:
|
||||
bool operator()(const cGuiRenderObject &aObjectA, const cGuiRenderObject &aObjectB) const;
|
||||
};
|
||||
|
||||
typedef Hpl1::Std::multiset<cGuiRenderObject, cGuiRenderObjectCompare> tGuiRenderObjectSet;
|
||||
typedef tGuiRenderObjectSet::iterator tGuiRenderObjectSetIt;
|
||||
|
||||
//-----------------------------------------------
|
||||
|
||||
typedef Common::List<cGuiClipRegion *> tGuiClipRegionList;
|
||||
typedef tGuiClipRegionList::iterator tGuiClipRegionListIt;
|
||||
|
||||
class cGuiClipRegion {
|
||||
public:
|
||||
cGuiClipRegion() : mRect(0, 0, -1, -1) {}
|
||||
~cGuiClipRegion();
|
||||
|
||||
void Clear();
|
||||
cGuiClipRegion *CreateChild(const cVector3f &avPos, const cVector2f &avSize);
|
||||
|
||||
// tGuiRenderObjectSet m_setObjects;
|
||||
cRect2f mRect;
|
||||
|
||||
tGuiClipRegionList mlstChildren;
|
||||
};
|
||||
|
||||
//-----------------------------------------------
|
||||
|
||||
class cGuiSet {
|
||||
public:
|
||||
cGuiSet(const tString &asName, cGui *apGui, cGuiSkin *apSkin,
|
||||
cResources *apResources, cGraphics *apGraphics,
|
||||
cSound *apSound, cScene *apScene);
|
||||
~cGuiSet();
|
||||
|
||||
////////////////////////////////////
|
||||
// General
|
||||
|
||||
void Update(float afTimeStep);
|
||||
|
||||
void DrawAll(float afTimeStep);
|
||||
|
||||
bool SendMessage(eGuiMessage aMessage, cGuiMessageData &aData);
|
||||
|
||||
////////////////////////////////////
|
||||
// Rendering
|
||||
void Render();
|
||||
|
||||
void SetDrawOffset(const cVector3f &avOffset) { mvDrawOffset = avOffset; }
|
||||
void SetCurrentClipRegion(cGuiClipRegion *apRegion) { mpCurrentClipRegion = apRegion; }
|
||||
|
||||
void DrawGfx(cGuiGfxElement *apGfx,
|
||||
const cVector3f &avPos,
|
||||
const cVector2f &avSize = -1,
|
||||
const cColor &aColor = cColor(1, 1),
|
||||
eGuiMaterial aMaterial = eGuiMaterial_LastEnum);
|
||||
void DrawFont(const tWString &asText,
|
||||
FontData *apFont, const cVector3f &avPos,
|
||||
const cVector2f &avSize, const cColor &aColor,
|
||||
eFontAlign aAlign = eFontAlign_Left,
|
||||
eGuiMaterial aMaterial = eGuiMaterial_FontNormal);
|
||||
|
||||
////////////////////////////////////
|
||||
// Widget Creation
|
||||
cWidgetWindow *CreateWidgetWindow(const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = 0,
|
||||
const tWString &asText = {},
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
cWidgetFrame *CreateWidgetFrame(const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = 0,
|
||||
bool abDrawFrame = false,
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
cWidgetButton *CreateWidgetButton(const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = 0,
|
||||
const tWString &asText = {},
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
cWidgetLabel *CreateWidgetLabel(const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = 0,
|
||||
const tWString &asText = {},
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
cWidgetSlider *CreateWidgetSlider(eWidgetSliderOrientation aOrientation,
|
||||
const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = 0,
|
||||
int alMaxValue = 10,
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
cWidgetTextBox *CreateWidgetTextBox(const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = 0,
|
||||
const tWString &asText = {},
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
cWidgetCheckBox *CreateWidgetCheckBox(const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = 0,
|
||||
const tWString &asText = {},
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
cWidgetImage *CreateWidgetImage(const tString &asFile = "",
|
||||
const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = -1,
|
||||
eGuiMaterial aMaterial = eGuiMaterial_Alpha,
|
||||
bool abAnimate = false,
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
cWidgetListBox *CreateWidgetListBox(const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = 0,
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
cWidgetComboBox *CreateWidgetComboBox(const cVector3f &avLocalPos = 0,
|
||||
const cVector2f &avSize = 0,
|
||||
const tWString &asText = {},
|
||||
iWidget *apParent = NULL,
|
||||
const tString &asName = "");
|
||||
|
||||
iWidget *GetWidgetFromName(const tString &asName);
|
||||
|
||||
void DestroyWidget(iWidget *apWidget);
|
||||
|
||||
////////////////////////////////////
|
||||
// Popup
|
||||
void CreatePopUpMessageBox(const tWString &asLabel, const tWString &asText,
|
||||
const tWString &asButton1, const tWString &asButton2,
|
||||
void *apCallbackObject, tGuiCallbackFunc apCallback);
|
||||
|
||||
void DestroyPopUp(iGuiPopUp *apPopUp);
|
||||
|
||||
////////////////////////////////////
|
||||
// Properties
|
||||
void SetActive(bool abX);
|
||||
bool IsActive() { return mbActive; }
|
||||
|
||||
cGui *GetGui() { return mpGui; }
|
||||
|
||||
void SetDrawMouse(bool abX);
|
||||
bool GetDrawMouse() { return mbDrawMouse; }
|
||||
|
||||
void SetMouseZ(float afZ) { mfMouseZ = afZ; }
|
||||
float GetMouse() { return mfMouseZ; }
|
||||
|
||||
void SetRootWidgetClips(bool abX);
|
||||
bool GetRootWidgetClips();
|
||||
|
||||
void SetVirtualSize(const cVector2f &avSize, float afMinZ, float afMaxZ);
|
||||
const cVector2f &GetVirtualSize() { return mvVirtualSize; }
|
||||
|
||||
void SetFocusedWidget(iWidget *apWidget);
|
||||
iWidget *GetFocusedWidget() { return mpFocusedWidget; }
|
||||
|
||||
void SetAttentionWidget(iWidget *apWidget);
|
||||
iWidget *GetAttentionWidget() { return mpAttentionWidget; }
|
||||
|
||||
void SetIs3D(bool abX);
|
||||
bool Is3D() { return mbIs3D; }
|
||||
|
||||
int GetDrawPriority() { return mlDrawPrio; }
|
||||
void SetDrawPriority(int alPrio) { mlDrawPrio = alPrio; }
|
||||
|
||||
void SetCurrentPointer(cGuiGfxElement *apGfx);
|
||||
cGuiGfxElement *GetCurrentPointer() { return mpGfxCurrentPointer; }
|
||||
|
||||
void Set3DSize(const cVector3f &avSize);
|
||||
cVector3f Get3DSize() { return mv3DSize; }
|
||||
|
||||
void SetCullBackface(bool abX) { mbCullBackface = abX; }
|
||||
bool GetCullBackface() { return mbCullBackface; }
|
||||
|
||||
void Set3DTransform(const cMatrixf &a_mtxTransform);
|
||||
cMatrixf Get3DTransform() { return m_mtx3DTransform; }
|
||||
|
||||
bool HasFocus();
|
||||
|
||||
void SetSkin(cGuiSkin *apSkin);
|
||||
cGuiSkin *GetSkin() { return mpSkin; }
|
||||
|
||||
cResources *GetResources() { return mpResources; }
|
||||
|
||||
bool IsDestroyingSet() { return mbDestroyingSet; }
|
||||
|
||||
private:
|
||||
void RenderClipRegion();
|
||||
|
||||
void AddWidget(iWidget *apWidget, iWidget *apParent);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseDoubleClick(cGuiMessageData &aData);
|
||||
|
||||
bool OnKeyPress(cGuiMessageData &aData);
|
||||
|
||||
bool DrawMouse(iWidget *apWidget, cGuiMessageData &aData);
|
||||
kGuiCalllbackDeclarationEnd(DrawMouse);
|
||||
|
||||
cGui *mpGui;
|
||||
cGuiSkin *mpSkin;
|
||||
|
||||
tString msName;
|
||||
|
||||
cResources *mpResources;
|
||||
cGraphics *mpGraphics;
|
||||
cSound *mpSound;
|
||||
cScene *mpScene;
|
||||
|
||||
iWidget *mpAttentionWidget;
|
||||
|
||||
iWidget *mpFocusedWidget;
|
||||
|
||||
iWidget *mpWidgetRoot;
|
||||
tWidgetList mlstWidgets;
|
||||
|
||||
tGuiRenderObjectSet m_setRenderObjects;
|
||||
|
||||
cVector2f mvVirtualSize;
|
||||
float mfVirtualMinZ;
|
||||
float mfVirtualMaxZ;
|
||||
|
||||
cVector3f mvDrawOffset;
|
||||
|
||||
bool mbCullBackface;
|
||||
bool mbIs3D;
|
||||
cVector3f mv3DSize;
|
||||
cMatrixf m_mtx3DTransform;
|
||||
int mlDrawPrio;
|
||||
|
||||
bool mbActive;
|
||||
bool mbDrawMouse;
|
||||
float mfMouseZ;
|
||||
cGuiGfxElement *mpGfxCurrentPointer;
|
||||
|
||||
bool mvMouseDown[3];
|
||||
cVector2f mvMousePos;
|
||||
|
||||
tGuiPopUpList mlstPopUps;
|
||||
|
||||
cGuiClipRegion mBaseClipRegion;
|
||||
cGuiClipRegion *mpCurrentClipRegion;
|
||||
|
||||
bool mbDestroyingSet;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GUI_SET_H
|
||||
283
engines/hpl1/engine/gui/GuiSkin.cpp
Normal file
283
engines/hpl1/engine/gui/GuiSkin.cpp
Normal file
@@ -0,0 +1,283 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/impl/tinyXML/tinyxml.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
|
||||
#include "hpl1/engine/resources/FontManager.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// FONT
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiSkinFont::cGuiSkinFont(cGui *apGui) {
|
||||
mpGui = apGui;
|
||||
|
||||
mpMaterial = NULL;
|
||||
}
|
||||
cGuiSkinFont::~cGuiSkinFont() {
|
||||
// Skip deleting font...
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiSkin::cGuiSkin(const tString &asName, cGui *apGui) {
|
||||
mpGui = apGui;
|
||||
msName = asName;
|
||||
|
||||
Hpl1::resizeAndFill(mvGfxElements, eGuiSkinGfx_LastEnum, nullptr);
|
||||
Hpl1::resizeAndFill(mvFonts, eGuiSkinGfx_LastEnum, nullptr);
|
||||
mvAttributes.resize(eGuiSkinAttribute_LastEnum);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiSkin::~cGuiSkin() {
|
||||
for (size_t i = 0; i < mvGfxElements.size(); ++i)
|
||||
mpGui->DestroyGfx(mvGfxElements[i]);
|
||||
|
||||
STLDeleteAll(mvFonts);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
static eGuiGfxAnimationType ToAnimType(const char *apString) {
|
||||
if (apString == NULL)
|
||||
return eGuiGfxAnimationType_Loop;
|
||||
|
||||
tString sLow = cString::ToLowerCase(apString);
|
||||
|
||||
if (sLow == "loop")
|
||||
return eGuiGfxAnimationType_Loop;
|
||||
if (sLow == "oscillate")
|
||||
return eGuiGfxAnimationType_Oscillate;
|
||||
if (sLow == "random")
|
||||
return eGuiGfxAnimationType_Random;
|
||||
if (sLow == "stop_at_end")
|
||||
return eGuiGfxAnimationType_StopAtEnd;
|
||||
|
||||
Warning("Animation type '%s' does not exist!\n", sLow.c_str());
|
||||
|
||||
return eGuiGfxAnimationType_Loop;
|
||||
}
|
||||
|
||||
static eGuiMaterial ToMaterial(const char *apString) {
|
||||
if (apString == NULL)
|
||||
return eGuiMaterial_Alpha;
|
||||
|
||||
tString sLow = cString::ToLowerCase(apString);
|
||||
|
||||
if (sLow == "alpha")
|
||||
return eGuiMaterial_Alpha;
|
||||
if (sLow == "diffuse")
|
||||
return eGuiMaterial_Diffuse;
|
||||
if (sLow == "font_normal")
|
||||
return eGuiMaterial_FontNormal;
|
||||
if (sLow == "additive")
|
||||
return eGuiMaterial_Additive;
|
||||
if (sLow == "modulative")
|
||||
return eGuiMaterial_Modulative;
|
||||
|
||||
Warning("Material type '%s' does not exist!\n", sLow.c_str());
|
||||
|
||||
return eGuiMaterial_Alpha;
|
||||
}
|
||||
|
||||
bool cGuiSkin::LoadFromFile(const tString &asFile) {
|
||||
//////////////////////////////////
|
||||
// Open document
|
||||
TiXmlDocument *pXmlDoc = hplNew(TiXmlDocument, (asFile.c_str()));
|
||||
if (pXmlDoc->LoadFile() == false) {
|
||||
Error("Couldn't load skin file '%s'!\n", asFile.c_str());
|
||||
hplDelete(pXmlDoc);
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
// Get the root.
|
||||
TiXmlElement *pRootElem = pXmlDoc->RootElement();
|
||||
|
||||
//////////////////////////////////////
|
||||
// ATTRIBUTES
|
||||
TiXmlElement *pAttributesElement = pRootElem->FirstChildElement("Attributes");
|
||||
|
||||
// Iterate font elements
|
||||
TiXmlElement *pAttributeElem = pAttributesElement->FirstChildElement();
|
||||
for (; pAttributeElem != NULL; pAttributeElem = pAttributeElem->NextSiblingElement()) {
|
||||
tString sType = cString::ToString(pAttributeElem->Attribute("type"), "");
|
||||
|
||||
eGuiSkinAttribute type = mpGui->GetSkinAttributeFromString(sType);
|
||||
if (type == eGuiSkinAttribute_LastEnum)
|
||||
continue;
|
||||
|
||||
tString sValue = cString::ToString(pAttributeElem->Attribute("value"), "");
|
||||
|
||||
cVector3f vVal(0);
|
||||
tFloatVec vValues;
|
||||
tString sSepp = " ";
|
||||
cString::GetFloatVec(sValue, vValues, &sSepp);
|
||||
|
||||
if (vValues.size() > 0)
|
||||
vVal.x = vValues[0];
|
||||
if (vValues.size() > 1)
|
||||
vVal.y = vValues[1];
|
||||
if (vValues.size() > 2)
|
||||
vVal.z = vValues[2];
|
||||
|
||||
mvAttributes[type] = vVal;
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// FONTS
|
||||
TiXmlElement *pFontsElement = pRootElem->FirstChildElement("Fonts");
|
||||
|
||||
// Iterate font elements
|
||||
TiXmlElement *pFontElem = pFontsElement->FirstChildElement();
|
||||
for (; pFontElem != NULL; pFontElem = pFontElem->NextSiblingElement()) {
|
||||
tString sType = cString::ToString(pFontElem->Attribute("type"), "");
|
||||
|
||||
eGuiSkinFont type = mpGui->GetSkinFontFromString(sType);
|
||||
if (type == eGuiSkinFont_LastEnum)
|
||||
continue;
|
||||
|
||||
tString sFontFile = cString::ToString(pFontElem->Attribute("file"), "");
|
||||
cVector2f vSize = cString::ToVector2f(pFontElem->Attribute("size"), 1);
|
||||
cColor color = cString::ToColor(pFontElem->Attribute("color"), cColor(1, 1));
|
||||
|
||||
cGuiSkinFont *pFont = hplNew(cGuiSkinFont, (mpGui));
|
||||
|
||||
pFont->mpFont = mpGui->GetResources()->GetFontManager()->CreateFontData(sFontFile);
|
||||
pFont->mvSize = vSize;
|
||||
pFont->mColor = color;
|
||||
|
||||
mvFonts[type] = pFont;
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
// GFX ELEMENTS
|
||||
|
||||
// Get gfx element
|
||||
TiXmlElement *pGfxElementsElement = pRootElem->FirstChildElement("GfxElements");
|
||||
|
||||
// Iterate gfx elements
|
||||
TiXmlElement *pGfxElem = pGfxElementsElement->FirstChildElement();
|
||||
for (; pGfxElem != NULL; pGfxElem = pGfxElem->NextSiblingElement()) {
|
||||
tString sType = cString::ToString(pGfxElem->Attribute("type"), "");
|
||||
|
||||
eGuiSkinGfx type = mpGui->GetSkinGfxFromString(sType);
|
||||
if (type == eGuiSkinGfx_LastEnum)
|
||||
continue;
|
||||
|
||||
tString sFile = cString::ToString(pGfxElem->Attribute("file"), "");
|
||||
cVector2f vOffset = cString::ToVector2f(pGfxElem->Attribute("offset"), 0);
|
||||
cVector2f vSize = cString::ToVector2f(pGfxElem->Attribute("active_size"), -1);
|
||||
cColor color = cString::ToColor(pGfxElem->Attribute("color"), cColor(1, 1));
|
||||
eGuiMaterial material = ToMaterial(pGfxElem->Attribute("material"));
|
||||
|
||||
bool bAnimated = cString::ToBool(pGfxElem->Attribute("animated"), false);
|
||||
float fAnimFrameTime = cString::ToFloat(pGfxElem->Attribute("anim_frame_time"), 1);
|
||||
eGuiGfxAnimationType animType = ToAnimType(pGfxElem->Attribute("anim_mode"));
|
||||
|
||||
cGuiGfxElement *pGfx = NULL;
|
||||
if (sFile != "") {
|
||||
if (bAnimated) {
|
||||
pGfx = mpGui->CreateGfxImageBuffer(sFile, material, true, color);
|
||||
} else {
|
||||
pGfx = mpGui->CreateGfxImage(sFile, material, color);
|
||||
}
|
||||
} else {
|
||||
pGfx = mpGui->CreateGfxFilledRect(color, material);
|
||||
}
|
||||
|
||||
if (pGfx) {
|
||||
if (bAnimated) {
|
||||
cGuiGfxAnimation *pAnim = pGfx->GetAnimation(0);
|
||||
pAnim->SetFrameLength(fAnimFrameTime);
|
||||
pAnim->SetType(animType);
|
||||
}
|
||||
|
||||
if (vSize.x >= 0)
|
||||
pGfx->SetActiveSize(vSize);
|
||||
pGfx->SetOffset(cVector3f(vOffset.x, vOffset.y, 0));
|
||||
|
||||
mvGfxElements[type] = pGfx;
|
||||
}
|
||||
}
|
||||
|
||||
hplDelete(pXmlDoc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiGfxElement *cGuiSkin::GetGfx(eGuiSkinGfx aType) {
|
||||
return mvGfxElements[aType];
|
||||
}
|
||||
|
||||
cGuiSkinFont *cGuiSkin::GetFont(eGuiSkinFont aType) {
|
||||
return mvFonts[aType];
|
||||
}
|
||||
|
||||
const cVector3f &cGuiSkin::GetAttribute(eGuiSkinAttribute aType) {
|
||||
return mvAttributes[aType];
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
83
engines/hpl1/engine/gui/GuiSkin.h
Normal file
83
engines/hpl1/engine/gui/GuiSkin.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GUI_SKIN_H
|
||||
#define HPL_GUI_SKIN_H
|
||||
|
||||
#include "hpl1/engine/gui/GuiTypes.h"
|
||||
#include "common/stablemap.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGui;
|
||||
class cGuiGfxElement;
|
||||
class FontData;
|
||||
class iGuiMaterial;
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
class cGuiSkinFont {
|
||||
public:
|
||||
cGuiSkinFont(cGui *apGui);
|
||||
~cGuiSkinFont();
|
||||
|
||||
FontData *mpFont;
|
||||
cVector2f mvSize;
|
||||
cColor mColor;
|
||||
iGuiMaterial *mpMaterial;
|
||||
|
||||
private:
|
||||
cGui *mpGui;
|
||||
};
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
class cGuiSkin {
|
||||
public:
|
||||
cGuiSkin(const tString &asName, cGui *apGui);
|
||||
~cGuiSkin();
|
||||
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
bool LoadFromFile(const tString &asFile);
|
||||
|
||||
cGuiGfxElement *GetGfx(eGuiSkinGfx aType);
|
||||
cGuiSkinFont *GetFont(eGuiSkinFont aType);
|
||||
const cVector3f &GetAttribute(eGuiSkinAttribute aType);
|
||||
|
||||
private:
|
||||
tString msName;
|
||||
cGui *mpGui;
|
||||
|
||||
Common::Array<cGuiGfxElement *> mvGfxElements;
|
||||
Common::Array<cGuiSkinFont *> mvFonts;
|
||||
Common::Array<cVector3f> mvAttributes;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GUI_SKIN_H
|
||||
330
engines/hpl1/engine/gui/GuiTypes.h
Normal file
330
engines/hpl1/engine/gui/GuiTypes.h
Normal file
@@ -0,0 +1,330 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_GUI_TYPES_H
|
||||
#define HPL_GUI_TYPES_H
|
||||
|
||||
#include "common/keyboard.h"
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/graphics/GraphicsTypes.h"
|
||||
#include "hpl1/engine/input/InputTypes.h"
|
||||
#include "hpl1/engine/math/MathTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//--------------------------------
|
||||
|
||||
enum eGuiMouseButton {
|
||||
eGuiMouseButton_Left = 0x00000001,
|
||||
eGuiMouseButton_Middle = 0x00000002,
|
||||
eGuiMouseButton_Right = 0x00000004,
|
||||
eGuiMouseButton_LastEnum = 4
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
enum eGuiArrowKey {
|
||||
eGuiArrowKey_Left,
|
||||
eGuiArrowKey_Right,
|
||||
eGuiArrowKey_Up,
|
||||
eGuiArrowKey_Down,
|
||||
eGuiArrowKey_LastEnum
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
enum eGuiMaterial {
|
||||
eGuiMaterial_Diffuse,
|
||||
eGuiMaterial_Alpha,
|
||||
eGuiMaterial_FontNormal,
|
||||
eGuiMaterial_Additive,
|
||||
eGuiMaterial_Modulative,
|
||||
eGuiMaterial_LastEnum,
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
enum eWidgetType {
|
||||
eWidgetType_Root,
|
||||
eWidgetType_Window,
|
||||
eWidgetType_Button,
|
||||
eWidgetType_Frame,
|
||||
eWidgetType_Label,
|
||||
eWidgetType_Slider,
|
||||
eWidgetType_TextBox,
|
||||
eWidgetType_CheckBox,
|
||||
eWidgetType_Image,
|
||||
eWidgetType_ListBox,
|
||||
eWidgetType_ComboBox,
|
||||
|
||||
eWidgetType_User,
|
||||
eWidgetType_LastEnum,
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
enum eGuiSkinFont {
|
||||
eGuiSkinFont_Default,
|
||||
eGuiSkinFont_Disabled,
|
||||
eGuiSkinFont_WindowLabel,
|
||||
|
||||
eGuiSkinFont_LastEnum
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
enum eGuiSkinAttribute {
|
||||
eGuiSkinAttribute_WindowLabelTextOffset,
|
||||
|
||||
eGuiSkinAttribute_ButtonPressedContentOffset,
|
||||
|
||||
eGuiSkinAttribute_SliderButtonSize,
|
||||
|
||||
eGuiSkinAttribute_ListBoxSliderWidth,
|
||||
|
||||
eGuiSkinAttribute_ComboBoxButtonWidth,
|
||||
eGuiSkinAttribute_ComboBoxSliderWidth,
|
||||
|
||||
eGuiSkinAttribute_LastEnum
|
||||
};
|
||||
//--------------------------------
|
||||
|
||||
enum eGuiSkinGfx {
|
||||
///////////////////////////////////
|
||||
// Pointer
|
||||
eGuiSkinGfx_PointerNormal,
|
||||
eGuiSkinGfx_PointerText,
|
||||
|
||||
///////////////////////////////////
|
||||
// Window
|
||||
eGuiSkinGfx_WindowBorderRight,
|
||||
eGuiSkinGfx_WindowBorderLeft,
|
||||
eGuiSkinGfx_WindowBorderUp,
|
||||
eGuiSkinGfx_WindowBorderDown,
|
||||
|
||||
eGuiSkinGfx_WindowCornerLU,
|
||||
eGuiSkinGfx_WindowCornerRU,
|
||||
eGuiSkinGfx_WindowCornerRD,
|
||||
eGuiSkinGfx_WindowCornerLD,
|
||||
|
||||
eGuiSkinGfx_WindowLabel,
|
||||
eGuiSkinGfx_WindowBackground,
|
||||
|
||||
///////////////////////////////////
|
||||
// Frame
|
||||
eGuiSkinGfx_FrameBorderRight,
|
||||
eGuiSkinGfx_FrameBorderLeft,
|
||||
eGuiSkinGfx_FrameBorderUp,
|
||||
eGuiSkinGfx_FrameBorderDown,
|
||||
|
||||
eGuiSkinGfx_FrameCornerLU,
|
||||
eGuiSkinGfx_FrameCornerRU,
|
||||
eGuiSkinGfx_FrameCornerRD,
|
||||
eGuiSkinGfx_FrameCornerLD,
|
||||
|
||||
eGuiSkinGfx_FrameBackground,
|
||||
|
||||
///////////////////////////////////
|
||||
// Check Box
|
||||
eGuiSkinGfx_CheckBoxEnabledUnchecked,
|
||||
eGuiSkinGfx_CheckBoxEnabledChecked,
|
||||
eGuiSkinGfx_CheckBoxDisabledUnchecked,
|
||||
eGuiSkinGfx_CheckBoxDisabledChecked,
|
||||
|
||||
///////////////////////////////////
|
||||
// Text Box
|
||||
eGuiSkinGfx_TextBoxBackground,
|
||||
eGuiSkinGfx_TextBoxSelectedTextBack,
|
||||
eGuiSkinGfx_TextBoxMarker,
|
||||
|
||||
///////////////////////////////////
|
||||
// List Box
|
||||
eGuiSkinGfx_ListBoxBackground,
|
||||
|
||||
///////////////////////////////////
|
||||
// Combo Box
|
||||
eGuiSkinGfx_ComboBoxButtonIcon,
|
||||
|
||||
eGuiSkinGfx_ComboBoxBorderRight,
|
||||
eGuiSkinGfx_ComboBoxBorderLeft,
|
||||
eGuiSkinGfx_ComboBoxBorderUp,
|
||||
eGuiSkinGfx_ComboBoxBorderDown,
|
||||
|
||||
eGuiSkinGfx_ComboBoxCornerLU,
|
||||
eGuiSkinGfx_ComboBoxCornerRU,
|
||||
eGuiSkinGfx_ComboBoxCornerRD,
|
||||
eGuiSkinGfx_ComboBoxCornerLD,
|
||||
|
||||
eGuiSkinGfx_ComboBoxBackground,
|
||||
|
||||
///////////////////////////////////
|
||||
// Slider
|
||||
eGuiSkinGfx_SliderVertArrowUp,
|
||||
eGuiSkinGfx_SliderVertArrowDown,
|
||||
eGuiSkinGfx_SliderVertBackground,
|
||||
|
||||
eGuiSkinGfx_SliderHoriArrowUp,
|
||||
eGuiSkinGfx_SliderHoriArrowDown,
|
||||
eGuiSkinGfx_SliderHoriBackground,
|
||||
|
||||
///////////////////////////////////
|
||||
// Button
|
||||
eGuiSkinGfx_ButtonUpBorderRight,
|
||||
eGuiSkinGfx_ButtonUpBorderLeft,
|
||||
eGuiSkinGfx_ButtonUpBorderUp,
|
||||
eGuiSkinGfx_ButtonUpBorderDown,
|
||||
|
||||
eGuiSkinGfx_ButtonUpCornerLU,
|
||||
eGuiSkinGfx_ButtonUpCornerRU,
|
||||
eGuiSkinGfx_ButtonUpCornerRD,
|
||||
eGuiSkinGfx_ButtonUpCornerLD,
|
||||
|
||||
eGuiSkinGfx_ButtonUpBackground,
|
||||
|
||||
eGuiSkinGfx_ButtonDownBorderRight,
|
||||
eGuiSkinGfx_ButtonDownBorderLeft,
|
||||
eGuiSkinGfx_ButtonDownBorderUp,
|
||||
eGuiSkinGfx_ButtonDownBorderDown,
|
||||
|
||||
eGuiSkinGfx_ButtonDownCornerLU,
|
||||
eGuiSkinGfx_ButtonDownCornerRU,
|
||||
eGuiSkinGfx_ButtonDownCornerRD,
|
||||
eGuiSkinGfx_ButtonDownCornerLD,
|
||||
|
||||
eGuiSkinGfx_ButtonDownBackground,
|
||||
|
||||
eGuiSkinGfx_LastEnum,
|
||||
};
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
enum eWidgetSliderOrientation {
|
||||
eWidgetSliderOrientation_Horisontal,
|
||||
eWidgetSliderOrientation_Vertical,
|
||||
eWidgetSliderOrientation_LastEnum
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
enum eGuiMessage {
|
||||
eGuiMessage_MouseMove, // pos= mouse pos, lVal=buttons down
|
||||
eGuiMessage_MouseDown, // pos= mouse pos, lVal=button
|
||||
eGuiMessage_MouseUp, // pos= mouse pos, lVal=button
|
||||
eGuiMessage_MouseDoubleClick, // pos= mouse pos, lVal=button
|
||||
eGuiMessage_MouseEnter, // pos= mouse pos, lVal=buttons down
|
||||
eGuiMessage_MouseLeave, // pos= mouse pos, lVal=buttons down
|
||||
|
||||
eGuiMessage_GotFocus, // pos= mouse pos, lVal=buttons down
|
||||
eGuiMessage_LostFocus, // pos= mouse pos, lVal=buttons down
|
||||
|
||||
eGuiMessage_OnDraw, // fVal = TimeStep, data = clipregion pointer
|
||||
|
||||
eGuiMessage_ButtonPressed, // pos= mouse pos, lVal=buttons down
|
||||
|
||||
eGuiMessage_TextChange, // nothing
|
||||
|
||||
eGuiMessage_CheckChange, // lVal = checked or not.
|
||||
|
||||
eGuiMessage_KeyPress, // pos= mouse pos, lVal=char code.
|
||||
|
||||
eGuiMessage_SliderMove, // val=slider value
|
||||
|
||||
eGuiMessage_SelectionChange, // val=selected val
|
||||
|
||||
eGuiMessage_LastEnum,
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
struct cGuiMessageData {
|
||||
cGuiMessageData() {}
|
||||
cGuiMessageData(const cVector2f &avPos, const cVector2f &avRel) {
|
||||
mvPos = avPos;
|
||||
mvRel = avRel;
|
||||
}
|
||||
cGuiMessageData(const cVector2f &avPos, const cVector2f &avRel, int alVal) {
|
||||
mvPos = avPos;
|
||||
mvRel = avRel;
|
||||
mlVal = alVal;
|
||||
}
|
||||
cGuiMessageData(int alVal) {
|
||||
mlVal = alVal;
|
||||
}
|
||||
cGuiMessageData(float afVal) {
|
||||
mfVal = afVal;
|
||||
}
|
||||
cGuiMessageData(Common::KeyState aKeyPress) {
|
||||
mKeyPress = aKeyPress;
|
||||
}
|
||||
|
||||
cVector2f mvPos;
|
||||
cVector2f mvRel;
|
||||
int mlVal;
|
||||
Common::KeyState mKeyPress;
|
||||
float mfVal;
|
||||
void *mpData;
|
||||
eGuiMessage mMessage;
|
||||
};
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class iWidget;
|
||||
|
||||
typedef bool (*tGuiCallbackFunc)(void *, iWidget *, cGuiMessageData &);
|
||||
|
||||
#define kGuiCalllbackDeclarationEnd(FuncName) \
|
||||
static bool FuncName##_static_gui(void *apObject, iWidget *apWidget, cGuiMessageData &aData)
|
||||
|
||||
#define kGuiCalllbackDeclaredFuncEnd(ThisClass, FuncName) \
|
||||
bool ThisClass::FuncName##_static_gui(void *apObject, iWidget *apWidget, cGuiMessageData &aData) { \
|
||||
return ((ThisClass *)apObject)->FuncName(apWidget, aData); \
|
||||
}
|
||||
|
||||
#define kGuiCalllbackFuncEnd(ThisClass, FuncName) \
|
||||
static bool FuncName##_static_gui(void *apObject, iWidget *apWidget, cGuiMessageData &aData) { \
|
||||
return ((ThisClass *)apObject)->FuncName(apWidget, aData); \
|
||||
}
|
||||
|
||||
#define kGuiCallback(FuncName) &FuncName##_static_gui
|
||||
|
||||
//--------------------------------
|
||||
|
||||
typedef Common::List<iWidget *> tWidgetList;
|
||||
typedef tWidgetList::iterator tWidgetListIt;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class cGuiGfxElement;
|
||||
|
||||
typedef Common::List<cGuiGfxElement *> tGuiGfxElementList;
|
||||
typedef tGuiGfxElementList::iterator tGuiGfxElementListIt;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_GAME_TYPES_H
|
||||
558
engines/hpl1/engine/gui/Widget.cpp
Normal file
558
engines/hpl1/engine/gui/Widget.cpp
Normal file
@@ -0,0 +1,558 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iWidget::iWidget(eWidgetType aType, cGuiSet *apSet, cGuiSkin *apSkin) {
|
||||
mpSet = apSet;
|
||||
mpSkin = apSkin;
|
||||
mpGui = mpSet->GetGui();
|
||||
|
||||
mType = aType;
|
||||
|
||||
mvCallbackLists.resize(eGuiMessage_LastEnum);
|
||||
|
||||
mpParent = NULL;
|
||||
|
||||
mvPosition = 0;
|
||||
mvSize = 0;
|
||||
|
||||
mbEnabled = true;
|
||||
mbVisible = true;
|
||||
|
||||
mbClipsGraphics = false;
|
||||
|
||||
mbMouseIsOver = false;
|
||||
|
||||
msText = _W("");
|
||||
|
||||
mbPositionIsUpdated = true;
|
||||
|
||||
mlPositionCount = 0;
|
||||
|
||||
mbConnectedToChildren = true;
|
||||
|
||||
if (mpSkin)
|
||||
mpPointerGfx = mpSkin->GetGfx(eGuiSkinGfx_PointerNormal);
|
||||
else
|
||||
mpPointerGfx = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
iWidget::~iWidget() {
|
||||
////////////////////////
|
||||
// Remove all children
|
||||
tWidgetListIt it = mlstChildren.begin();
|
||||
while (it != mlstChildren.end()) {
|
||||
RemoveChild(*it);
|
||||
it = mlstChildren.begin();
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
// Remove from parent
|
||||
if (mpParent)
|
||||
mpParent->RemoveChild(this);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::Update(float afTimeStep) {
|
||||
OnUpdate(afTimeStep);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::Draw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
if (mbVisible == false)
|
||||
return;
|
||||
|
||||
OnDraw(afTimeStep, apClipRegion);
|
||||
|
||||
cGuiClipRegion *pChildRegion = apClipRegion;
|
||||
if (mbClipsGraphics) {
|
||||
pChildRegion = apClipRegion->CreateChild(GetGlobalPosition(), mvSize);
|
||||
mpSet->SetCurrentClipRegion(pChildRegion);
|
||||
}
|
||||
|
||||
OnDrawAfterClip(afTimeStep, apClipRegion);
|
||||
|
||||
/////////////////////////////////
|
||||
// Draw callbacks
|
||||
cGuiMessageData data;
|
||||
data.mfVal = afTimeStep;
|
||||
data.mpData = apClipRegion;
|
||||
ProcessMessage(eGuiMessage_OnDraw, data);
|
||||
|
||||
/////////////////////////////////
|
||||
// Draw children
|
||||
tWidgetListIt it = mlstChildren.begin();
|
||||
for (; it != mlstChildren.end(); ++it) {
|
||||
iWidget *pChild = *it;
|
||||
|
||||
pChild->Draw(afTimeStep, pChildRegion);
|
||||
}
|
||||
|
||||
if (mbClipsGraphics)
|
||||
mpSet->SetCurrentClipRegion(apClipRegion);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::Init() {
|
||||
OnInit();
|
||||
LoadGraphics();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iWidget::ProcessMessage(eGuiMessage aMessage, cGuiMessageData &aData) {
|
||||
if (IsEnabled() == false)
|
||||
return false;
|
||||
|
||||
aData.mMessage = aMessage;
|
||||
|
||||
bool bRet = false;
|
||||
bRet = OnMessage(aMessage, aData); // This can override any message.
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Call the correct virtual function
|
||||
if (bRet == false) {
|
||||
switch (aMessage) {
|
||||
case eGuiMessage_MouseMove:
|
||||
bRet = OnMouseMove(aData);
|
||||
break;
|
||||
case eGuiMessage_MouseDown:
|
||||
bRet = OnMouseDown(aData);
|
||||
break;
|
||||
case eGuiMessage_MouseUp:
|
||||
bRet = OnMouseUp(aData);
|
||||
break;
|
||||
case eGuiMessage_MouseDoubleClick:
|
||||
bRet = OnMouseDoubleClick(aData);
|
||||
break;
|
||||
case eGuiMessage_MouseEnter:
|
||||
bRet = OnMouseEnter(aData);
|
||||
break;
|
||||
case eGuiMessage_MouseLeave:
|
||||
bRet = OnMouseLeave(aData);
|
||||
break;
|
||||
case eGuiMessage_KeyPress:
|
||||
bRet = OnKeyPress(aData);
|
||||
break;
|
||||
case eGuiMessage_GotFocus:
|
||||
bRet = OnGotFocus(aData);
|
||||
break;
|
||||
case eGuiMessage_LostFocus:
|
||||
bRet = OnLostFocus(aData);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Process user callbacks for the event.
|
||||
if (ProcessCallbacks(aMessage, aData))
|
||||
bRet = true;
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::AddCallback(eGuiMessage aMessage, void *apObject, tGuiCallbackFunc apFunc) {
|
||||
mvCallbackLists[aMessage].push_back(cWidgetCallback(apObject, apFunc));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iWidget::PointIsInside(const cVector2f &avPoint, bool abOnlyClipped) {
|
||||
if (mpParent && mpParent->ClipsGraphics()) {
|
||||
if (mpParent->PointIsInside(avPoint, true) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (abOnlyClipped && mbClipsGraphics == false)
|
||||
return true;
|
||||
|
||||
cVector3f vGlobalPos = GetGlobalPosition();
|
||||
|
||||
if (avPoint.x < vGlobalPos.x || avPoint.x > vGlobalPos.x + mvSize.x ||
|
||||
avPoint.y < vGlobalPos.y || avPoint.y > vGlobalPos.y + mvSize.y) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::AttachChild(iWidget *apChild) {
|
||||
if (apChild->mpParent) {
|
||||
iWidget *pParent = apChild->mpParent;
|
||||
pParent->RemoveChild(apChild);
|
||||
apChild->SetPosition(apChild->mvPosition + pParent->GetGlobalPosition());
|
||||
apChild->SetPosition(apChild->mvPosition - GetGlobalPosition());
|
||||
}
|
||||
apChild->mpParent = this;
|
||||
apChild->SetPositionUpdated();
|
||||
mlstChildren.push_back(apChild);
|
||||
}
|
||||
|
||||
void iWidget::RemoveChild(iWidget *apChild) {
|
||||
tWidgetListIt it = mlstChildren.begin();
|
||||
for (; it != mlstChildren.end(); ++it) {
|
||||
iWidget *pChild = *it;
|
||||
|
||||
if (pChild == apChild) {
|
||||
mlstChildren.erase(it);
|
||||
|
||||
pChild->mpParent = NULL;
|
||||
pChild->SetPositionUpdated();
|
||||
pChild->SetPosition(pChild->mvPosition + GetGlobalPosition());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::SetEnabled(bool abX) {
|
||||
if (mbEnabled == abX)
|
||||
return;
|
||||
|
||||
mbEnabled = abX;
|
||||
}
|
||||
|
||||
bool iWidget::IsEnabled() {
|
||||
if (mpParent) {
|
||||
if (mpParent->IsEnabled())
|
||||
return mbEnabled;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return mbEnabled;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::SetVisible(bool abX) {
|
||||
if (mbVisible == abX)
|
||||
return;
|
||||
|
||||
mbVisible = abX;
|
||||
}
|
||||
|
||||
bool iWidget::IsVisible() {
|
||||
if (mpParent) {
|
||||
if (mpParent->IsVisible())
|
||||
return mbVisible;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
return mbVisible;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iWidget::HasFocus() {
|
||||
return mpSet->GetFocusedWidget() == this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::SetText(const tWString &asText) {
|
||||
if (asText == msText)
|
||||
return;
|
||||
|
||||
msText = asText;
|
||||
|
||||
OnChangeText();
|
||||
cGuiMessageData data = cGuiMessageData();
|
||||
ProcessMessage(eGuiMessage_TextChange, data);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::SetPosition(const cVector3f &avPos) {
|
||||
mvPosition = avPos;
|
||||
|
||||
SetPositionUpdated();
|
||||
}
|
||||
|
||||
void iWidget::SetGlobalPosition(const cVector3f &avPos) {
|
||||
SetPosition(avPos - mpParent->GetGlobalPosition());
|
||||
}
|
||||
|
||||
const cVector3f &iWidget::GetLocalPosition() {
|
||||
return mvPosition;
|
||||
}
|
||||
|
||||
const cVector3f &iWidget::GetGlobalPosition() {
|
||||
if (mpParent) {
|
||||
if (mbPositionIsUpdated) {
|
||||
mbPositionIsUpdated = false;
|
||||
mvGlobalPosition = mpParent->GetGlobalPosition() + mvPosition;
|
||||
}
|
||||
return mvGlobalPosition;
|
||||
} else {
|
||||
return mvPosition;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::SetSize(const cVector2f &avSize) {
|
||||
mvSize = avSize;
|
||||
|
||||
OnChangeSize();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iWidget::ClipsGraphics() {
|
||||
if (mpParent && mpParent->ClipsGraphics())
|
||||
return true;
|
||||
|
||||
return mbClipsGraphics;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iWidget::IsConnectedTo(iWidget *apWidget, bool abIsStartWidget) {
|
||||
if (abIsStartWidget == false && mbConnectedToChildren == false)
|
||||
return false;
|
||||
|
||||
if (apWidget == NULL)
|
||||
return false;
|
||||
if (apWidget == this)
|
||||
return true;
|
||||
|
||||
if (mpParent)
|
||||
return mpParent->IsConnectedTo(apWidget, false);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cGuiGfxElement *iWidget::GetPointerGfx() {
|
||||
return mpPointerGfx;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iWidget::OnGotFocus(cGuiMessageData &aData) {
|
||||
return mbEnabled;
|
||||
}
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector3f iWidget::WorldToLocalPosition(const cVector3f &avPos) {
|
||||
return avPos - GetGlobalPosition();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2f iWidget::GetPosRelativeToMouse(cGuiMessageData &aData) {
|
||||
cVector3f vTemp = GetGlobalPosition() - aData.mvPos;
|
||||
return cVector2f(vTemp.x, vTemp.y);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::DrawBordersAndCorners(cGuiGfxElement *apBackground,
|
||||
cGuiGfxElement **apBorderVec, cGuiGfxElement **apCornerVec,
|
||||
const cVector3f &avPosition, const cVector2f &avSize) {
|
||||
mpSet->SetDrawOffset(avPosition);
|
||||
|
||||
///////////////////////
|
||||
// Background
|
||||
if (apBackground) {
|
||||
|
||||
mpSet->DrawGfx(apBackground, cVector3f(apCornerVec[0]->GetActiveSize().x, apCornerVec[0]->GetActiveSize().y, 0),
|
||||
avSize - apCornerVec[2]->GetActiveSize() - apCornerVec[0]->GetActiveSize(),
|
||||
cColor(1, 1));
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
// Borders
|
||||
// Right
|
||||
mpSet->DrawGfx(apBorderVec[0],
|
||||
cVector3f(avSize.x - apBorderVec[0]->GetActiveSize().x,
|
||||
apCornerVec[1]->GetActiveSize().y, 0),
|
||||
cVector2f(apBorderVec[0]->GetImageSize().x,
|
||||
avSize.y - (apCornerVec[2]->GetActiveSize().y +
|
||||
apCornerVec[1]->GetActiveSize().y)));
|
||||
// Left
|
||||
mpSet->DrawGfx(apBorderVec[1],
|
||||
cVector3f(0, apCornerVec[0]->GetActiveSize().y, 0),
|
||||
cVector2f(apBorderVec[1]->GetImageSize().x,
|
||||
avSize.y - (apCornerVec[3]->GetActiveSize().y +
|
||||
apCornerVec[0]->GetActiveSize().y)));
|
||||
|
||||
// Up
|
||||
mpSet->DrawGfx(apBorderVec[2],
|
||||
cVector3f(apCornerVec[0]->GetActiveSize().x, 0, 0),
|
||||
cVector2f(avSize.x - (apCornerVec[0]->GetActiveSize().x +
|
||||
apCornerVec[1]->GetActiveSize().x),
|
||||
apBorderVec[2]->GetImageSize().y));
|
||||
|
||||
// Down
|
||||
mpSet->DrawGfx(apBorderVec[3],
|
||||
cVector3f(apCornerVec[3]->GetActiveSize().x,
|
||||
avSize.y - apBorderVec[3]->GetActiveSize().y, 0),
|
||||
cVector2f(avSize.x - (apCornerVec[2]->GetActiveSize().x +
|
||||
apCornerVec[3]->GetActiveSize().x),
|
||||
apBorderVec[3]->GetImageSize().y));
|
||||
|
||||
///////////////////////
|
||||
// Corners
|
||||
// Left Up
|
||||
mpSet->DrawGfx(apCornerVec[0], cVector3f(0, 0, 0));
|
||||
// Right Up
|
||||
mpSet->DrawGfx(apCornerVec[1], cVector3f(avSize.x - apCornerVec[1]->GetActiveSize().x, 0, 0));
|
||||
|
||||
// Right Down
|
||||
mpSet->DrawGfx(apCornerVec[2], cVector3f(avSize.x - apCornerVec[2]->GetActiveSize().x,
|
||||
avSize.y - apCornerVec[2]->GetActiveSize().y, 0));
|
||||
// Left Down
|
||||
mpSet->DrawGfx(apCornerVec[3], cVector3f(0, avSize.y - apCornerVec[3]->GetActiveSize().y, 0));
|
||||
|
||||
mpSet->SetDrawOffset(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::DrawSkinText(const tWString &asText, eGuiSkinFont aFont,
|
||||
const cVector3f &avPosition, eFontAlign aAlign) {
|
||||
cGuiSkinFont *pFont = mpSkin->GetFont(aFont);
|
||||
mpSet->DrawFont(asText, pFont->mpFont, avPosition, pFont->mvSize, pFont->mColor,
|
||||
aAlign);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::DrawDefaultText(const tWString &asText,
|
||||
const cVector3f &avPosition, eFontAlign aAlign) {
|
||||
if (mpDefaultFontType == NULL)
|
||||
return;
|
||||
|
||||
mpSet->DrawFont(asText, mpDefaultFontType, avPosition, mvDefaultFontSize,
|
||||
mDefaultFontColor, aAlign);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PRIVATE METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool iWidget::ProcessCallbacks(eGuiMessage aMessage, cGuiMessageData &aData) {
|
||||
tWidgetCallbackList &lstCallbacks = mvCallbackLists[aMessage];
|
||||
|
||||
if (lstCallbacks.empty())
|
||||
return false;
|
||||
|
||||
bool bRet = false;
|
||||
tWidgetCallbackListIt it = lstCallbacks.begin();
|
||||
for (; it != lstCallbacks.end(); ++it) {
|
||||
cWidgetCallback &callback = *it;
|
||||
|
||||
bool bX = (callback.mpFunc)(callback.mpObject, this, aData);
|
||||
if (bX)
|
||||
bRet = true;
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidget::LoadGraphics() {
|
||||
if (mpSkin) {
|
||||
mpDefaultFont = mpSkin->GetFont(eGuiSkinFont_Default);
|
||||
|
||||
mpDefaultFontType = mpDefaultFont->mpFont;
|
||||
mDefaultFontColor = mpDefaultFont->mColor;
|
||||
mvDefaultFontSize = mpDefaultFont->mvSize;
|
||||
} else {
|
||||
mpDefaultFont = NULL;
|
||||
}
|
||||
|
||||
OnLoadGraphics();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void iWidget::SetPositionUpdated() {
|
||||
mbPositionIsUpdated = true;
|
||||
mlPositionCount++;
|
||||
|
||||
OnChangePosition();
|
||||
|
||||
tWidgetListIt it = mlstChildren.begin();
|
||||
for (; it != mlstChildren.end(); ++it) {
|
||||
iWidget *pChild = *it;
|
||||
pChild->SetPositionUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
243
engines/hpl1/engine/gui/Widget.h
Normal file
243
engines/hpl1/engine/gui/Widget.h
Normal file
@@ -0,0 +1,243 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_H
|
||||
#define HPL_WIDGET_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/gui/GuiTypes.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGui;
|
||||
class cGuiSet;
|
||||
class cGuiSkin;
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cGuiGfxElement;
|
||||
class cGuiClipRegion;
|
||||
|
||||
class FontData;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
struct cWidgetCallback {
|
||||
cWidgetCallback(void *apObject, tGuiCallbackFunc apFunc) {
|
||||
mpObject = apObject;
|
||||
mpFunc = apFunc;
|
||||
}
|
||||
|
||||
void *mpObject;
|
||||
tGuiCallbackFunc mpFunc;
|
||||
};
|
||||
|
||||
typedef Common::List<cWidgetCallback> tWidgetCallbackList;
|
||||
typedef tWidgetCallbackList::iterator tWidgetCallbackListIt;
|
||||
|
||||
//--------------------------------
|
||||
|
||||
class iWidget {
|
||||
friend class cGuiSet;
|
||||
|
||||
public:
|
||||
iWidget(eWidgetType aType, cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~iWidget();
|
||||
|
||||
/////////////////////////
|
||||
// General
|
||||
void Update(float afTimeStep);
|
||||
|
||||
void Draw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool ProcessMessage(eGuiMessage aMessage, cGuiMessageData &aData);
|
||||
|
||||
void AddCallback(eGuiMessage aMessage, void *apObject, tGuiCallbackFunc apFunc);
|
||||
|
||||
eWidgetType GetType() { return mType; }
|
||||
|
||||
void Init();
|
||||
|
||||
/////////////////////////
|
||||
// Public Helper functions
|
||||
bool PointIsInside(const cVector2f &avPoint, bool abOnlyClipped);
|
||||
|
||||
/////////////////////////
|
||||
// Hierarchy
|
||||
void AttachChild(iWidget *apChild);
|
||||
void RemoveChild(iWidget *apChild);
|
||||
|
||||
/////////////////////////
|
||||
// Properties
|
||||
cGuiSet *GetSet() { return mpSet; }
|
||||
|
||||
iWidget *GetParent() { return mpParent; }
|
||||
|
||||
void SetEnabled(bool abX);
|
||||
bool IsEnabled();
|
||||
void SetVisible(bool abX);
|
||||
bool IsVisible();
|
||||
|
||||
bool HasFocus();
|
||||
|
||||
void SetName(const tString &asName) { msName = asName; }
|
||||
const tString &GetName() { return msName; }
|
||||
|
||||
void SetText(const tWString &asText);
|
||||
const tWString &GetText() { return msText; }
|
||||
|
||||
FontData *GetDefaultFontType() { return mpDefaultFontType; }
|
||||
void SetDefaultFontType(FontData *apFont) { mpDefaultFontType = apFont; }
|
||||
|
||||
const cColor &GetDefaultFontColor() { return mDefaultFontColor; }
|
||||
void SetDefaultFontColor(const cColor &aColor) { mDefaultFontColor = aColor; }
|
||||
|
||||
const cVector2f &GetDefaultFontSize() { return mvDefaultFontSize; }
|
||||
void SetDefaultFontSize(const cVector2f &avSize) { mvDefaultFontSize = avSize; }
|
||||
|
||||
void SetClipActive(bool abX) { mbClipsGraphics = abX; }
|
||||
bool GetClipActive() { return mbClipsGraphics; }
|
||||
|
||||
void SetPosition(const cVector3f &avPos);
|
||||
void SetGlobalPosition(const cVector3f &avPos);
|
||||
const cVector3f &GetLocalPosition();
|
||||
const cVector3f &GetGlobalPosition();
|
||||
|
||||
void SetSize(const cVector2f &avSize);
|
||||
cVector2f GetSize() { return mvSize; }
|
||||
|
||||
bool ClipsGraphics();
|
||||
|
||||
bool GetMouseIsOver() { return mbMouseIsOver; }
|
||||
|
||||
bool IsConnectedTo(iWidget *apWidget, bool abIsStartWidget = true);
|
||||
bool IsConnectedToChildren() { return mbConnectedToChildren; }
|
||||
void SetConnectedToChildren(bool abX) { mbConnectedToChildren = abX; }
|
||||
|
||||
cGuiGfxElement *GetPointerGfx();
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Upper Widget functions
|
||||
virtual void OnLoadGraphics() {}
|
||||
|
||||
virtual void OnChangeSize() {}
|
||||
virtual void OnChangePosition() {}
|
||||
virtual void OnChangeText() {}
|
||||
|
||||
virtual void OnInit() {}
|
||||
|
||||
virtual void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {}
|
||||
virtual void OnDrawAfterClip(float afTimeStep, cGuiClipRegion *apClipRegion) {}
|
||||
|
||||
virtual void OnUpdate(float afTimeStep) {}
|
||||
|
||||
virtual bool OnMessage(eGuiMessage aMessage, cGuiMessageData &aData) { return false; }
|
||||
virtual bool OnMouseMove(cGuiMessageData &aData) { return false; }
|
||||
virtual bool OnMouseDown(cGuiMessageData &aData) { return false; }
|
||||
virtual bool OnMouseUp(cGuiMessageData &aData) { return false; }
|
||||
virtual bool OnMouseDoubleClick(cGuiMessageData &aData) { return false; }
|
||||
virtual bool OnMouseEnter(cGuiMessageData &aData) { return false; }
|
||||
virtual bool OnMouseLeave(cGuiMessageData &aData) { return false; }
|
||||
|
||||
virtual bool OnGotFocus(cGuiMessageData &aData);
|
||||
virtual bool OnLostFocus(cGuiMessageData &aData) { return false; }
|
||||
|
||||
virtual bool OnKeyPress(cGuiMessageData &aData) { return false; }
|
||||
|
||||
/////////////////////////
|
||||
// Private Helper functions
|
||||
cVector3f WorldToLocalPosition(const cVector3f &avPos);
|
||||
cVector2f GetPosRelativeToMouse(cGuiMessageData &aData);
|
||||
|
||||
// The order must be like this:
|
||||
// Borders: Right, Left, Up and Down
|
||||
// Corners: LEftUp, RightUp, RightDown and LEftDown.
|
||||
void DrawBordersAndCorners(cGuiGfxElement *apBackground,
|
||||
cGuiGfxElement **apBorderVec, cGuiGfxElement **apCornerVec,
|
||||
const cVector3f &avPosition, const cVector2f &avSize);
|
||||
|
||||
void DrawSkinText(const tWString &asText, eGuiSkinFont aFont, const cVector3f &avPosition,
|
||||
eFontAlign aAlign = eFontAlign_Left);
|
||||
|
||||
void DrawDefaultText(const tWString &asText,
|
||||
const cVector3f &avPosition, eFontAlign aAlign);
|
||||
|
||||
void SetPositionUpdated();
|
||||
|
||||
void LoadGraphics();
|
||||
|
||||
/////////////////////////
|
||||
// Variables
|
||||
cGuiSet *mpSet;
|
||||
cGuiSkin *mpSkin;
|
||||
cGui *mpGui;
|
||||
|
||||
tWString msText;
|
||||
cVector3f mvPosition;
|
||||
cVector3f mvGlobalPosition;
|
||||
cVector2f mvSize;
|
||||
|
||||
tString msName;
|
||||
|
||||
eWidgetType mType;
|
||||
|
||||
int mlPositionCount;
|
||||
|
||||
cGuiSkinFont *mpDefaultFont;
|
||||
FontData *mpDefaultFontType;
|
||||
cColor mDefaultFontColor;
|
||||
cVector2f mvDefaultFontSize;
|
||||
|
||||
iWidget *mpParent;
|
||||
|
||||
tWidgetList mlstChildren;
|
||||
|
||||
bool mbEnabled;
|
||||
bool mbVisible;
|
||||
|
||||
bool mbMouseIsOver;
|
||||
|
||||
bool mbClipsGraphics;
|
||||
|
||||
cGuiGfxElement *mpPointerGfx;
|
||||
|
||||
bool mbConnectedToChildren;
|
||||
|
||||
private:
|
||||
void SetMouseIsOver(bool abX) { mbMouseIsOver = abX; }
|
||||
bool ProcessCallbacks(eGuiMessage aMessage, cGuiMessageData &aData);
|
||||
|
||||
Common::Array<tWidgetCallbackList> mvCallbackLists;
|
||||
|
||||
bool mbPositionIsUpdated;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_H
|
||||
101
engines/hpl1/engine/gui/WidgetBaseClasses.cpp
Normal file
101
engines/hpl1/engine/gui/WidgetBaseClasses.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetBaseClasses.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// ITEM CONTAINER
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void iWidgetItemContainer::AddItem(const tWString &asItem) {
|
||||
mvItems.push_back(asItem);
|
||||
|
||||
UpdateProperties();
|
||||
}
|
||||
|
||||
void iWidgetItemContainer::RemoveItem(int alX) {
|
||||
int lCount = 0;
|
||||
tWStringVecIt it = mvItems.begin();
|
||||
for (; it != mvItems.end(); ++it, ++lCount) {
|
||||
if (lCount == alX) {
|
||||
mvItems.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
UpdateProperties();
|
||||
}
|
||||
|
||||
void iWidgetItemContainer::RemoveItem(const tWString &asItem) {
|
||||
tWStringVecIt it = mvItems.begin();
|
||||
for (; it != mvItems.end(); ++it) {
|
||||
if (*it == asItem) {
|
||||
mvItems.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const tWString &iWidgetItemContainer::GetItem(int alX) const {
|
||||
return mvItems[alX];
|
||||
}
|
||||
void iWidgetItemContainer::SetItem(int alX, const tWString &asText) {
|
||||
mvItems[alX] = asText;
|
||||
}
|
||||
|
||||
int iWidgetItemContainer::GetItemNum() const {
|
||||
return (int)mvItems.size();
|
||||
}
|
||||
bool iWidgetItemContainer::HasItem(const tWString &asItem) {
|
||||
tWStringVecIt it = mvItems.begin();
|
||||
for (; it != mvItems.end(); ++it) {
|
||||
if (*it == asItem)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
59
engines/hpl1/engine/gui/WidgetBaseClasses.h
Normal file
59
engines/hpl1/engine/gui/WidgetBaseClasses.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_BASE_CLASSES_H
|
||||
#define HPL_WIDGET_BASE_CLASSES_H
|
||||
|
||||
#include "hpl1/engine/gui/GuiTypes.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
class iWidgetItemContainer {
|
||||
public:
|
||||
virtual ~iWidgetItemContainer() = default;
|
||||
void AddItem(const tWString &asItem);
|
||||
void RemoveItem(int alX);
|
||||
void RemoveItem(const tWString &asItem);
|
||||
|
||||
const tWString &GetItem(int alX) const;
|
||||
void SetItem(int alX, const tWString &asText);
|
||||
int GetItemNum() const;
|
||||
bool HasItem(const tWString &asItem);
|
||||
|
||||
protected:
|
||||
virtual void UpdateProperties() = 0;
|
||||
|
||||
tWStringVec mvItems;
|
||||
};
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_BASE_CLASSES_H
|
||||
195
engines/hpl1/engine/gui/WidgetButton.cpp
Normal file
195
engines/hpl1/engine/gui/WidgetButton.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetButton.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/system/String.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
#include "hpl1/engine/graphics/font_data.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetButton::cWidgetButton(cGuiSet *apSet, cGuiSkin *apSkin) : iWidget(eWidgetType_Button, apSet, apSkin) {
|
||||
mbPressed = false;
|
||||
mpImage = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetButton::~cWidgetButton() {
|
||||
if (mpImage && mbDestroyImage) {
|
||||
mpGui->DestroyGfx(mpImage);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetButton::SetImage(cGuiGfxElement *apImage, bool abDestroyImage) {
|
||||
mpImage = apImage;
|
||||
mbDestroyImage = abDestroyImage;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetButton::OnLoadGraphics() {
|
||||
/////////////////////////
|
||||
// Up
|
||||
mpGfxBackgroundUp = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBackground);
|
||||
|
||||
mvGfxBordersUp[0] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBorderRight);
|
||||
mvGfxBordersUp[1] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBorderLeft);
|
||||
mvGfxBordersUp[2] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBorderUp);
|
||||
mvGfxBordersUp[3] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBorderDown);
|
||||
|
||||
mvGfxCornersUp[0] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpCornerLU);
|
||||
mvGfxCornersUp[1] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpCornerRU);
|
||||
mvGfxCornersUp[2] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpCornerRD);
|
||||
mvGfxCornersUp[3] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpCornerLD);
|
||||
|
||||
/////////////////////////
|
||||
// Down
|
||||
mpGfxBackgroundDown = mpSkin->GetGfx(eGuiSkinGfx_ButtonDownBackground);
|
||||
|
||||
mvGfxBordersDown[0] = mpSkin->GetGfx(eGuiSkinGfx_ButtonDownBorderRight);
|
||||
mvGfxBordersDown[1] = mpSkin->GetGfx(eGuiSkinGfx_ButtonDownBorderLeft);
|
||||
mvGfxBordersDown[2] = mpSkin->GetGfx(eGuiSkinGfx_ButtonDownBorderUp);
|
||||
mvGfxBordersDown[3] = mpSkin->GetGfx(eGuiSkinGfx_ButtonDownBorderDown);
|
||||
|
||||
mvGfxCornersDown[0] = mpSkin->GetGfx(eGuiSkinGfx_ButtonDownCornerLU);
|
||||
mvGfxCornersDown[1] = mpSkin->GetGfx(eGuiSkinGfx_ButtonDownCornerRU);
|
||||
mvGfxCornersDown[2] = mpSkin->GetGfx(eGuiSkinGfx_ButtonDownCornerRD);
|
||||
mvGfxCornersDown[3] = mpSkin->GetGfx(eGuiSkinGfx_ButtonDownCornerLD);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetButton::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
cVector3f vOffset = 0;
|
||||
if (mbPressed)
|
||||
vOffset = mpSkin->GetAttribute(eGuiSkinAttribute_ButtonPressedContentOffset);
|
||||
|
||||
////////////////////////////////
|
||||
// Image
|
||||
if (mpImage) {
|
||||
mpSet->DrawGfx(mpImage, GetGlobalPosition() +
|
||||
cVector3f(mvSize.x / 2 - mpImage->GetImageSize().x / 2,
|
||||
mvSize.y / 2 - mpImage->GetImageSize().y / 2, 0.2f) +
|
||||
vOffset);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Text
|
||||
if (IsEnabled()) {
|
||||
DrawDefaultText(msText, GetGlobalPosition() + cVector3f(mvSize.x / 2, mvSize.y / 2 - mvDefaultFontSize.y / 2, 0.5f) + vOffset,
|
||||
eFontAlign_Center);
|
||||
} else {
|
||||
DrawSkinText(msText, eGuiSkinFont_Disabled, GetGlobalPosition() + cVector3f(mvSize.x / 2, mvSize.y / 2 - mvDefaultFontSize.y / 2, 0.5f) + vOffset,
|
||||
eFontAlign_Center);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Borders and background
|
||||
if (mbPressed) {
|
||||
DrawBordersAndCorners(mpGfxBackgroundDown, mvGfxBordersDown, mvGfxCornersDown,
|
||||
GetGlobalPosition(), mvSize);
|
||||
} else {
|
||||
DrawBordersAndCorners(mpGfxBackgroundUp, mvGfxBordersUp, mvGfxCornersUp,
|
||||
GetGlobalPosition(), mvSize);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetButton::OnMouseMove(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetButton::OnMouseDown(cGuiMessageData &aData) {
|
||||
mbPressed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetButton::OnMouseUp(cGuiMessageData &aData) {
|
||||
if (GetMouseIsOver() == false)
|
||||
return false;
|
||||
|
||||
if (mbPressed)
|
||||
ProcessMessage(eGuiMessage_ButtonPressed, aData);
|
||||
|
||||
mbPressed = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetButton::OnMouseEnter(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetButton::OnMouseLeave(cGuiMessageData &aData) {
|
||||
mbPressed = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
76
engines/hpl1/engine/gui/WidgetButton.h
Normal file
76
engines/hpl1/engine/gui/WidgetButton.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_BUTTON_H
|
||||
#define HPL_WIDGET_BUTTON_H
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetButton : public iWidget {
|
||||
public:
|
||||
cWidgetButton(cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~cWidgetButton();
|
||||
|
||||
void SetImage(cGuiGfxElement *apImage, bool abDestroyImage = true);
|
||||
cGuiGfxElement *GetImage() { return mpImage; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnLoadGraphics();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
bool mbPressed;
|
||||
|
||||
cGuiGfxElement *mpImage;
|
||||
bool mbDestroyImage;
|
||||
|
||||
cGuiGfxElement *mpGfxBackgroundUp;
|
||||
cGuiGfxElement *mvGfxBordersUp[4];
|
||||
cGuiGfxElement *mvGfxCornersUp[4];
|
||||
|
||||
cGuiGfxElement *mpGfxBackgroundDown;
|
||||
cGuiGfxElement *mvGfxBordersDown[4];
|
||||
cGuiGfxElement *mvGfxCornersDown[4];
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_BUTTON_H
|
||||
154
engines/hpl1/engine/gui/WidgetCheckBox.cpp
Normal file
154
engines/hpl1/engine/gui/WidgetCheckBox.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetCheckBox.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetCheckBox::cWidgetCheckBox(cGuiSet *apSet, cGuiSkin *apSkin) : iWidget(eWidgetType_CheckBox, apSet, apSkin) {
|
||||
mbChecked = false;
|
||||
mbPressed = false;
|
||||
|
||||
LoadGraphics();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetCheckBox::~cWidgetCheckBox() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetCheckBox::SetChecked(bool abX) {
|
||||
if (mbChecked == abX)
|
||||
return;
|
||||
|
||||
mbChecked = abX;
|
||||
|
||||
cGuiMessageData data = cGuiMessageData(mbChecked);
|
||||
ProcessMessage(eGuiMessage_CheckChange, data);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetCheckBox::OnLoadGraphics() {
|
||||
mvGfxBox[1][0] = mpSkin->GetGfx(eGuiSkinGfx_CheckBoxEnabledUnchecked);
|
||||
mvGfxBox[1][1] = mpSkin->GetGfx(eGuiSkinGfx_CheckBoxEnabledChecked);
|
||||
mvGfxBox[0][0] = mpSkin->GetGfx(eGuiSkinGfx_CheckBoxDisabledUnchecked);
|
||||
mvGfxBox[0][1] = mpSkin->GetGfx(eGuiSkinGfx_CheckBoxDisabledChecked);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetCheckBox::OnChangeSize() {
|
||||
if (mvSize.y < mvDefaultFontSize.y)
|
||||
mvSize.y = mvDefaultFontSize.y;
|
||||
if (mvSize.x < mvGfxBox[0][0]->GetActiveSize().x)
|
||||
mvSize.x = mvGfxBox[0][0]->GetActiveSize().x;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetCheckBox::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
////////////////////////////////
|
||||
// Box
|
||||
mpSet->DrawGfx(mvGfxBox[IsEnabled()][mbChecked], GetGlobalPosition() +
|
||||
cVector3f(0, mvSize.y / 2 - mvGfxBox[0][0]->GetActiveSize().y / 2, 0));
|
||||
|
||||
////////////////////////////////
|
||||
// Text
|
||||
eGuiSkinFont font = IsEnabled() ? eGuiSkinFont_Default : eGuiSkinFont_Disabled;
|
||||
DrawSkinText(msText, font, GetGlobalPosition() + cVector3f(mvGfxBox[0][0]->GetActiveSize().x + 3.0f, mvSize.y / 2 - mvDefaultFontSize.y / 2, 0),
|
||||
eFontAlign_Left);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetCheckBox::OnMouseMove(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetCheckBox::OnMouseDown(cGuiMessageData &aData) {
|
||||
mbPressed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetCheckBox::OnMouseUp(cGuiMessageData &aData) {
|
||||
if (mbPressed)
|
||||
SetChecked(!mbChecked);
|
||||
|
||||
mbPressed = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetCheckBox::OnMouseEnter(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetCheckBox::OnMouseLeave(cGuiMessageData &aData) {
|
||||
mbPressed = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
69
engines/hpl1/engine/gui/WidgetCheckBox.h
Normal file
69
engines/hpl1/engine/gui/WidgetCheckBox.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_CHECK_BOX_H
|
||||
#define HPL_WIDGET_CHECK_BOX_H
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetCheckBox : public iWidget {
|
||||
public:
|
||||
cWidgetCheckBox(cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~cWidgetCheckBox();
|
||||
|
||||
void SetChecked(bool abX);
|
||||
bool IsChecked() { return mbChecked; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnLoadGraphics();
|
||||
void OnChangeSize();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
bool mbChecked;
|
||||
bool mbPressed;
|
||||
|
||||
cGuiGfxElement *mvGfxBox[2][2];
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_CHECK_BOX_H
|
||||
431
engines/hpl1/engine/gui/WidgetComboBox.cpp
Normal file
431
engines/hpl1/engine/gui/WidgetComboBox.cpp
Normal file
@@ -0,0 +1,431 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetComboBox.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
#include "hpl1/engine/gui/WidgetButton.h"
|
||||
#include "hpl1/engine/gui/WidgetSlider.h"
|
||||
#include "hpl1/engine/gui/WidgetTextBox.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetComboBox::cWidgetComboBox(cGuiSet *apSet, cGuiSkin *apSkin) : iWidget(eWidgetType_ComboBox, apSet, apSkin) {
|
||||
mfButtonWidth = mpSkin->GetAttribute(eGuiSkinAttribute_ComboBoxButtonWidth).x;
|
||||
mfSliderWidth = mpSkin->GetAttribute(eGuiSkinAttribute_ComboBoxSliderWidth).x;
|
||||
|
||||
mpText = NULL;
|
||||
mpButton = NULL;
|
||||
mpSlider = NULL;
|
||||
|
||||
mbMenuOpen = false;
|
||||
|
||||
// mbConnectedToChildren = false;
|
||||
|
||||
mfMenuHeight = 0;
|
||||
|
||||
mlSelectedItem = -1;
|
||||
mlMouseOverSelection = -1;
|
||||
|
||||
mlFirstItem = 0;
|
||||
mlMaxItems = 12;
|
||||
mlItemsShown = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetComboBox::~cWidgetComboBox() {
|
||||
if (mpSet->IsDestroyingSet() == false) {
|
||||
mpSet->DestroyWidget(mpText);
|
||||
mpSet->DestroyWidget(mpButton);
|
||||
mpSet->DestroyWidget(mpSlider);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::SetSelectedItem(int alX, bool abMoveList) {
|
||||
if (mlSelectedItem == alX && (mlSelectedItem < 0 ||
|
||||
mpText->GetText() == mvItems[mlSelectedItem]))
|
||||
return;
|
||||
|
||||
mlSelectedItem = alX;
|
||||
|
||||
if (abMoveList && mlSelectedItem >= mlFirstItem + mlMaxItems) {
|
||||
while (mlSelectedItem >= mlFirstItem + mlMaxItems) {
|
||||
mlFirstItem++;
|
||||
}
|
||||
mpSlider->SetValue(mlFirstItem);
|
||||
}
|
||||
if (abMoveList && mlSelectedItem < mlFirstItem && mlSelectedItem >= 0) {
|
||||
while (mlSelectedItem < mlFirstItem) {
|
||||
mlFirstItem--;
|
||||
}
|
||||
mpSlider->SetValue(mlSelectedItem);
|
||||
}
|
||||
|
||||
if (mlSelectedItem >= 0)
|
||||
SetText(mvItems[mlSelectedItem]);
|
||||
|
||||
cGuiMessageData data = cGuiMessageData(mlSelectedItem);
|
||||
ProcessMessage(eGuiMessage_SelectionChange, data);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::SetCanEdit(bool abX) {
|
||||
mpText->SetCanEdit(abX);
|
||||
}
|
||||
|
||||
bool cWidgetComboBox::GetCanEdit() {
|
||||
return mpText->GetCanEdit();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::SetMaxShownItems(int alX) {
|
||||
mlMaxItems = alX;
|
||||
|
||||
UpdateProperties();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::UpdateProperties() {
|
||||
if ((int)mvItems.size() <= mlMaxItems)
|
||||
mlItemsShown = (int)mvItems.size();
|
||||
else
|
||||
mlItemsShown = mlMaxItems;
|
||||
|
||||
mfMenuHeight = 2 + (mvDefaultFontSize.y + 2) * (float)mlItemsShown + 2;
|
||||
|
||||
OnChangeSize();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::OpenMenu() {
|
||||
if (mvItems.empty())
|
||||
return;
|
||||
|
||||
if (mbMenuOpen)
|
||||
return;
|
||||
mpSet->SetAttentionWidget(this);
|
||||
mbMenuOpen = true;
|
||||
|
||||
mlMouseOverSelection = mlSelectedItem;
|
||||
|
||||
mvSize = cVector2f(mvSize.x, mvSize.y + mfMenuHeight);
|
||||
|
||||
if ((int)mvItems.size() > mlMaxItems) {
|
||||
mpSlider->SetEnabled(true);
|
||||
mpSlider->SetVisible(true);
|
||||
|
||||
mpSlider->SetPosition(cVector3f(mvSize.x - 20 - mvGfxBorders[1]->GetActiveSize().x,
|
||||
(mvSize.y - mfMenuHeight) + mvGfxBorders[1]->GetActiveSize().y,
|
||||
1.2f));
|
||||
mpSlider->SetSize(cVector2f(20, mfMenuHeight - mvGfxBorders[1]->GetActiveSize().y -
|
||||
mvGfxBorders[2]->GetActiveSize().y));
|
||||
|
||||
mpSlider->SetBarValueSize(mlMaxItems);
|
||||
mpSlider->SetMaxValue((int)mvItems.size() - mlMaxItems);
|
||||
|
||||
mpSet->SetFocusedWidget(mpSlider);
|
||||
} else {
|
||||
mpSet->SetFocusedWidget(this);
|
||||
}
|
||||
|
||||
mbClipsGraphics = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::CloseMenu() {
|
||||
if (mbMenuOpen == false)
|
||||
return;
|
||||
|
||||
mpSet->SetAttentionWidget(NULL);
|
||||
mbMenuOpen = false;
|
||||
|
||||
mvSize = mpText->GetSize();
|
||||
|
||||
mpSlider->SetEnabled(false);
|
||||
mpSlider->SetVisible(false);
|
||||
|
||||
mbClipsGraphics = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetComboBox::ButtonPress(iWidget *apWidget, cGuiMessageData &aData) {
|
||||
if (mbMenuOpen)
|
||||
CloseMenu();
|
||||
else
|
||||
OpenMenu();
|
||||
|
||||
return true;
|
||||
}
|
||||
kGuiCalllbackDeclaredFuncEnd(cWidgetComboBox, ButtonPress)
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetComboBox::SliderMove(iWidget *apWidget, cGuiMessageData &aData) {
|
||||
mlFirstItem = aData.mlVal;
|
||||
|
||||
return true;
|
||||
}
|
||||
kGuiCalllbackDeclaredFuncEnd(cWidgetComboBox, SliderMove)
|
||||
|
||||
bool cWidgetComboBox::SliderLostFocus(iWidget *apWidget, cGuiMessageData &aData) {
|
||||
if (mbMenuOpen && GetMouseIsOver() == false) {
|
||||
CloseMenu();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
kGuiCalllbackDeclaredFuncEnd(cWidgetComboBox, SliderLostFocus)
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::OnInit() {
|
||||
mpText = mpSet->CreateWidgetTextBox(0, mvSize, Common::U32String(), this);
|
||||
mpText->SetText(msText);
|
||||
mpText->SetCanEdit(false);
|
||||
|
||||
mpButton = mpSet->CreateWidgetButton(0, 0, Common::U32String(), this);
|
||||
mpButton->SetImage(mpSkin->GetGfx(eGuiSkinGfx_ComboBoxButtonIcon), false);
|
||||
mpButton->AddCallback(eGuiMessage_MouseDown, this, kGuiCallback(ButtonPress));
|
||||
|
||||
mpSlider = mpSet->CreateWidgetSlider(eWidgetSliderOrientation_Vertical, 0, 0, 0, this);
|
||||
mpSlider->AddCallback(eGuiMessage_SliderMove, this, kGuiCallback(SliderMove));
|
||||
mpSlider->AddCallback(eGuiMessage_LostFocus, this, kGuiCallback(SliderLostFocus));
|
||||
mpSlider->SetEnabled(false);
|
||||
mpSlider->SetVisible(false);
|
||||
|
||||
AddCallback(eGuiMessage_OnDraw, this, kGuiCallback(DrawText));
|
||||
|
||||
OnChangeSize();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::OnChangeSize() {
|
||||
if (mpText && mpButton && mpSlider) {
|
||||
mpText->SetSize(mvSize);
|
||||
mvSize = mpText->GetSize();
|
||||
|
||||
cVector2f vBackSize = mpText->GetBackgroundSize();
|
||||
|
||||
mpButton->SetSize(cVector2f(mfButtonWidth, vBackSize.y));
|
||||
mpButton->SetPosition(cVector3f(mvSize.x - (mvSize.x - vBackSize.x) / 2 - mfButtonWidth,
|
||||
(mvSize.y - vBackSize.y) / 2, 0.3f));
|
||||
|
||||
mpSlider->SetBarValueSize(mlMaxItems);
|
||||
mpSlider->SetMaxValue((int)mvItems.size() - mlMaxItems);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::OnChangeText() {
|
||||
if (mpText)
|
||||
mpText->SetText(msText);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::OnLoadGraphics() {
|
||||
mpGfxBackground = mpSkin->GetGfx(eGuiSkinGfx_ComboBoxBackground);
|
||||
|
||||
mpGfxSelection = mpSkin->GetGfx(eGuiSkinGfx_TextBoxSelectedTextBack);
|
||||
|
||||
mvGfxBorders[0] = mpSkin->GetGfx(eGuiSkinGfx_ComboBoxBorderRight);
|
||||
mvGfxBorders[1] = mpSkin->GetGfx(eGuiSkinGfx_ComboBoxBorderLeft);
|
||||
mvGfxBorders[2] = mpSkin->GetGfx(eGuiSkinGfx_ComboBoxBorderUp);
|
||||
mvGfxBorders[3] = mpSkin->GetGfx(eGuiSkinGfx_ComboBoxBorderDown);
|
||||
|
||||
mvGfxCorners[0] = mpSkin->GetGfx(eGuiSkinGfx_ComboBoxCornerLU);
|
||||
mvGfxCorners[1] = mpSkin->GetGfx(eGuiSkinGfx_ComboBoxCornerRU);
|
||||
mvGfxCorners[2] = mpSkin->GetGfx(eGuiSkinGfx_ComboBoxCornerRD);
|
||||
mvGfxCorners[3] = mpSkin->GetGfx(eGuiSkinGfx_ComboBoxCornerLD);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetComboBox::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
if (mbMenuOpen) {
|
||||
mpSet->DrawGfx(mpGfxBackground, GetGlobalPosition() + cVector3f(0, mvSize.y - mfMenuHeight, 1),
|
||||
cVector2f(mvSize.x, mfMenuHeight));
|
||||
|
||||
////////////////////////////////
|
||||
// Background and borders
|
||||
DrawBordersAndCorners(NULL, mvGfxBorders, mvGfxCorners,
|
||||
GetGlobalPosition() + cVector3f(0, mvSize.y - mfMenuHeight, 1.4f),
|
||||
cVector2f(mvSize.x, mfMenuHeight));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetComboBox::DrawText(iWidget *apWidget, cGuiMessageData &aData) {
|
||||
if (mbMenuOpen == false)
|
||||
return false;
|
||||
|
||||
cVector3f vPos = GetGlobalPosition() +
|
||||
cVector3f(mvGfxBorders[0]->GetActiveSize().x + 3, mpText->GetSize().y + 2, 1.2f);
|
||||
|
||||
for (int i = mlFirstItem; i < (int)mvItems.size(); ++i) {
|
||||
if (i - mlFirstItem >= mlMaxItems)
|
||||
break;
|
||||
|
||||
if (i == mlMouseOverSelection) {
|
||||
mpSet->DrawGfx(mpGfxSelection, vPos - cVector3f(3, 0, 0),
|
||||
cVector2f(mvSize.x, mvDefaultFontSize.y));
|
||||
}
|
||||
|
||||
DrawDefaultText(mvItems[i], vPos, eFontAlign_Left);
|
||||
vPos.y += mvDefaultFontSize.y + 2;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
kGuiCalllbackDeclaredFuncEnd(cWidgetComboBox, DrawText)
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetComboBox::OnMouseMove(cGuiMessageData &aData) {
|
||||
if (mbMenuOpen == false)
|
||||
return false;
|
||||
|
||||
if (GetMouseIsOver() == false)
|
||||
return false;
|
||||
|
||||
cVector3f vLocalPos = WorldToLocalPosition(aData.mvPos);
|
||||
|
||||
if (vLocalPos.y <= mpText->GetSize().y)
|
||||
return false;
|
||||
if (mpSlider->IsEnabled() && vLocalPos.x >= mvSize.x - 20)
|
||||
return false;
|
||||
|
||||
float fToTextStart = 2 + mpText->GetSize().y + mvGfxCorners[0]->GetActiveSize().y;
|
||||
int lSelection = (int)((vLocalPos.y - fToTextStart) / (mvDefaultFontSize.y + 2));
|
||||
if (lSelection < 0)
|
||||
lSelection = 0;
|
||||
|
||||
lSelection = lSelection + mlFirstItem;
|
||||
|
||||
if (lSelection >= (int)mvItems.size())
|
||||
lSelection = (int)mvItems.size() - 1;
|
||||
|
||||
mlMouseOverSelection = lSelection;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetComboBox::OnMouseDown(cGuiMessageData &aData) {
|
||||
if (mbMenuOpen == false)
|
||||
return false;
|
||||
|
||||
cVector3f vLocal = WorldToLocalPosition(aData.mvPos);
|
||||
|
||||
if (vLocal.y < mpText->GetSize().y) {
|
||||
CloseMenu();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetComboBox::OnMouseUp(cGuiMessageData &aData) {
|
||||
if (mbMenuOpen == false)
|
||||
return false;
|
||||
|
||||
cVector3f vLocal = WorldToLocalPosition(aData.mvPos);
|
||||
|
||||
if (vLocal.y > mpText->GetSize().y) {
|
||||
SetSelectedItem(mlMouseOverSelection);
|
||||
CloseMenu();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetComboBox::OnMouseEnter(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetComboBox::OnMouseLeave(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetComboBox::OnLostFocus(cGuiMessageData &aData) {
|
||||
/*cVector3f vLocal = */ WorldToLocalPosition(aData.mvPos);
|
||||
|
||||
if (mbMenuOpen && mpSlider->IsEnabled() == false) {
|
||||
CloseMenu();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
121
engines/hpl1/engine/gui/WidgetComboBox.h
Normal file
121
engines/hpl1/engine/gui/WidgetComboBox.h
Normal file
@@ -0,0 +1,121 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_COMBO_BOX_H
|
||||
#define HPL_WIDGET_COMBO_BOX_H
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
#include "hpl1/engine/gui/WidgetBaseClasses.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetTextBox;
|
||||
class cWidgetButton;
|
||||
class cWidgetSlider;
|
||||
|
||||
class cWidgetComboBox : public iWidget, public iWidgetItemContainer {
|
||||
public:
|
||||
cWidgetComboBox(cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~cWidgetComboBox();
|
||||
|
||||
void SetSelectedItem(int alX, bool abMoveList = false);
|
||||
int GetSelectedItem() { return mlSelectedItem; }
|
||||
|
||||
void SetCanEdit(bool abX);
|
||||
bool GetCanEdit();
|
||||
|
||||
void SetMaxShownItems(int alX);
|
||||
int GetMaxShownItems() { return mlMaxItems; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Own functions
|
||||
void UpdateProperties();
|
||||
|
||||
void OpenMenu();
|
||||
void CloseMenu();
|
||||
|
||||
bool ButtonPress(iWidget *apWidget, cGuiMessageData &aData);
|
||||
kGuiCalllbackDeclarationEnd(ButtonPress);
|
||||
|
||||
bool DrawText(iWidget *apWidget, cGuiMessageData &aData);
|
||||
kGuiCalllbackDeclarationEnd(DrawText);
|
||||
|
||||
bool SliderMove(iWidget *apWidget, cGuiMessageData &aData);
|
||||
kGuiCalllbackDeclarationEnd(SliderMove);
|
||||
|
||||
bool SliderLostFocus(iWidget *apWidget, cGuiMessageData &aData);
|
||||
kGuiCalllbackDeclarationEnd(SliderLostFocus);
|
||||
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnLoadGraphics();
|
||||
void OnChangeSize();
|
||||
void OnChangeText();
|
||||
void OnInit();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
bool OnLostFocus(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
cWidgetTextBox *mpText;
|
||||
cWidgetButton *mpButton;
|
||||
cWidgetSlider *mpSlider;
|
||||
|
||||
bool mbMenuOpen;
|
||||
float mfMenuHeight;
|
||||
|
||||
float mfButtonWidth;
|
||||
float mfSliderWidth;
|
||||
|
||||
int mlMouseOverSelection;
|
||||
int mlSelectedItem;
|
||||
int mlFirstItem;
|
||||
int mlMaxItems;
|
||||
int mlItemsShown;
|
||||
|
||||
cGuiGfxElement *mpGfxBackground;
|
||||
|
||||
cGuiGfxElement *mpGfxSelection;
|
||||
|
||||
cGuiGfxElement *mvGfxBorders[4];
|
||||
cGuiGfxElement *mvGfxCorners[4];
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_COMBO_BOX_H
|
||||
151
engines/hpl1/engine/gui/WidgetFrame.cpp
Normal file
151
engines/hpl1/engine/gui/WidgetFrame.cpp
Normal file
@@ -0,0 +1,151 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetFrame.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetFrame::cWidgetFrame(cGuiSet *apSet, cGuiSkin *apSkin) : iWidget(eWidgetType_Frame, apSet, apSkin) {
|
||||
mbClipsGraphics = true;
|
||||
|
||||
mbDrawFrame = false;
|
||||
|
||||
mbDrawBackground = false;
|
||||
mfBackgroundZ = -0.5;
|
||||
mBackGroundColor = cColor(1, 1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetFrame::~cWidgetFrame() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetFrame::OnLoadGraphics() {
|
||||
mpGfxBackground = mpSkin->GetGfx(eGuiSkinGfx_FrameBackground);
|
||||
|
||||
mvGfxBorders[0] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderRight);
|
||||
mvGfxBorders[1] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderLeft);
|
||||
mvGfxBorders[2] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderUp);
|
||||
mvGfxBorders[3] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderDown);
|
||||
|
||||
mvGfxCorners[0] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerLU);
|
||||
mvGfxCorners[1] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerRU);
|
||||
mvGfxCorners[2] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerRD);
|
||||
mvGfxCorners[3] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerLD);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetFrame::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
////////////////////////////////
|
||||
// Borders
|
||||
if (mbDrawFrame) {
|
||||
// Background must be drawn first!
|
||||
DrawBordersAndCorners(NULL, mvGfxBorders, mvGfxCorners,
|
||||
GetGlobalPosition() -
|
||||
cVector3f(mvGfxCorners[0]->GetActiveSize().x,
|
||||
mvGfxCorners[0]->GetActiveSize().y, 0),
|
||||
mvSize + mvGfxCorners[0]->GetActiveSize() +
|
||||
mvGfxCorners[2]->GetActiveSize());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetFrame::OnDrawAfterClip(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
////////////////////////////////
|
||||
// Background
|
||||
if (mbDrawBackground) {
|
||||
mpSet->DrawGfx(mpGfxBackground, GetGlobalPosition() + cVector3f(0, 0, mfBackgroundZ),
|
||||
mvSize, mBackGroundColor);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetFrame::OnMouseMove(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetFrame::OnMouseDown(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetFrame::OnMouseUp(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetFrame::OnMouseEnter(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetFrame::OnMouseLeave(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
83
engines/hpl1/engine/gui/WidgetFrame.h
Normal file
83
engines/hpl1/engine/gui/WidgetFrame.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_FRAME_H
|
||||
#define HPL_WIDGET_FRAME_H
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetFrame : public iWidget {
|
||||
public:
|
||||
cWidgetFrame(cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~cWidgetFrame();
|
||||
|
||||
void SetDrawFrame(bool abX) { mbDrawFrame = abX; }
|
||||
bool GetDrawFrame() { return mbDrawFrame; }
|
||||
|
||||
void SetDrawBackground(bool abX) { mbDrawBackground = abX; }
|
||||
bool GetDrawBackground() { return mbDrawBackground; }
|
||||
|
||||
void SetBackgroundZ(float afZ) { mfBackgroundZ = afZ; }
|
||||
float GetBackgroundZ() { return mfBackgroundZ; }
|
||||
|
||||
void SetBackGroundColor(const cColor &aColor) { mBackGroundColor = aColor; }
|
||||
const cColor &GetBackGroundColor() { return mBackGroundColor; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnLoadGraphics();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
void OnDrawAfterClip(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
bool mbDrawFrame;
|
||||
bool mbDrawBackground;
|
||||
float mfBackgroundZ;
|
||||
cColor mBackGroundColor;
|
||||
|
||||
cGuiGfxElement *mpGfxBackground;
|
||||
|
||||
cGuiGfxElement *mvGfxBorders[4];
|
||||
cGuiGfxElement *mvGfxCorners[4];
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_FRAME_H
|
||||
130
engines/hpl1/engine/gui/WidgetImage.cpp
Normal file
130
engines/hpl1/engine/gui/WidgetImage.cpp
Normal file
@@ -0,0 +1,130 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetImage.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetImage::cWidgetImage(cGuiSet *apSet, cGuiSkin *apSkin) : iWidget(eWidgetType_Image, apSet, apSkin) {
|
||||
mpGfxImage = NULL;
|
||||
mColor = cColor(1, 1);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetImage::~cWidgetImage() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetImage::SetImage(cGuiGfxElement *apGfx) {
|
||||
if (mpGfxImage == apGfx)
|
||||
return;
|
||||
|
||||
mpGfxImage = apGfx;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetImage::OnLoadGraphics() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetImage::OnChangeSize() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetImage::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
////////////////////////////////
|
||||
// Background
|
||||
if (mpGfxImage) {
|
||||
mpSet->DrawGfx(mpGfxImage, GetGlobalPosition(), mvSize, mColor);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetImage::OnMouseMove(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetImage::OnMouseDown(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetImage::OnMouseUp(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetImage::OnMouseEnter(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetImage::OnMouseLeave(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
67
engines/hpl1/engine/gui/WidgetImage.h
Normal file
67
engines/hpl1/engine/gui/WidgetImage.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_IMAGE_H
|
||||
#define HPL_WIDGET_IMAGE_H
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetImage : public iWidget {
|
||||
public:
|
||||
cWidgetImage(cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~cWidgetImage();
|
||||
|
||||
void SetImage(cGuiGfxElement *apGfx);
|
||||
cGuiGfxElement *GetImage() { return mpGfxImage; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnLoadGraphics();
|
||||
void OnChangeSize();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
cGuiGfxElement *mpGfxImage;
|
||||
cColor mColor;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_IMAGE_H
|
||||
176
engines/hpl1/engine/gui/WidgetLabel.cpp
Normal file
176
engines/hpl1/engine/gui/WidgetLabel.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetLabel.h"
|
||||
|
||||
#include "hpl1/engine/system/String.h"
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/graphics/font_data.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetLabel::cWidgetLabel(cGuiSet *apSet, cGuiSkin *apSkin) : iWidget(eWidgetType_Label, apSet, apSkin) {
|
||||
mbWordWrap = false;
|
||||
mTextAlign = eFontAlign_Left;
|
||||
|
||||
mlMaxCharacters = -1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetLabel::~cWidgetLabel() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetLabel::SetMaxTextLength(int alLength) {
|
||||
if (mlMaxCharacters == alLength)
|
||||
return;
|
||||
|
||||
mlMaxCharacters = alLength;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetLabel::OnLoadGraphics() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetLabel::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
////////////////////////////////
|
||||
// Texts
|
||||
cVector3f vOffset = 0;
|
||||
// if(mTextAlign == eFontAlign_Center) vOffset.x += mvSize.x/2;
|
||||
// else
|
||||
if (mTextAlign == eFontAlign_Right)
|
||||
vOffset.x += mvSize.x;
|
||||
|
||||
if (mbWordWrap) {
|
||||
int lChars = 0;
|
||||
bool bEnabled = IsEnabled();
|
||||
float fHeight = mvDefaultFontSize.y + 2;
|
||||
tWStringVec vRows;
|
||||
mpDefaultFontType->getWordWrapRows(mvSize.x, fHeight,
|
||||
mvDefaultFontSize, msText,
|
||||
&vRows);
|
||||
|
||||
for (size_t i = 0; i < vRows.size(); ++i) {
|
||||
bool bBreak = false;
|
||||
if (mlMaxCharacters >= 0) {
|
||||
if (lChars + (int)vRows[i].size() > mlMaxCharacters) {
|
||||
vRows[i] = cString::SubW(vRows[i], 0, mlMaxCharacters - lChars);
|
||||
bBreak = true;
|
||||
}
|
||||
lChars += (int)vRows[i].size();
|
||||
}
|
||||
|
||||
if (bEnabled)
|
||||
DrawDefaultText(vRows[i], GetGlobalPosition() + vOffset, mTextAlign);
|
||||
else
|
||||
DrawSkinText(vRows[i], eGuiSkinFont_Disabled, GetGlobalPosition() + vOffset, mTextAlign);
|
||||
vOffset.y += fHeight;
|
||||
|
||||
if (bBreak)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (mlMaxCharacters >= 0 && (int)msText.size() > mlMaxCharacters) {
|
||||
if (IsEnabled())
|
||||
DrawDefaultText(cString::SubW(msText, 0, mlMaxCharacters), GetGlobalPosition() + vOffset, mTextAlign);
|
||||
else
|
||||
DrawSkinText(cString::SubW(msText, 0, mlMaxCharacters), eGuiSkinFont_Disabled, GetGlobalPosition() + vOffset, mTextAlign);
|
||||
} else {
|
||||
if (IsEnabled())
|
||||
DrawDefaultText(msText, GetGlobalPosition() + vOffset, mTextAlign);
|
||||
else
|
||||
DrawSkinText(msText, eGuiSkinFont_Disabled, GetGlobalPosition() + vOffset, mTextAlign);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetLabel::OnMouseMove(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetLabel::OnMouseDown(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetLabel::OnMouseUp(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetLabel::OnMouseEnter(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetLabel::OnMouseLeave(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
74
engines/hpl1/engine/gui/WidgetLabel.h
Normal file
74
engines/hpl1/engine/gui/WidgetLabel.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_LABEL_H
|
||||
#define HPL_WIDGET_LABEL_H
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetLabel : public iWidget {
|
||||
public:
|
||||
cWidgetLabel(cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~cWidgetLabel();
|
||||
|
||||
void SetTextAlign(eFontAlign aType) { mTextAlign = aType; }
|
||||
eFontAlign GetTextAlign() { return mTextAlign; }
|
||||
|
||||
bool GetWordWrap() { return mbWordWrap; }
|
||||
void SetWordWrap(bool abX) { mbWordWrap = abX; }
|
||||
|
||||
void SetMaxTextLength(int alLength);
|
||||
int GetMaxTextLength() { return mlMaxCharacters; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnLoadGraphics();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
eFontAlign mTextAlign;
|
||||
bool mbWordWrap;
|
||||
|
||||
int mlMaxCharacters;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_LABEL_H
|
||||
267
engines/hpl1/engine/gui/WidgetListBox.cpp
Normal file
267
engines/hpl1/engine/gui/WidgetListBox.cpp
Normal file
@@ -0,0 +1,267 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetListBox.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
#include "hpl1/engine/gui/WidgetSlider.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetListBox::cWidgetListBox(cGuiSet *apSet, cGuiSkin *apSkin) : iWidget(eWidgetType_ListBox, apSet, apSkin) {
|
||||
mbClipsGraphics = true;
|
||||
|
||||
mfBackgroundZ = -0.5;
|
||||
|
||||
mlFirstItem = 0;
|
||||
mlMaxItems = 1;
|
||||
|
||||
mlSelectedItem = -1;
|
||||
|
||||
mfSliderWidth = mpSkin->GetAttribute(eGuiSkinAttribute_ListBoxSliderWidth).x;
|
||||
|
||||
mpSlider = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetListBox::~cWidgetListBox() {
|
||||
if (mpSet->IsDestroyingSet() == false) {
|
||||
mpSet->DestroyWidget(mpSlider);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void cWidgetListBox::SetSelectedItem(int alX, bool abMoveList) {
|
||||
if (mlSelectedItem == alX)
|
||||
return;
|
||||
|
||||
mlSelectedItem = alX;
|
||||
|
||||
if (abMoveList && mlSelectedItem >= mlFirstItem + mlMaxItems) {
|
||||
while (mlSelectedItem >= mlFirstItem + mlMaxItems) {
|
||||
mlFirstItem++;
|
||||
}
|
||||
mpSlider->SetValue(mlFirstItem);
|
||||
}
|
||||
if (abMoveList && mlSelectedItem < mlFirstItem && mlSelectedItem >= 0) {
|
||||
while (mlSelectedItem < mlFirstItem) {
|
||||
mlFirstItem--;
|
||||
}
|
||||
mpSlider->SetValue(mlSelectedItem);
|
||||
}
|
||||
|
||||
cGuiMessageData data = cGuiMessageData(mlSelectedItem);
|
||||
ProcessMessage(eGuiMessage_SelectionChange, data);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool cWidgetListBox::DrawText(iWidget *apWidget, cGuiMessageData &aData) {
|
||||
cVector3f vPosition = GetGlobalPosition() + cVector3f(3, 2, 0);
|
||||
for (int i = mlFirstItem; i < (int)mvItems.size(); ++i) {
|
||||
if (i - mlFirstItem > mlMaxItems)
|
||||
break;
|
||||
|
||||
if (i == mlSelectedItem) {
|
||||
mpSet->DrawGfx(mpGfxSelection, vPosition - cVector3f(3, 0, 0),
|
||||
cVector2f(mvSize.x, mvDefaultFontSize.y));
|
||||
}
|
||||
|
||||
DrawDefaultText(mvItems[i], vPosition, eFontAlign_Left);
|
||||
vPosition.y += mvDefaultFontSize.y + 2;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
kGuiCalllbackDeclaredFuncEnd(cWidgetListBox, DrawText)
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetListBox::MoveSlider(iWidget *apWidget, cGuiMessageData &aData) {
|
||||
mlFirstItem = aData.mlVal;
|
||||
|
||||
return true;
|
||||
}
|
||||
kGuiCalllbackDeclaredFuncEnd(cWidgetListBox, MoveSlider)
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetListBox::UpdateProperties() {
|
||||
mlMaxItems = (int)(mvSize.y / (mvDefaultFontSize.y + 2));
|
||||
|
||||
if ((int)mvItems.size() > mlMaxItems) {
|
||||
mpSlider->SetBarValueSize(mlMaxItems);
|
||||
mpSlider->SetMaxValue((int)mvItems.size() - mlMaxItems);
|
||||
} else {
|
||||
mpSlider->SetMaxValue(0);
|
||||
mpSlider->SetBarValueSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetListBox::OnInit() {
|
||||
mpSlider = mpSet->CreateWidgetSlider(eWidgetSliderOrientation_Vertical, 0, 0, 0, this);
|
||||
mpSlider->AddCallback(eGuiMessage_SliderMove, this, kGuiCallback(MoveSlider));
|
||||
|
||||
AddCallback(eGuiMessage_OnDraw, this, kGuiCallback(DrawText));
|
||||
|
||||
OnChangeSize();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetListBox::OnChangeSize() {
|
||||
if (mpSlider) {
|
||||
mpSlider->SetSize(cVector2f(mfSliderWidth, mvSize.y));
|
||||
mpSlider->SetPosition(cVector3f(mvSize.x - mfSliderWidth, 0, 0.2f));
|
||||
|
||||
UpdateProperties();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetListBox::OnLoadGraphics() {
|
||||
mpGfxBackground = mpSkin->GetGfx(eGuiSkinGfx_ListBoxBackground);
|
||||
|
||||
mpGfxSelection = mpSkin->GetGfx(eGuiSkinGfx_TextBoxSelectedTextBack);
|
||||
|
||||
mvGfxBorders[0] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderRight);
|
||||
mvGfxBorders[1] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderLeft);
|
||||
mvGfxBorders[2] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderUp);
|
||||
mvGfxBorders[3] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderDown);
|
||||
|
||||
mvGfxCorners[0] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerLU);
|
||||
mvGfxCorners[1] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerRU);
|
||||
mvGfxCorners[2] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerRD);
|
||||
mvGfxCorners[3] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerLD);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetListBox::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
////////////////////////////////
|
||||
// Background
|
||||
mpSet->DrawGfx(mpGfxBackground, GetGlobalPosition() + cVector3f(0, 0, mfBackgroundZ),
|
||||
mvSize);
|
||||
|
||||
////////////////////////////////
|
||||
// Borders
|
||||
DrawBordersAndCorners(NULL, mvGfxBorders, mvGfxCorners,
|
||||
GetGlobalPosition() -
|
||||
cVector3f(mvGfxCorners[0]->GetActiveSize().x,
|
||||
mvGfxCorners[0]->GetActiveSize().y, 0),
|
||||
mvSize + mvGfxCorners[0]->GetActiveSize() +
|
||||
mvGfxCorners[2]->GetActiveSize());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetListBox::OnMouseMove(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetListBox::OnMouseDown(cGuiMessageData &aData) {
|
||||
cVector3f vLocalPos = WorldToLocalPosition(aData.mvPos);
|
||||
|
||||
int lSelection = (int)((vLocalPos.y - 2) / (mvDefaultFontSize.y + 2));
|
||||
if (lSelection < 0)
|
||||
lSelection = 0;
|
||||
|
||||
lSelection = lSelection + mlFirstItem;
|
||||
|
||||
if (lSelection >= (int)mvItems.size())
|
||||
lSelection = (int)mvItems.size() - 1;
|
||||
|
||||
SetSelectedItem(lSelection);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetListBox::OnMouseUp(cGuiMessageData &aData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetListBox::OnMouseEnter(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetListBox::OnMouseLeave(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetListBox::OnKeyPress(cGuiMessageData &aData) {
|
||||
auto key = aData.mKeyPress.keycode;
|
||||
if (key == Common::KEYCODE_UP) {
|
||||
if (mlSelectedItem > 0)
|
||||
SetSelectedItem(mlSelectedItem - 1, true);
|
||||
} else if (key == Common::KEYCODE_DOWN) {
|
||||
if (mlSelectedItem < (int)mvItems.size() - 1)
|
||||
SetSelectedItem(mlSelectedItem + 1, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
100
engines/hpl1/engine/gui/WidgetListBox.h
Normal file
100
engines/hpl1/engine/gui/WidgetListBox.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_LIST_BOX_H
|
||||
#define HPL_WIDGET_LIST_BOX_H
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
#include "hpl1/engine/gui/WidgetBaseClasses.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetSlider;
|
||||
|
||||
class cWidgetListBox : public iWidget, public iWidgetItemContainer {
|
||||
public:
|
||||
cWidgetListBox(cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~cWidgetListBox();
|
||||
|
||||
void SetBackgroundZ(float afZ) { mfBackgroundZ = afZ; }
|
||||
float GetBackgroundZ() { return mfBackgroundZ; }
|
||||
|
||||
void SetSelectedItem(int alX, bool abMoveList = false);
|
||||
int GetSelectedItem() { return mlSelectedItem; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Own functions
|
||||
void UpdateProperties();
|
||||
|
||||
bool DrawText(iWidget *apWidget, cGuiMessageData &aData);
|
||||
kGuiCalllbackDeclarationEnd(DrawText);
|
||||
|
||||
bool MoveSlider(iWidget *apWidget, cGuiMessageData &aData);
|
||||
kGuiCalllbackDeclarationEnd(MoveSlider);
|
||||
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnLoadGraphics();
|
||||
void OnInit();
|
||||
void OnChangeSize();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
bool OnKeyPress(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
float mfBackgroundZ;
|
||||
float mfSliderWidth;
|
||||
|
||||
int mlFirstItem;
|
||||
int mlMaxItems;
|
||||
|
||||
int mlSelectedItem;
|
||||
|
||||
cGuiGfxElement *mpGfxBackground;
|
||||
|
||||
cGuiGfxElement *mpGfxSelection;
|
||||
|
||||
cGuiGfxElement *mvGfxBorders[4];
|
||||
cGuiGfxElement *mvGfxCorners[4];
|
||||
|
||||
cWidgetSlider *mpSlider;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_LIST_BOX_H
|
||||
419
engines/hpl1/engine/gui/WidgetSlider.cpp
Normal file
419
engines/hpl1/engine/gui/WidgetSlider.cpp
Normal file
@@ -0,0 +1,419 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetSlider.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/system/String.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
#include "hpl1/engine/gui/WidgetButton.h"
|
||||
|
||||
#include "hpl1/engine/graphics/font_data.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetSlider::cWidgetSlider(cGuiSet *apSet, cGuiSkin *apSkin,
|
||||
eWidgetSliderOrientation aOrientation)
|
||||
: iWidget(eWidgetType_Slider, apSet, apSkin) {
|
||||
mOrientation = aOrientation;
|
||||
|
||||
mbPressed = false;
|
||||
|
||||
mlValue = 0;
|
||||
mlMaxValue = 10;
|
||||
mlButtonValueAdd = 1;
|
||||
mlBarValueSize = 1;
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
mvButtons[i] = NULL;
|
||||
|
||||
mfButtonSize = mpSkin->GetAttribute(eGuiSkinAttribute_SliderButtonSize).x;
|
||||
|
||||
LoadGraphics();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetSlider::~cWidgetSlider() {
|
||||
if (mpSet->IsDestroyingSet() == false) {
|
||||
for (int i = 0; i < 2; ++i)
|
||||
mpSet->DestroyWidget(mvButtons[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetSlider::SetValue(int alValue) {
|
||||
if (mlValue == alValue)
|
||||
return;
|
||||
|
||||
mlValue = alValue;
|
||||
if (mlValue < 0)
|
||||
mlValue = 0;
|
||||
if (mlValue > mlMaxValue)
|
||||
mlValue = mlMaxValue;
|
||||
|
||||
cGuiMessageData data = cGuiMessageData(mlValue);
|
||||
ProcessMessage(eGuiMessage_SliderMove, data);
|
||||
UpdateBarProperties();
|
||||
}
|
||||
|
||||
void cWidgetSlider::SetMaxValue(int alMax) {
|
||||
if (mlMaxValue == alMax)
|
||||
return;
|
||||
|
||||
mlMaxValue = alMax;
|
||||
if (mlMaxValue < 0)
|
||||
mlMaxValue = 0;
|
||||
|
||||
if (mlBarValueSize > mlMaxValue)
|
||||
mlBarValueSize = mlMaxValue;
|
||||
|
||||
UpdateBarProperties();
|
||||
}
|
||||
|
||||
void cWidgetSlider::SetButtonValueAdd(int alAdd) {
|
||||
mlButtonValueAdd = alAdd;
|
||||
}
|
||||
|
||||
void cWidgetSlider::SetBarValueSize(int alSize) {
|
||||
if (mlBarValueSize == alSize)
|
||||
return;
|
||||
|
||||
mlBarValueSize = alSize;
|
||||
if (mlBarValueSize > mlMaxValue + 1)
|
||||
mlBarValueSize = mlMaxValue + 1;
|
||||
|
||||
UpdateBarProperties();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetSlider::UpdateBarProperties() {
|
||||
//////////////////////////
|
||||
// Vertical
|
||||
if (mOrientation == eWidgetSliderOrientation_Vertical) {
|
||||
mfSliderSize = mvSize.y - mfButtonSize * 2;
|
||||
|
||||
mvBarSize = cVector2f(mvSize.x,
|
||||
((float)mlBarValueSize / (float)(mlMaxValue + 1)) * (mfSliderSize));
|
||||
|
||||
float fMinSize = mvGfxCorners[0]->GetActiveSize().y + mvGfxCorners[3]->GetActiveSize().y + 2;
|
||||
if (mvBarSize.y < fMinSize)
|
||||
mvBarSize.y = fMinSize;
|
||||
|
||||
// The set taken for each value
|
||||
if (mlMaxValue > 0)
|
||||
mfValueStep = (1 / (float)(mlMaxValue)) * (mfSliderSize - mvBarSize.y);
|
||||
else
|
||||
mfValueStep = 0;
|
||||
|
||||
mvBarPos = cVector3f(0, mfButtonSize + mfValueStep * (float)mlValue, 0.2f);
|
||||
}
|
||||
//////////////////////////
|
||||
// Horizontal
|
||||
else {
|
||||
mfSliderSize = mvSize.x - mfButtonSize * 2;
|
||||
|
||||
mvBarSize = cVector2f(((float)mlBarValueSize / (float)(mlMaxValue + 1)) * (mfSliderSize),
|
||||
mvSize.y);
|
||||
|
||||
float fMinSize = mvGfxCorners[0]->GetActiveSize().x + mvGfxCorners[3]->GetActiveSize().x + 2;
|
||||
if (mvBarSize.x < fMinSize)
|
||||
mvBarSize.x = fMinSize;
|
||||
|
||||
// The set taken for each value
|
||||
if (mlMaxValue > 0)
|
||||
mfValueStep = (1 / (float)(mlMaxValue)) * (mfSliderSize - mvBarSize.x);
|
||||
else
|
||||
mfValueStep = 0;
|
||||
|
||||
mvBarPos = cVector3f(mfButtonSize + mfValueStep * (float)mlValue, 0, 0.2f);
|
||||
}
|
||||
|
||||
mBarRect.x = GetGlobalPosition().x + mvBarPos.x;
|
||||
mBarRect.y = GetGlobalPosition().y + mvBarPos.y;
|
||||
mBarRect.w = mvBarSize.x;
|
||||
mBarRect.h = mvBarSize.y;
|
||||
|
||||
mfMaxPos = mfButtonSize + mfValueStep * (float)(mlMaxValue);
|
||||
mfMinPos = mfButtonSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetSlider::ArrowButtonDown(iWidget *apWidget, cGuiMessageData &aData) {
|
||||
int i;
|
||||
for (i = 0; i < 2; ++i)
|
||||
if (mvButtons[i] == apWidget)
|
||||
break;
|
||||
|
||||
if (i == 0)
|
||||
SetValue(mlValue - 1);
|
||||
if (i == 1)
|
||||
SetValue(mlValue + 1);
|
||||
|
||||
// Call callbacks.
|
||||
cGuiMessageData data = cGuiMessageData(mlValue);
|
||||
ProcessMessage(eGuiMessage_SliderMove, data);
|
||||
|
||||
return true;
|
||||
}
|
||||
kGuiCalllbackDeclaredFuncEnd(cWidgetSlider, ArrowButtonDown)
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetSlider::OnInit() {
|
||||
mvButtons[0] = mpSet->CreateWidgetButton(0, 0, Common::U32String(""), this);
|
||||
mvButtons[1] = mpSet->CreateWidgetButton(0, 0, Common::U32String(""), this);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
mvButtons[i]->SetImage(mvGfxArrow[i], false);
|
||||
|
||||
mvButtons[i]->AddCallback(eGuiMessage_MouseDown, this, kGuiCallback(ArrowButtonDown));
|
||||
}
|
||||
|
||||
OnChangeSize();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetSlider::OnLoadGraphics() {
|
||||
/////////////////////////
|
||||
// Background, corners and borders
|
||||
mpGfxButtonBackground = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBackground);
|
||||
|
||||
mvGfxBorders[0] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBorderRight);
|
||||
mvGfxBorders[1] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBorderLeft);
|
||||
mvGfxBorders[2] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBorderUp);
|
||||
mvGfxBorders[3] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpBorderDown);
|
||||
|
||||
mvGfxCorners[0] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpCornerLU);
|
||||
mvGfxCorners[1] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpCornerRU);
|
||||
mvGfxCorners[2] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpCornerRD);
|
||||
mvGfxCorners[3] = mpSkin->GetGfx(eGuiSkinGfx_ButtonUpCornerLD);
|
||||
|
||||
//////////////////////////
|
||||
// Vertical
|
||||
if (mOrientation == eWidgetSliderOrientation_Vertical) {
|
||||
mvGfxArrow[0] = mpSkin->GetGfx(eGuiSkinGfx_SliderVertArrowUp);
|
||||
mvGfxArrow[1] = mpSkin->GetGfx(eGuiSkinGfx_SliderVertArrowDown);
|
||||
mpGfxBackground = mpSkin->GetGfx(eGuiSkinGfx_SliderVertBackground);
|
||||
}
|
||||
//////////////////////////
|
||||
// Horizontal
|
||||
else {
|
||||
mvGfxArrow[0] = mpSkin->GetGfx(eGuiSkinGfx_SliderHoriArrowUp);
|
||||
mvGfxArrow[1] = mpSkin->GetGfx(eGuiSkinGfx_SliderHoriArrowDown);
|
||||
mpGfxBackground = mpSkin->GetGfx(eGuiSkinGfx_SliderHoriBackground);
|
||||
}
|
||||
|
||||
mfButtonSize = mpSkin->GetAttribute(eGuiSkinAttribute_SliderButtonSize).x;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetSlider::OnChangeSize() {
|
||||
if (mvButtons[0] == NULL || mvButtons[1] == NULL)
|
||||
return;
|
||||
|
||||
//////////////////////////
|
||||
// Vertical
|
||||
if (mOrientation == eWidgetSliderOrientation_Vertical) {
|
||||
mvButtons[0]->SetPosition(cVector3f(0, 0, 0.2f));
|
||||
mvButtons[0]->SetSize(cVector2f(mvSize.x, mfButtonSize));
|
||||
|
||||
mvButtons[1]->SetPosition(cVector3f(0, mvSize.y - mfButtonSize, 0.2f));
|
||||
mvButtons[1]->SetSize(cVector2f(mvSize.x, mfButtonSize));
|
||||
}
|
||||
//////////////////////////
|
||||
// Horizontal
|
||||
else {
|
||||
mvButtons[0]->SetPosition(cVector3f(0, 0, 0.2f));
|
||||
mvButtons[0]->SetSize(cVector2f(mfButtonSize, mvSize.y));
|
||||
|
||||
mvButtons[1]->SetPosition(cVector3f(mvSize.x - mfButtonSize, 0, 0.2f));
|
||||
mvButtons[1]->SetSize(cVector2f(mfButtonSize, mvSize.y));
|
||||
}
|
||||
|
||||
UpdateBarProperties();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetSlider::OnChangePosition() {
|
||||
UpdateBarProperties();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetSlider::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
////////////////////////////////
|
||||
// Background
|
||||
|
||||
// Vertical
|
||||
if (mOrientation == eWidgetSliderOrientation_Vertical) {
|
||||
mpSet->DrawGfx(mpGfxBackground, GetGlobalPosition() + cVector3f(0, mfButtonSize, 0.1f),
|
||||
cVector2f(mvSize.x, mvSize.y - mfButtonSize * 2));
|
||||
}
|
||||
// Horizontal
|
||||
else {
|
||||
mpSet->DrawGfx(mpGfxBackground, GetGlobalPosition() + cVector3f(mfButtonSize, 0, 0.1f),
|
||||
cVector2f(mvSize.x - mfButtonSize * 2, mvSize.y));
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Borders and button background
|
||||
DrawBordersAndCorners(mpGfxButtonBackground, mvGfxBorders, mvGfxCorners,
|
||||
GetGlobalPosition() + mvBarPos, mvBarSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetSlider::OnMouseMove(cGuiMessageData &aData) {
|
||||
if (mbPressed) {
|
||||
|
||||
int lVal;
|
||||
// Vertical
|
||||
if (mOrientation == eWidgetSliderOrientation_Vertical) {
|
||||
mvBarPos.y = WorldToLocalPosition(aData.mvPos).y + mvRelMousePos.y;
|
||||
|
||||
if (mvBarPos.y > mfMaxPos)
|
||||
mvBarPos.y = mfMaxPos;
|
||||
if (mvBarPos.y < mfMinPos)
|
||||
mvBarPos.y = mfMinPos;
|
||||
|
||||
mBarRect.y = GetGlobalPosition().y + mvBarPos.y;
|
||||
lVal = (int)((mvBarPos.y - mfButtonSize) / mfValueStep + 0.5f);
|
||||
}
|
||||
// Horizontal
|
||||
else {
|
||||
mvBarPos.x = WorldToLocalPosition(aData.mvPos).x + mvRelMousePos.x;
|
||||
|
||||
if (mvBarPos.x > mfMaxPos)
|
||||
mvBarPos.x = mfMaxPos;
|
||||
if (mvBarPos.x < mfMinPos)
|
||||
mvBarPos.x = mfMinPos;
|
||||
|
||||
mBarRect.x = GetGlobalPosition().x + mvBarPos.x;
|
||||
lVal = (int)((mvBarPos.x - mfButtonSize) / mfValueStep + 0.5f);
|
||||
}
|
||||
|
||||
if (lVal > mlMaxValue)
|
||||
lVal = mlMaxValue;
|
||||
if (lVal < 0)
|
||||
lVal = 0;
|
||||
if (lVal != mlValue) {
|
||||
mlValue = lVal;
|
||||
cGuiMessageData data = cGuiMessageData(mlValue);
|
||||
ProcessMessage(eGuiMessage_SliderMove, data);
|
||||
}
|
||||
}
|
||||
|
||||
/*if(mbPressed && cMath::PointBoxCollision(aData.mvPos,mBarRect)==false)
|
||||
{
|
||||
mbPressed = false;
|
||||
}*/
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetSlider::OnMouseDown(cGuiMessageData &aData) {
|
||||
if (cMath::PointBoxCollision(aData.mvPos, mBarRect)) {
|
||||
mbPressed = true;
|
||||
cVector3f vRel = mvBarPos - WorldToLocalPosition(aData.mvPos);
|
||||
mvRelMousePos.x = vRel.x;
|
||||
mvRelMousePos.y = vRel.y;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetSlider::OnMouseUp(cGuiMessageData &aData) {
|
||||
if (mbPressed) {
|
||||
mbPressed = false;
|
||||
UpdateBarProperties();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetSlider::OnMouseEnter(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetSlider::OnMouseLeave(cGuiMessageData &aData) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cWidgetSlider::OnLostFocus(cGuiMessageData &aData) {
|
||||
if (mbPressed) {
|
||||
mbPressed = false;
|
||||
UpdateBarProperties();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
120
engines/hpl1/engine/gui/WidgetSlider.h
Normal file
120
engines/hpl1/engine/gui/WidgetSlider.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_SLIDER_H
|
||||
#define HPL_WIDGET_SLIDER_H
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetButton;
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
class cWidgetSlider : public iWidget {
|
||||
public:
|
||||
cWidgetSlider(cGuiSet *apSet, cGuiSkin *apSkin, eWidgetSliderOrientation aOrientation);
|
||||
virtual ~cWidgetSlider();
|
||||
|
||||
int GetValue() { return mlValue; }
|
||||
void SetValue(int alValue);
|
||||
|
||||
int GetMaxValue() { return mlMaxValue; }
|
||||
void SetMaxValue(int alMax);
|
||||
|
||||
int GetButtonValueAdd() { return mlButtonValueAdd; }
|
||||
void SetButtonValueAdd(int alAdd);
|
||||
|
||||
int GetBarValueSize() { return mlBarValueSize; }
|
||||
void SetBarValueSize(int alSize);
|
||||
|
||||
float GetButtonSize() const { return mfButtonSize; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Own functions
|
||||
void UpdateBarProperties();
|
||||
|
||||
bool ArrowButtonDown(iWidget *apWidget, cGuiMessageData &aData);
|
||||
kGuiCalllbackDeclarationEnd(ArrowButtonDown);
|
||||
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnInit();
|
||||
void OnLoadGraphics();
|
||||
void OnChangeSize();
|
||||
void OnChangePosition();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
bool OnLostFocus(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
eWidgetSliderOrientation mOrientation;
|
||||
|
||||
bool mbPressed;
|
||||
|
||||
float mfButtonSize;
|
||||
|
||||
int mlValue;
|
||||
int mlMaxValue;
|
||||
int mlButtonValueAdd;
|
||||
int mlBarValueSize; // This is how big the bar is compared to the max value of the slider
|
||||
float mfValueStep;
|
||||
|
||||
cVector3f mvBarPos;
|
||||
cVector2f mvBarSize;
|
||||
float mfSliderSize;
|
||||
cRect2f mBarRect;
|
||||
float mfMaxPos;
|
||||
float mfMinPos;
|
||||
|
||||
cVector2f mvRelMousePos;
|
||||
|
||||
cWidgetButton *mvButtons[2];
|
||||
|
||||
cGuiGfxElement *mpGfxButtonBackground;
|
||||
cGuiGfxElement *mvGfxBorders[4];
|
||||
cGuiGfxElement *mvGfxCorners[4];
|
||||
|
||||
cGuiGfxElement *mvGfxArrow[2];
|
||||
cGuiGfxElement *mpGfxBackground;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_SLIDER_H
|
||||
605
engines/hpl1/engine/gui/WidgetTextBox.cpp
Normal file
605
engines/hpl1/engine/gui/WidgetTextBox.cpp
Normal file
@@ -0,0 +1,605 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetTextBox.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/graphics/font_data.h"
|
||||
|
||||
#include "hpl1/engine/system/String.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetTextBox::cWidgetTextBox(cGuiSet *apSet, cGuiSkin *apSkin) : iWidget(eWidgetType_TextBox, apSet, apSkin) {
|
||||
LoadGraphics();
|
||||
|
||||
mlMarkerCharPos = -1;
|
||||
mlSelectedTextEnd = -1;
|
||||
|
||||
mlFirstVisibleChar = 0;
|
||||
mlVisibleCharSize = 0;
|
||||
|
||||
mfTextMaxSize = 0;
|
||||
mfMaxTextSizeNeg = 0;
|
||||
|
||||
mlMaxCharacters = -1;
|
||||
|
||||
mlVisibleCharSize = 0;
|
||||
|
||||
mbPressed = false;
|
||||
|
||||
mbCanEdit = true;
|
||||
|
||||
mpPointerGfx = mpSkin->GetGfx(eGuiSkinGfx_PointerText);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetTextBox::~cWidgetTextBox() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetTextBox::SetMaxTextLength(int alLength) {
|
||||
if (mlMaxCharacters == alLength)
|
||||
return;
|
||||
|
||||
mlMaxCharacters = alLength;
|
||||
|
||||
if (mlMaxCharacters >= 0 && (int)msText.size() > mlMaxCharacters) {
|
||||
SetText(cString::SubW(msText, 0, mlMaxCharacters));
|
||||
|
||||
if (mlSelectedTextEnd >= mlMaxCharacters)
|
||||
mlSelectedTextEnd = mlMaxCharacters - 1;
|
||||
if (mlMarkerCharPos >= mlMaxCharacters)
|
||||
mlMarkerCharPos = mlMaxCharacters - 1;
|
||||
|
||||
OnChangeText();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cVector2f cWidgetTextBox::GetBackgroundSize() {
|
||||
return cVector2f(mvSize.x - mvGfxCorners[0]->GetActiveSize().x -
|
||||
mvGfxCorners[1]->GetActiveSize().x,
|
||||
mvSize.y - mvGfxCorners[0]->GetActiveSize().y -
|
||||
mvGfxCorners[2]->GetActiveSize().y);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetTextBox::SetMaxTextSizeNeg(float afX) {
|
||||
mfMaxTextSizeNeg = afX;
|
||||
|
||||
OnChangeSize();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetTextBox::SetCanEdit(bool abX) {
|
||||
mbCanEdit = abX;
|
||||
|
||||
if (mbCanEdit)
|
||||
mpPointerGfx = mpSkin->GetGfx(eGuiSkinGfx_PointerText);
|
||||
else
|
||||
mpPointerGfx = mpSkin->GetGfx(eGuiSkinGfx_PointerNormal);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cWidgetTextBox::GetLastCharInSize(int alStartPos, float afMaxSize, float afLengthAdd) {
|
||||
int lCharPos = (int)msText.size();
|
||||
float fLength = 0;
|
||||
int lFirst = mpDefaultFontType->getFirstChar();
|
||||
int lLast = mpDefaultFontType->getLastChar();
|
||||
for (int i = alStartPos; i < (int)msText.size(); ++i) {
|
||||
if (i < lFirst || i > lLast)
|
||||
continue;
|
||||
|
||||
Glyph *pGlyph = mpDefaultFontType->getGlyph(msText[i] - lFirst);
|
||||
if (pGlyph == NULL)
|
||||
continue;
|
||||
|
||||
fLength += pGlyph->_advance * mvDefaultFontSize.x;
|
||||
if (fLength + afLengthAdd >= afMaxSize) {
|
||||
lCharPos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lCharPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cWidgetTextBox::GetFirstCharInSize(int alStartPos, float afMaxSize, float afLengthAdd) {
|
||||
int lCharPos = 0;
|
||||
float fLength = 0;
|
||||
int lFirst = mpDefaultFontType->getFirstChar();
|
||||
int lLast = mpDefaultFontType->getLastChar();
|
||||
for (int i = alStartPos; i >= 0; --i) {
|
||||
if (i < lFirst || i > lLast)
|
||||
continue;
|
||||
|
||||
Glyph *pGlyph = mpDefaultFontType->getGlyph(msText[i] - lFirst);
|
||||
if (pGlyph == NULL)
|
||||
continue;
|
||||
|
||||
fLength += pGlyph->_advance * mvDefaultFontSize.x;
|
||||
if (fLength + afLengthAdd >= afMaxSize) {
|
||||
lCharPos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return lCharPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
int cWidgetTextBox::WorldToCharPos(const cVector2f &avWorldPos) {
|
||||
float fTextPos = WorldToLocalPosition(avWorldPos).x -
|
||||
mvGfxCorners[0]->GetActiveSize().x + 3;
|
||||
|
||||
int lMarkerCharPos;
|
||||
if (fTextPos > 0) {
|
||||
lMarkerCharPos = GetLastCharInSize(mlFirstVisibleChar, fTextPos, 3.0f);
|
||||
} else {
|
||||
lMarkerCharPos = mlFirstVisibleChar;
|
||||
}
|
||||
|
||||
return lMarkerCharPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
float cWidgetTextBox::CharToLocalPos(int alChar) {
|
||||
float fMarkerPos = -2;
|
||||
if (alChar > 0 && alChar - mlFirstVisibleChar > 0) {
|
||||
fMarkerPos = mpDefaultFontType->getLength(mvDefaultFontSize,
|
||||
cString::SubW(msText, mlFirstVisibleChar, alChar - mlFirstVisibleChar).c_str());
|
||||
}
|
||||
return fMarkerPos;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetTextBox::SetMarkerPos(int alPos) {
|
||||
mlMarkerCharPos = alPos;
|
||||
if (mlMarkerCharPos < 0)
|
||||
mlMarkerCharPos = 0;
|
||||
if (mlMarkerCharPos > (int)msText.size() && msText.size() > 0)
|
||||
mlMarkerCharPos = (int)msText.size();
|
||||
|
||||
if (mlMarkerCharPos > mlFirstVisibleChar + mlVisibleCharSize) {
|
||||
mlFirstVisibleChar = GetFirstCharInSize(mlMarkerCharPos, mfTextMaxSize, 0) + 1;
|
||||
if (msText.size() <= 1)
|
||||
mlFirstVisibleChar = 0;
|
||||
OnChangeText();
|
||||
} else if (mlMarkerCharPos < mlFirstVisibleChar) {
|
||||
mlFirstVisibleChar = mlMarkerCharPos;
|
||||
OnChangeText();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetTextBox::OnChangeSize() {
|
||||
mvSize.y = mvGfxBorders[0]->GetActiveSize().y +
|
||||
mvGfxBorders[2]->GetActiveSize().y +
|
||||
mvDefaultFontSize.y + 2 * 2;
|
||||
|
||||
mfTextMaxSize = mvSize.x - mvGfxBorders[0]->GetActiveSize().x -
|
||||
mvGfxBorders[1]->GetActiveSize().x - 3 * 2 -
|
||||
mfMaxTextSizeNeg;
|
||||
|
||||
OnChangeText();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetTextBox::OnChangeText() {
|
||||
if (msText == _W(""))
|
||||
mlVisibleCharSize = 0;
|
||||
else
|
||||
mlVisibleCharSize = GetLastCharInSize(mlFirstVisibleChar, mfTextMaxSize, 0) -
|
||||
mlFirstVisibleChar;
|
||||
|
||||
if (mlMaxCharacters >= 0 && (int)msText.size() > mlMaxCharacters) {
|
||||
SetText(cString::SubW(msText, 0, mlMaxCharacters));
|
||||
|
||||
if (mlSelectedTextEnd >= mlMaxCharacters)
|
||||
mlSelectedTextEnd = mlMaxCharacters - 1;
|
||||
if (mlMarkerCharPos >= mlMaxCharacters)
|
||||
mlMarkerCharPos = mlMaxCharacters - 1;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetTextBox::OnLoadGraphics() {
|
||||
mpGfxMarker = mpSkin->GetGfx(eGuiSkinGfx_TextBoxMarker);
|
||||
mpGfxSelectedTextBack = mpSkin->GetGfx(eGuiSkinGfx_TextBoxSelectedTextBack);
|
||||
|
||||
mpGfxBackground = mpSkin->GetGfx(eGuiSkinGfx_TextBoxBackground);
|
||||
|
||||
mvGfxBorders[0] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderRight);
|
||||
mvGfxBorders[1] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderLeft);
|
||||
mvGfxBorders[2] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderUp);
|
||||
mvGfxBorders[3] = mpSkin->GetGfx(eGuiSkinGfx_FrameBorderDown);
|
||||
|
||||
mvGfxCorners[0] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerLU);
|
||||
mvGfxCorners[1] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerRU);
|
||||
mvGfxCorners[2] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerRD);
|
||||
mvGfxCorners[3] = mpSkin->GetGfx(eGuiSkinGfx_FrameCornerLD);
|
||||
|
||||
OnChangeSize();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetTextBox::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
////////////////////////////////
|
||||
// Text
|
||||
cVector3f vTextAdd = cVector3f(3, 2, 0.2f) + mvGfxCorners[0]->GetActiveSize();
|
||||
DrawDefaultText(cString::SubW(msText, mlFirstVisibleChar, mlVisibleCharSize),
|
||||
GetGlobalPosition() + vTextAdd,
|
||||
eFontAlign_Left);
|
||||
|
||||
// Marker
|
||||
if (mlMarkerCharPos >= 0) {
|
||||
float fMarkerPos = CharToLocalPos(mlMarkerCharPos);
|
||||
mpSet->DrawGfx(mpGfxMarker, GetGlobalPosition() + vTextAdd + cVector3f(fMarkerPos, 0, 0.1f),
|
||||
cVector2f(2, mvDefaultFontSize.y));
|
||||
|
||||
// Selected text
|
||||
if (mlSelectedTextEnd >= 0) {
|
||||
float fSelectEnd = CharToLocalPos(mlSelectedTextEnd);
|
||||
|
||||
float fPos = fSelectEnd < fMarkerPos ? fSelectEnd : fMarkerPos;
|
||||
float fEnd = fSelectEnd > fMarkerPos ? fSelectEnd : fMarkerPos;
|
||||
|
||||
if (fPos < 0)
|
||||
fPos = 0;
|
||||
if (fEnd > mfTextMaxSize)
|
||||
fEnd = mfTextMaxSize;
|
||||
|
||||
float fSize = fEnd - fPos;
|
||||
|
||||
mpSet->DrawGfx(mpGfxSelectedTextBack, GetGlobalPosition() + vTextAdd + cVector3f(fPos, 0, 0.2f),
|
||||
cVector2f(fSize, mvDefaultFontSize.y));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
// Background and Borders
|
||||
DrawBordersAndCorners(mpGfxBackground, mvGfxBorders, mvGfxCorners,
|
||||
GetGlobalPosition(), mvSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetTextBox::OnMouseMove(cGuiMessageData &aData) {
|
||||
if (mbPressed) {
|
||||
int lPos = WorldToCharPos(aData.mvPos);
|
||||
if (lPos != mlMarkerCharPos) {
|
||||
if (mlSelectedTextEnd == -1)
|
||||
mlSelectedTextEnd = mlMarkerCharPos;
|
||||
SetMarkerPos(lPos);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetTextBox::OnMouseDown(cGuiMessageData &aData) {
|
||||
if ((aData.mlVal & eGuiMouseButton_Left) == 0)
|
||||
return true;
|
||||
if (mbCanEdit == false)
|
||||
return true;
|
||||
|
||||
SetMarkerPos(WorldToCharPos(aData.mvPos));
|
||||
mlSelectedTextEnd = -1;
|
||||
mbPressed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetTextBox::OnMouseUp(cGuiMessageData &aData) {
|
||||
if ((aData.mlVal & eGuiMouseButton_Left) == 0)
|
||||
return true;
|
||||
if (mbCanEdit == false)
|
||||
return true;
|
||||
|
||||
mbPressed = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetTextBox::OnMouseDoubleClick(cGuiMessageData &aData) {
|
||||
if ((aData.mlVal & eGuiMouseButton_Left) == 0)
|
||||
return true;
|
||||
if (mbCanEdit == false)
|
||||
return true;
|
||||
|
||||
SetMarkerPos(WorldToCharPos(aData.mvPos));
|
||||
|
||||
if (msText[mlMarkerCharPos] == ' ')
|
||||
return true;
|
||||
|
||||
/////////////////////////////
|
||||
// Get space to the right.
|
||||
mlSelectedTextEnd = 0;
|
||||
for (size_t i = mlMarkerCharPos; i > 0; --i) {
|
||||
if (msText[i] == ' ') {
|
||||
mlSelectedTextEnd = (int)i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Get space to the left
|
||||
for (size_t i = mlMarkerCharPos + 1; i < (size_t)msText.size(); ++i) {
|
||||
if (msText[i] == ' ' || i == (size_t)msText.size() - 1) {
|
||||
if (i == (size_t)msText.size() - 1)
|
||||
SetMarkerPos((int)msText.size() - 1);
|
||||
else
|
||||
SetMarkerPos((int)i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mbPressed = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetTextBox::OnMouseEnter(cGuiMessageData &aData) {
|
||||
mpSet->SetCurrentPointer(mpSkin->GetGfx(eGuiSkinGfx_PointerText));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetTextBox::OnMouseLeave(cGuiMessageData &aData) {
|
||||
mpSet->SetCurrentPointer(mpSkin->GetGfx(eGuiSkinGfx_PointerNormal));
|
||||
mbPressed = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetTextBox::OnLostFocus(cGuiMessageData &aData) {
|
||||
mlMarkerCharPos = -1;
|
||||
mlSelectedTextEnd = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetTextBox::OnKeyPress(cGuiMessageData &aData) {
|
||||
if (mbCanEdit == false)
|
||||
return true;
|
||||
if (mlMarkerCharPos < 0)
|
||||
return false;
|
||||
|
||||
auto key = aData.mKeyPress.keycode;
|
||||
int mod = aData.mKeyPress.flags;
|
||||
|
||||
if (mpGfxMarker)
|
||||
mpGfxMarker->SetAnimationTime(0);
|
||||
|
||||
//////////////////////////////
|
||||
// Copy / Pase / Cut
|
||||
if ((mod & Common::KBD_CTRL)) {
|
||||
int lStart = mlMarkerCharPos < mlSelectedTextEnd ? mlMarkerCharPos : mlSelectedTextEnd;
|
||||
int lEnd = mlMarkerCharPos > mlSelectedTextEnd ? mlMarkerCharPos : mlSelectedTextEnd;
|
||||
int lSelectSize = lEnd - lStart;
|
||||
|
||||
/////////////////////////////
|
||||
// Select all
|
||||
if (key == Common::KEYCODE_a) {
|
||||
mlSelectedTextEnd = 0;
|
||||
mlMarkerCharPos = (int)msText.size() - 1;
|
||||
}
|
||||
/////////////////////////////
|
||||
// Copy
|
||||
else if (key == Common::KEYCODE_c) {
|
||||
if (mlSelectedTextEnd >= 0)
|
||||
CopyTextToClipboard(cString::SubW(msText, lStart, lSelectSize));
|
||||
}
|
||||
/////////////////////////////
|
||||
// Cut
|
||||
else if (key == Common::KEYCODE_x) {
|
||||
if (mlSelectedTextEnd >= 0) {
|
||||
CopyTextToClipboard(cString::SubW(msText, lStart, lSelectSize));
|
||||
SetText(cString::SubW(msText, 0, lStart) + cString::SubW(msText, lEnd));
|
||||
mlSelectedTextEnd = -1;
|
||||
}
|
||||
}
|
||||
/////////////////////////////
|
||||
// Paste
|
||||
else if (key == Common::KEYCODE_v) {
|
||||
tWString sExtra = LoadTextFromClipboard();
|
||||
|
||||
if (mlSelectedTextEnd < 0) {
|
||||
if (mlMaxCharacters == -1 ||
|
||||
(int)msText.size() + (int)sExtra.size() <= mlMaxCharacters) {
|
||||
SetText(cString::SubW(msText, 0, mlMarkerCharPos) + sExtra +
|
||||
cString::SubW(msText, mlMarkerCharPos));
|
||||
|
||||
SetMarkerPos(mlMarkerCharPos + (int)sExtra.size());
|
||||
}
|
||||
} else {
|
||||
if (mlMaxCharacters < 0 ||
|
||||
(int)sExtra.size() <= lSelectSize ||
|
||||
(int)sExtra.size() + (int)msText.size() - lSelectSize <= mlMaxCharacters) {
|
||||
SetText(cString::SubW(msText, 0, lStart) + sExtra +
|
||||
cString::SubW(msText, lEnd));
|
||||
|
||||
mlSelectedTextEnd = -1;
|
||||
SetMarkerPos(lStart + (int)sExtra.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//////////////////////////////
|
||||
// Arrow keys
|
||||
else if (key == Common::KEYCODE_LEFT || key == Common::KEYCODE_RIGHT) {
|
||||
if (mod & Common::KBD_SHIFT) {
|
||||
if (mlSelectedTextEnd == -1)
|
||||
mlSelectedTextEnd = mlMarkerCharPos;
|
||||
|
||||
if (key == Common::KEYCODE_LEFT)
|
||||
SetMarkerPos(mlMarkerCharPos - 1);
|
||||
else
|
||||
SetMarkerPos(mlMarkerCharPos + 1);
|
||||
} else {
|
||||
if (key == Common::KEYCODE_LEFT)
|
||||
SetMarkerPos(mlMarkerCharPos - 1);
|
||||
else
|
||||
SetMarkerPos(mlMarkerCharPos + 1);
|
||||
|
||||
mlSelectedTextEnd = -1;
|
||||
}
|
||||
}
|
||||
//////////////////////////////
|
||||
// Delete and backspace
|
||||
else if (key == Common::KEYCODE_DELETE || key == Common::KEYCODE_BACKSPACE) {
|
||||
if (mlSelectedTextEnd >= 0) {
|
||||
int lStart = mlMarkerCharPos < mlSelectedTextEnd ? mlMarkerCharPos : mlSelectedTextEnd;
|
||||
int lEnd = mlMarkerCharPos > mlSelectedTextEnd ? mlMarkerCharPos : mlSelectedTextEnd;
|
||||
|
||||
SetText(cString::SubW(msText, 0, lStart) + cString::SubW(msText, lEnd));
|
||||
|
||||
mlSelectedTextEnd = -1;
|
||||
SetMarkerPos(lStart);
|
||||
} else {
|
||||
if (key == Common::KEYCODE_DELETE) {
|
||||
SetText(cString::SubW(msText, 0, mlMarkerCharPos) +
|
||||
cString::SubW(msText, mlMarkerCharPos + 1));
|
||||
} else {
|
||||
SetText(cString::SubW(msText, 0, mlMarkerCharPos - 1) +
|
||||
cString::SubW(msText, mlMarkerCharPos));
|
||||
SetMarkerPos(mlMarkerCharPos - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
//////////////////////////////
|
||||
// Home
|
||||
else if (key == Common::KEYCODE_HOME) {
|
||||
if (mod & Common::KBD_SHIFT) {
|
||||
if (mlSelectedTextEnd == -1)
|
||||
mlSelectedTextEnd = mlMarkerCharPos;
|
||||
} else {
|
||||
mlSelectedTextEnd = -1;
|
||||
}
|
||||
SetMarkerPos(0);
|
||||
}
|
||||
//////////////////////////////
|
||||
// End
|
||||
else if (key == Common::KEYCODE_END) {
|
||||
if (mod & Common::KBD_SHIFT) {
|
||||
if (mlSelectedTextEnd == -1)
|
||||
mlSelectedTextEnd = mlMarkerCharPos;
|
||||
} else {
|
||||
mlSelectedTextEnd = -1;
|
||||
}
|
||||
SetMarkerPos((int)msText.size());
|
||||
}
|
||||
//////////////////////////////////
|
||||
// Character
|
||||
else {
|
||||
int lFirstFontChar = mpDefaultFontType->getFirstChar();
|
||||
int lLastFontChar = mpDefaultFontType->getLastChar();
|
||||
auto textInput = aData.mKeyPress.ascii;
|
||||
|
||||
// Check so press is valid
|
||||
if (textInput >= lFirstFontChar && textInput <= lLastFontChar &&
|
||||
mpDefaultFontType->getGlyph(textInput - lFirstFontChar)) {
|
||||
if (mlSelectedTextEnd < 0) {
|
||||
if (mlMaxCharacters == -1 || (int)msText.size() < mlMaxCharacters) {
|
||||
SetText(cString::SubW(msText, 0, mlMarkerCharPos) + textInput +
|
||||
cString::SubW(msText, mlMarkerCharPos));
|
||||
|
||||
SetMarkerPos(mlMarkerCharPos + 1);
|
||||
}
|
||||
} else {
|
||||
int lStart = mlMarkerCharPos < mlSelectedTextEnd ? mlMarkerCharPos : mlSelectedTextEnd;
|
||||
int lEnd = mlMarkerCharPos > mlSelectedTextEnd ? mlMarkerCharPos : mlSelectedTextEnd;
|
||||
|
||||
SetText(cString::SubW(msText, 0, lStart) + textInput +
|
||||
cString::SubW(msText, lEnd));
|
||||
|
||||
mlSelectedTextEnd = -1;
|
||||
|
||||
SetMarkerPos(lStart + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
106
engines/hpl1/engine/gui/WidgetTextBox.h
Normal file
106
engines/hpl1/engine/gui/WidgetTextBox.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_TEXT_BOX_H
|
||||
#define HPL_WIDGET_TEXT_BOX_H
|
||||
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetTextBox : public iWidget {
|
||||
public:
|
||||
cWidgetTextBox(cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~cWidgetTextBox();
|
||||
|
||||
void SetMaxTextLength(int alLength);
|
||||
int GetMaxTextLength() { return mlMaxCharacters; }
|
||||
|
||||
cVector2f GetBackgroundSize();
|
||||
|
||||
void SetMaxTextSizeNeg(float afX);
|
||||
|
||||
void SetCanEdit(bool abX);
|
||||
bool GetCanEdit() { return mbCanEdit; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Own functions
|
||||
int WorldToCharPos(const cVector2f &avWorldPos);
|
||||
float CharToLocalPos(int alChar);
|
||||
void SetMarkerPos(int alPos);
|
||||
int GetLastCharInSize(int alStartPos, float afMaxSize, float afLengthAdd);
|
||||
int GetFirstCharInSize(int alStartPos, float afMaxSize, float afLengthAdd);
|
||||
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnLoadGraphics();
|
||||
void OnChangeSize();
|
||||
void OnChangeText();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseDoubleClick(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
bool OnLostFocus(cGuiMessageData &aData);
|
||||
|
||||
bool OnKeyPress(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
bool mbPressed;
|
||||
int mlMarkerCharPos;
|
||||
int mlSelectedTextEnd;
|
||||
int mlFirstVisibleChar;
|
||||
int mlVisibleCharSize;
|
||||
float mfTextMaxSize;
|
||||
|
||||
int mlMaxCharacters;
|
||||
|
||||
float mfMaxTextSizeNeg;
|
||||
|
||||
bool mbCanEdit;
|
||||
|
||||
cGuiGfxElement *mpGfxMarker;
|
||||
cGuiGfxElement *mpGfxSelectedTextBack;
|
||||
|
||||
cGuiGfxElement *mpGfxBackground;
|
||||
|
||||
cGuiGfxElement *mvGfxBorders[4];
|
||||
cGuiGfxElement *mvGfxCorners[4];
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_TEXT_BOX_H
|
||||
195
engines/hpl1/engine/gui/WidgetWindow.cpp
Normal file
195
engines/hpl1/engine/gui/WidgetWindow.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#include "hpl1/engine/gui/WidgetWindow.h"
|
||||
|
||||
#include "hpl1/engine/system/low_level_system.h"
|
||||
|
||||
#include "hpl1/engine/math/Math.h"
|
||||
|
||||
#include "hpl1/engine/gui/Gui.h"
|
||||
#include "hpl1/engine/gui/GuiGfxElement.h"
|
||||
#include "hpl1/engine/gui/GuiSet.h"
|
||||
#include "hpl1/engine/gui/GuiSkin.h"
|
||||
|
||||
#include "hpl1/engine/resources/FontManager.h"
|
||||
#include "hpl1/engine/resources/Resources.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CONSTRUCTORS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetWindow::cWidgetWindow(cGuiSet *apSet, cGuiSkin *apSkin) : iWidget(eWidgetType_Window, apSet, apSkin) {
|
||||
mvRelMousePos = 0;
|
||||
mbMoving = false;
|
||||
mbStatic = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
cWidgetWindow::~cWidgetWindow() {
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetWindow::SetStatic(bool abX) {
|
||||
mbStatic = abX;
|
||||
|
||||
if (mbStatic == false) {
|
||||
mbMoving = false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// PROTECTED METHODS
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetWindow::OnLoadGraphics() {
|
||||
mpGfxBackground = mpSkin->GetGfx(eGuiSkinGfx_WindowBackground);
|
||||
|
||||
mpGfxLabel = mpSkin->GetGfx(eGuiSkinGfx_WindowLabel);
|
||||
|
||||
mvGfxBorders[0] = mpSkin->GetGfx(eGuiSkinGfx_WindowBorderRight);
|
||||
mvGfxBorders[1] = mpSkin->GetGfx(eGuiSkinGfx_WindowBorderLeft);
|
||||
mvGfxBorders[2] = mpSkin->GetGfx(eGuiSkinGfx_WindowBorderUp);
|
||||
mvGfxBorders[3] = mpSkin->GetGfx(eGuiSkinGfx_WindowBorderDown);
|
||||
|
||||
mvGfxCorners[0] = mpSkin->GetGfx(eGuiSkinGfx_WindowCornerLU);
|
||||
mvGfxCorners[1] = mpSkin->GetGfx(eGuiSkinGfx_WindowCornerRU);
|
||||
mvGfxCorners[2] = mpSkin->GetGfx(eGuiSkinGfx_WindowCornerRD);
|
||||
mvGfxCorners[3] = mpSkin->GetGfx(eGuiSkinGfx_WindowCornerLD);
|
||||
|
||||
mpLabelFont = mpSkin->GetFont(eGuiSkinFont_WindowLabel);
|
||||
|
||||
mvLabelTextOffset = mpSkin->GetAttribute(eGuiSkinAttribute_WindowLabelTextOffset);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void cWidgetWindow::OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion) {
|
||||
////////////////////////////////
|
||||
// Calc label size
|
||||
cVector2f vLabelSize;
|
||||
vLabelSize.x = mvSize.x - (mvGfxCorners[0]->GetActiveSize().x + mvGfxCorners[1]->GetActiveSize().x);
|
||||
vLabelSize.y = mpLabelFont->mvSize.y + mvLabelTextOffset.y * 2;
|
||||
|
||||
////////////////////////////////
|
||||
// Label
|
||||
mpSet->DrawGfx(mpGfxLabel, GetGlobalPosition() + cVector3f(mvGfxCorners[0]->GetActiveSize().x, mvGfxCorners[0]->GetActiveSize().y, 0.2f),
|
||||
vLabelSize);
|
||||
|
||||
////////////////////////////////
|
||||
// Label text
|
||||
DrawSkinText(msText, eGuiSkinFont_WindowLabel, GetGlobalPosition() + cVector3f(mvGfxCorners[0]->GetActiveSize().x + mvLabelTextOffset.x, mvGfxCorners[0]->GetActiveSize().y + mvLabelTextOffset.y, 0.4f));
|
||||
|
||||
////////////////////////////////
|
||||
// Borders and background
|
||||
DrawBordersAndCorners(mpGfxBackground, mvGfxBorders, mvGfxCorners, GetGlobalPosition(), mvSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetWindow::OnMouseMove(cGuiMessageData &aData) {
|
||||
if (mbMoving)
|
||||
SetGlobalPosition(mvRelMousePos + cVector3f(aData.mvPos.x, aData.mvPos.y, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetWindow::OnMouseDown(cGuiMessageData &aData) {
|
||||
if (mbStatic)
|
||||
return false;
|
||||
|
||||
////////////////////////////////
|
||||
// Calculate label rectangle
|
||||
cRect2f labelRect;
|
||||
labelRect.w = mvSize.x - (mvGfxCorners[0]->GetActiveSize().x + mvGfxCorners[1]->GetActiveSize().x);
|
||||
labelRect.h = mpLabelFont->mvSize.y + mvLabelTextOffset.y * 2;
|
||||
labelRect.x = GetGlobalPosition().x + mvGfxCorners[0]->GetActiveSize().x;
|
||||
labelRect.y = GetGlobalPosition().y + mvGfxCorners[0]->GetActiveSize().y;
|
||||
|
||||
////////////////////////////////
|
||||
// Check for collision
|
||||
if (cMath::PointBoxCollision(aData.mvPos, labelRect) && aData.mlVal & eGuiMouseButton_Left) {
|
||||
mbMoving = true;
|
||||
mvRelMousePos = GetPosRelativeToMouse(aData);
|
||||
mvRelMousePos.z = GetGlobalPosition().z;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetWindow::OnMouseUp(cGuiMessageData &aData) {
|
||||
if (aData.mlVal & eGuiMouseButton_Left)
|
||||
mbMoving = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetWindow::OnMouseEnter(cGuiMessageData &aData) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool cWidgetWindow::OnMouseLeave(cGuiMessageData &aData) {
|
||||
cVector3f vLastGlobal = GetGlobalPosition();
|
||||
|
||||
if (mbMoving)
|
||||
SetGlobalPosition(mvRelMousePos + cVector3f(aData.mvPos.x, aData.mvPos.y, 0));
|
||||
|
||||
// Check so that mouse is not outside of clip area.
|
||||
if (PointIsInside(aData.mvPos, false) == false) {
|
||||
SetGlobalPosition(vLastGlobal);
|
||||
mbMoving = false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
} // namespace hpl
|
||||
80
engines/hpl1/engine/gui/WidgetWindow.h
Normal file
80
engines/hpl1/engine/gui/WidgetWindow.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2010 - Frictional Games
|
||||
*
|
||||
* This file is part of HPL1 Engine.
|
||||
*/
|
||||
|
||||
#ifndef HPL_WIDGET_WINDOW_H
|
||||
#define HPL_WIDGET_WINDOW_H
|
||||
|
||||
#include "common/array.h"
|
||||
#include "common/list.h"
|
||||
#include "hpl1/engine/gui/Widget.h"
|
||||
|
||||
namespace hpl {
|
||||
|
||||
class cGuiSkinFont;
|
||||
|
||||
class cWidgetWindow : public iWidget {
|
||||
public:
|
||||
cWidgetWindow(cGuiSet *apSet, cGuiSkin *apSkin);
|
||||
virtual ~cWidgetWindow();
|
||||
|
||||
void SetStatic(bool abX);
|
||||
bool GetStatic() { return mbStatic; }
|
||||
|
||||
protected:
|
||||
/////////////////////////
|
||||
// Implemented functions
|
||||
void OnLoadGraphics();
|
||||
|
||||
void OnDraw(float afTimeStep, cGuiClipRegion *apClipRegion);
|
||||
|
||||
bool OnMouseMove(cGuiMessageData &aData);
|
||||
bool OnMouseDown(cGuiMessageData &aData);
|
||||
bool OnMouseUp(cGuiMessageData &aData);
|
||||
bool OnMouseEnter(cGuiMessageData &aData);
|
||||
bool OnMouseLeave(cGuiMessageData &aData);
|
||||
|
||||
/////////////////////////
|
||||
// Data
|
||||
cGuiSkinFont *mpLabelFont;
|
||||
|
||||
cGuiGfxElement *mpGfxBackground;
|
||||
cGuiGfxElement *mpGfxLabel;
|
||||
|
||||
cGuiGfxElement *mvGfxBorders[4];
|
||||
cGuiGfxElement *mvGfxCorners[4];
|
||||
|
||||
cVector3f mvLabelTextOffset;
|
||||
|
||||
bool mbStatic;
|
||||
|
||||
cVector3f mvRelMousePos;
|
||||
bool mbMoving;
|
||||
};
|
||||
|
||||
} // namespace hpl
|
||||
|
||||
#endif // HPL_WIDGET_H
|
||||
Reference in New Issue
Block a user