From 64e54f24c1d923c074e1cc4f3442a82543827c63 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Thu, 14 Mar 2019 22:59:33 +0200 Subject: [PATCH] Changed: Form element styling --HG-- branch : develop --- code/nel/include/nel/gui/ctrl_text_button.h | 7 + code/nel/include/nel/gui/dbgroup_combo_box.h | 1 + code/nel/include/nel/gui/group_html.h | 8 ++ code/nel/include/nel/gui/group_menu.h | 3 + code/nel/src/gui/ctrl_text_button.cpp | 37 ++++++ code/nel/src/gui/dbgroup_combo_box.cpp | 9 ++ code/nel/src/gui/group_html.cpp | 133 ++++++++++++++++--- code/nel/src/gui/group_menu.cpp | 6 + 8 files changed, 188 insertions(+), 16 deletions(-) diff --git a/code/nel/include/nel/gui/ctrl_text_button.h b/code/nel/include/nel/gui/ctrl_text_button.h index 367e527f8..e88ec81e1 100644 --- a/code/nel/include/nel/gui/ctrl_text_button.h +++ b/code/nel/include/nel/gui/ctrl_text_button.h @@ -117,6 +117,13 @@ namespace NLGUI // Compute Size according to bitmap and Text (Ensure as big as possible button) 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); REFLECT_EXPORT_START(CCtrlTextButton, CCtrlBaseButton) diff --git a/code/nel/include/nel/gui/dbgroup_combo_box.h b/code/nel/include/nel/gui/dbgroup_combo_box.h index 87e6d758a..723afbdc0 100644 --- a/code/nel/include/nel/gui/dbgroup_combo_box.h +++ b/code/nel/include/nel/gui/dbgroup_combo_box.h @@ -85,6 +85,7 @@ namespace NLGUI // view text void setViewText(const ucstring & text); ucstring getViewText() const; + CViewText *getViewText(); void setTexture(uint i, const ucstring &texture); diff --git a/code/nel/include/nel/gui/group_html.h b/code/nel/include/nel/gui/group_html.h index 8b296f114..71d7b9ff0 100644 --- a/code/nel/include/nel/gui/group_html.h +++ b/code/nel/include/nel/gui/group_html.h @@ -33,6 +33,7 @@ typedef std::map TStyle; namespace NLGUI { class CCtrlButton; + class CCtrlTextButton; class CCtrlScroll; class CGroupList; class CGroupMenu; @@ -105,7 +106,9 @@ namespace NLGUI Height=-1; MaxWidth=-1; MaxHeight=-1; + BorderWidth=1; BackgroundColor=NLMISC::CRGBA::Black; + BackgroundColorOver=NLMISC::CRGBA::Black; } uint FontSize; uint FontWeight; @@ -120,7 +123,9 @@ namespace NLGUI sint32 Height; sint32 MaxWidth; sint32 MaxHeight; + sint32 BorderWidth; NLMISC::CRGBA BackgroundColor; + NLMISC::CRGBA BackgroundColorOver; }; // ImageDownload system @@ -857,6 +862,9 @@ namespace NLGUI void setImage(CViewBase *view, const std::string &file, const TImageType type); void setImageSize(CViewBase *view, const CStyleParams &style = CStyleParams()); + void setTextButtonStyle(CCtrlTextButton *ctrlButton, const CStyleParams &style); + void setTextStyle(CViewText *pVT, const CStyleParams &style); + // BnpDownload system void initBnpDownload(); void checkBnpDownload(); diff --git a/code/nel/include/nel/gui/group_menu.h b/code/nel/include/nel/gui/group_menu.h index d4f940088..cfe91f7f9 100644 --- a/code/nel/include/nel/gui/group_menu.h +++ b/code/nel/include/nel/gui/group_menu.h @@ -351,6 +351,9 @@ namespace NLGUI void setMinW(sint32 minW); void setMinH(sint32 minH); + // change fontsize for new menu items + void setFontSize(uint32 fontSize); + // Gray a line on the RootMenu void setGrayedLine(uint line, bool g); diff --git a/code/nel/src/gui/ctrl_text_button.cpp b/code/nel/src/gui/ctrl_text_button.cpp index 9775b1b07..d10dfa0c9 100644 --- a/code/nel/src/gui/ctrl_text_button.cpp +++ b/code/nel/src/gui/ctrl_text_button.cpp @@ -728,6 +728,43 @@ namespace NLGUI 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 () { diff --git a/code/nel/src/gui/dbgroup_combo_box.cpp b/code/nel/src/gui/dbgroup_combo_box.cpp index 2afd8c570..5893c0b72 100644 --- a/code/nel/src/gui/dbgroup_combo_box.cpp +++ b/code/nel/src/gui/dbgroup_combo_box.cpp @@ -473,6 +473,12 @@ namespace NLGUI return _ViewText->getText(); } + // *************************************************************************** + CViewText *CDBGroupComboBox::getViewText() + { + return _ViewText; + } + // *************************************************************************** std::string CDBGroupComboBox::getSelectionText() const { @@ -633,6 +639,9 @@ namespace NLGUI { nlassert(groupMenu); + if (_ViewText) + groupMenu->setFontSize(_ViewText->getFontSize()); + // Setup the menu with combo action. groupMenu->reset(); for(uint i=0; i 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 string CGroupHTML::localImageName(const string &url) { @@ -1556,6 +1610,10 @@ namespace NLGUI _Style.TextColor = LinkColor; _Style.Underlined = true; _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]) getStyleParams(value[HTML_A_STYLE], _Style); @@ -1956,6 +2014,13 @@ namespace NLGUI _Style.FontSize = TextFontSize; _Style.FontWeight = FONT_WEIGHT_NORMAL; _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 if (present[MY_HTML_INPUT_GLOBAL_COLOR]) @@ -2058,6 +2123,8 @@ namespace NLGUI } ctrlButton->setText(ucstring::makeFromUtf8(text)); + + setTextButtonStyle(ctrlButton, _Style); } getParagraph()->addChild (buttonGroup); paragraphChange (); @@ -2226,6 +2293,7 @@ namespace NLGUI sb->setMinH(style.Height); sb->setMaxVisibleLine(size); + sb->setFontSize(style.FontSize); } entry.SelectBox = sb; @@ -2234,6 +2302,14 @@ namespace NLGUI { CDBGroupComboBox *cb = addComboBox(DefaultFormSelectGroup, name.c_str()); entry.ComboBox = cb; + + if (cb) + { + // create view text + cb->updateCoords(); + if (cb->getViewText()) + setTextStyle(cb->getViewText(), style); + } } _Forms.back().Entries.push_back (entry); } @@ -2460,6 +2536,9 @@ namespace NLGUI _Style.FontOblique = false; _Style.FontSize = TextFontSize; _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]) getStyleParams(value[MY_HTML_TEXTAREA_STYLE], _Style); @@ -4494,6 +4573,8 @@ namespace NLGUI // Translate the tooltip ctrlButton->setDefaultContextHelp(ucstring::makeFromUtf8(getLinkTitle())); ctrlButton->setText(tmpStr); + + setTextButtonStyle(ctrlButton, _Style); } getParagraph()->addChild (buttonGroup); paragraphChange (); @@ -4516,23 +4597,10 @@ namespace NLGUI } } 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->setMultiLine(true); newLink->setModulateGlobalColor(_Style.GlobalColor); - if (_Style.TextShadow.Enabled) - { - newLink->setShadow(true); - newLink->setShadowColor(_Style.TextShadow.Color); - newLink->setShadowOutline(_Style.TextShadow.Outline); - newLink->setShadowOffset(_Style.TextShadow.X, _Style.TextShadow.Y); - } + setTextStyle(newLink, _Style); // newLink->setLineAtBottom (true); registerAnchor(newLink); @@ -4638,6 +4706,10 @@ namespace NLGUI _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 ? std::vector > templateParams; templateParams.push_back (std::pair ("w", toString (cols*_Style.FontSize))); @@ -4675,7 +4747,18 @@ namespace NLGUI // Set the content CGroupEditBox *eb = dynamic_cast(textArea->getGroup("eb")); if (eb) + { eb->setInputString(decodeHTMLEntities(content)); + if (_Style.BackgroundColor.A > 0) + { + CViewBitmap *bg = dynamic_cast(eb->getView("bg")); + if (bg) + { + bg->setTexture("blank.tga"); + bg->setColor(_Style.BackgroundColor); + } + } + } textArea->invalidateCoords(); getParagraph()->addChild (textArea); @@ -6327,6 +6410,16 @@ namespace NLGUI // second pass: rest of style 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->second == "inherit") @@ -6581,10 +6674,18 @@ namespace NLGUI if (it->first == "background-color") { if (it->second == "inherit") - style.BackgroundColor = current.backgroundColor; + style.BackgroundColor = current.BackgroundColor; else 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); + } } } diff --git a/code/nel/src/gui/group_menu.cpp b/code/nel/src/gui/group_menu.cpp index 7d002cfd6..d8b3452ed 100644 --- a/code/nel/src/gui/group_menu.cpp +++ b/code/nel/src/gui/group_menu.cpp @@ -2561,6 +2561,12 @@ namespace NLGUI } } + // ------------------------------------------------------------------------------------------------ + void CGroupMenu::setFontSize(uint fontSize) + { + _FontSize = fontSize; + } + // ------------------------------------------------------------------------------------------------ uint CGroupMenu::getNumLine() const {