forked from OpenMW/openmw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add imported font colors from openmw.cfg to MyGUI plugin
- Loading branch information
scrawl
committed
Sep 24, 2014
1 parent
62ab358
commit 1afcc7a
Showing
6 changed files
with
135 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "tags.hpp" | ||
|
||
#include <MyGUI_Colour.h> | ||
|
||
namespace Gui | ||
{ | ||
|
||
bool replaceTag(const MyGUI::UString& tag, MyGUI::UString& out, const std::map<std::string,std::string>& fallbackSettings) | ||
{ | ||
std::string fontcolour = "fontcolour="; | ||
size_t fontcolourLength = fontcolour.length(); | ||
|
||
std::string fontcolourhtml = "fontcolourhtml="; | ||
size_t fontcolourhtmlLength = fontcolourhtml.length(); | ||
|
||
if (tag.compare(0, fontcolourLength, fontcolour) == 0) | ||
{ | ||
std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourLength); | ||
std::map<std::string, std::string>::const_iterator it = fallbackSettings.find(fallbackName); | ||
if (it == fallbackSettings.end()) | ||
throw std::runtime_error("Unknown fallback name: " + fallbackName); | ||
std::string str = it->second; | ||
|
||
std::string ret[3]; | ||
unsigned int j=0; | ||
for(unsigned int i=0;i<str.length();++i){ | ||
if(str[i]==',') j++; | ||
else if (str[i] != ' ') ret[j]+=str[i]; | ||
} | ||
MyGUI::Colour col (MyGUI::utility::parseInt(ret[0])/255.f,MyGUI::utility::parseInt(ret[1])/255.f,MyGUI::utility::parseInt(ret[2])/255.f); | ||
out = col.print(); | ||
return true; | ||
} | ||
else if (tag.compare(0, fontcolourhtmlLength, fontcolourhtml) == 0) | ||
{ | ||
std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourhtmlLength); | ||
std::map<std::string, std::string>::const_iterator it = fallbackSettings.find(fallbackName); | ||
if (it == fallbackSettings.end()) | ||
throw std::runtime_error("Unknown fallback name: " + fallbackName); | ||
std::string str = it->second; | ||
|
||
std::string ret[3]; | ||
unsigned int j=0; | ||
for(unsigned int i=0;i<str.length();++i){ | ||
if(str[i]==',') j++; | ||
else if (str[i] != ' ') ret[j]+=str[i]; | ||
} | ||
std::stringstream html; | ||
html << "#" << std::hex << MyGUI::utility::parseInt(ret[0]) << MyGUI::utility::parseInt(ret[1]) << MyGUI::utility::parseInt(ret[2]); | ||
out = html.str(); | ||
return true; | ||
} | ||
return false; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef OPENMW_WIDGETS_TAGS_H | ||
#define OPENMW_WIDGETS_TAGS_H | ||
|
||
#include <MyGUI_UString.h> | ||
#include <string> | ||
#include <map> | ||
|
||
namespace Gui | ||
{ | ||
|
||
/// Try to replace a tag. Returns true on success and writes the result to \a out. | ||
bool replaceTag (const MyGUI::UString& tag, MyGUI::UString& out, const std::map<std::string,std::string>& fallbackSettings); | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters