Changed: Replace icon bitmap text with a font

--HG--
branch : experimental-ui-scaling
This commit is contained in:
Nimetu 2016-08-14 10:41:27 +03:00
parent b5717de4fc
commit a6b9da78fc
2 changed files with 197 additions and 103 deletions

View file

@ -542,6 +542,15 @@ CCtrlDraggable(param)
_ItemRMClassType= NULL; _ItemRMClassType= NULL;
_ItemRMFaberStatType= NULL; _ItemRMFaberStatType= NULL;
_NotifyAnimEndTime = 0; _NotifyAnimEndTime = 0;
_SheetText = NULL;
_QualityText = NULL;
_QuantityText = NULL;
_SapText = NULL;
_QualityTextValue = -1;
_QuantityTextValue = -1;
_SapTextValue = -1;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -562,6 +571,30 @@ CDBCtrlSheet::~CDBCtrlSheet()
_GuildSymb = NULL; _GuildSymb = NULL;
} }
if (_SheetText)
{
delete _SheetText;
_SheetText = NULL;
}
if (_QualityText)
{
delete _QualityText;
_QualityText = NULL;
}
if (_QuantityText)
{
delete _QuantityText;
_QuantityText = NULL;
}
if (_SapText)
{
delete _SapText;
_SapText = NULL;
}
// ensure erase static // ensure erase static
if(this==_CurrMenuSheet) _CurrMenuSheet = NULL; if(this==_CurrMenuSheet) _CurrMenuSheet = NULL;
if(this == dynamic_cast< CDBCtrlSheet* >( CCtrlDraggable::getDraggedSheet() ) ) if(this == dynamic_cast< CDBCtrlSheet* >( CCtrlDraggable::getDraggedSheet() ) )
@ -1020,6 +1053,19 @@ void CDBCtrlSheet::updateCoords ()
} }
} }
CInterfaceElement::updateCoords(); CInterfaceElement::updateCoords();
if (getActive())
{
// updateCoords() is called to apply possible UI scale change to font
if (_SheetText)
_SheetText->updateCoords();
if (_QualityText)
_QualityText->updateCoords();
if (_QuantityText)
_QuantityText->updateCoords();
if (_SapText)
_SapText->updateCoords();
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -1733,81 +1779,106 @@ sint32 CDBCtrlSheet::getSPhraseId() const
// *************************************************************************** // ***************************************************************************
void CDBCtrlSheet::resetCharBitmaps() void CDBCtrlSheet::resetCharBitmaps()
{ {
_CharBitmaps.clear(); if (_SheetText)
_SheetText->setActive(false);
if (_QualityText)
_QualityText->setActive(false);
if (_QuantityText)
_QuantityText->setActive(false);
if (_SapText)
_SapText->setActive(false);
}
CViewText* CDBCtrlSheet::createViewText(const std::string &id, sint fontSize)
{
CViewText *text = new CViewText(CViewBase::TCtorParam());
text->setActive(false);
text->setId(getId() + ":" + id);
// icon slot does not inherit from CInterfaceGroup and cannot be used as parent
text->setParent(_Parent);
text->setParentPos(_ParentPos);
text->setParentPosRef(_ParentPosRef);
text->setFontSize(fontSize);
text->setShadow(true);
text->setColor(CRGBA::White);
text->setOverflowText(ucstring(""));
text->setModulateGlobalColor(false);
text->setMultiLineSpace(0);
text->setMultiLineMaxWOnly(true);
text->setMultiLine(false);
return text;
} }
// *************************************************************************** // ***************************************************************************
void CDBCtrlSheet::setupCharBitmaps(sint32 maxW, sint32 maxLine, sint32 maxWChar, bool topDown) void CDBCtrlSheet::setupCharBitmaps(sint32 maxW, sint32 maxLine, sint32 maxWChar, bool topDown)
{ {
// Use the optString for the Macro name // Use the optString for the Macro name
_OptString = toLower(_OptString);
CInterfaceManager *pIM = CInterfaceManager::getInstance(); CInterfaceManager *pIM = CInterfaceManager::getInstance();
CViewRenderer &rVR = *CViewRenderer::getInstance(); CViewRenderer &rVR = *CViewRenderer::getInstance();
_CharBitmaps.clear();
if(maxLine<=0) if(maxLine<=0)
{
if (_SheetText)
_SheetText->setActive(false);
return; return;
uint h = rVR.getTypoTextureH('a');
sint lineNb = 0;
sint curLineSize = 0;
uint i;
uint xChar= 0;
for (i = 0; i < _OptString.size(); ++i)
{
char c = _OptString[i];
sint32 w = rVR.getTypoTextureW(c);
if ((curLineSize + w) > maxW || (sint32)xChar>=maxWChar)
{
lineNb ++;
if (lineNb == maxLine) break;
curLineSize = 0;
xChar = 0;
}
sint32 id = rVR.getTypoTextureId(c);
if (id != -1)
{
CCharBitmap bmp;
bmp.X= curLineSize;
bmp.Y= lineNb;
bmp.Id= id;
_CharBitmaps.push_back(bmp);
}
curLineSize += w;
++xChar;
} }
if (lineNb == maxLine) lineNb = maxLine-1; if (!_SheetText)
_SheetText = createViewText("opt", 8);
for (i = 0; i < _CharBitmaps.size(); ++i) _SheetText->setX(0);
{
_CharBitmaps[i].Y = (lineNb - _CharBitmaps[i].Y)*h;
}
// if topDown, revert Y
if (topDown) if (topDown)
{ {
for (i = 0; i < _CharBitmaps.size(); ++i) _SheetText->setY(_IconH);
{ _SheetText->setPosRef(Hotspot_TL);
_CharBitmaps[i].Y = _IconH - _CharBitmaps[i].Y - h;
}
} }
else
_SheetText->setPosRef(Hotspot_BL);
_SheetText->setActive(true);
ucstring txt;
txt.fromUtf8(_OptString);
_SheetText->setText(txt);
_SheetText->setLineMaxW(maxW);
_SheetText->setMultiLine(maxLine > 1);
_SheetText->updateTextContext();
} }
// *************************************************************************** // ***************************************************************************
void CDBCtrlSheet::displayCharBitmaps(sint32 rdrLayer, sint32 x, sint32 y, CRGBA color) void CDBCtrlSheet::displayCharBitmaps(sint32 rdrLayer, sint32 x, sint32 y, CRGBA color)
{ {
CInterfaceManager *pIM = CInterfaceManager::getInstance();
CViewRenderer &rVR = *CViewRenderer::getInstance(); CViewRenderer &rVR = *CViewRenderer::getInstance();
for (uint i = 0; i < _CharBitmaps.size(); ++i) if (_SheetText)
{ {
rVR.draw11RotFlipBitmap (rdrLayer, x+_CharBitmaps[i].X, y+_CharBitmaps[i].Y, 0, false, sint32 ClipX, ClipY, ClipW, ClipH;
_CharBitmaps[i].Id, color); rVR.getClipWindow (ClipX, ClipY, ClipW, ClipH);
}
}
// clip region is bbox from parent
if (isIn(ClipX, ClipY, ClipW, ClipH))
{
// position text over icon
sint32 sx = x + _SheetText->getX();
sint32 sy = y + _SheetText->getY();
if (_SheetText->getPosRef() & Hotspot_Tx)
sy -= _SheetText->getHReal();
_SheetText->setRenderLayer(rdrLayer);
_SheetText->setXReal(sx);
_SheetText->setYReal(sy);
_SheetText->setColor(color);
// set clip area over icon to hide oversize text
rVR.setClipWindow(sx, sy, _WReal-2, _HReal-2);
_SheetText->draw();
rVR.setClipWindow (ClipX, ClipY, ClipW, ClipH);
}
}
}
// *************************************************************************** // ***************************************************************************
void CDBCtrlSheet::draw() void CDBCtrlSheet::draw()
@ -2128,7 +2199,7 @@ void CDBCtrlSheet::drawSheet (sint32 x, sint32 y, bool draging, bool showSelecti
if (_DispQuality != -1) if (_DispQuality != -1)
{ {
// For pact sheets, the quality gives the level of the sheet // For pact sheets, the quality gives the level of the sheet
drawNumber(x+1, y+1, wSheet, hSheet, numberColor, _DispQuality+1); drawQuality(x+1, y+1, wSheet, hSheet, numberColor, _DispQuality+1);
} }
break; break;
case CCtrlSheetInfo::SheetType_Skill: case CCtrlSheetInfo::SheetType_Skill:
@ -2183,7 +2254,7 @@ void CDBCtrlSheet::drawSheet (sint32 x, sint32 y, bool draging, bool showSelecti
// Draw Quality. -1 for lookandfeel. Draw it with global color // Draw Quality. -1 for lookandfeel. Draw it with global color
if (_DispQuality != -1) if (_DispQuality != -1)
{ {
drawNumber(x-1,y+1,wSheet, hSheet, numberColor, _DispQuality); drawQuality(x-1,y+1, wSheet, hSheet, numberColor, _DispQuality);
} }
// Draw Quantity // Draw Quantity
if (_UseQuantity && _DispQuantity>-1) if (_UseQuantity && _DispQuantity>-1)
@ -2200,7 +2271,7 @@ void CDBCtrlSheet::drawSheet (sint32 x, sint32 y, bool draging, bool showSelecti
{ {
quantity -= getLockValuePtr()->getValue32(); quantity -= getLockValuePtr()->getValue32();
} }
drawNumber(x+1+crossW, y+1, wSheet, hSheet, curSheetColor, quantity, false); drawQuantity(x+1+crossW, y+1, wSheet, hSheet, curSheetColor, quantity);
} }
// Is the item enchanted ? // Is the item enchanted ?
sint32 enchant = _Enchant.getSInt32(); sint32 enchant = _Enchant.getSInt32();
@ -2209,7 +2280,7 @@ void CDBCtrlSheet::drawSheet (sint32 x, sint32 y, bool draging, bool showSelecti
// Yes draw the additionnal bitmap and the charge (number of enchanted spell we can launch with the enchanted item) // Yes draw the additionnal bitmap and the charge (number of enchanted spell we can launch with the enchanted item)
enchant--; enchant--;
rVR.draw11RotFlipBitmap (_RenderLayer+2, x, y, 0, false, rVR.getSystemTextureId(CViewRenderer::ItemEnchantedTexture), curSheetColor); rVR.draw11RotFlipBitmap (_RenderLayer+2, x, y, 0, false, rVR.getSystemTextureId(CViewRenderer::ItemEnchantedTexture), curSheetColor);
drawNumber(x+1, y-2+hSheet-rVR.getFigurTextureH(), wSheet, hSheet, numberColor, enchant, false); drawSap(x+1, y+1, wSheet, hSheet, numberColor, enchant);
} }
// if a raw material for example, must add special icon text. // if a raw material for example, must add special icon text.
@ -2472,7 +2543,10 @@ void CDBCtrlSheet::drawSheet (sint32 x, sint32 y, bool draging, bool showSelecti
// Draw Quality. -1 for lookandfeel. // Draw Quality. -1 for lookandfeel.
if( _ActualType == CCtrlSheetInfo::SheetType_SBrick ) if( _ActualType == CCtrlSheetInfo::SheetType_SBrick )
{ {
if (_UseQuality && _MustDisplayLevel) drawNumber(px-1,py+1,BrickSheetWidth, BrickSheetHeight, curSheetColor, _DispLevel); if (_UseQuality && _MustDisplayLevel)
{
drawQuality(px-1, py+1, BrickSheetWidth, BrickSheetHeight, curSheetColor, _DispLevel);
}
} }
else else
{ {
@ -2540,51 +2614,63 @@ void CDBCtrlSheet::drawSheet (sint32 x, sint32 y, bool draging, bool showSelecti
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
sint32 CDBCtrlSheet::drawNumber(sint32 x, sint32 y, sint32 wSheet, sint32 /* hSheet */, CRGBA color, sint32 value, bool rightAlign) sint32 CDBCtrlSheet::drawQuality(sint32 x, sint32 y, sint32 wSheet, sint32 /* hSheet */, CRGBA color, sint32 value)
{ {
CInterfaceManager *pIM = CInterfaceManager::getInstance(); if (!_QualityText)
CViewRenderer &rVR = *CViewRenderer::getInstance(); _QualityText = createViewText("quality", 7);
sint32 wDigit= rVR.getFigurTextureW();
sint32 hDigit= rVR.getFigurTextureH();
sint32 totalWidth = 0; if (_QualityTextValue != value)
{
_QualityText->setText(toString(value));
_QualityText->updateTextContext();
_QualityTextValue = value;
}
_QualityText->setActive(true);
_QualityText->setRenderLayer(_RenderLayer + 2);
_QualityText->setXReal(x + wSheet - _QualityText->getW());
_QualityText->setYReal(y);
_QualityText->setColor(color);
_QualityText->draw();
}
if (value > -1) // ----------------------------------------------------------------------------
sint32 CDBCtrlSheet::drawQuantity(sint32 x, sint32 y, sint32 wSheet, sint32 /* hSheet */, CRGBA color, sint32 value)
{ {
// compute start pos if (!_QuantityText)
sint32 units = value; _QuantityText = createViewText(getId() + ":quantity", 7);
sint32 pos;
if(rightAlign) if (_QuantityTextValue != value)
pos= wSheet-wDigit;
else
{ {
// compute number of digits to display _QuantityText->setText(toString(value));
pos= 0; _QuantityText->updateTextContext();
uint numDigits= 0; _QuantityTextValue = value;
do }
_QuantityText->setActive(true);
_QuantityText->setRenderLayer(_RenderLayer + 2);
_QuantityText->setXReal(x);
_QuantityText->setYReal(y);
_QuantityText->setColor(color);
_QuantityText->draw();
}
// ----------------------------------------------------------------------------
sint32 CDBCtrlSheet::drawSap(sint32 x, sint32 y, sint32 wSheet, sint32 hSheet, CRGBA color, sint32 value)
{ {
units = units / 10; if (!_SapText)
numDigits++; _SapText = createViewText(getId() + ":sap", 8);
}
while (units != 0); if (_SapTextValue != value)
// so pos is:
pos= numDigits*wDigit - wDigit;
}
// display digits
units = value;
do
{ {
sint32 unitsID = rVR.getFigurTextureId (units % 10); _SapText->setText(toString(value));
// decal layer because must drawn after Items/Brick in DXTC _SapText->updateTextContext();
rVR.drawRotFlipBitmap (_RenderLayer+2, x+pos, y, wDigit, hDigit, 0, false, unitsID, color); _SapTextValue = value;
units = units / 10;
pos-= wDigit;
totalWidth += wDigit;
} }
while (units != 0); _SapText->setActive(true);
return totalWidth; _SapText->setRenderLayer(_RenderLayer + 2);
} _SapText->setXReal(x);
return -1; _SapText->setYReal(y + hSheet - _SapText->getH());
_SapText->setColor(color);
_SapText->draw();
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View file

@ -27,6 +27,7 @@
#include "nel/gui/ctrl_draggable.h" #include "nel/gui/ctrl_draggable.h"
#include "nel/gui/interface_expr.h" #include "nel/gui/interface_expr.h"
#include "nel/gui/action_handler.h" #include "nel/gui/action_handler.h"
#include "nel/gui/view_text.h"
#include "sphrase_manager.h" #include "sphrase_manager.h"
// game share // game share
#include "game_share/brick_types.h" #include "game_share/brick_types.h"
@ -50,6 +51,7 @@ class COutpostBuildingSheet;
namespace NLGUI namespace NLGUI
{ {
class CViewRenderer; class CViewRenderer;
class CViewText;
} }
@ -589,8 +591,10 @@ protected:
// setup icon from phrases // setup icon from phrases
void setupDisplayAsPhrase(const std::vector<NLMISC::CSheetId> &bricks, const ucstring &phraseName); void setupDisplayAsPhrase(const std::vector<NLMISC::CSheetId> &bricks, const ucstring &phraseName);
// draw a number and returns the width of the drawn number //
sint32 drawNumber(sint32 x, sint32 y, sint32 wSheet, sint32 hSheet, NLMISC::CRGBA color, sint32 value, bool rightAlign=true); sint32 drawQuality(sint32 x, sint32 y, sint32 wSheet, sint32 hSheet, NLMISC::CRGBA color, sint32 value);
sint32 drawQuantity(sint32 x, sint32 y, sint32 wSheet, sint32 hSheet, NLMISC::CRGBA color, sint32 value);
sint32 drawSap(sint32 x, sint32 y, sint32 wSheet, sint32 hSheet, NLMISC::CRGBA color, sint32 value);
protected: protected:
@ -703,13 +707,15 @@ protected:
NLMISC::CCDBNodeLeaf *_GrayedLink; NLMISC::CCDBNodeLeaf *_GrayedLink;
// Macro or sentence String compiled as texture Ids and positions, from the _OptString. //
struct CCharBitmap CViewText *_SheetText;
{ CViewText *_QualityText;
sint32 X,Y; CViewText *_QuantityText;
sint32 Id; CViewText *_SapText;
}; // cached values for faster comparing
std::vector<CCharBitmap> _CharBitmaps; sint32 _QualityTextValue;
sint32 _QuantityTextValue;
sint32 _SapTextValue;
// Macro Id // Macro Id
sint32 _MacroID; sint32 _MacroID;
@ -753,6 +759,8 @@ private:
void resetAllTexIDs(); void resetAllTexIDs();
void setupInit(); void setupInit();
CViewText *createViewText(const std::string &id, sint fontSize);
void setupCharBitmaps(sint32 maxW, sint32 maxLine, sint32 maxWChar= 1000, bool topDown= false); void setupCharBitmaps(sint32 maxW, sint32 maxLine, sint32 maxWChar= 1000, bool topDown= false);
void resetCharBitmaps(); void resetCharBitmaps();
void displayCharBitmaps(sint32 rdrLayer, sint32 x, sint32 y, NLMISC::CRGBA color); void displayCharBitmaps(sint32 rdrLayer, sint32 x, sint32 y, NLMISC::CRGBA color);