Changed: Form element styling

--HG--
branch : develop
This commit is contained in:
Nimetu 2019-03-14 22:59:33 +02:00
parent 69f73ba28b
commit 64e54f24c1
8 changed files with 188 additions and 16 deletions

View file

@ -117,6 +117,13 @@ namespace NLGUI
// Compute Size according to bitmap and Text (Ensure as big as possible button) // Compute Size according to bitmap and Text (Ensure as big as possible button)
sint32 getWMax() const; sint32 getWMax() const;
// Set texture directly without _l.tga, _m.tga, _r.tga convention
// Texture size is only read from normal textures
// If updateHeight == false, then _BmpH will keep its value
void setTexture(const std::string &l, const std::string &m, const std::string &r, bool updateHeight = true);
void setTexturePushed(const std::string &l, const std::string &m, const std::string &r);
void setTextureOver(const std::string &l, const std::string &m, const std::string &r);
int luaGetViewText(CLuaState &ls); int luaGetViewText(CLuaState &ls);
REFLECT_EXPORT_START(CCtrlTextButton, CCtrlBaseButton) REFLECT_EXPORT_START(CCtrlTextButton, CCtrlBaseButton)

View file

@ -85,6 +85,7 @@ namespace NLGUI
// view text // view text
void setViewText(const ucstring & text); void setViewText(const ucstring & text);
ucstring getViewText() const; ucstring getViewText() const;
CViewText *getViewText();
void setTexture(uint i, const ucstring &texture); void setTexture(uint i, const ucstring &texture);

View file

@ -33,6 +33,7 @@ typedef std::map<std::string, std::string> TStyle;
namespace NLGUI namespace NLGUI
{ {
class CCtrlButton; class CCtrlButton;
class CCtrlTextButton;
class CCtrlScroll; class CCtrlScroll;
class CGroupList; class CGroupList;
class CGroupMenu; class CGroupMenu;
@ -105,7 +106,9 @@ namespace NLGUI
Height=-1; Height=-1;
MaxWidth=-1; MaxWidth=-1;
MaxHeight=-1; MaxHeight=-1;
BorderWidth=1;
BackgroundColor=NLMISC::CRGBA::Black; BackgroundColor=NLMISC::CRGBA::Black;
BackgroundColorOver=NLMISC::CRGBA::Black;
} }
uint FontSize; uint FontSize;
uint FontWeight; uint FontWeight;
@ -120,7 +123,9 @@ namespace NLGUI
sint32 Height; sint32 Height;
sint32 MaxWidth; sint32 MaxWidth;
sint32 MaxHeight; sint32 MaxHeight;
sint32 BorderWidth;
NLMISC::CRGBA BackgroundColor; NLMISC::CRGBA BackgroundColor;
NLMISC::CRGBA BackgroundColorOver;
}; };
// ImageDownload system // ImageDownload system
@ -857,6 +862,9 @@ namespace NLGUI
void setImage(CViewBase *view, const std::string &file, const TImageType type); void setImage(CViewBase *view, const std::string &file, const TImageType type);
void setImageSize(CViewBase *view, const CStyleParams &style = CStyleParams()); void setImageSize(CViewBase *view, const CStyleParams &style = CStyleParams());
void setTextButtonStyle(CCtrlTextButton *ctrlButton, const CStyleParams &style);
void setTextStyle(CViewText *pVT, const CStyleParams &style);
// BnpDownload system // BnpDownload system
void initBnpDownload(); void initBnpDownload();
void checkBnpDownload(); void checkBnpDownload();

View file

@ -351,6 +351,9 @@ namespace NLGUI
void setMinW(sint32 minW); void setMinW(sint32 minW);
void setMinH(sint32 minH); void setMinH(sint32 minH);
// change fontsize for new menu items
void setFontSize(uint32 fontSize);
// Gray a line on the RootMenu // Gray a line on the RootMenu
void setGrayedLine(uint line, bool g); void setGrayedLine(uint line, bool g);

View file

