Fix text size and underline in dialogxml #592
@@ -2,7 +2,7 @@
|
|||||||
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
|
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
|
||||||
<dialog defbtn='cancel'>
|
<dialog defbtn='cancel'>
|
||||||
<pict type='dlog' num='2' top='8' left='8'/>
|
<pict type='dlog' num='2' top='8' left='8'/>
|
||||||
<text size='large' top='2' left='48' width='248' height='33'>
|
<text size='large' top='8' left='48' width='248' height='33'>
|
||||||
This item will be gone forever. Still drop it?
|
This item will be gone forever. Still drop it?
|
||||||
</text>
|
</text>
|
||||||
<button name='cancel' type='regular' def-key='esc' top='42' left='238'>Cancel</button>
|
<button name='cancel' type='regular' def-key='esc' top='42' left='238'>Cancel</button>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<!-- OK button -->
|
<!-- OK button -->
|
||||||
<field name='text' top='34' left='55' width='293' height='98'/>
|
<field name='text' top='34' left='55' width='293' height='98'/>
|
||||||
<button name='cancel' type='regular' top='141' left='222' def-key='esc'>Cancel</button>
|
<button name='cancel' type='regular' top='141' left='222' def-key='esc'>Cancel</button>
|
||||||
<text top='142' left='7' width='198' height='15'>Use a '|' to indicate a line break.</text>
|
<text top='142' left='7' width='198' height='15' show-pipes='true'>Use a '|' to indicate a line break.</text>
|
||||||
<text name='num' top='8' left='287' width='37' height='14'/>
|
<text name='num' top='8' left='287' width='37' height='14'/>
|
||||||
<pict name='pic' type='dlog' num='16' top='8' left='12'/>
|
<pict name='pic' type='dlog' num='16' top='8' left='12'/>
|
||||||
<text size='large' top='6' left='50' width='138' height='17'>Editing Sign</text>
|
<text size='large' top='6' left='50' width='138' height='17'>Editing Sign</text>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
<led name='target-adjacent' relative='pos-in pos' anchor='keyshift-head' top='4' left='15'>Select adjacent tiles</led>
|
<led name='target-adjacent' relative='pos-in pos' anchor='keyshift-head' top='4' left='15'>Select adjacent tiles</led>
|
||||||
<led name='screen-shift' relative='pos pos-in' anchor='target-adjacent' top='0' left='15'>Move the screen</led>
|
<led name='screen-shift' relative='pos pos-in' anchor='target-adjacent' top='0' left='15'>Move the screen</led>
|
||||||
</group>
|
</group>
|
||||||
<text name='keyshift-note' size='large' relative='pos-in pos' anchor='keyshift-head' top='20' left='15' width='300' height='17'>(Holding Shift while using directional keys will do the opposite.)</text>
|
<text name='keyshift-note' relative='pos-in pos' anchor='keyshift-head' top='20' left='15' width='300' height='17'>(Holding Shift while using directional keys will do the opposite.)</text>
|
||||||
<text name='misc-head' size='large' relative='neg pos' anchor='keyshift-note' top='15' left='15' width='182' height='17'>Miscellaneous:</text>
|
<text name='misc-head' size='large' relative='neg pos' anchor='keyshift-note' top='15' left='15' width='182' height='17'>Miscellaneous:</text>
|
||||||
<led name='nosound' relative='pos-in pos' anchor='misc-head' top='6' left='15'>No Sounds</led>
|
<led name='nosound' relative='pos-in pos' anchor='misc-head' top='6' left='15'>No Sounds</led>
|
||||||
<led name='repeatdesc' relative='pos-in pos' rel-anchor='prev' top='10' left='0'>Show room descriptions more than once</led>
|
<led name='repeatdesc' relative='pos-in pos' rel-anchor='prev' top='10' left='0'>Show room descriptions more than once</led>
|
||||||
|
|||||||
@@ -125,11 +125,18 @@
|
|||||||
</xs:attribute>
|
</xs:attribute>
|
||||||
<xs:attribute name="size" default="small">
|
<xs:attribute name="size" default="small">
|
||||||
<xs:simpleType>
|
<xs:simpleType>
|
||||||
<xs:restriction base="xs:token">
|
<xs:union>
|
||||||
<xs:enumeration value="small"/>
|
<xs:simpleType>
|
||||||
<xs:enumeration value="large"/>
|
<xs:restriction base="xs:token">
|
||||||
<xs:enumeration value="title"/>
|
<xs:enumeration value="small"/>
|
||||||
</xs:restriction>
|
<xs:enumeration value="large"/>
|
||||||
|
<xs:enumeration value="title"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
<xs:simpleType>
|
||||||
|
<xs:restriction base="xs:integer"/>
|
||||||
|
</xs:simpleType>
|
||||||
|
</xs:union>
|
||||||
</xs:simpleType>
|
</xs:simpleType>
|
||||||
</xs:attribute>
|
</xs:attribute>
|
||||||
<xs:attribute name="color"/>
|
<xs:attribute name="color"/>
|
||||||
@@ -179,6 +186,7 @@
|
|||||||
</xs:restriction>
|
</xs:restriction>
|
||||||
</xs:simpleType>
|
</xs:simpleType>
|
||||||
</xs:attribute>
|
</xs:attribute>
|
||||||
|
<xs:attribute name="show-pipes" type="xs:boolean" default="false"/>
|
||||||
<xs:attribute ref="def-key"/>
|
<xs:attribute ref="def-key"/>
|
||||||
<xs:attribute name="fromlist" default="none" type="xs:string"/>
|
<xs:attribute name="fromlist" default="none" type="xs:string"/>
|
||||||
<xs:attributeGroup ref="rect-size"/>
|
<xs:attributeGroup ref="rect-size"/>
|
||||||
|
|||||||
@@ -1152,12 +1152,14 @@ void preview_dialog_xml() {
|
|||||||
fs::path dialog_xml = nav_get_rsrc({"xml"});
|
fs::path dialog_xml = nav_get_rsrc({"xml"});
|
||||||
std::unique_ptr<DialogDefn> defn(load_dialog_defn(dialog_xml));
|
std::unique_ptr<DialogDefn> defn(load_dialog_defn(dialog_xml));
|
||||||
cDialog dialog(*defn);
|
cDialog dialog(*defn);
|
||||||
// Make every control's click event close the dialog
|
// Make every clickable control's click event close the dialog
|
||||||
for (auto control : dialog){
|
for (auto control : dialog){
|
||||||
control.second->attachClickHandler([](cDialog& me, std::string item_hit, eKeyMod mod) -> bool {
|
try{
|
||||||
me.toast(false);
|
control.second->attachClickHandler([](cDialog& me, std::string item_hit, eKeyMod mod) -> bool {
|
||||||
return true;
|
me.toast(false);
|
||||||
});
|
return true;
|
||||||
|
});
|
||||||
|
}catch(...){}
|
||||||
}
|
}
|
||||||
dialog.run();
|
dialog.run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -535,7 +535,16 @@ bool cControl::parseAttribute(ticpp::Attribute& attr, std::string tagName, std::
|
|||||||
if(val == "small") setFormat(TXT_SIZE, 10);
|
if(val == "small") setFormat(TXT_SIZE, 10);
|
||||||
else if(val == "large") setFormat(TXT_SIZE, 12);
|
else if(val == "large") setFormat(TXT_SIZE, 12);
|
||||||
else if(val == "title") setFormat(TXT_SIZE, 18);
|
else if(val == "title") setFormat(TXT_SIZE, 18);
|
||||||
else throw xBadVal(tagName, name, val, attr.Row(), attr.Column(), fname);
|
else{
|
||||||
|
auto err = xBadVal(tagName, name, val, attr.Row(), attr.Column(), fname);
|
||||||
|
try{
|
||||||
|
setFormat(TXT_SIZE, std::stoi(val));
|
||||||
|
}catch(std::invalid_argument& e){
|
||||||
|
throw err;
|
||||||
|
}catch(std::out_of_range& e){
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(name == "wrap" && canFormat(TXT_WRAP)) {
|
if(name == "wrap" && canFormat(TXT_WRAP)) {
|
||||||
|
|||||||
@@ -65,6 +65,9 @@ bool cTextMsg::parseAttribute(ticpp::Attribute& attr, std::string tagName, std::
|
|||||||
else if(val == "left") right_align = false;
|
else if(val == "left") right_align = false;
|
||||||
else throw xBadVal(tagName, attr.Name(), val, attr.Row(), attr.Column(), fname);
|
else throw xBadVal(tagName, attr.Name(), val, attr.Row(), attr.Column(), fname);
|
||||||
return true;
|
return true;
|
||||||
|
}else if(attr.Name() == "show-pipes"){
|
||||||
|
style.showPipes = str_to_bool(attr.Value());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return cControl::parseAttribute(attr, tagName, fname);
|
return cControl::parseAttribute(attr, tagName, fname);
|
||||||
}
|
}
|
||||||
@@ -130,14 +133,13 @@ void cTextMsg::calculate_layout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cTextMsg::recalcRect() {
|
void cTextMsg::recalcRect() {
|
||||||
|
style.pointSize = textSize;
|
||||||
|
style.underline = underlined;
|
||||||
|
style.font = textFont;
|
||||||
if(fixedWidth && fixedHeight){
|
if(fixedWidth && fixedHeight){
|
||||||
calculate_layout();
|
calculate_layout();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
TextStyle style;
|
|
||||||
style.font = textFont;
|
|
||||||
style.pointSize = textSize;
|
|
||||||
style.underline = underlined;
|
|
||||||
style.lineHeight = textSize + 2;
|
style.lineHeight = textSize + 2;
|
||||||
std::string test = getText();
|
std::string test = getText();
|
||||||
size_t lines = 1, cur_line_chars = 0, max_line_chars = 0;
|
size_t lines = 1, cur_line_chars = 0, max_line_chars = 0;
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ The `<text>` tag accepts the following attributes:
|
|||||||
|
|
||||||
* `framed` - See **Common Attributes** above. Defaults to `false`.
|
* `framed` - See **Common Attributes** above. Defaults to `false`.
|
||||||
* `outline` - See **Common Attributes** above.
|
* `outline` - See **Common Attributes** above.
|
||||||
|
* `show-pipes` - If true the | character will appear literally.
|
||||||
* `underline` - If true, the text will be underlined.
|
* `underline` - If true, the text will be underlined.
|
||||||
* `align` - `right` or `left`. Defaults to `left`.
|
* `align` - `right` or `left`. Defaults to `left`.
|
||||||
* `fromlist`, `font`, `size`, `color`, `colour`, `def-key` -
|
* `fromlist`, `font`, `size`, `color`, `colour`, `def-key` -
|
||||||
@@ -343,9 +344,7 @@ values.
|
|||||||
`bold`, `dungeon`, `maidenword`. It defaults to `bold`. The latter two
|
`bold`, `dungeon`, `maidenword`. It defaults to `bold`. The latter two
|
||||||
options are fantasy-style scripts such as that used for the conversation
|
options are fantasy-style scripts such as that used for the conversation
|
||||||
screen.
|
screen.
|
||||||
* `size` - Although the dialog engine supports any font size, the XML
|
* `size` - The point size of the text. An integer, or one of three presets: `small` (10pt), `large` (12pt), and `title` (18pt).
|
||||||
specification simplifies it to three keywords: `small`, `large`, and
|
|
||||||
`title`, representing 10pt, 12pt, and 18pt font, respectively.
|
|
||||||
* `color` or `colour` - This is the only truly unrestricted attribute,
|
* `color` or `colour` - This is the only truly unrestricted attribute,
|
||||||
accepting any HTML colour code. It understands three-digit hex codes (eg
|
accepting any HTML colour code. It understands three-digit hex codes (eg
|
||||||
`#333`, which is equivalent to `#333333`), six-digit hex codes, and the
|
`#333`, which is equivalent to `#333333`), six-digit hex codes, and the
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ break_info_t calculate_line_wrapping(rectangle dest_rect, std::string str, TextS
|
|||||||
for(i = 0; text_len(i) != text_len(i + 1) && i < str_len; i++) {
|
for(i = 0; text_len(i) != text_len(i + 1) && i < str_len; i++) {
|
||||||
unsigned short line_width = text_len(i) - text_len(last_line_break);
|
unsigned short line_width = text_len(i) - text_len(last_line_break);
|
||||||
if(((line_width > (dest_rect.width() - 6))
|
if(((line_width > (dest_rect.width() - 6))
|
||||||
&& (last_word_break >= last_line_break)) || (str[i] == '|')) {
|
&& (last_word_break >= last_line_break)) || (str[i] == '|' && !style.showPipes)) {
|
||||||
if(str[i] == '|') {
|
if(str[i] == '|') {
|
||||||
last_word_break = i + 1;
|
last_word_break = i + 1;
|
||||||
} else if(last_line_break == last_word_break)
|
} else if(last_line_break == last_word_break)
|
||||||
@@ -151,7 +151,7 @@ static void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,st
|
|||||||
eTextMode mode = options.mode;
|
eTextMode mode = options.mode;
|
||||||
if(mode == eTextMode::WRAP && total_width < dest_rect.width() && !options.right_align)
|
if(mode == eTextMode::WRAP && total_width < dest_rect.width() && !options.right_align)
|
||||||
mode = eTextMode::LEFT_TOP;
|
mode = eTextMode::LEFT_TOP;
|
||||||
if(mode == eTextMode::LEFT_TOP && str.find('|') != std::string::npos)
|
if(mode == eTextMode::LEFT_TOP && !options.style.showPipes && str.find('|') != std::string::npos)
|
||||||
mode = eTextMode::WRAP;
|
mode = eTextMode::WRAP;
|
||||||
|
|
||||||
// Special stuff
|
// Special stuff
|
||||||
@@ -164,7 +164,7 @@ static void win_draw_string(sf::RenderTarget& dest_window,rectangle dest_rect,st
|
|||||||
// to calculate_line_wrapping() or frame calculation is
|
// to calculate_line_wrapping() or frame calculation is
|
||||||
// broken.
|
// broken.
|
||||||
std::string str_with_pipes = str;
|
std::string str_with_pipes = str;
|
||||||
if(!options.showBreaks){
|
if(!options.showBreaks && !options.style.showPipes){
|
||||||
for(int i=0; i < str.length(); ++i){
|
for(int i=0; i < str.length(); ++i){
|
||||||
if(str[i] == '|') str[i] = ' ';
|
if(str[i] == '|') str[i] = ' ';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ enum eFont {
|
|||||||
|
|
||||||
struct TextStyle {
|
struct TextStyle {
|
||||||
bool italic = false, underline = false;
|
bool italic = false, underline = false;
|
||||||
|
bool showPipes = false;
|
||||||
eFont font = FONT_BOLD;
|
eFont font = FONT_BOLD;
|
||||||
int pointSize = 10, lineHeight = 10;
|
int pointSize = 10, lineHeight = 10;
|
||||||
sf::Color colour;
|
sf::Color colour;
|
||||||
|
|||||||
Reference in New Issue
Block a user