DialogXML: Make the frame style format parameter a first-class citizen

- It's now exposed in the schema with a new attribute, outline, on all elements that accept framed
- It now has four possible values: solid, outset, inset, double. Dashed or dotted may be added later; they're a lot harder.
- Second make scenario dialog uses a custom frame style
This commit is contained in:
2015-10-03 11:07:20 -04:00
parent 967f24a83b
commit b176918dda
10 changed files with 92 additions and 30 deletions

View File

@@ -98,7 +98,7 @@ void cButton::draw(){
void cButton::setFormat(eFormat prop, short val) throw(xUnsupportedProp){
if(prop == TXT_WRAP) wrapLabel = val;
else if(prop == TXT_FRAMESTYLE) frameStyle = val;
else if(prop == TXT_FRAMESTYLE) frameStyle = eFrameStyle(val);
else throw xUnsupportedProp(prop);
}

View File

@@ -264,9 +264,9 @@ void cControl::detachKey(){
this->key.c = 0;
}
cControl::cControl(eControlType t, cDialog& p) : parent(&p), inWindow(&p.win), type(t), visible(true), key({false, 0, mod_none}), frameStyle(0) {}
cControl::cControl(eControlType t, cDialog& p) : parent(&p), inWindow(&p.win), type(t), visible(true), key({false, 0, mod_none}), frameStyle(FRM_INSET) {}
cControl::cControl(eControlType t, sf::RenderWindow& p) : parent(nullptr), inWindow(&p), type(t), visible(true), key({false, 0, mod_none}), frameStyle(0) {}
cControl::cControl(eControlType t, sf::RenderWindow& p) : parent(nullptr), inWindow(&p), type(t), visible(true), key({false, 0, mod_none}), frameStyle(FRM_INSET) {}
bool cControl::triggerClickHandler(cDialog&, std::string, eKeyMod){
return true;
@@ -276,7 +276,7 @@ bool cControl::triggerFocusHandler(cDialog&, std::string, bool){
return true;
}
void cControl::drawFrame(short amt, bool){
void cControl::drawFrame(short amt, eFrameStyle frameStyle){
// dk_gray had a 0..65535 component of 12287, and med_gray had a 0..65535 component of 24574
static sf::Color lt_gray = {224,224,224},dk_gray = {48,48,48};
rectangle rect = frame, ul_rect;
@@ -285,13 +285,24 @@ void cControl::drawFrame(short amt, bool){
rect.inset(-amt,-amt);
ul_rect = rect;
ul_rect.right -= 1;
ul_rect.bottom -= 1;
frame_rect(*inWindow, rect, lt_gray);
clip_rect(*inWindow, ul_rect);
if(frameStyle == FRM_OUTSET) {
ul_rect.right -= 1;
ul_rect.bottom -= 1;
} else if(frameStyle == FRM_INSET) {
ul_rect.top += 1;
ul_rect.left += 1;
}
frame_rect(*inWindow, rect, dk_gray);
undo_clip(*inWindow);
if(frameStyle == FRM_OUTSET || frameStyle == FRM_INSET) {
clip_rect(*inWindow, ul_rect);
frame_rect(*inWindow, rect, lt_gray);
undo_clip(*inWindow);
} else if(frameStyle == FRM_DOUBLE) {
rect.inset(-amt, -amt);
frame_rect(*inWindow, rect, dk_gray);
}
}
cControl::~cControl() {}

View File

@@ -33,7 +33,15 @@ enum eFormat {
TXT_FONT, ///< The control's text font. Should be one of the constants FONT_PLAIN, FONT_BOLD, FONT_DUNGEON, FONT_MAIDEN.
TXT_SIZE, ///< The control's text size. Should be an integer indicating point size.
TXT_WRAP, ///< Whether the control should wrap. Should be a boolean (true or false).
TXT_FRAMESTYLE, ///< The control's frame style. Should be a boolean (true or false). @see cControl::drawFrame()
TXT_FRAMESTYLE, ///< The control's frame style. Should be an enum from @a eFrameStyle.
};
/// Frame styles
enum eFrameStyle {
FRM_INSET, ///< An outline style that makes it look like the interior is slightly depressed.
FRM_OUTSET, ///< An outline style that makes it look like the interior is slightly raise.
FRM_SOLID, ///< A solid outline.
FRM_DOUBLE, ///< A solid double outline.
};
/// Specifies the type of a control.
@@ -260,14 +268,14 @@ protected:
/// The control's bounding rect.
rectangle frame;
/// The control's frame style.
int frameStyle;
eFrameStyle frameStyle;
/// The control's attached key.
cKey key;
/// Draw a frame around the control.
/// @param amt How much to offset the frame from the control's bounding rect.
/// @param med_or_lt true to use a darker colour for the frame.
/// @note The TXT_FRAMESTYLE formatting property is normally used for the second parameter.
void drawFrame(short amt, bool med_or_lt);
void drawFrame(short amt, eFrameStyle frameStyle);
/// Redraws the parent dialog, if any.
/// Intended to be called from handleClick(), where there is usually a minor event loop happening.
void redraw();

View File

@@ -37,7 +37,7 @@ void cTextMsg::setFormat(eFormat prop, short val) throw(xUnsupportedProp){
drawFramed = val;
break;
case TXT_FRAMESTYLE:
frameStyle = val;
frameStyle = eFrameStyle(val);
break;
case TXT_SIZE:
textSize = val;
@@ -91,6 +91,13 @@ std::string cTextMsg::parse(ticpp::Element& who, std::string fname) {
std::string val;
attr->GetValue(&val);
if(val == "true") setFormat(TXT_FRAME, true);
}else if(name == "outline") {
std::string val;
attr->GetValue(&val);
if(val == "solid") setFormat(TXT_FRAMESTYLE, FRM_SOLID);
else if(val == "inset") setFormat(TXT_FRAMESTYLE, FRM_INSET);
else if(val == "outset") setFormat(TXT_FRAMESTYLE, FRM_OUTSET);
else if(val == "double") setFormat(TXT_FRAMESTYLE, FRM_DOUBLE);
}else if(name == "font"){
std::string val;
attr->GetValue(&val);

View File

@@ -91,7 +91,7 @@ bool cPict::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods){
void cPict::setFormat(eFormat prop, short val) throw(xUnsupportedProp){
if(prop == TXT_FRAME) drawFramed = val;
else if(prop == TXT_FRAMESTYLE) frameStyle = val;
else if(prop == TXT_FRAMESTYLE) frameStyle = eFrameStyle(val);
else if(prop == TXT_WRAP) drawScaled = !val;
else throw xUnsupportedProp(prop);
}
@@ -539,6 +539,13 @@ std::string cPict::parse(ticpp::Element& who, std::string fname) {
attr->GetValue(&val);
if(val == "true") setFormat(TXT_FRAME, true);
else setFormat(TXT_FRAME, false);
}else if(name == "outline") {
std::string val;
attr->GetValue(&val);
if(val == "solid") setFormat(TXT_FRAMESTYLE, FRM_SOLID);
else if(val == "inset") setFormat(TXT_FRAMESTYLE, FRM_INSET);
else if(val == "outset") setFormat(TXT_FRAMESTYLE, FRM_OUTSET);
else if(val == "double") setFormat(TXT_FRAMESTYLE, FRM_DOUBLE);
}else throw xBadAttr("pict",name,attr->Row(),attr->Column(),fname);
}
if(!foundType) throw xMissingAttr("pict","type",who.Row(),who.Column(),fname);

View File

@@ -72,7 +72,7 @@ void cScrollPane::recalcRect() {
void cScrollPane::setFormat(eFormat prop, short val) throw(xUnsupportedProp) {
if(prop == TXT_FRAME) framed = val;
else if(prop == TXT_FRAMESTYLE) frameStyle = val;
else if(prop == TXT_FRAMESTYLE) frameStyle = eFrameStyle(val);
else throw xUnsupportedProp(prop);
}
@@ -163,7 +163,7 @@ void cScrollPane::draw() {
undo_clip(*inWindow);
scroll.draw();
if(framed)
drawFrame(4, getFormat(TXT_FRAMESTYLE));
drawFrame(4, frameStyle);
}
std::string cScrollPane::parse(ticpp::Element& who, std::string fname) {
@@ -192,6 +192,13 @@ std::string cScrollPane::parse(ticpp::Element& who, std::string fname) {
attr->GetValue(&val);
if(val == "true") setFormat(TXT_FRAME, true);
else setFormat(TXT_FRAME, false);
}else if(name == "outline") {
std::string val;
attr->GetValue(&val);
if(val == "solid") setFormat(TXT_FRAMESTYLE, FRM_SOLID);
else if(val == "inset") setFormat(TXT_FRAMESTYLE, FRM_INSET);
else if(val == "outset") setFormat(TXT_FRAMESTYLE, FRM_OUTSET);
else if(val == "double") setFormat(TXT_FRAMESTYLE, FRM_DOUBLE);
}else if(name == "style"){
std::string val;
attr->GetValue(&val);

View File

@@ -19,7 +19,6 @@ class cScrollPane : public cContainer {
cScrollbar scroll;
std::map<std::string, cControl*> contents;
rectangle globalFrame;
bool frameStyle;
bool framed = false;
public:
/// Create a new scroll pane

View File

@@ -38,6 +38,11 @@ refer to it from the code. If omitted, the code will generate a random
identifier. All controls support this attribute.
* `fromlist` - Currently unused, but the intended use is to look up the
control's text value in a string list (in _rsrc/strings_)
* `framed` - Specifies whether the control should be drawn with a frame
around it, and what type of frame. Can be either `true` or `false`
* `outline` - Sets the type of frame to use for this control. Must be one
of `solid`, `inset`, `outset`, `double`. It defaults to `inset` and is
meaningless if `framed` is `false`.
The `<dialog>` tag
------------------
@@ -65,8 +70,8 @@ of the intended whitespace collapsing behaviour.
The `<text>` tag accepts the following attributes:
* `framed` - Specifies whether a frame is drawn around the text. Can be
either `true` or `false`; defaults to `false`.
* `framed` - See **Common Attributes** above. Defaults to `false`.
* `outline` - See **Common Attributes** above.
* `clickable` - Specifies that the text is clickable. This attribute is
useless, as clickability is determined solely by having a click handler
set in the code.
@@ -158,10 +163,16 @@ is useless, as clickability is determined solely by having a click
handler set in the code.
* `custom` - Specifies whether the picture is custom or preset. Can be
either `true` or `false`; defaults to `false`.
* `framed` - Specifies whether a frame is drawn around the picture. Can
be either `true` or `false`; defaults to `true`.
* `framed` - See **Common Attributes** above. Defaults to `true`.
* `outline` - See **Common Attributes** above.
* `size` - For certain types of graphics, this provides an additional
hint. Can be one of `small`, `wide`, `tall`, or `large`.
hint. Can be one of `small`, `wide`, `tall`, or `large`. See the list of
types below to determine if this attribute is relevant.
* `scaled` - For certain larger types of graphics, this determines
whether it should be scaled to fit within the provided bounds. It only
has an effect for types `full`, `dlog`, and `scen`, and the latter two
only if `size` is `large`. Can be either `true` or `false`, defaults to
`false`.
* `def-key` - See **Common Attributes** above.
The possible values for the `type` attribute are:
@@ -176,7 +187,8 @@ default) or `large`.
* `talk` - A conversation graphic.
* `scen` - A scenario icon. The `size` attribute can be `small` (the
default) or `large`.
* `item` - An item graphic.
* `item` - An item graphic. The `size` attribute can be `large` (the
default) or `small`.
* `pc` - A PC graphic.
* `field` - A field graphic.
* `boom` - A boom graphic.
@@ -245,8 +257,8 @@ It can contain any elements except for nested `<stack>` or `<pane>` elements.
The `<pane>` tag accepts the following attributes:
* `framed` - Specifies whether a frame is drawn around the pane. Can
be either `true` or `false`; defaults to `true`.
* `framed` - See **Common Attributes** above. Defaults to `false`.
* `outline` - See **Common Attributes** above.
* `style` - Same as for `<slider>`, see above. Applies to the pane's scrollbar.
Keyboard Shortcuts