@ -728,6 +728,43 @@ namespace NLGUI
return true; return true;
} }
// ***************************************************************************
void CCtrlTextButton::setTexture(const std::string &l, const std::string &m, const std::string &r, bool updateHeight)
{
nlctassert(NumTexture==3);
_TextureIdNormal[0].setTexture(l.c_str());
_TextureIdNormal[1].setTexture(m.c_str());
_TextureIdNormal[2].setTexture(r.c_str());
sint32 newH;
// Compute Bmp Sizes
CViewRenderer &rVR = *CViewRenderer::getInstance();
rVR.getTextureSizeFromId(_TextureIdNormal[0], _BmpLeftW, newH);
rVR.getTextureSizeFromId(_TextureIdNormal[1], _BmpMiddleW, newH);
rVR.getTextureSizeFromId(_TextureIdNormal[2], _BmpRightW, newH);
if (updateHeight) _BmpH = newH;
}
// ***************************************************************************
void CCtrlTextButton::setTexturePushed(const std::string &l, const std::string &m, const std::string &r)
{
nlctassert(NumTexture==3);
_TextureIdPushed[0].setTexture(l.c_str());
_TextureIdPushed[1].setTexture(m.c_str());
_TextureIdPushed[2].setTexture(r.c_str());
}
// ***************************************************************************
void CCtrlTextButton::setTextureOver(const std::string &l, const std::string &m, const std::string &r)
{
nlctassert(NumTexture==3);
_TextureIdOver[0].setTexture(l.c_str());
_TextureIdOver[1].setTexture(m.c_str());
_TextureIdOver[2].setTexture(r.c_str());
}
// *************************************************************************** // ***************************************************************************
void CCtrlTextButton::draw () void CCtrlTextButton::draw ()
{ {

View file

@ -473,6 +473,12 @@ namespace NLGUI
return _ViewText->getText(); return _ViewText->getText();
} }
// ***************************************************************************
CViewText *CDBGroupComboBox::getViewText()
{
return _ViewText;
}
// *************************************************************************** // ***************************************************************************
std::string CDBGroupComboBox::getSelectionText() const std::string CDBGroupComboBox::getSelectionText() const
{ {
@ -633,6 +639,9 @@ namespace NLGUI
{ {
nlassert(groupMenu); nlassert(groupMenu);
if (_ViewText)
groupMenu->setFontSize(_ViewText->getFontSize());
// Setup the menu with combo action. // Setup the menu with combo action.
groupMenu->reset(); groupMenu->reset();
for(uint i=0; i<getNumTexts(); i++) for(uint i=0; i<getNumTexts(); i++)

View file

@ -382,6 +382,60 @@ namespace NLGUI
} }
} }
void CGroupHTML::setTextButtonStyle(CCtrlTextButton *ctrlButton, const CStyleParams &style)
{
// this will also set size for <a class="ryzom-ui-button"> treating it like "display: inline-block;"
if (style.Width > 0) ctrlButton->setWMin(_Style.Width);
if (style.Height > 0) ctrlButton->setHMin(_Style.Height);
CViewText *pVT = ctrlButton->getViewText();
if (pVT)
{
setTextStyle(pVT, _Style);
}
if (_Style.BackgroundColor.A > 0)
{
if (_Style.BackgroundColorOver.A == 0)
_Style.BackgroundColorOver = _Style.BackgroundColor;
ctrlButton->setColor(_Style.BackgroundColor);
ctrlButton->setColorOver(_Style.BackgroundColorOver);
ctrlButton->setTexture("", "blank.tga", "", false);
ctrlButton->setTextureOver("", "blank.tga", "");
ctrlButton->setProperty("force_text_over", "true");
}
else if (_Style.BackgroundColorOver.A > 0)
{
ctrlButton->setColorOver(_Style.BackgroundColorOver);
ctrlButton->setProperty("force_text_over", "true");
ctrlButton->setTextureOver("blank.tga", "blank.tga", "blank.tga");
}
}
void CGroupHTML::setTextStyle(CViewText *pVT, const CStyleParams &style)
{
if (pVT)
{
pVT->setFontSize(style.FontSize);
pVT->setColor(style.TextColor);
pVT->setColor(style.TextColor);
pVT->setFontName(style.FontFamily);
pVT->setFontSize(style.FontSize);
pVT->setEmbolden(style.FontWeight >= FONT_WEIGHT_BOLD);
pVT->setOblique(style.FontOblique);
pVT->setUnderlined(style.Underlined);
pVT->setStrikeThrough(style.StrikeThrough);
if (style.TextShadow.Enabled)
{
pVT->setShadow(true);
pVT->setShadowColor(style.TextShadow.Color);
pVT->setShadowOutline(style.TextShadow.Outline);
pVT->setShadowOffset(style.TextShadow.X, style.TextShadow.Y);
}
}
}
// Get an url and return the local filename with the path where the url image should be // Get an url and return the local filename with the path where the url image should be
string CGroupHTML::localImageName(const string &url) string CGroupHTML::localImageName(const string &url)
{ {
@ -1556,6 +1610,10 @@ namespace NLGUI
_Style.TextColor = LinkColor; _Style.TextColor = LinkColor;
_Style.Underlined = true; _Style.Underlined = true;
_Style.GlobalColor = LinkColorGlobalColor; _Style.GlobalColor = LinkColorGlobalColor;
_Style.BackgroundColor.A = 0;
_Style.BackgroundColorOver.A = 0;
_Style.Width = -1;
_Style.Height = -1;
if (present[HTML_A_STYLE] && value[HTML_A_STYLE]) if (present[HTML_A_STYLE] && value[HTML_A_STYLE])
getStyleParams(value[HTML_A_STYLE], _Style); getStyleParams(value[HTML_A_STYLE], _Style);
@ -1956,6 +2014,13 @@ namespace NLGUI
_Style.FontSize = TextFontSize; _Style.FontSize = TextFontSize;
_Style.FontWeight = FONT_WEIGHT_NORMAL; _Style.FontWeight = FONT_WEIGHT_NORMAL;
_Style.FontOblique = false; _Style.FontOblique = false;
_Style.TextShadow = STextShadow(true);
_Style.Width = -1;
_Style.Height = -1;
// by default background texture is transparent,
// using alpha value to decide if to change it to 'blank.tga' for coloring
_Style.BackgroundColor.A = 0;
_Style.BackgroundColorOver.A = 0;
// Global color flag // Global color flag
if (present[MY_HTML_INPUT_GLOBAL_COLOR]) if (present[MY_HTML_INPUT_GLOBAL_COLOR])
@ -2058,6 +2123,8 @@ namespace NLGUI
} }
ctrlButton->setText(ucstring::makeFromUtf8(text)); ctrlButton->setText(ucstring::makeFromUtf8(text));
setTextButtonStyle(ctrlButton, _Style);
} }
getParagraph()->addChild (buttonGroup); getParagraph()->addChild (buttonGroup);
paragraphChange (); paragraphChange ();
@ -2226,6 +2293,7 @@ namespace NLGUI
sb->setMinH(style.Height); sb->setMinH(style.Height);
sb->setMaxVisibleLine(size); sb->setMaxVisibleLine(size);
sb->setFontSize(style.FontSize);
} }
entry.SelectBox = sb; entry.SelectBox = sb;
@ -2234,6 +2302,14 @@ namespace NLGUI
{ {
CDBGroupComboBox *cb = addComboBox(DefaultFormSelectGroup, name.c_str()); CDBGroupComboBox *cb = addComboBox(DefaultFormSelectGroup, name.c_str());
entry.ComboBox = cb; entry.ComboBox = cb;
if (cb)
{
// create view text
cb->updateCoords();
if (cb->getViewText())
setTextStyle(cb->getViewText(), style);
}
} }
_Forms.back().Entries.push_back (entry); _Forms.back().Entries.push_back (entry);
} }
@ -2460,6 +2536,9 @@ namespace NLGUI
_Style.FontOblique = false; _Style.FontOblique = false;
_Style.FontSize = TextFontSize; _Style.FontSize = TextFontSize;
_Style.TextShadow = STextShadow(true); _Style.TextShadow = STextShadow(true);
_Style.Width = -1;
_Style.Height = -1;
_Style.BackgroundColor.A = 0;
if (present[MY_HTML_TEXTAREA_STYLE] && value[MY_HTML_TEXTAREA_STYLE]) if (present[MY_HTML_TEXTAREA_STYLE] && value[MY_HTML_TEXTAREA_STYLE])
getStyleParams(value[MY_HTML_TEXTAREA_STYLE], _Style); getStyleParams(value[MY_HTML_TEXTAREA_STYLE], _Style);
@ -4494,6 +4573,8 @@ namespace NLGUI
// Translate the tooltip // Translate the tooltip
ctrlButton->setDefaultContextHelp(ucstring::makeFromUtf8(getLinkTitle())); ctrlButton->setDefaultContextHelp(ucstring::makeFromUtf8(getLinkTitle()));
ctrlButton->setText(tmpStr); ctrlButton->setText(tmpStr);
setTextButtonStyle(ctrlButton, _Style);
} }
getParagraph()->addChild (buttonGroup); getParagraph()->addChild (buttonGroup);
paragraphChange (); paragraphChange ();
@ -4516,23 +4597,10 @@ namespace NLGUI
} }
} }
newLink->setText(tmpStr); newLink->setText(tmpStr);
newLink->setColor(_Style.TextColor);
newLink->setFontName(_Style.FontFamily);
newLink->setFontSize(_Style.FontSize);
newLink->setEmbolden(embolden);
newLink->setOblique(_Style.FontOblique);
newLink->setUnderlined(_Style.Underlined);
newLink->setStrikeThrough(_Style.StrikeThrough);
newLink->setMultiLineSpace((uint)((float)(_Style.FontSize)*LineSpaceFontFactor)); newLink->setMultiLineSpace((uint)((float)(_Style.FontSize)*LineSpaceFontFactor));
newLink->setMultiLine(true); newLink->setMultiLine(true);
newLink->setModulateGlobalColor(_Style.GlobalColor); newLink->setModulateGlobalColor(_Style.GlobalColor);
if (_Style.TextShadow.Enabled) setTextStyle(newLink, _Style);
{
newLink->setShadow(true);
newLink->setShadowColor(_Style.TextShadow.Color);
newLink->setShadowOutline(_Style.TextShadow.Outline);
newLink->setShadowOffset(_Style.TextShadow.X, _Style.TextShadow.Y);
}
// newLink->setLineAtBottom (true); // newLink->setLineAtBottom (true);
registerAnchor(newLink); registerAnchor(newLink);
@ -4638,6 +4706,10 @@ namespace NLGUI
_CurrentViewLink = NULL; _CurrentViewLink = NULL;
{ {
// override cols/rows values from style
if (_Style.Width > 0) cols = _Style.Width / _Style.FontSize;
if (_Style.Height > 0) rows = _Style.Height / _Style.FontSize;
// Not added ? // Not added ?
std::vector<std::pair<std::string,std::string> > templateParams; std::vector<std::pair<std::string,std::string> > templateParams;
templateParams.push_back (std::pair<std::string,std::string> ("w", toString (cols*_Style.FontSize))); templateParams.push_back (std::pair<std::string,std::string> ("w", toString (cols*_Style.FontSize)));
@ -4675,7 +4747,18 @@ namespace NLGUI
// Set the content // Set the content
CGroupEditBox *eb = dynamic_cast<CGroupEditBox*>(textArea->getGroup("eb")); CGroupEditBox *eb = dynamic_cast<CGroupEditBox*>(textArea->getGroup("eb"));
if (eb) if (eb)
{
eb->setInputString(decodeHTMLEntities(content)); eb->setInputString(decodeHTMLEntities(content));
if (_Style.BackgroundColor.A > 0)
{
CViewBitmap *bg = dynamic_cast<CViewBitmap*>(eb->getView("bg"));
if (bg)
{
bg->setTexture("blank.tga");
bg->setColor(_Style.BackgroundColor);
}
}
}
textArea->invalidateCoords(); textArea->invalidateCoords();
getParagraph()->addChild (textArea); getParagraph()->addChild (textArea);
@ -6327,6 +6410,16 @@ namespace NLGUI
// second pass: rest of style // second pass: rest of style
for (it=styles.begin(); it != styles.end(); ++it) for (it=styles.begin(); it != styles.end(); ++it)
{ {
if (it->first == "border")
{
sint32 b;
if (it->second == "none")
style.BorderWidth = 0;
else
if (fromString(it->second, b))
style.BorderWidth = b;
}
else
if (it->first == "font-style") if (it->first == "font-style")
{ {
if (it->second == "inherit") if (it->second == "inherit")
@ -6581,10 +6674,18 @@ namespace NLGUI
if (it->first == "background-color") if (it->first == "background-color")
{ {
if (it->second == "inherit") if (it->second == "inherit")
style.BackgroundColor = current.backgroundColor; style.BackgroundColor = current.BackgroundColor;
else else
scanHTMLColor(it->second.c_str(), style.BackgroundColor); scanHTMLColor(it->second.c_str(), style.BackgroundColor);
} }
else
if (it->first == "-ryzom-background-color-over")
{
if (it->second == "inherit")
style.BackgroundColorOver = current.BackgroundColorOver;
else
scanHTMLColor(it->second.c_str(), style.BackgroundColorOver);
}
} }
} }

View file

@ -2561,6 +2561,12 @@ namespace NLGUI
} }
} }
// ------------------------------------------------------------------------------------------------
void CGroupMenu::setFontSize(uint fontSize)
{
_FontSize = fontSize;
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
uint CGroupMenu::getNumLine() const uint CGroupMenu::getNumLine() const
{ {