Tear out most of the legacy code in the game - see below for details

(PC Editor and Scenario Editor are unaffected by this commit.)

Things removed:
- All references to Carbon and QuickDraw are gone.
- No more Resource Manager; the game no longer relies on old resource files at all
- The old dialog framework (from dlogtool.c, functions usually prefixed with cd_) is no longer used.
- Files that weren't being compiled
- Boost libraries that are now in the C++ library (function, shared_ptr)
- Obsolete build settings

Replacement dependencies:
- Boost Filesystem replaces references to things like FSSpec
- SFML replaces all the QuickDraw code and most window management
- Cocoa replaces AppleEvent management, menu management, and some window management
- I wrote a resource manager interface to mimick the important aspects of the behaviour of the Mac Resource Manager
- I had to rewrite some functions that QuickDraw provided natively, such as clipping regions; not all of these are tested

Things added:
- Every referenced dialog has been converted from a DITL resource into the new XML-based dialog format.
- All referenced STR# resources have been extracted into simple text files
- Now compiles against Mac OSX 10.7 SDK and libc++
- The first item in the Help menu opens the docs on Sylae's website
- It seems all the constants for soundtool vanished somewhere, so I added them back from the original Mac source

Other changes:
- Updated to XCode 4(?) project format
- Added the xcschemes created by XCode 4; I'm not sure how important these are, but they seem like they might be important
- Added document on converting dialogs to the XML format.
- Make string formatting mismatches into errors instead of warnings
- Disable error limit
- Graphics sheets that previously used masking now have alpha transparency
- Converted all graphics sheets to 8-bit PNG
- Trimmed white border from intro image
- Converted dialogs in the resource file have their resource name set to the name of the XML file of the converted version
- Referenced string resources in the resource file have their resource name set to the name of the text file of the extracted version
- Add the black-and-white patterns from the PAT resources to the pixpats.png; at least one of them is used somewhere in the game
- Recreated the menu.xib as a Cocoa xib file instead of a Carbon xib file
- Disable GNU C++ extensions; maybe this'll make it easier to compile with cl.exe later
- Add marks to the enormous handle_action function to make it easier to navigate\
- A build step to validate the XML dialogs using xmllint (doesn't quite work properly yet but does at least catch dialogs that are not well-formed)- Fix a lot of warnings about assigning string constants to non-const char pointers
- Fixed the file and application icons (which had somehow become corrupted at some point)
- Lots of additional functions in the custom location and rectangle classes, including implicit conversion to and from SFML rects and vectors; also they now store coordinates as int instead of char
- A new enum for encounter note types
- Much tweaking of the encounter note recording mechanisms
- To ease porting, I added a simple function that converts from classic Mac ticks (about 1/60 of a second) to the SFML time type
- Python script to convert STR# resources to txt files, replacing newlines with vertical bars
- Extracted the Mac font (Dungeon Bold) from the resource file and also added the Windows font (MaidenWord)

XML Dialog Framework changes:
- Remove the static initialization object in favour of manually calling cDialog::init()
- {set,get}Format() no longer used for colour; there's a dedicated {set,get}Colour() instead
- draw() methods unprotected in the control classes so that controls can be drawn in the main window
- There's no longer a friend relationship between the dialogs and the controls
- Fixed buttons duplicating the "depressed" boolean
- Buttons now properly offset the label for tiny and push buttons, and for LEDs
- Buttons no longer assume that either none or both of "width" and "height" are given in the XML
- Add {get,set}BtnType() to cButton
- cLedGroup now overrides handleClick(), which has also been made virtual; this was necessary for LEDs within a group to properly hilite while being clicked
- Add addChoice() to cLedGroup to insert additional LED choices
- Moved the key enums and cKey to a separate file
- Add a method to get a control's attached key
- Add methods to get and set a control's rect and position
- Controls can now directly take a window as a parent rather than a dialog
- Add addLabelFor() method to cDialog which adds a static text control as a label for another control
- Remove hack for storing a dialog result of arbitrary type in favour of boost::any
- Add method to get default text colour for a dialog
- Add method to get a dialog's rect
- Add method to add the same event handler to multiple controls in a dialog
- Add concept of default button to dialogs
- Add enum for text field type (currently either number or text)
- Implement the text field without use of native controls, including somewhat decent text input and a flashing insertion point
- cPict no longer stores references to every sheet; it fetches them as needed from the resource manager
- The many draw functions in cPict are no longer static, since they need to access the window containing the pict (before they could only be static due to QuickDraw's global state)
- Add setPict() without a type argument to change the graphic without changing the type, which is a common operation
- Add a scrollbar control; the specifics aren't implemented yet
- Change signature of the record callback for cStrDlog; it will no longer be passed the strings
- Publicize the no-button constructor of cChoiceDlog; it'll assume "okay" is the only button
- Add operator-> to cPictChoice for accessing the underlying dialog
- Add constructor to cPictChoice that takes a starting and ending pic num
- Remove err parameter from giveError
- Many more keys handled, plus support for catching copy, paste, cut, and select all keyboard shortcuts
- Text input fields take priority, overriding any other keyboard shortcuts in the dialog, but they never catch help (F1), escape, or enter
- Some changes to the format itself:
-> keys go in the "def-key" attribute, but modifiers go in "key-mod"
-> "clickable" is no longer a recognized attribute
-> "title" is now a recognized text size (18pt, even larger than "large" at 12pt)
-> "defbtn" attribute on the root element
This commit is contained in:
2014-04-09 23:39:55 -04:00
parent b9de23897e
commit c413d292a9
286 changed files with 13970 additions and 13970 deletions

View File

@@ -1,9 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light'>
<pict name='pict' type='dlog' size='large' num='0' top='9' left='9'/>
<text name='str1' framed='true' top='8' left='91' width='257' height='90'/>
<button name='okay' type='done' key='enter' top='107' left='287'/>
<button name='record' type='regular' key='r' top='107' left='8'>Record</button>
</dialog>

View File

@@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light'>
<pict name='pict' type='dlog' size='large' num='0' top='9' left='9'/>
<text name='title' framed='true' top='9' left='91' width='257' height='19'/>
<text name='str1' framed='true' top='39' left='91' width='257' height='87'/>
<button name='okay' type='done' key='enter' top='140' left='287'/>
<button name='record' type='regular' key='r' top='140' left='8'>Record</button>
</dialog>

View File

@@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light'>
<pict name='pict' type='dlog' num='8' top='9' left='9'/>
<text name='title' framed='true' top='9' left='55' width='257' height='19'/>
<text name='str1' framed='true' top='39' left='55' width='257' height='87'/>
<button name='okay' type='done' key='enter' top='140' left='251'/>
<button name='record' type='regular' key='r' top='140' left='8'>Record</button>
</dialog>

View File

@@ -1,9 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light'>
<pict name='pict' type='dlog' num='8' top='9' left='9'/>
<text name='str1' framed='true' top='8' left='55' width='257' height='90'/>
<button name='okay' type='done' key='enter' top='107' left='251'/>
<button name='record' type='regular' key='r' top='107' left='8'>Record</button>
</dialog>

View File

@@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light'>
<pict name='pict' type='dlog' size='large' num='0' top='9' left='9'/>
<text name='str1' framed='true' top='8' left='91' width='257' height='90'/>
<text name='str1' framed='true' top='107' left='91' width='257' height='98'/>
<button name='okay' type='done' key='enter' top='212' left='287'/>
<button name='record' type='regular' key='r' top='212' left='8'>Record</button>
</dialog>

View File

@@ -1,11 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light'>
<pict name='pict' type='dlog' size='large' num='0' top='9' left='9'/>
<text name='title' framed='true' top='9' left='91' width='257' height='19'/>
<text name='str1' framed='true' top='39' left='91' width='257' height='87'/>
<text name='str2' framed='true' top='136' left='91' width='257' height='93'/>
<button name='okay' type='done' key='enter' top='238' left='287'/>
<button name='record' type='regular' key='r' top='238' left='8'>Record</button>
</dialog>

View File

@@ -1,11 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light'>
<pict name='pict' type='dlog' num='8' top='9' left='9'/>
<text name='title' framed='true' top='9' left='55' width='257' height='19'/>
<text name='str1' framed='true' top='39' left='55' width='257' height='87'/>
<text name='str2' framed='true' top='136' left='55' width='257' height='93'/>
<button name='okay' type='done' key='enter' top='238' left='251'/>
<button name='record' type='regular' key='r' top='238' left='8'>Record</button>
</dialog>

View File

@@ -1,10 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light'>
<pict name='pict' type='dlog' num='8' top='9' left='9'/>
<text name='str1' framed='true' top='8' left='55' width='257' height='90'/>
<text name='str1' framed='true' top='107' left='55' width='257' height='98'/>
<button name='okay' type='done' key='enter' top='212' left='251'/>
<button name='record' type='regular' key='r' top='212' left='8'>Record</button>
</dialog>

View File

@@ -1,3 +1,4 @@
/*
* button.cpp
* BoE
@@ -6,7 +7,7 @@
*
*/
#include <Carbon/Carbon.h>
#include "button.h"
#include <vector>
#include <map>
#include <stdexcept>
@@ -16,7 +17,9 @@
#include <cmath>
extern GWorldPtr bg_gworld;
#include "restypes.hpp"
extern sf::Texture bg_gworld;
void cButton::attachFocusHandler(focus_callback_t f __attribute__((unused))) throw(xHandlerNotSupported){
throw xHandlerNotSupported(true);
@@ -26,18 +29,19 @@ void cButton::attachClickHandler(click_callback_t f) throw(){
onClick = f;
}
bool cButton::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where){
if(onClick != NULL) return onClick(me,id,mods);
bool cButton::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where){
if(onClick) return onClick(me,id,mods);
return false;
}
cButton::cButton(cDialog* parent) :
cControl(parent,CTRL_BTN),
cControl(CTRL_BTN,*parent),
wrapLabel(false),
type(BTN_REG),
fromList("none") {}
cButton::cButton(cDialog* parent,eControlType t) :
cControl(parent,t),
cControl(t,*parent),
fromList("none"),
wrapLabel("true") {/* This constructor is only called for LEDs. TODO: Should wrapLabel be true for LEDs? */}
@@ -46,43 +50,47 @@ bool cButton::isClickable(){
}
void cButton::draw(){
GrafPtr old_port;
Rect from_rect, to_rect;
GWorldPtr from_gw, to_gw;
RECT from_rect, to_rect;
GetPort(&old_port);
SetPortWindowPort(parent->win);
inWindow->setActive();
if(visible){
TextFont(font_nums[GENEVA]);
if(foundSilom())TextFace(normal);
else TextFace(bold);
if(type == BTN_TINY) TextSize(9);
else if(type == BTN_PUSH) TextSize(10);
else TextSize(12);
from_gw = buttons[btnGW[type]];
from_rect = btnRects[btnGW[type]][depressed];
TEXT.font = "Geneva";
if(foundSilom()) {
TEXT.style = sf::Text::Regular;
TEXT.font = "Silom";
} else TEXT.style = sf::Text::Bold;
if(type == BTN_TINY) TEXT.pointSize = 9;
else if(type == BTN_PUSH) TEXT.pointSize = 10;
else TEXT.pointSize = 12;
from_rect = btnRects[type][depressed];
to_rect = frame;
rect_draw_some_item(from_gw,from_rect,to_rect,(Point){0,0}); // TODO: This originally drew to dest 2 (dialog window); does it still?
RGBForeColor(&parent->defTextClr);
char_win_draw_string(parent->win,to_rect,lbl.c_str(),1,8);
rect_draw_some_item(buttons[btnGW[type]],from_rect,*inWindow,to_rect,sf::BlendAlpha);
TEXT.colour = sf::Color::Black;
int textMode = 1;
if(type == BTN_TINY) {
textMode = 2;
to_rect.left += 18;
} else if(type == BTN_PUSH) {
to_rect.top += 34;
}
win_draw_string(*inWindow,to_rect,lbl.c_str(),textMode,8);
// TODO: Adjust string location as appropriate
// Tiny button string location should be shifted right 20 pixels (or possibly 18)
// Push button string should be centred below the button
// Others may need adjustments too, not sure
ForeColor(blackColor);
TEXT.colour = sf::Color::Black;
// TODO: When should we pass 1 as the second parameter?
// TODO: How is it supposed to know it's a default button when this fact is stored in the dialog, not the button?
if(key.spec && key.k == key_enter) drawFrame(2,0); // frame default button, to provide a visual cue that it's the default
}else{
tileImage(frame,bg_gworld,bg[parent->bg]);
tileImage(*inWindow,frame,bg_gworld,bg[parent->bg]);
}
SetPort(old_port);
}
void cButton::setFormat(eFormat prop, short val) throw(xUnsupportedProp){
if(prop == TXT_WRAP) wrapLabel = val;
else throw xUnsupportedProp(prop);
if(isVisible()) draw();
}
short cButton::getFormat(eFormat prop) throw(xUnsupportedProp){
@@ -90,6 +98,22 @@ short cButton::getFormat(eFormat prop) throw(xUnsupportedProp){
else throw xUnsupportedProp(prop);
}
void cButton::setColour(sf::Color clr) throw(xUnsupportedProp) {
// TODO: Colour is not supported
}
sf::Color cButton::getColour() throw(xUnsupportedProp) {
// TODO: Colour is not supported
}
void cButton::setBtnType(eBtnType newType) {
type = newType;
}
eBtnType cButton::getBtnType() {
return type;
}
// Indices within the buttons array.
size_t cButton::btnGW[14] = {
0, // BTN_SM
@@ -108,64 +132,59 @@ size_t cButton::btnGW[14] = {
5, // BTN_LED
};
GWorldPtr cButton::buttons[7] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
Rect cButton::btnRects[13][2];
sf::Texture cButton::buttons[7];
RECT cButton::btnRects[13][2];
void cButton::init(){
static const char*const buttonFiles[7] = {
"dlogbtnsm.png",
"dlogbtnmed.png",
"dlogbtnlg.png",
"dlogbtntall.png",
"dlogbtnhelp.png",
"dlogbtnled.png",
"dlogbtnred.png"
"dlogbtnsm",
"dlogbtnmed",
"dlogbtnlg",
"dlogbtntall",
"dlogbtnhelp",
"dlogbtnled",
"dlgbtnred"
};
for(int i = 0; i < 7; i++)
buttons[i] = load_pict(buttonFiles[i]);
SetRect(&btnRects[BTN_SM][0],0,0,23,23);
SetRect(&btnRects[BTN_REG][0],0,0,63,23);
SetRect(&btnRects[BTN_LEFT][0],0,23,63,46);
SetRect(&btnRects[BTN_RIGHT][0],0,46,63,69);
SetRect(&btnRects[BTN_UP][0],0,69,63,92);
SetRect(&btnRects[BTN_DOWN][0],0,92,63,115);
SetRect(&btnRects[BTN_DONE][0],0,115,63,138);
SetRect(&btnRects[BTN_LG][0],0,0,104,23);
SetRect(&btnRects[BTN_HELP][0],0,0,16,13);
SetRect(&btnRects[BTN_TINY][0],42,0,56,10);
SetRect(&btnRects[BTN_TALL][0],0,0,63,40);
SetRect(&btnRects[BTN_TRAIT][0],0,40,63,80);
SetRect(&btnRects[BTN_PUSH][0],0,0,30,30);
buttons[i].loadFromImage(*ResMgr::get<ImageRsrc>(buttonFiles[i]));
btnRects[BTN_SM][0] = {0,0,23,23};
btnRects[BTN_REG][0] = {0,0,23,63};
btnRects[BTN_LEFT][0] = {23,0,46,63};
btnRects[BTN_RIGHT][0] = {46,0,69,63};
btnRects[BTN_UP][0] = {69,0,92,63};
btnRects[BTN_DOWN][0] = {92,0,115,63};
btnRects[BTN_DONE][0] = {115,0,138,63};
btnRects[BTN_LG][0] = {0,0,23,102};
btnRects[BTN_HELP][0] = {0,0,13,16};
btnRects[BTN_TINY][0] = {0,42,10,56};
btnRects[BTN_TALL][0] = {0,0,40,63};
btnRects[BTN_TRAIT][0] = {40,0,80,63};
btnRects[BTN_PUSH][0] = {0,0,30,30};
for(int j = 0; j < 12; j++)
btnRects[j][1] = btnRects[j][0];
OffsetRect(&btnRects[BTN_SM][1],23,0);
OffsetRect(&btnRects[BTN_REG][1],63,0);
OffsetRect(&btnRects[BTN_LEFT][1],63,0);
OffsetRect(&btnRects[BTN_RIGHT][1],63,0);
OffsetRect(&btnRects[BTN_UP][1],63,0);
OffsetRect(&btnRects[BTN_DOWN][1],63,0);
OffsetRect(&btnRects[BTN_DONE][1],63,0);
OffsetRect(&btnRects[BTN_LG][1],104,0);
OffsetRect(&btnRects[BTN_HELP][1],16,0);
OffsetRect(&btnRects[BTN_TINY][1],0,10);
OffsetRect(&btnRects[BTN_TALL][1],63,0);
OffsetRect(&btnRects[BTN_TRAIT][1],63,0);
OffsetRect(&btnRects[BTN_PUSH][1],30,0);
btnRects[BTN_SM][1].offset(23,0);
btnRects[BTN_REG][1].offset(63,0);
btnRects[BTN_LEFT][1].offset(63,0);
btnRects[BTN_RIGHT][1].offset(63,0);
btnRects[BTN_UP][1].offset(63,0);
btnRects[BTN_DOWN][1].offset(63,0);
btnRects[BTN_DONE][1].offset(63,0);
btnRects[BTN_LG][1].offset(102,0);
btnRects[BTN_HELP][1].offset(16,0);
btnRects[BTN_TINY][1].offset(0,10);
btnRects[BTN_TALL][1].offset(63,0);
btnRects[BTN_TRAIT][1].offset(63,0);
btnRects[BTN_PUSH][1].offset(30,0);
}
void cButton::finalize(){
for(int i = 0; i < 7; i++)
DisposeGWorld(buttons[i]);
}
Rect cLed::ledRects[3][2];
RECT cLed::ledRects[3][2];
void cLed::init(){
Rect baseLed = {0,0,10,14};
RECT baseLed = {0,0,10,14};
for(int i = 0; i < 3; i++)
for(int j = 0; j < 2; j++){
ledRects[i][j] = baseLed;
OffsetRect(&ledRects[i][j],i * 14, j * 10);
ledRects[i][j].offset(i * 14, j * 10);
}
}
@@ -174,7 +193,9 @@ cLed::cLed(cDialog* parent) :
state(led_off),
textFont(SILOM),
textSize(10),
color(parent->defTextClr) {}
color(parent->defTextClr) {
setBtnType(BTN_LED);
}
void cLed::attachClickHandler(click_callback_t f) throw(){
onClick = f;
@@ -189,7 +210,7 @@ bool cLed::triggerFocusHandler(cDialog& me, std::string id, bool losing){
return true;
}
bool cLed::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where){
bool cLed::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where){
bool result;
eLedState oldState = state;
if(onClick != NULL) result = onClick(me,id,mods);
@@ -220,36 +241,31 @@ short cLed::getFormat(eFormat prop __attribute__((unused))) throw(xUnsupportedPr
}
void cLed::draw(){
GrafPtr old_port;
Rect from_rect, to_rect;
GWorldPtr from_gw, to_gw;
RECT from_rect, to_rect;
GetPort(&old_port);
SetPortWindowPort(parent->win);
inWindow->setActive();
if(visible){
TextFont(font_nums[GENEVA]);
if(foundSilom())TextFace(normal);
else TextFace(bold);
TextSize(9);
from_gw = buttons[btnGW[BTN_LED]];
TEXT.font = "Geneva";
if(foundSilom()) TEXT.style = sf::Text::Regular;
else TEXT.style = sf::Text::Bold;
TEXT.pointSize = 9;
from_rect = ledRects[state][depressed];
to_rect = frame;
rect_draw_some_item(from_gw,from_rect,to_rect,(Point){0,0});
RGBForeColor(&parent->defTextClr);
char_win_draw_string(parent->win,to_rect,lbl.c_str(),1,8);
// TODO: Adjust string location as appropriate
// String location should be shifted right 20 pixels (or possibly 18)
ForeColor(blackColor);
to_rect.right = to_rect.left + 14;
rect_draw_some_item(buttons[btnGW[BTN_LED]],from_rect,*inWindow,to_rect);
TEXT.colour = parent->defTextClr;
to_rect.right = frame.right;
to_rect.left = frame.left + 18; // Possibly could be 20
win_draw_string(*inWindow,to_rect,lbl.c_str(),2,8);
TEXT.colour = sf::Color::Black;
}else{
tileImage(frame,bg_gworld,bg[parent->bg]);
tileImage(*inWindow,frame,bg_gworld,bg[parent->bg]);
}
SetPort(old_port);
}
cLedGroup::cLedGroup(cDialog* parent) :
cControl(parent,CTRL_GROUP),
cControl(CTRL_GROUP,*parent),
fromList("none") {}
cButton::~cButton() {}
@@ -267,10 +283,11 @@ cLedGroup::~cLedGroup(){
void cLedGroup::recalcRect(){
ledIter iter = choices.begin();
while(iter != choices.end()){
if(iter->second->frame.right > frame.right)
frame.right = iter->second->frame.right;
if(iter->second->frame.bottom > frame.bottom)
frame.bottom = iter->second->frame.bottom;
RECT otherFrame = iter->second->getBounds();
if(otherFrame.right > frame.right)
frame.right = otherFrame.right;
if(otherFrame.bottom > frame.bottom)
frame.bottom = otherFrame.bottom;
iter++;
}
frame.right += 6;
@@ -295,19 +312,34 @@ eLedState cLed::getState(){
return state;
}
bool cLedGroup::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where){
void cLedGroup::addChoice(cLed* ctrl, std::string key) {
choices[key] = ctrl;
}
bool cLedGroup::handleClick() {
location where = sf::Mouse::getPosition(*inWindow);
std::string which_clicked;
ledIter iter = choices.begin();
while(iter != choices.end()){
if(iter->second->visible && PtInRect(where,&iter->second->frame)){
if(iter->second->handleClick())
if(iter->second->isVisible() && where.in(iter->second->getBounds())){
if(iter->second->handleClick()) {
which_clicked = iter->first;
break;
}
}
iter++;
}
if(which_clicked == "") return false;
clicking = which_clicked;
return true;
}
bool cLedGroup::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where){
std::string which_clicked = clicking;
clicking = "";
if(choices[which_clicked]->triggerClickHandler(me,which_clicked,mods,where)){
eLedState a, b;
a = choices[curSelect]->getState();
@@ -359,6 +391,14 @@ short cLedGroup::getFormat(eFormat prop __attribute__((unused))) throw(xUnsuppor
throw xUnsupportedProp(prop);
}
void cLedGroup::setColour(sf::Color clr) throw(xUnsupportedProp) {
// TODO: Colour is not supported
}
sf::Color cLedGroup::getColour() throw(xUnsupportedProp) {
// TODO: Colour is not supported
}
bool cLedGroup::isClickable(){
return true;
}
@@ -371,6 +411,7 @@ cLed& cLedGroup::operator[](std::string id){
void cLedGroup::setSelected(std::string id){
if(id == "") { // deselect all
if(curSelect == "") return;
eLedState was = choices[curSelect]->getState();
choices[curSelect]->setState(led_off);
if(choices[curSelect]->triggerFocusHandler(*parent,curSelect,true))

View File

@@ -9,9 +9,12 @@
#ifndef BUTTON_H
#define BUTTON_H
#include <SFML/Graphics.hpp>
#include <string>
#include <map>
#include <vector>
#include "control.h"
enum eBtnType { // w x h
BTN_SM = 0, // 23x23 (PICT id 2000 / 2001)
@@ -35,34 +38,34 @@ enum eLedState {led_green = 0, led_red, led_off};
class cButton : public cControl {
public:
static void init();
static void finalize();
void attachClickHandler(click_callback_t f) throw();
void attachFocusHandler(focus_callback_t f) throw(xHandlerNotSupported);
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where);
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where);
//virtual void setPict(short pict, short type) = 0;
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
short getFormat(eFormat prop) throw(xUnsupportedProp);
void setColour(sf::Color clr) throw(xUnsupportedProp);
sf::Color getColour() throw(xUnsupportedProp);
void setBtnType(eBtnType type);
eBtnType getBtnType();
explicit cButton(cDialog* parent);
bool isClickable();
void setType(eBtnType newType);
eBtnType getType();
virtual ~cButton();
protected:
//friend class cDialog;
void draw();
protected:
eBtnType type;
click_callback_t onClick;
cButton(cDialog* parent,eControlType t);
private:
friend class cDialog;
bool wrapLabel;
bool labelWithKey;
bool pressed;
std::string fromList;
static Rect btnRects[13][2];
static RECT btnRects[13][2];
protected:
static size_t btnGW[14];
static GWorldPtr buttons[7];
static sf::Texture buttons[7];
};
class cLed : public cButton {
@@ -70,7 +73,7 @@ public:
static void init();
void attachClickHandler(click_callback_t f) throw();
void attachFocusHandler(focus_callback_t f) throw();
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where);
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where);
bool triggerFocusHandler(cDialog& me, std::string id, bool losingFocus);
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
short getFormat(eFormat prop) throw(xUnsupportedProp);
@@ -78,16 +81,13 @@ public:
virtual ~cLed();
void setState(eLedState to);
eLedState getState();
protected:
void draw();
private:
friend class cDialog;
friend class cLedGroup;
eLedState state;
eTextFont textFont;
RGBColor color;
sf::Color color;
short textSize;
static Rect ledRects[3][2];
static RECT ledRects[3][2];
focus_callback_t onFocus;
};
@@ -98,11 +98,13 @@ class cLedGroup : public cControl {
std::map<std::string,cLed*> choices;
std::string fromList;
std::string curSelect, prevSelect;
std::string clicking;
public:
void attachClickHandler(click_callback_t f) throw(); // activated whenever a click is received, even on the currently active LED
void attachFocusHandler(focus_callback_t f) throw(); // activated only when the selection changes
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where);
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where);
bool triggerFocusHandler(cDialog& me, std::string id, bool losingFocus);
void addChoice(cLed* ctrl, std::string key);
void disable(std::string id);
void enable(std::string id);
using cControl::show;
@@ -111,8 +113,11 @@ public:
void show(std::string id);
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
short getFormat(eFormat prop) throw(xUnsupportedProp);
void setColour(sf::Color clr) throw(xUnsupportedProp);
sf::Color getColour() throw(xUnsupportedProp);
explicit cLedGroup(cDialog* parent);
bool isClickable();
bool handleClick();
virtual ~cLedGroup();
cLed& operator[](std::string id);
void setSelected(std::string id);
@@ -120,8 +125,6 @@ public:
std::string getPrevSelection(); // The id of the element that was last selected before the selection changed to the current selection.
void recalcRect();
typedef std::map<std::string,cLed*>::iterator ledIter;
protected:
void draw();
friend class cDialog;
};
#endif

View File

@@ -1,86 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light' debug='true'>
<pict type='dlog' num='16' top='6' left='6'/>
<text size='large' top='6' left='50' width='248' height='14'>Select a graphic:</text>
<group name='group'>
<led name='led1' state='off' top='29' left='55' width='16'/>
<led name='led2' state='off' top='74' left='55' width='16'/>
<led name='led3' state='off' top='119' left='55' width='16'/>
<led name='led4' state='off' top='164' left='55' width='16'/>
<led name='led5' state='off' top='209' left='55' width='16'/>
<led name='led6' state='off' top='254' left='55' width='16'/>
<led name='led7' state='off' top='29' left='119' width='16'/>
<led name='led8' state='off' top='74' left='119' width='16'/>
<led name='led9' state='off' top='119' left='119' width='16'/>
<led name='led10' state='off' top='164' left='119' width='16'/>
<led name='led11' state='off' top='209' left='119' width='16'/>
<led name='led12' state='off' top='254' left='119' width='16'/>
<led name='led13' state='off' top='29' left='183' width='16'/>
<led name='led14' state='off' top='74' left='183' width='16'/>
<led name='led15' state='off' top='119' left='183' width='16'/>
<led name='led16' state='off' top='164' left='183' width='16'/>
<led name='led17' state='off' top='209' left='183' width='16'/>
<led name='led18' state='off' top='254' left='183' width='16'/>
<led name='led19' state='off' top='29' left='251' width='16'/>
<led name='led20' state='off' top='74' left='251' width='16'/>
<led name='led21' state='off' top='119' left='251' width='16'/>
<led name='led22' state='off' top='164' left='251' width='16'/>
<led name='led23' state='off' top='209' left='251' width='16'/>
<led name='led24' state='off' top='254' left='251' width='16'/>
<led name='led25' state='off' top='29' left='320' width='16'/>
<led name='led26' state='off' top='74' left='320' width='16'/>
<led name='led27' state='off' top='119' left='320' width='16'/>
<led name='led28' state='off' top='164' left='320' width='16'/>
<led name='led29' state='off' top='209' left='320' width='16'/>
<led name='led30' state='off' top='254' left='320' width='16'/>
<led name='led31' state='off' top='29' left='388' width='16'/>
<led name='led32' state='off' top='74' left='388' width='16'/>
<led name='led33' state='off' top='119' left='388' width='16'/>
<led name='led34' state='off' top='164' left='388' width='16'/>
<led name='led35' state='off' top='209' left='388' width='16'/>
<led name='led36' state='off' top='254' left='388' width='16'/>
</group>
<pict name='pic1' type='ter' num='0' top='29' left='76'/>
<pict name='pic2' type='ter' num='1' top='74' left='76'/>
<pict name='pic3' type='ter' num='2' top='119' left='76'/>
<pict name='pic4' type='ter' num='3' top='164' left='76'/>
<pict name='pic5' type='ter' num='4' top='209' left='76'/>
<pict name='pic6' type='ter' num='5' top='254' left='76'/>
<pict name='pic7' type='ter' num='6' top='29' left='140'/>
<pict name='pic8' type='ter' num='7' top='74' left='140'/>
<pict name='pic9' type='ter' num='8' top='119' left='140'/>
<pict name='pic10' type='ter' num='9' top='164' left='140'/>
<pict name='pic11' type='ter' num='10' top='209' left='140'/>
<pict name='pic12' type='ter' num='11' top='254' left='140'/>
<pict name='pic13' type='ter' num='12' top='29' left='204'/>
<pict name='pic14' type='ter' num='13' top='74' left='204'/>
<pict name='pic15' type='ter' num='14' top='119' left='204'/>
<pict name='pic16' type='ter' num='15' top='164' left='204'/>
<pict name='pic17' type='ter' num='16' top='209' left='204'/>
<pict name='pic18' type='ter' num='17' top='254' left='204'/>
<pict name='pic19' type='ter' num='18' top='29' left='272'/>
<pict name='pic20' type='ter' num='19' top='74' left='272'/>
<pict name='pic21' type='ter' num='20' top='119' left='272'/>
<pict name='pic22' type='ter' num='21' top='164' left='272'/>
<pict name='pic23' type='ter' num='22' top='209' left='272'/>
<pict name='pic24' type='ter' num='23' top='254' left='272'/>
<pict name='pic25' type='ter' num='24' top='29' left='341'/>
<pict name='pic26' type='ter' num='25' top='74' left='341'/>
<pict name='pic27' type='ter' num='26' top='119' left='341'/>
<pict name='pic28' type='ter' num='27' top='164' left='341'/>
<pict name='pic29' type='ter' num='28' top='209' left='341'/>
<pict name='pic30' type='ter' num='29' top='254' left='341'/>
<pict name='pic31' type='ter' num='30' top='29' left='409'/>
<pict name='pic32' type='ter' num='31' top='74' left='409'/>
<pict name='pic33' type='ter' num='32' top='119' left='409'/>
<pict name='pic34' type='ter' num='33' top='164' left='409'/>
<pict name='pic35' type='ter' num='34' top='209' left='409'/>
<pict name='pic36' type='ter' num='35' top='254' left='409'/>
<text top='294' left='6' width='422' height='16'>Click button to left of graphic to select. Use arrows to change pages.</text>
<button name='left' type='left' top='314' left='6' key='left'/>
<button name='right' type='right' top='314' left='69' key='right'/>
<button name='done' type='done' top='314' left='393' key='return'/>
<button name='cancel' type='regular' top='314' left='322' key='esc'>Cancel</button>
</dialog>

View File

@@ -1,53 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light' debug='true'>
<pict type='dlog' num='16' top='8' left='8'/>
<text size='large' top='6' left='50' width='256' height='14'>Select:</text>
<group>
<led name='led1' state='off' top='54' left='8' width='180'/>
<led name='led2' state='off' top='69' left='8' width='180'/>
<led name='led3' state='off' top='84' left='8' width='180'/>
<led name='led4' state='off' top='99' left='8' width='180'/>
<led name='led5' state='off' top='114' left='8' width='180'/>
<led name='led6' state='off' top='129' left='8' width='180'/>
<led name='led7' state='off' top='144' left='8' width='180'/>
<led name='led8' state='off' top='159' left='8' width='180'/>
<led name='led9' state='off' top='174' left='8' width='180'/>
<led name='led10' state='off' top='189' left='8' width='180'/>
<led name='led11' state='off' top='204' left='8' width='180'/>
<led name='led12' state='off' top='219' left='8' width='180'/>
<led name='led13' state='off' top='234' left='8' width='180'/>
<led name='led14' state='off' top='249' left='8' width='180'/>
<led name='led15' state='off' top='264' left='8' width='180'/>
<led name='led16' state='off' top='279' left='8' width='180'/>
<led name='led17' state='off' top='294' left='8' width='180'/>
<led name='led18' state='off' top='309' left='8' width='180'/>
<led name='led19' state='off' top='324' left='8' width='180'/>
<led name='led20' state='off' top='339' left='8' width='180'/>
<led name='led21' state='off' top='54' left='216' width='180'/>
<led name='led22' state='off' top='69' left='216' width='180'/>
<led name='led23' state='off' top='84' left='216' width='180'/>
<led name='led24' state='off' top='99' left='216' width='180'/>
<led name='led25' state='off' top='114' left='216' width='180'/>
<led name='led26' state='off' top='129' left='216' width='180'/>
<led name='led27' state='off' top='144' left='216' width='180'/>
<led name='led28' state='off' top='159' left='216' width='180'/>
<led name='led29' state='off' top='174' left='216' width='180'/>
<led name='led30' state='off' top='189' left='216' width='180'/>
<led name='led31' state='off' top='204' left='216' width='180'/>
<led name='led32' state='off' top='219' left='216' width='180'/>
<led name='led33' state='off' top='234' left='216' width='180'/>
<led name='led34' state='off' top='249' left='216' width='180'/>
<led name='led35' state='off' top='264' left='216' width='180'/>
<led name='led36' state='off' top='279' left='216' width='180'/>
<led name='led37' state='off' top='294' left='216' width='180'/>
<led name='led38' state='off' top='309' left='216' width='180'/>
<led name='led39' state='off' top='324' left='216' width='180'/>
<led name='led40' state='off' top='339' left='216' width='180'/>
</group>
<button name='left' type='left' key='left' top='358' left='8'/>
<button name='right' type='right' key='right' top='358' left='71'/>
<button name='done' type='regular' key='enter' top='358' left='338'>OK</button>
<button name='cancel' type='regular' key='esc' top='358' left='272'>Cancel</button>
</dialog>

View File

@@ -6,22 +6,37 @@
*
*/
#include <Carbon/Carbon.h>
#include "control.h"
#include <sstream>
#include "dialog.h"
#include "soundtool.h"
#include "button.h"
#include "graphtool.h"
#include "restypes.hpp"
#include "mathutil.h"
extern bool play_sounds;
void cControl::setText(std::string l){
lbl = l;
if(isVisible()) draw();
}
std::string cControl::getText(){
return lbl;
}
RECT cControl::getBounds() {
return frame;
}
void cControl::setBounds(RECT newFrame) {
frame = newFrame;
}
void cControl::relocate(location to) {
frame.offset(to.x - frame.left, to.y - frame.top);
}
const char* xHandlerNotSupported::focusMsg = "This control cannot handle focus events.\n";
const char* xHandlerNotSupported::clickMsg = "This control cannot handle click events.\n";
@@ -45,9 +60,6 @@ const char* xUnsupportedProp::what() throw(){
msg = new char[60];
std::string s;
switch(whichProp){
case TXT_COLOR:
s = "TXT_COLOR";
break;
case TXT_FRAME:
s = "TXT_FRAME";
break;
@@ -61,6 +73,7 @@ const char* xUnsupportedProp::what() throw(){
s = "TXT_WRAP";
break;
}
// TODO: Support colour, which doesn't use the setFormat function
sprintf(msg,"Format property %s not valid for this control.\n",s.c_str());
}
return msg;
@@ -129,61 +142,74 @@ eKeyMod& operator -= (eKeyMod&lhs, eKeyMod rhs){
return lhs;
}
bool operator== (cKey& a, cKey& b){
bool operator== (cKey a, cKey b){
if(a.spec != b.spec) return false;
if(a.mod != b.mod) return false;
return a.spec ? a.k == b.k : a.c == b.c;
}
bool mod_contains(eKeyMod mods, eKeyMod mod) {
if((mods & mod) != 0) return true;
return false;
}
void cControl::show(){
visible = true;
if(isVisible()) draw();
}
void cControl::hide(){
visible = false;
if(isVisible()) draw();
}
bool cControl::isVisible(){
if(parent->dialogNotToast)
if(!parent || parent->dialogNotToast)
return visible;
else return false;
}
cKey cControl::getAttachedKey() {
return key;
}
void cControl::setActive(bool active) {
depressed = active;
}
bool cControl::handleClick(){
EventRecord e;
sf::Event e;
unsigned long dummy;
bool done = false, clicked = false;
GrafPtr old_port;
GetPort(&old_port);
SetPortWindowPort(parent->win);
RgnHandle in_region = NewRgn(), out_region = NewRgn();
RectRgn(in_region,&frame);
RectRgn(out_region,&parent->winRect);
DiffRgn(out_region,in_region,out_region);
inWindow->setActive();
depressed = true;
draw();
while(!done){
WaitNextEvent(mUpMask,&e,0L,depressed ? in_region : out_region);
if(e.what == mouseUp){
done = true;
clicked = PtInRect(e.where, &frame);
depressed = false;
}else if(e.message >> 8 == mouseMovedMessage){
depressed = !depressed;
if(parent) parent->draw();
else {
// TODO: This only redraws this one control; should probably redraw the entire dialog? But what if there is no dialog?
draw();
inWindow->display();
}
if(!inWindow->pollEvent(e)) continue;
if(e.type == sf::Event::MouseButtonReleased){
done = true;
clicked = frame.contains(e.mouseButton.x, e.mouseButton.y);
depressed = false;
} else if(e.type == sf::Event::MouseMoved){
depressed = frame.contains(e.mouseMove.x, e.mouseMove.y);
}
}
if (play_sounds) {
if(typeid(this) == typeid(cLed*))
play_sound(34);
else play_sound(37);
Delay(6,&dummy);
sf::sleep(time_in_ticks(6));
}
else sf::sleep(time_in_ticks(14));
if(parent) parent->draw();
else {
// TODO: This only redraws this one control; should probably redraw the entire dialog? But what if there is no dialog?
draw();
inWindow->display();
}
else Delay(14,&dummy);
draw();
SetPort(old_port);
return clicked;
}
@@ -233,14 +259,11 @@ void cControl::detachKey(){
this->key.c = 0;
}
cControl::cControl(cDialog* p, eControlType t) : parent(p), type(t), visible(true) {
// No key by default.
key.spec = false;
key.c = 0;
key.mod = mod_none;
}
cControl::cControl(eControlType t, cDialog& p) : parent(&p), inWindow(&p.win), type(t), visible(true), key({false, 0, mod_none}) {}
bool cControl::triggerClickHandler(cDialog& __attribute__((unused)), std::string __attribute__((unused)), eKeyMod __attribute__((unused)), Point __attribute__((unused))){
cControl::cControl(eControlType t, sf::RenderWindow& p) : parent(NULL), inWindow(&p), type(t), visible(true), key({false, 0, mod_none}) {}
bool cControl::triggerClickHandler(cDialog& __attribute__((unused)), std::string __attribute__((unused)), eKeyMod __attribute__((unused)), location __attribute__((unused))){
return true;
}
@@ -248,54 +271,42 @@ bool cControl::triggerFocusHandler(cDialog& me __attribute__((unused)), std::str
return true;
}
short cControl::font_nums[4];
std::string cControl::font_nums[4] = {"Dungeon", "Geneva", "Silom", "MaidenWord"};
void cControl::init(){
Str255 fnGeneva = "\pGeneva";
Str255 fnDungeon = "\pDungeon Bold";
Str255 fnMaiden = "\pMaidenWord";
Str255 fnSilom = "\pSilom";
Str255 fnPalatino = "\pPalatino";
Str255 fnChancery = "\pApple Chancery";
char fnGeneva[] = "Geneva";
char fnDungeon[] = "Dungeon Bold";
char fnMaiden[] = "MaidenWord";
char fnSilom[] = "Silom";
char fnPalatino[] = "Palatino";
char fnChancery[] = "Apple Chancery";
GetFNum(fnGeneva,&font_nums[GENEVA]);
if(font_nums[GENEVA] == 0)
GetFNum(fnPalatino,&font_nums[GENEVA]);
GetFNum(fnDungeon,&font_nums[DUNGEON]);
if(font_nums[DUNGEON] == 0)
GetFNum(fnChancery,&font_nums[DUNGEON]);
GetFNum(fnSilom,&font_nums[SILOM]);
if(font_nums[SILOM] == 0){
GetFNum(fnPalatino,&font_nums[SILOM]);
// Check if Silom is available
// TODO: Ultimately, I'd like to distribute all needed fonts with the game, rendering this unnecessary
try {
ResMgr::get<FontRsrc>("Silom");
found_silom = true;
} catch(ResMgr::xResMgrErr) {
found_silom = false;
}else found_silom = true;
GetFNum(fnMaiden,&font_nums[MAIDENWORD]);
if(font_nums[MAIDENWORD] == 0)
GetFNum(fnChancery,&font_nums[MAIDENWORD]);
}
}
void cControl::drawFrame(short amt, short med_or_lt){
static RGBColor lt_gray = {57344,57344,57344},dk_gray = {12287,12287,12287},med_gray = {24574,24574,24574};
GrafPtr old_port;
Rect rect = frame;
void cControl::drawFrame(short amt, bool med_or_lt){
// 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},med_gray = {96,96,96};
RECT rect = frame, ul_rect;
GetPort(&old_port);
SetPortWindowPort(parent->win);
inWindow->setActive();
InsetRect(&rect,-1 * amt,-1 * amt);
rect.inset(-amt,-amt);
ul_rect = rect;
ul_rect.left -= 1;
ul_rect.top -= 1;
RGBForeColor(&dk_gray);
MoveTo(rect.left,rect.top);
LineTo(rect.right,rect.top);
if (med_or_lt == 1) // hDlg == GetWindowPort(mainPtr) // ie for the pc editor only
RGBForeColor(&med_gray);
else RGBForeColor(&lt_gray);
LineTo(rect.right,rect.bottom);
LineTo(rect.left,rect.bottom);
RGBForeColor(&dk_gray);
LineTo(rect.left,rect.top);
ForeColor(blackColor);
SetPort(old_port);
frame_rect(*inWindow, rect, med_or_lt ? med_gray : lt_gray);
clip_rect(*inWindow, ul_rect);
frame_rect(*inWindow, rect, dk_gray);
undo_clip(*inWindow);
}
bool cControl::found_silom;

View File

@@ -9,45 +9,21 @@
#ifndef CONTROL_H
#define CONTROL_H
#include <SFML/Graphics.hpp>
#include <string>
#include <exception>
#include <boost/function.hpp>
#include <functional>
#include "dialog.h"
#include "location.h"
//struct cPict {
// short pict;
// short type;
//};
enum eKeyMod {
mod_none = 0,
mod_alt = 1, mod_shift = 2, mod_ctrl = 4,
mod_altshift = mod_alt + mod_shift,
mod_altctrl = mod_alt + mod_ctrl,
mod_shiftctrl = mod_shift + mod_ctrl,
mod_all = mod_alt + mod_shift + mod_ctrl,
};
enum eSpecKey {
key_left, key_right, key_up, key_down,
key_esc, key_enter, key_tab, key_help, // key_help should bind to the help key on Mac and the F1 key on Windows
key_bsp, key_del, key_home, key_end, key_pgup, key_pgdn, // TODO: Implement these
// On Mac, command-left should trigger key_home; command-right should trigger key_end;
// command-up should trigger key_pgup; and command-down should trigger key_pgdn.
// This is in addition to the home, end, pgup, pgdn keys triggering these.
};
struct cKey {
bool spec;
union {
unsigned char c;
eSpecKey k;
};
eKeyMod mod;
};
bool operator== (cKey& a, cKey& b);
enum eFormat {
TXT_COLOR,
TXT_FRAME,
TXT_FONT,
TXT_SIZE,
@@ -63,15 +39,15 @@ enum eControlType {
CTRL_TEXT, // A static text object
CTRL_GROUP, // A LED radiobutton-like group
CTRL_STACK, // A group of controls that display pages (not implemented yet)
CTRL_SCROLL,// A scrollbar (not implemented yet)
};
enum eTextFont {DUNGEON, GENEVA, SILOM, MAIDENWORD};
class cDialog;
//typedef bool (*click_callback_t)(cDialog&/*me*/,std::string/*id*/, eKeyMod/*mods*/);
//typedef bool (*focus_callback_t)(cDialog&/*me*/,std::string/*id*/,bool/*losing*/); // losing is true if losing focus, false if gaining focus.
typedef boost::function<bool(cDialog&,std::string,eKeyMod)> click_callback_t;
typedef boost::function<bool(cDialog&,std::string,bool)> focus_callback_t;
typedef std::function<bool(cDialog&,std::string,eKeyMod)> click_callback_t;
typedef std::function<bool(cDialog&,std::string,bool)> focus_callback_t;
class xHandlerNotSupported : std::exception {
static const char* focusMsg;
@@ -98,45 +74,47 @@ public:
void detachKey();
void setTextToKey();
bool hasKey();
cKey getAttachedKey();
virtual void attachClickHandler(click_callback_t f) throw(xHandlerNotSupported) = 0;
virtual void attachFocusHandler(focus_callback_t f) throw(xHandlerNotSupported) = 0;
virtual bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where);
virtual bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where);
virtual bool triggerFocusHandler(cDialog& me, std::string id, bool losingFocus);
//virtual void setPict(short pict, short type) = 0;
virtual void show(); // cd_activate_item true
virtual void hide(); // cd_activate_item false
bool isVisible(); // cd_get_active
void setActive(bool active); // "active" here means "selected", so if it's a button, draw it pressed
eControlType getType();
virtual void setText(std::string l);
virtual std::string getText();
RECT getBounds();
void setBounds(RECT newBounds);
void relocate(location to);
long getTextAsNum();
void setTextToNum(long what);
virtual void setFormat(eFormat prop, short val) throw(xUnsupportedProp) = 0;
virtual short getFormat(eFormat prop) throw(xUnsupportedProp) = 0;
virtual void setColour(sf::Color clr) throw(xUnsupportedProp) = 0;
virtual sf::Color getColour() throw(xUnsupportedProp) = 0;
virtual bool isClickable() = 0;
bool handleClick();
cControl(cDialog* p,eControlType t);
virtual bool handleClick();
cControl(eControlType t, sf::RenderWindow& p);
cControl(eControlType t, cDialog& p);
virtual ~cControl();
virtual void draw() = 0;
protected:
cDialog* parent;
sf::RenderWindow* inWindow;
std::string lbl;
bool visible, depressed; // depressed is only applicable for clickable controls
Rect frame;
bool visible, depressed = false; // depressed is only applicable for clickable controls
RECT frame;
cKey key;
friend class cDialog;
friend class cLedGroup;
//friend class cStack;
virtual void draw() = 0;
static bool foundSilom();
static short font_nums[4];
void drawFrame(short amt, short med_or_lt);
static std::string font_nums[4];
void drawFrame(short amt, bool med_or_lt);
private:
eControlType type;
static bool found_silom;
};
eKeyMod operator + (eKeyMod lhs, eKeyMod rhs);
eKeyMod operator - (eKeyMod lhs, eKeyMod rhs);
eKeyMod&operator += (eKeyMod&lhs, eKeyMod rhs);
eKeyMod&operator -= (eKeyMod&lhs, eKeyMod rhs);
#endif

View File

@@ -0,0 +1,99 @@
The old dialogs are represented as DITL resource (technically a DLOG resource, but the DITL contains all the important stuff). All items in the DITL resource are either static text or editable text fields.
The static text entries have magic characters in them to specify their purpose. An empty static text is equivalent to one consisting solely of the character "+".
Actual text entries are anything that doesn't begin with a digit. (The original code actually requires them to begin with [A-z"] or a formatting character.) They may begin with any of the following characters to represent formatting:
type flag meaning
+ 3 1 white Geneva bold 10pt framed
* 3 0 white Geneva bold 10pt
~ 7 0 white Geneva bold 12pt
! 4 0 white Geneva plain 10pt
= 9 1 same as 3,1, but text wraps
9 0 same as 3,0, but text wraps
^ 10 1 or 2 -- note, this type would never be reached by the original code
& 11 1 or 2
For ^ or &, flag=2 if string_length > 55. I think string_length is pixel length, not character length. These are buttons, not text, so the upshot is that longer text is automatically put on a larger button.
All other entries are of the form %d_%d, ie two numbers separated by an underscore. The first number is the type, and the second is the flag.
Item types 0, 1, 10, 11 are buttons. I think 10 and 11 are buttons with arbitrary text, while 0 and 1 are predefined buttons. The flag is the button style. There seems to be no difference whatsoever between 0 and 1 or between 10 and 11, but I think the intention was that 1 and 11 function as the "default button", meaning pressing enter selects them. The button styles are:
0 = small
1 = regular
2 = large
3 = white help button with ? on it
4 = left arrow
5 = right arrow
6 = up arrow
7 = down arrow
8 = LED indicator (probably unused?)
9 = LED on (probably unused?)
10 = LED off (probably unused?)
11 = Done
12 = tall
13 = Race Good/Bad Traits
14 = Round red push button (unused?)
If a button has a flag of 143, no button graphic is drawn, but the label is, so this would make clickable text (ie hyperlinks).
Item type 2 is an LED button. The flag specifies its state:
0 = black (off)
1 = red
2 = green
for. If the flag is 0 it uses button type 10 (BTN_TALL), while if the flag is 1 or 2 it uses button type 9 (BTN_DONE). It looks like flag 1 always uses the pressed state. (Oh, maybe this is an LED?)
Item types 3, 4, 7, 8, and 9 are text. They are formatted as follows:
3 = Geneva bold 10pt, line height 12
4 = Geneva plain 10pt, line height 12
7 = Geneva bold 12pt, line height 14
8 = Dungeon plain 18pt, line height 12? (only used for one dialog)
9 = Geneva bold 10pt, line height 12
(Note, I have substituted Silom for Geneva bold.)
The flag is interpreted as follows:
0 = White, no frame
1 = White, framed
10 = Red, no frame
11 = Red, framed
However, type 8 is never red; it appears to be clickable, and can even have a key equivalent. Also notice that 9 and 3 are in fact identical.
Item type 6 is processed when creating a new window and then never again touched. I think it might be a clickable area.
Item type 5 is a graphic. The flag specifies which graphic to draw, according to the following table:
-1 solid black
0 + x number of terrain graphic
300 + x animated terrain graphic (grabs the first frame only)
400 + x monster graphic num
700 + x dlog graphic (large dlog graphics were done by using four of these arranged in the correct way)
800 + x pc graphic
900 + x B&W graphic - the PICT resource for this does not exist
950 null item
1000 + x Talking face
1100 item info help
1200 pc screen help
1300 combat ap
1400-1402 button help
1410-1412 large scen graphics
1500 stat symbols help
1600 + x scen graphics
1700 + x anim graphic -- drawn from fields_gworld, so a boom or barrier icon?
1800 + x items
2000 + x custom graphics up to 2399
2400 + x custom graphics up to 2799, BUT it's a split graphic ...
it looks at the size of rect, and places a 32 x 32 or 36 x 36 graphic drawn
from the custom gworld, depending on the size of rect. half of graphic is
drawn from one custom slot, and half is drawn from next one.
+3000 suppress drawing a frame around the graphic
Item types 12+ are unused.
Dialog ID 1098 has some special stuff done by draw_pc_effects for item_nums 18...23. It looks like this is status effects in the spellcasting window.
Hotkeys can be attached to buttons (types 0, 1, 2) and, for some reason, to type 8.
Label flags for cd_add_label are of the form xyzz, where:
- x is 0 for Geneva plain, 1 for bold
- y is 0 for left, 1 for above, 2 for right, 3 for below
- zz specifies the distance of the label from its control, in multiples of 2 pixels

File diff suppressed because it is too large Load Diff

View File

@@ -1,155 +0,0 @@
* {
position: absolute;
display: block;
margin: 0px;
}
.debug {
border: dotted black thin;
}
title {
display:none;
}
.dialog {
border: dashed green thin;
}
.text, .led, .button, .field {
overflow: hidden ! important;
}
.pict {
padding: 2px;
border: inset black thin;
background-repeat: no-repeat;
background-position: center;
}
.pict.dlog {
width: 36px;
height: 36px;
}
.pict.ter , .pict.teranim , .pict.item ,
.pict.monst , .pict.field , .pict.boom ,
.pict.pc {
width: 28px;
height: 36px;
}
.pict.scen , .pict.talk {
width: 32px;
height: 32px;
}
.pict.missile {
width: 18px;
height: 18px;
}
.pict.scen.large {
width: 64px;
height: 64px;
}
.pict.dlog.large {
width: 72px;
height: 72px;
}
.pict.status {
width: 12px;
height: 12px;
}
.pict.map {
width: 24px;
height: 24px;
}
.button , .led {
padding: 0px;
background-repeat: no-repeat;
background-position: center;
text-align: center;
font-size: 12px;
font-family: Silom;
vertical-align: middle;
padding-top: 6px;
}
.button.small {
width: 23px;
height: 23px;
}
.button.regular , .button.left , .button.right ,
.button.up , .button.down , .button.done {
width: 63px;
height: 23px;
}
.button.large {
width: 102px;
height: 23px;
}
.button.help {
width: 16px;
height: 13px;
}
.button.tiny , .led {
min-width: 14px;
height: 10px;
text-align: left;
background-position: left center;
padding-left: 18px;
padding-top: 0px;
padding-bottom: 5px;
font-family: Geneva;
font-size: 10px;
}
.button.tall , .button.trait {
width: 63px;
height: 40px;
padding-top: 22px;
}
.button.push {
min-width: 30px;
height: 30px;
background-position: top center;
padding-top: 30px;
}
.field {
padding: 2px;
border: solid black thin;
}
.field-inner {
background-color:white;
}
.text {
font-size: 10px;
font-family: Silom;
line-height: 12px;
}
.text.framed {
padding: 2px;
border: inset thin black;
}
.text.large {
font-size: 12px;
}
.text.plain {
font-family: Geneva;
}

View File

@@ -1,84 +0,0 @@
<!ELEMENT dialog ((field | text | pict | button | led | group)*)>
<!ELEMENT field EMPTY>
<!ELEMENT br EMPTY>
<!ELEMENT text ((#PCDATA|br)*)>
<!ELEMENT pict EMPTY>
<!ELEMENT key EMPTY>
<!ELEMENT button (#PCDATA*|key)>
<!ELEMENT led (CDATA)>
<!ELEMENT group (led+)>
<!ELEMENT stack ((field | text | pict | button | led | group)*)>
<!ENTITY % num 'NUMBER'>
<!ENTITY % bool '(true|false)'>
<!ENTITY % picttype '(blank|ter|teranim|monst|dlog|talk|scen|item|pc|field|boom|missile|full|map|status)'>
<!ENTITY % btntype '(small|regular|large|help|left|right|up|down|tiny|done|tall|trait|push)'>
<!ENTITY % digit '(0|1|2|3|4|5|6|7|8|9)'>
<!ENTITY % letter '(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)'>
<!ENTITY % symbol '(`|-|=|[|]|\|;|'|,|.|/)'>
<!ENTITY % mod '((ctrl|shift|alt)*)'>
<!ENTITY % key '(%mod; (%digit;|%letter;|%symbol;|left|right|up|down|esc|enter|return|tab|help|space))'>
<!ENTITY % rect '
top %num; #REQUIRED
left %num; #REQUIRED
width %num; #IMPLIED
height %num; #IMPLIED
'>
<!ENTITY % font "
font (dungeon|geneva|silom|maidenword) 'silom'
size (small|large) 'small'
color CDATA #IMPLIED
colour CDATA #IMPLIED
">
<!ATTLIST dialog
skin (light|dark) 'dark'
debug %bool; 'false'
fore CDATA 'black'
>
<!ATTLIST field
name ID #IMPLIED
type (num|text) 'text'
%rect;
>
<!ATTLIST text
name ID #IMPLIED
framed %bool; 'true'
%font;
def-key (%key;|none) 'none'
clickable %bool; 'false'
fromlist (none|CDATA) 'none'
%rect;
>
<!ATTLIST pict
name ID #IMPLIED
type %picttype; #REQUIRED
custom %bool; 'false'
size (small|wide|tall|large) #IMPLIED
def-key (%key;|none) 'none'
clickable %bool; 'false'
num %num; #REQUIRED
%rect;
>
<!ATTLIST button
name ID #IMPLIED
type %btntype; #REQUIRED
wrap %bool; 'false'
def-key (%key;|none) 'none'
fromlist (none|CDATA) 'none'
%rect;
>
<!ATTLIST led
name ID #IMPLIED
state (red|green|off) 'off'
fromlist (none|CDATA) 'none'
%rect;
%font;
>
<!ATTLIST group
name ID #IMPLIED
fromlist (none|CDATA) 'none'
>
<!ATTLIST stack
name ID #IMPLIED
>

View File

@@ -9,59 +9,69 @@
#ifndef DIALOG_H
#define DIALOG_H
#include <SFML/Graphics.hpp>
#include <string>
#include <map>
#include <exception>
#include "ticpp.h"
#include "dialog.keys.h"
#include "location.h"
#include <boost/any.hpp>
#include "control.h"
#include "button.h"
#include "field.h"
#include "pict.h"
#include "message.h"
class cControl;
class cTextField;
enum eLabelPos {
LABEL_LEFT, LABEL_ABOVE, LABEL_RIGHT, LABEL_BELOW,
};
class cDialog {
typedef std::map<std::string,cControl*>::iterator ctrlIter;
std::map<std::string,cControl*> controls;
short bg;
RGBColor defTextClr;
sf::Color defTextClr;
template<class T> std::pair<std::string,T*> parse(ticpp::Element& who);
RGBColor parseColor(std::string what);
sf::Color parseColor(std::string what);
cKey parseKey(std::string what);
WindowRef win;
sf::RenderWindow win;
cTextField* currentFocus;
class _init {
_init();
~_init();
friend class cDialog;
};
static _init init;
cDialog* parent;
void loadFromFile(std::string path);
public:
static void init();
static bool noAction(cDialog&,std::string,eKeyMod) {}
static const short BG_LIGHT, BG_DARK;
explicit cDialog(cDialog* p = NULL); // dialog with no items
explicit cDialog(std::string path); // cd_create_dialog
cDialog(std::string path,cDialog* p); // cd_create_dialog_parent_num
~cDialog(); // cd_kill_dialog
bool add(cControl* what, Rect ctrl_frame, std::string key); // returns false if the key is used, true if the control was added
bool add(cControl* what, RECT ctrl_frame, std::string key); // returns false if the key is used, true if the control was added
bool remove(std::string key); // returns true if the key existed and was removed, false if the key did not exist
bool addLabelFor(std::string key, std::string label, eLabelPos where, short offset, bool bold); // returns true if the label was added
void run(); // cd_run_dialog
template<class type> type& getResult();
template<class type> type getResult();
template<class type> void setResult(const type& val);
void setBg(short n);
void setDefTextClr(RGBColor clr);
void setDefTextClr(sf::Color clr);
sf::Color getDefTextClr();
bool toast();
cControl& getControl(std::string id);
cControl& operator[](std::string id);
void recalcRect();
// TODO: It seems like a bad thing for these two to not use the typedefs...
void attachClickHandlers(std::function<bool(cDialog&,std::string,eKeyMod)> handler, std::vector<std::string> controls);
void attachFocusHandlers(std::function<bool(cDialog&,std::string,bool)> handler, std::vector<std::string> controls);
RECT getBounds() {return winRect;}
private:
void draw();
std::string process_keystroke(cKey keyHit);
std::string process_click(Point where, eKeyMod mods);
std::string process_click(location where, eKeyMod mods);
bool dialogNotToast;
Rect winRect;
unsigned long long result;
RECT winRect;
std::string defaultButton;
boost::any result;
friend class cControl;
friend class cButton;
friend class cLed;
@@ -69,6 +79,7 @@ private:
friend class cPict;
friend class cTextField;
friend class cTextMsg;
friend class cScrollbar;
friend class _init;
};

View File

@@ -0,0 +1,48 @@
//
// dialog.keys.h
// BoE
//
// Created by Celtic Minstrel on 14-03-31.
//
//
#ifndef BoE_dialog_keys_h
#define BoE_dialog_keys_h
enum eKeyMod {
mod_none = 0,
mod_alt = 1, mod_shift = 2, mod_ctrl = 4,
mod_altshift = mod_alt + mod_shift,
mod_altctrl = mod_alt + mod_ctrl,
mod_shiftctrl = mod_shift + mod_ctrl,
mod_all = mod_alt + mod_shift + mod_ctrl,
};
enum eSpecKey {
key_left, key_right, key_up, key_down,
key_esc, key_enter, key_tab, key_help, // key_help should bind to the help key on Mac and the F1 key on Windows
key_bsp, key_del, key_home, key_end, key_pgup, key_pgdn, // TODO: Implement these
key_copy, key_cut, key_paste, key_selectall
// On Mac, command-left should trigger key_home; command-right should trigger key_end;
// command-up should trigger key_pgup; and command-down should trigger key_pgdn.
// This is in addition to the home, end, pgup, pgdn keys triggering these.
};
struct cKey {
bool spec;
union {
unsigned char c;
eSpecKey k;
};
eKeyMod mod;
};
eKeyMod operator + (eKeyMod lhs, eKeyMod rhs);
eKeyMod operator - (eKeyMod lhs, eKeyMod rhs);
eKeyMod&operator += (eKeyMod&lhs, eKeyMod rhs);
eKeyMod&operator -= (eKeyMod&lhs, eKeyMod rhs);
bool operator== (cKey a, cKey b);
bool mod_contains(eKeyMod haystack, eKeyMod needle);
#endif

View File

@@ -7,113 +7,11 @@
*/
// Functions for allowing the dialog to have a result which can be of any type.
// Be sure to call setResult and getResult with the exact same template parameters!
// If you don't, bad things could happen. (Especially if you get the result as
// a pointer when it was set as an integral type.)
// Note however that for non-integral types it's safe to set it as type pointer to X and then
// get it as type X or vice versa, since setting it as type X stores the address anyway.
template<typename type> inline void cDialog::setResult(const type& val){
const type* ptr = &val;
result = reinterpret_cast<const unsigned long long&>(ptr);
result = val;
}
template<> inline void cDialog::setResult<char>(const char& val){
result = reinterpret_cast<const unsigned long long&>(val);
template<typename type> inline type cDialog::getResult(){
return boost::any_cast<type>(result);
}
template<> inline void cDialog::setResult<signed char>(const signed char& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<unsigned char>(const unsigned char& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<signed short>(const signed short& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<unsigned short>(const unsigned short& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<signed int>(const signed int& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<unsigned int>(const unsigned int& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<signed long>(const signed long& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<unsigned long>(const unsigned long& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<signed long long>(const signed long long& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<unsigned long long>(const unsigned long long& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<> inline void cDialog::setResult<bool>(const bool& val){
result = reinterpret_cast<const unsigned long long&>(val);
}
template<typename type> inline type& cDialog::getResult(){
return *reinterpret_cast<type*>(result);
}
template<> inline char& cDialog::getResult<char>(){
return reinterpret_cast<char&>(result);
}
template<> inline signed char& cDialog::getResult<signed char>(){
return reinterpret_cast<signed char&>(result);
}
template<> inline unsigned char& cDialog::getResult<unsigned char>(){
return reinterpret_cast<unsigned char&>(result);
}
template<> inline signed short& cDialog::getResult<signed short>(){
return reinterpret_cast<signed short&>(result);
}
template<> inline unsigned short& cDialog::getResult<unsigned short>(){
return reinterpret_cast<unsigned short&>(result);
}
template<> inline signed int& cDialog::getResult<signed int>(){
return reinterpret_cast<signed int&>(result);
}
template<> inline unsigned int& cDialog::getResult<unsigned int>(){
return reinterpret_cast<unsigned int&>(result);
}
template<> inline signed long& cDialog::getResult<signed long>(){
return reinterpret_cast<signed long&>(result);
}
template<> inline unsigned long& cDialog::getResult<unsigned long>(){
return reinterpret_cast<unsigned long&>(result);
}
template<> inline signed long long& cDialog::getResult<signed long long>(){
return reinterpret_cast<signed long long&>(result);
}
template<> inline unsigned long long& cDialog::getResult<unsigned long long>(){
return reinterpret_cast<unsigned long long&>(result);
}
template<> inline bool& cDialog::getResult<bool>(){
return reinterpret_cast<bool&>(result);
}

View File

@@ -1,167 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- <?xml-stylesheet href="http://www.w3.org/StyleSheets/TR/W3C-REC.css" type="text/css"?>
<?xml-stylesheet href="" type="text/css"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match='/'>
<html> <!-- xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" -->
<head>
<title>Dialog Preview</title>
<link rel='stylesheet' type='text/css' href='dialog.css'/>
</head>
<body>
<xsl:attribute name='style'>
background-image: url('bg/<xsl:value-of select='/dialog/@skin'/>.png');
</xsl:attribute>
<div class='dialog'>
<xsl:for-each select='dialog/pict'>
<xsl:choose>
<xsl:when test='@type = "full"'>
<div>
<xsl:attribute name='class'>pict <xsl:value-of select='./@type'/></xsl:attribute>
<xsl:attribute name='style'>
background-image: url('other/<xsl:value-of select='./@num'/>.png');
left: <xsl:value-of select='./@left'/>px; top: <xsl:value-of select='./@top'/>px;
width: <xsl:value-of select='./@width'/>px; height: <xsl:value-of select='./@height'/>px;
</xsl:attribute>
</div>
</xsl:when>
<xsl:when test='@type = "blank"'>
<div>
<xsl:attribute name='class'>pict <xsl:value-of select='./@type'/></xsl:attribute>
<xsl:attribute name='style'>
background-color: black;
left: <xsl:value-of select='./@left'/>px; top: <xsl:value-of select='./@top'/>px;
</xsl:attribute>
</div>
</xsl:when>
<xsl:when test='@size = "large" and @type != "monst"'>
<div>
<xsl:attribute name='class'>pict large <xsl:value-of select='./@type'/></xsl:attribute>
<xsl:attribute name='style'>
background-image: url('<xsl:value-of select='./@type'/>/large<xsl:value-of select='./@num'/>.png');
left: <xsl:value-of select='./@left'/>px; top: <xsl:value-of select='./@top'/>px;
</xsl:attribute>
</div>
</xsl:when>
<xsl:otherwise>
<div>
<xsl:attribute name='class'>pict <xsl:value-of select='./@type'/></xsl:attribute>
<xsl:attribute name='style'>
background-image: url('<xsl:value-of select='./@type'/>/<xsl:value-of select='./@num'/>.png');
left: <xsl:value-of select='./@left'/>px; top: <xsl:value-of select='./@top'/>px;
</xsl:attribute>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select='dialog/button'>
<div>
<xsl:attribute name='class'>
button <xsl:value-of select='./@type'/>
</xsl:attribute>
<xsl:attribute name='style'>
background-image: url('button/<xsl:value-of select='./@type'/>.png');
left: <xsl:value-of select='./@left'/>px; top: <xsl:value-of select='./@top'/>px;
<xsl:if test='@type = "push"'>width: <xsl:value-of select='./@width'/>;</xsl:if>
</xsl:attribute>
<xsl:attribute name='title'>
<xsl:value-of select='./@key'/>
</xsl:attribute>
<xsl:value-of select='.'/>
</div>
</xsl:for-each>
<xsl:for-each select='dialog/led'>
<div>
<xsl:attribute name='class'>
led
<xsl:if test='/dialog/@debug = "true"'>debug</xsl:if>
</xsl:attribute>
<xsl:attribute name='style'>
color: <xsl:value-of select='./@color'/> <xsl:value-of select='/dialog/@fore'/>;
font-family:
<xsl:choose>
<xsl:when test='@font = "plain"'>Geneva</xsl:when>
<xsl:when test='@font = "bold"'>Silom</xsl:when>
<xsl:otherwise><xsl:value-of select='./@font'/></xsl:otherwise>
</xsl:choose>;
background-image: url('button/led-<xsl:value-of select='./@state'/>.png');
left: <xsl:value-of select='./@left'/>px; top: <xsl:value-of select='./@top'/>px;
width: <xsl:value-of select='./@width'/>px;
</xsl:attribute>
<xsl:value-of select='.'/>
</div>
</xsl:for-each>
<xsl:for-each select='dialog/group/led'>
<div>
<xsl:attribute name='class'>
led
<xsl:if test='/dialog/@debug = "true"'>debug</xsl:if>
</xsl:attribute>
<xsl:attribute name='style'>
color: <xsl:value-of select='./@color'/> <xsl:value-of select='/dialog/@fore'/>;
font-family:
<xsl:choose>
<xsl:when test='@font = "plain"'>Geneva</xsl:when>
<xsl:when test='@font = "bold"'>Silom</xsl:when>
<xsl:otherwise><xsl:value-of select='./@font'/></xsl:otherwise>
</xsl:choose>;
border-color: red;
background-image: url('button/led-<xsl:value-of select='./@state'/>.png');
left: <xsl:value-of select='./@left'/>px; top: <xsl:value-of select='./@top'/>px;
width: <xsl:value-of select='./@width'/>px;
</xsl:attribute>
<xsl:value-of select='.'/>
</div>
</xsl:for-each>
<xsl:for-each select='dialog/text'>
<div>
<xsl:attribute name='class'>
text
<xsl:if test='@framed = "true"'>framed </xsl:if>
<xsl:if test='@size = "large"'>large </xsl:if>
<xsl:if test='/dialog/@debug = "true"'>debug</xsl:if>
</xsl:attribute>
<xsl:attribute name='style'>
color: <xsl:value-of select='./@color'/> <xsl:value-of select='/dialog/@fore'/>;
font-family: <xsl:value-of select='./@font'/>;
left: <xsl:value-of select='./@left'/>px; top: <xsl:value-of select='./@top'/>px;
width: <xsl:value-of select='./@width'/>px; height: <xsl:value-of select='./@height'/>px;
</xsl:attribute>
<xsl:value-of select='.'/>
</div>
</xsl:for-each>
<xsl:for-each select='dialog/field'>
<div class='field'>
<xsl:attribute name='style'>
left: <xsl:value-of select='./@left'/>px; top: <xsl:value-of select='./@top'/>px;
width: <xsl:value-of select='./@width'/>px; height: <xsl:value-of select='./@height'/>px;
</xsl:attribute>
<div class='field-inner'>
<xsl:attribute name='style'>
width: <xsl:value-of select='./@width'/>px; height: <xsl:value-of select='./@height'/>px;
font-family: Geneva;
font-size: 12px;
</xsl:attribute>
(<xsl:value-of select='@name'/>)
</div>
</div>
</xsl:for-each>
</div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

View File

@@ -15,7 +15,7 @@ size_t available_btns[] = { // This array is a list of indices into the followin
135,136,137
};
cBasicButtonType basic_buttons[] = {
bbtt basic_buttons[] = {
{BTN_DONE, " ", {false,0,mod_none}}, // Formerly DLG_BTN_REG with "Done " as the string
{BTN_REG, "Ask", {false,0,mod_none}},
{BTN_LEFT, " ", {true,key_left,mod_none}},
@@ -82,7 +82,7 @@ cBasicButtonType basic_buttons[] = {
{BTN_LG, "Bash Door", {false,0,mod_none}},
{BTN_LG, "Pick Lock", {false,0,mod_none}},
//60
{BTN_REG, "Leave", {false,0,mod_none}},
{BTN_REG, "Leave", {false,0,mod_none}}, // dupe
{BTN_REG, "Steal", {false,0,mod_none}},
{BTN_REG, "Attack", {false,0,mod_none}},
{BTN_REG, "OK", {false,0,mod_none}},

View File

@@ -7,24 +7,23 @@
*/
#define BTNS_DEFINED
#include <Carbon/Carbon.h>
#include <sstream>
#include <algorithm>
#include <boost/bind.hpp>
#include <functional>
#include "dialog.h"
#include "dlogutil.h"
#include "mathutil.h"
#include <array>
#include "message.h"
// TODO: This should probably be a source file instead of a header
#include "dlogutil.buttons.h" // must be included here and only here
const size_t cPictChoice::per_page = 36;
cPictChoice::cPictChoice(std::vector<pic_num_t>& pics,ePicType t,cDialog* parent) : dlg("choose-pict.xml",parent), type(t) {
dlg["left"].attachClickHandler(boost::bind(&cPictChoice::onLeft,this,_1,_2));
dlg["right"].attachClickHandler(boost::bind(&cPictChoice::onRight,this,_1,_2));
dlg["done"].attachClickHandler(boost::bind(&cPictChoice::onOkay,this,_1,_2));
dlg["cancel"].attachClickHandler(boost::bind(&cPictChoice::onCancel,this,_1,_2));
attachClickHandlers();
picts = pics;
sort(picts.begin(),picts.end());
}
@@ -35,18 +34,35 @@ cPictChoice::cPictChoice(
ePicType t,
cDialog* parent
) : dlg("choose-pict.xml",parent), type(t) {
dlg["left"].attachClickHandler(boost::bind(&cPictChoice::onLeft,this,_1,_2));
dlg["right"].attachClickHandler(boost::bind(&cPictChoice::onRight,this,_1,_2));
dlg["done"].attachClickHandler(boost::bind(&cPictChoice::onOkay,this,_1,_2));
dlg["cancel"].attachClickHandler(boost::bind(&cPictChoice::onCancel,this,_1,_2));
attachClickHandlers();
copy(begin,end,picts.begin());
sort(picts.begin(),picts.end());
}
cPictChoice::cPictChoice(pic_num_t begin, pic_num_t end, ePicType t, cDialog* parent) : dlg("choose-pict.xml",parent), type(t) {
attachClickHandlers();
for(pic_num_t i = begin; i < end; i++) {
picts.push_back(i);
}
}
void cPictChoice::attachClickHandlers() {
using namespace std::placeholders;
dlg["left"].attachClickHandler(std::bind(&cPictChoice::onLeft,this,_1,_2));
dlg["right"].attachClickHandler(std::bind(&cPictChoice::onRight,this,_1,_2));
dlg["done"].attachClickHandler(std::bind(&cPictChoice::onOkay,this,_1,_2));
dlg["cancel"].attachClickHandler(std::bind(&cPictChoice::onCancel,this,_1,_2));
}
cDialog* cPictChoice::operator->() {
return &dlg;
}
pic_num_t cPictChoice::show(pic_num_t fallback, pic_num_t cur_sel){
dlg.setResult(fallback);
cur = cur_sel;
page = cur / per_page;
// TODO: Hide left/right buttons if only one page?
fillPage();
dlg.run();
return dlg.getResult<pic_num_t>();
@@ -76,14 +92,14 @@ void cPictChoice::fillPage(){
}
bool cPictChoice::onLeft(cDialog& m, std::string ide){
if(page == 0) page = picts.size() / per_page;
if(page == 0) page = (picts.size() - 1) / per_page;
else page--;
fillPage();
return true;
}
bool cPictChoice::onRight(cDialog& me, std::string id){
if(page == picts.size() / per_page) page = 0;
if(page == (picts.size() - 1) / per_page) page = 0;
else page++;
fillPage();
return true;
@@ -106,10 +122,11 @@ cStringChoice::cStringChoice(
std::vector<std::string>& strs,
cDialog* parent
) : dlg("choose-string.xml",parent) {
dlg["left"].attachClickHandler(boost::bind(&cStringChoice::onLeft,this,_1,_2));
dlg["right"].attachClickHandler(boost::bind(&cStringChoice::onRight,this,_1,_2));
dlg["done"].attachClickHandler(boost::bind(&cStringChoice::onOkay,this,_1,_2));
dlg["cancel"].attachClickHandler(boost::bind(&cStringChoice::onCancel,this,_1,_2));
using namespace std::placeholders;
dlg["left"].attachClickHandler(std::bind(&cStringChoice::onLeft,this,_1,_2));
dlg["right"].attachClickHandler(std::bind(&cStringChoice::onRight,this,_1,_2));
dlg["done"].attachClickHandler(std::bind(&cStringChoice::onOkay,this,_1,_2));
dlg["cancel"].attachClickHandler(std::bind(&cStringChoice::onCancel,this,_1,_2));
strings = strs;
}
@@ -118,10 +135,11 @@ cStringChoice::cStringChoice(
std::vector<std::string>::iterator end,
cDialog* parent
) : dlg("choose-string.xml",parent) {
dlg["left"].attachClickHandler(boost::bind(&cStringChoice::onLeft,this,_1,_2));
dlg["right"].attachClickHandler(boost::bind(&cStringChoice::onRight,this,_1,_2));
dlg["done"].attachClickHandler(boost::bind(&cStringChoice::onOkay,this,_1,_2));
dlg["cancel"].attachClickHandler(boost::bind(&cStringChoice::onCancel,this,_1,_2));
using namespace std::placeholders;
dlg["left"].attachClickHandler(std::bind(&cStringChoice::onLeft,this,_1,_2));
dlg["right"].attachClickHandler(std::bind(&cStringChoice::onRight,this,_1,_2));
dlg["done"].attachClickHandler(std::bind(&cStringChoice::onOkay,this,_1,_2));
dlg["cancel"].attachClickHandler(std::bind(&cStringChoice::onCancel,this,_1,_2));
copy(begin,end,strings.begin());
}
@@ -181,20 +199,18 @@ bool cStringChoice::onOkay(cDialog& me, std::string id __attribute__((unused))){
}
cChoiceDlog::cChoiceDlog(std::string file, std::vector<std::string> buttons, cDialog* p) : dlg(file, p) {
using namespace std::placeholders;
std::vector<std::string>::iterator iter = buttons.begin();
while(iter != buttons.end()){
dlg[*iter].attachClickHandler(boost::bind(&cChoiceDlog::onClick,this,_1,_2));
dlg[*iter].attachClickHandler(std::bind(&cChoiceDlog::onClick,this,_1,_2));
iter++;
}
}
cChoiceDlog::cChoiceDlog(std::vector<std::string> buttons, cDialog* p) : dlg(p) {
std::vector<std::string>::iterator iter = buttons.begin();
while(iter != buttons.end()){
dlg[*iter].attachClickHandler(boost::bind(&cChoiceDlog::onClick,this,_1,_2));
iter++;
}
}
cChoiceDlog::cChoiceDlog(cDialog* p) : dlg(p) {}
cChoiceDlog::cChoiceDlog(std::string file, cDialog* p)
: cChoiceDlog(file, {"okay"}, p) {}
// so that the caller can set up aspects of the dialog if necessary
cDialog* cChoiceDlog::operator->(){
@@ -212,49 +228,38 @@ bool cChoiceDlog::onClick(cDialog& me, std::string id){
return true;
}
template<bool b> bbtt<b>::operator bool(){
return b;
}
template<bool b> bbtt<b>& bbtt<b>::operator=(bbtt<!b>&){
return *this;
}
cThreeChoice::cThreeChoice
(std::vector<std::string> strings,short btn1,short btn2,short btn3,pic_num_t pic,ePicType t,cDialog* parent)
: cChoiceDlog(/*cThreeChoice<type>::getFileName(strings.size()),*/ std::vector<std::string>(), parent), type(t){
(std::vector<std::string>& strings, std::array<cBasicButtonType, 3>& buttons, pic_num_t pic, ePicType t, cDialog* parent)
: cChoiceDlog(parent), type(t){
if(type == PIC_CUSTOM_DLOG_LG || type == PIC_DLOG_LG || type == PIC_SCEN_LG)
init_strings(strings,86);
else
init_strings(strings,50);
if(btn1 < 0){
if(btn2 < 0){
if(btn3 < 0)
init_buttons(basic_buttons[available_btns[63]],null_btn,null_btn);
else init_buttons(null_btn,null_btn,basic_buttons[available_btns[btn3]]);
}else{
if(btn3 < 0)
init_buttons(null_btn,basic_buttons[available_btns[btn2]],null_btn);
else init_buttons(null_btn,basic_buttons[available_btns[btn2]],basic_buttons[available_btns[btn3]]);
}
}else{
if(btn2 < 0){
if(btn3 < 0)
init_buttons(basic_buttons[available_btns[btn1]],null_btn,null_btn);
else init_buttons(basic_buttons[available_btns[btn1]],null_btn,basic_buttons[available_btns[btn3]]);
}else{
if(btn3 < 0)
init_buttons(basic_buttons[available_btns[btn1]],basic_buttons[available_btns[btn2]],null_btn);
else init_buttons(basic_buttons[available_btns[btn1]],basic_buttons[available_btns[btn2]],
basic_buttons[available_btns[btn3]]);
}
init_buttons(buttons[1], buttons[2], buttons[3]);
init_pict(pic);
operator->()->recalcRect();
}
cThreeChoice::cThreeChoice
(std::vector<std::string>& strings,std::array<short, 3>& buttons,pic_num_t pic,ePicType t,cDialog* parent)
: cChoiceDlog(parent), type(t){
if(type == PIC_CUSTOM_DLOG_LG || type == PIC_DLOG_LG || type == PIC_SCEN_LG)
init_strings(strings,86);
else
init_strings(strings,50);
std::array<cBasicButtonType, 3> buttonDefs;
int i = 0;
for(short j : buttons) {
if(j < 0) buttonDefs[i++] = null_btn;
else buttonDefs[i++] = basic_buttons[available_btns[j]];
}
init_buttons(buttonDefs[0], buttonDefs[1], buttonDefs[2]);
init_pict(pic);
operator->()->recalcRect();
}
void cThreeChoice::init_strings(std::vector<std::string>& strings, unsigned short left){
Rect cur_text_rect = {2, left, 0, 0};
RECT cur_text_rect = {2, left, 0, 0};
size_t total_len, str_width, str_height;
for (unsigned int i = 0; i < strings.size(); i++)
total_len += string_length(strings[i].c_str());
@@ -279,22 +284,22 @@ void cThreeChoice::init_strings(std::vector<std::string>& strings, unsigned shor
buttons_top = cur_text_rect.top;
}
template<bool a, bool b, bool c> void cThreeChoice::init_buttons(bbtt<a> btn1,bbtt<b> btn2,bbtt<c> btn3){
Rect cur_btn_rect = {buttons_top,0,0,buttons_right};
// The assignments in the if statements are intentional here.
if(btn_used[0] = a) btns[0] = btn1;
if(btn_used[1] = b) btns[1] = btn2;
if(btn_used[2] = c) btns[2] = btn3;
void cThreeChoice::init_buttons(cBasicButtonType btn1, cBasicButtonType btn2, cBasicButtonType btn3){
using namespace std::placeholders;
RECT cur_btn_rect = {buttons_top,0,0,buttons_right};
if(btn1) btns[0] = btn1;
if(btn2) btns[1] = btn2;
if(btn3) btns[2] = btn3;
cDialog* me = operator->();
for(int i = 0; i < 3; i++){
if(!btn_used[i]) continue;
if(!btns[i]) continue;
std::ostringstream sout;
sout << "btn" << i + 1;
cButton* btn = new cButton(me);
btn->attachKey(btns[i].defaultKey);
btn->setText(btns[i].label);
btn->setType(btns[i].type);
btn->attachClickHandler(boost::bind(&cChoiceDlog::onClick,this,_1,_2));
btn->attachKey(btns[i]->defaultKey);
btn->setText(btns[i]->label);
btn->setType(btns[i]->type);
btn->attachClickHandler(std::bind(&cChoiceDlog::onClick,this,_1,_2));
switch(type){
case BTN_HELP:
cur_btn_rect.bottom = cur_btn_rect.top + 13;
@@ -339,50 +344,50 @@ template<bool a, bool b, bool c> void cThreeChoice::init_buttons(bbtt<a> btn1,bb
}
void cThreeChoice::init_pict(pic_num_t pic){
Rect pic_rect;
RECT pic_rect;
switch(type){
case PIC_DLOG:
case PIC_CUSTOM_DLOG:
SetRect(&pic_rect,0,0,36,36);
pic_rect = {0,0,36,36};
break;
case PIC_TALK:
case PIC_CUSTOM_TALK:
case PIC_SCEN:
case PIC_CUSTOM_SCEN:
SetRect(&pic_rect,0,0,32,32);
pic_rect = {0,0,32,32};
break;
case PIC_MISSILE:
case PIC_CUSTOM_MISSILE:
SetRect(&pic_rect,0,0,18,18);
pic_rect = {0,0,18,18};
break;
case PIC_DLOG_LG:
case PIC_CUSTOM_DLOG_LG:
SetRect(&pic_rect,0,0,72,72);
pic_rect = {0,0,72,72};
break;
case PIC_SCEN_LG:
SetRect(&pic_rect,0,0,64,64);
pic_rect = {0,0,64,64};
break;
case PIC_TER_MAP:
case PIC_CUSTOM_TER_MAP:
SetRect(&pic_rect,0,0,24,24);
pic_rect = {0,0,24,24};
break;
case PIC_STATUS:
SetRect(&pic_rect,0,0,12,12);
pic_rect = {0,0,12,12};
default:
SetRect(&pic_rect,0,0,28,36);
pic_rect = {0,0,28,36};
}
OffsetRect(&pic_rect,8,8);
pic_rect.offset(8,8);
cDialog* me = operator->();
cPict* pic_ctrl = new cPict(me);
cPict* pic_ctrl = new cPict(*me);
pic_ctrl->setPict(pic,type);
me->add(pic_ctrl, pic_rect, "pict");
}
std::string cThreeChoice::show(){
std::string result = cChoiceDlog::show();
if(result == "btn1") return btns[0].label;
else if(result == "btn2") return btns[1].label;
else if(result == "btn3") return btns[2].label;
if(result == "btn1") return btns[0]->label;
else if(result == "btn2") return btns[1]->label;
else if(result == "btn3") return btns[2]->label;
return "**ERROR**"; // shouldn't be reached
}
@@ -398,6 +403,7 @@ std::string cStrDlog::getFileName(short n_strs, ePicType type, bool hasTitle){
cStrDlog::cStrDlog(std::string str1,std::string str2,std::string title,pic_num_t pic,ePicType t,cDialog* parent)
: dlg(cStrDlog::getFileName((str1 != "") + (str2 != ""), t, title != ""), parent), type(t) {
using namespace std::placeholders;
cPict& pic_ctrl = dynamic_cast<cPict&>(dlg["pict"]);
pic_ctrl.setPict(pic, type);
if(str1 != "") {
@@ -406,14 +412,12 @@ cStrDlog::cStrDlog(std::string str1,std::string str2,std::string title,pic_num_t
}else if(str2 != "") dlg["str1"].setText(str2);
if(title != "") dlg["title"].setText(title);
dlg["record"].hide();
dlg["record"].attachClickHandler(boost::bind(&cStrDlog::onRecord, this, _1, _2));
dlg["okay"].attachClickHandler(boost::bind(&cStrDlog::onDismiss, this, _1, _2));
this->str1 = str1;
this->str2 = str2;
dlg["record"].attachClickHandler(std::bind(&cStrDlog::onRecord, this, _1, _2));
dlg["done"].attachClickHandler(std::bind(&cStrDlog::onDismiss, this, _1, _2));
}
bool cStrDlog::onRecord(cDialog& me, std::string id){
if(hasRecord) rec_f(str1, str2);
if(hasRecord) rec_f(me);
else me[id].hide();
return hasRecord;
}
@@ -445,10 +449,21 @@ void cStrDlog::show(){
dlg.run();
}
void giveError(std::string str1, std::string str2, short err, cDialog* parent){
// TODO: ...
void giveError(std::string str1, std::string str2, cDialog* parent){
cStrDlog error(str1,str2,"Error!!!",25,PIC_DLOG,parent);
error.show();
}
void oopsError(short error, short code, short mode){
// TODO: ...
void oopsError(short error, short code, short mode){ // mode is 0 for scened, 1 for game, 2 for pced
char error_str1[256], error_str2[256];
static const char* progname[3] = {"the scenario editor", "Blades of Exile", "the PC editor"};
static const char* filetname[3] = {"scenario", "game", "game"};
sprintf(error_str1,"The program encountered an error while loading/saving/creating the %s. To prevent future problems, the program will now terminate. Trying again may solve the problem.", filetname[mode]);
// TODO: Update this error message - giving more memory is no longer an option in OSX.
sprintf(error_str2,"Giving %s more memory might also help. Be sure to back your %s up often. Error number: %d.",progname[mode],filetname[mode],error);
if(code != 0)
sprintf(error_str2,"%s Result code: %i.",error_str2,code);
giveError(error_str1,error_str2,0);
exit(1);
}

View File

@@ -11,17 +11,20 @@
#include <string>
#include <vector>
#include <boost/function.hpp>
#include <functional>
#include "graphtool.h" // for pic_num_t
#include "soundtool.h" // for snd_num_t
#include "pict.h"
#include "dialog.h"
#include "button.h"
#include <boost/optional.hpp>
//typedef void (*record_callback_t)(std::string,std::string);
typedef boost::function<void(std::string,std::string)> record_callback_t;
typedef std::function<void(cDialog&)> record_callback_t;
class cStrDlog {
static std::string getFileName(short n_strs, ePicType type, bool hasTitle);
cDialog dlg;
std::string str1, str2;
short sound;
record_callback_t rec_f;
bool hasRecord;
@@ -29,7 +32,7 @@ class cStrDlog {
bool onRecord(cDialog& me, std::string id);
bool onDismiss(cDialog& me, std::string id);
public:
cStrDlog(std::string str1,std::string str2,std::string title,pic_num_t pic,ePicType t,cDialog* parent);
cStrDlog(std::string str1,std::string str2,std::string title,pic_num_t pic,ePicType t,cDialog* parent = NULL);
cStrDlog& setSound(snd_num_t num);
cStrDlog& setRecordHandler(record_callback_t rec);
void show();
@@ -39,28 +42,23 @@ class cChoiceDlog {
cDialog dlg;
protected:
bool onClick(cDialog& me, std::string id);
explicit cChoiceDlog(cDialog* p = NULL);
public:
explicit cChoiceDlog(std::string file, cDialog* p = NULL);
cChoiceDlog(std::string file, std::vector<std::string> buttons, cDialog* p = NULL);
explicit cChoiceDlog(std::vector<std::string> buttons, cDialog* p = NULL);
cDialog* operator->();
std::string show();
};
template<bool b> struct bbtt { // stands for "basic button type template"
struct bbtt { // stands for "basic button type template"
eBtnType type;
std::string label;
cKey defaultKey;
operator bool();
bbtt<b>& operator=(bbtt<!b>&);
};
template<> struct bbtt<false> {
operator bool();
bbtt<false>& operator=(bbtt<true>&);
};
typedef bbtt<true> cBasicButtonType;
typedef boost::optional<bbtt> cBasicButtonType;
namespace {const bbtt<false> null_btn = {};}
namespace {cBasicButtonType null_btn = boost::none;}
#ifndef BTNS_DEFINED
extern cBasicButtonType basic_buttons[];
extern size_t available_btns[];
@@ -68,26 +66,15 @@ extern size_t available_btns[];
class cThreeChoice : public cChoiceDlog {
//static std::string getFileName(size_t n_strs);
bool btn_used[3];
cBasicButtonType btns[3];
unsigned short buttons_right, buttons_top;
void init_strings(std::vector<std::string>& strings, unsigned short left);
template<bool a, bool b, bool c> void init_buttons(bbtt<a> btn1, bbtt<b> btn2, bbtt<c> btn3);
void init_buttons(cBasicButtonType btn1, cBasicButtonType btn2, cBasicButtonType btn3);
void init_pict(pic_num_t pic);
const ePicType type;
public:
template<bool a, bool b, bool c> cThreeChoice
(std::vector<std::string> strings, bbtt<a> btn1, bbtt<b> btn2, bbtt<c> btn3, pic_num_t pic, ePicType t, cDialog* parent = NULL)
: cChoiceDlog(std::vector<std::string>(), parent), type(t){
if(type == PIC_CUSTOM_DLOG_LG || type == PIC_DLOG_LG || type == PIC_SCEN_LG)
init_strings(strings,86);
else
init_strings(strings,50);
init_buttons(btn1, btn2, btn3);
init_pict(pic);
operator->()->recalcRect();
}
cThreeChoice(std::vector<std::string> strings, short btn1, short btn2, short btn3, pic_num_t pic, ePicType t, cDialog* parent = NULL);
cThreeChoice(std::vector<std::string>& strings, std::array<cBasicButtonType, 3>& buttons, pic_num_t pic, ePicType t, cDialog* parent = NULL);
cThreeChoice(std::vector<std::string>& strings, std::array<short, 3>& buttons, pic_num_t pic, ePicType t, cDialog* parent = NULL);
std::string show();
};
@@ -111,6 +98,7 @@ public:
class cPictChoice {
static const size_t per_page;
cDialog dlg;
void attachClickHandlers();
bool onLeft(cDialog& me, std::string id);
bool onRight(cDialog& me, std::string id);
bool onCancel(cDialog& me, std::string id);
@@ -122,10 +110,12 @@ class cPictChoice {
public:
cPictChoice(std::vector<pic_num_t>& pics, ePicType t, cDialog* parent = NULL);
cPictChoice(std::vector<pic_num_t>::iterator begin, std::vector<pic_num_t>::iterator end, ePicType t, cDialog* parent = NULL);
cPictChoice(pic_num_t begin, pic_num_t end, ePicType t, cDialog* parent = NULL);
cDialog* operator->();
pic_num_t show(pic_num_t fallback, pic_num_t cur_sel); // returns the _number_ of the chosen picture, _not_ the index; there's no way to distinguish between duplicates
// returns fallback if the user cancels
};
#endif
void giveError(std::string str1, std::string str2, short err, cDialog* parent = NULL);
void giveError(std::string str1, std::string str2 = "", cDialog* parent = NULL);
void oopsError(short error,short code = 0, short mode = 0);

View File

@@ -1,101 +0,0 @@
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<?xml-stylesheet href="dialog.xsl" type="text/xsl"?>
<!DOCTYPE dialog SYSTEM "dialog.dtd">
<dialog skin='light' fore='black' debug='true'>
<text size='large' top='6' left='50' height='17' width='138'>Edit Terrain Type</text>
<pict name='graphic' type='ter' num='0' top='8' left='8'/>
<text top='8' left='222' height='14' width='111'>Terrain number:</text>
<text name='number' top='8' left='340' height='14' width='37'>*num</text>
<text top='31' left='50' height='14' width='120'>Terrain type name:</text>
<field name='name' top='30' left='186' height='16' width='186'/>
<text top='63' left='9' height='14' width='120'>Terrain picture:</text>
<field name='pict' top='62' left='141' height='16' width='52' />
<button name='pickpict' type='large' top='59' left='205'>Pick Picture</button>
<button name='pickanim' type='large' top='59' left='319'>Animated</button>
<text top='90' left='8' height='14' width='120'>Terrain blockage:</text>
<group name='blockage'>
<led name='clear' top='90' left='132' state='off' width='120'>Clear</led>
<led name='curtain' top='107' left='132' state='off' width='120'>Walk through, opaque</led>
<led name='special' top='124' left='132' state='off' width='120'>Clear, special</led>
<led name='window' top='90' left='293' state='off' width='120'>Clear, blocked</led>
<led name='obstructed' top='107' left='293' state='off' width='120'>Blocked, obstructed</led>
<led name='opaque' top='124' left='293' state='off' width='120'>Blocked, opaque</led>
</group>
<led name='flight' top='150' left='26' state='off' width='120' font='silom'>Can fly over?</led>
<led name='boat' top='150' left='154' state='off' width='120' font='silom'>Can boat over?</led>
<led name='horse' top='150' left='307' state='off' width='120' font='silom'>Blocked to horses?</led>
<text top='165' left='8' height='14' width='91'>Step sound:</text>
<group name='sound'>
<led name="step" top='167' left='102' state='off' width='60'>Footstep</led>
<led name="squish" top='167' left='186' state='off' width='60'>Squish</led>
<led name="crunch" top='167' left='282' state='off' width='60'>Crunch</led>
<led name="nosound" top='167' left='386' state='off' width='60'>Silence</led>
<led name="splash" top='167' left='497' state='off' width='60'>Big Splash</led>
</group>
<text top='194' left='8' height='14' width='91'>Shortcut key:</text>
<field name='key' top='193' left='109' height='16' width='52' />
<text top='194' left='171' height='14' width='91'>Light radius:</text>
<field name='light' top='193' left='271' height='16' width='52' />
<text top='193' left='333' height='14' width='128'>Transform to what?</text>
<field name='trans' top='193' left='467' height='16' width='52' />
<text top='217' left='8' height='14' width='91'>Ground type:</text>
<field name='ground' top='216' left='109' height='16' width='52' />
<text top='217' left='171' height='14' width='91'>Trim terrain:</text>
<field name='trimter' top='216' left='271' height='16' width='52' />
<text top='217' left='333' height='14' width='128'>Trim type:</text>
<field name='trim' top='216' left='467' height='16' width='52' />
<button name='picktrim' top='213' left='530' type='regular'>Choose</button>
<text size='large' top='238' left='8' height='14' width='175'>Special properties:</text>
<group name="prop">
<led name='0' top='254' left='8' state='off' width='116'>None</led>
<led name='1' top='269' left='8' state='off' width='116'>Change when step on</led>
<led name='2' top='284' left='8' state='off' width='116'>Damaging terrain</led>
<led name='3' top='299' left='8' state='off' width='116'>Is a bridge</led>
<led name='4' top='314' left='8' state='off' width='116'>Change while occupied</led>
<led name='5' top='329' left='8' state='off' width='116'>Dangerous terrain</led>
<led name='6' top='344' left='8' state='off' width='116'>Reserved</led>
<led name='7' top='359' left='8' state='off' width='116'>Crumbling terrain</led>
<led name='8' top='254' left='146' state='off' width='116'>Lockable terrain</led>
<led name='9' top='269' left='146' state='off' width='116'>Unlockable terrain</led>
<led name='10' top='284' left='146' state='off' width='116'>Reserved</led>
<led name='11' top='299' left='146' state='off' width='116'>Is a sign</led>
<led name='12' top='314' left='146' state='off' width='116'>Call special when step</led>
<led name='13' top='329' left='146' state='off' width='116'>Reserved</led>
<led name='14' top='344' left='146' state='off' width='116'>Is a container</led>
<led name='15' top='359' left='146' state='off' width='116'>Waterfall</led>
<led name='16' top='254' left='285' state='off' width='116'>Conveyor belt</led>
<led name='17' top='269' left='285' state='off' width='116'>Reserved</led>
<led name='18' top='284' left='285' state='off' width='116'>Reserved</led>
<led name='19' top='299' left='285' state='off' width='116'>Reserved</led>
<led name='20' top='314' left='285' state='off' width='116'>Blocked to monsters</led>
<led name='21' top='329' left='285' state='off' width='116'>Town entrance</led>
<led name='22' top='344' left='285' state='off' width='116'>Change when used</led>
<led name='23' top='359' left='285' state='off' width='116'>Call special when used</led>
</group>
<text top='385' left='9' height='14' width='91'>Extra values:</text>
<text name='flag1text' framed='true' top='385' left='109' height='14' width='209'>*flag1</text>
<field name='flag1' top='384' left='329' height='16' width='64' />
<button name='pickflag1' top='381' left='404' type='regular'>Choose</button>
<text name='flag2text' framed='true' top='410' left='109' height='14' width='209'>*flag2</text>
<field name='flag2' top='409' left='329' height='16' width='64' />
<button name='pickflag2' top='406' left='404' type='regular'>Choose</button>
<text name='flag3text' framed='true' top='435' left='109' height='14' width='209'>*flag3</text>
<field name='flag3' top='434' left='329' height='16' width='64' />
<button name='pickflag3' top='431' left='404' type='regular'>Choose</button>
<text top='254' left='467' height='14' width='100'>Combat Arena:</text>
<field name='arena' top='275' left='467' height='16' width='64'/>
<button name='pickarena' type='regular' top='299' left='467'>Choose</button>
<button name='object' top='344' left='467' type='large'>Object Details</button>
<text top='385' left='470' width='60' height='14'>Map icon:</text>
<pict name='seemap' top='375' left='550' type='map' num='0'/>
<field name='map' top='406' left='470' width='100' height='16'/>
<button name='done' type='regular' def-key='enter' top='455' left='517'>OK</button>
<button name='cancel' type='regular' def-key='esc' top='455' left='451'>Cancel</button>
<button name='left' type='left' def-key='left' top='455' left='11'/>
<button name='right' type='right' def-key='right' top='455' left='74'/>
<text top='7' left='451' height='131' width='137'>Enter properties for this terrain type. For a detailed description of the fields, see the documentation. Note that, for terrain types 90 and below, only changes to the picture and shortcut key will be recorded.</text>
<button name='help' type='help' def-key='help' top='5' left='588'/>
</dialog>

View File

@@ -6,9 +6,10 @@
*
*/
#include <Carbon/Carbon.h>
#include "field.h"
#include <sstream>
#include "dialog.h"
#include "graphtool.h"
void cTextField::attachClickHandler(click_callback_t f __attribute__((unused))) throw(xHandlerNotSupported){
throw xHandlerNotSupported(false);
@@ -21,6 +22,9 @@ void cTextField::attachFocusHandler(focus_callback_t f __attribute__((unused)))
bool cTextField::triggerFocusHandler(cDialog& me, std::string id, bool losingFocus){
// TODO: If isNumericField, verify that the contents are in fact a number.
if(onFocus != NULL) onFocus(me,id,losingFocus);
haveFocus = !losingFocus;
if(haveFocus && insertionPoint < 0)
insertionPoint = getText().length();
return true;
}
@@ -32,50 +36,201 @@ short cTextField::getFormat(eFormat prop) throw(xUnsupportedProp){
throw xUnsupportedProp(prop);
}
void cTextField::setText(std::string what){
char message[1024];
strcpy(message,what.c_str());
c2pstr(message);
OSErr err = SetControlData(theField,kControlEditTextPart,kControlEditTextTextTag,what.size() + 1,message);
if(isVisible()) draw();
void cTextField::setColour(sf::Color clr) throw(xUnsupportedProp) {
color = clr;
}
std::string cTextField::getText(){
unsigned char message[1024];
OSErr err = GetControlData(theField,kControlEditTextPart,kControlEditTextTextTag,1024,message,NULL);
p2cstr(message);
return std::string((char*)message);
sf::Color cTextField::getColour() throw(xUnsupportedProp) {
return color;
}
eFldType cTextField::getInputType() {
if(isNumericField) return FLD_NUM;
else return FLD_TEXT;
}
void cTextField::setInputType(eFldType type) {
switch(type) {
case FLD_NUM:
isNumericField = true;
break;
case FLD_TEXT:
isNumericField = false;
break;
}
}
bool cTextField::isClickable(){
// TODO: Should be clickable in order to handle text selection
return false;
}
bool cTextField::hasFocus() {
return haveFocus;
}
cTextField::cTextField(cDialog* parent) :
cControl(parent,CTRL_FIELD),
isNumericField(false) {
OSStatus err;
err = CreateEditTextControl(parent->win,&frame,NULL,false,true/*useInlineInput*/,NULL,&theField);
}
cControl(CTRL_FIELD,*parent),
color(sf::Color::Black),
insertionPoint(-1),
selectionPoint(0),
isNumericField(false) {}
cTextField::~cTextField(){
DisposeControl(theField);
}
void cTextField::show(){
ShowControl(theField);
cControl::show();
}
void cTextField::hide(){
HideControl(theField);
cControl::hide();
}
cTextField::~cTextField(){}
void cTextField::draw(){
GrafPtr cur_port;
GetPort(&cur_port);
SetPortWindowPort(parent->win);
Draw1Control(theField);
SetPort(cur_port);
static const sf::Color hiliteClr = {127,127,127}, ipClr = {92, 92, 92};
inWindow->setActive();
RECT outline = frame;
outline.inset(-2,-2);
fill_rect(*inWindow, outline, sf::Color::White);
frame_rect(*inWindow, outline, sf::Color::Black);
std::string contents = getText();
RECT rect = frame;
rect.inset(2,6);
TEXT.font = "Geneva";
TEXT.style = sf::Text::Regular;
TEXT.pointSize = 12;
TEXT.colour = sf::Color::Black;
// TODO: Proper support for multiline fields
int ip_offset, sel_offset;
if(haveFocus) {
std::string pre_ip = contents.substr(0, insertionPoint);
// TODO: Update string_length to take a std::string
ip_offset = string_length(pre_ip.c_str());
if(insertionPoint != selectionPoint) {
std::string pre_sel = contents.substr(0, selectionPoint);
sel_offset = string_length(pre_sel.c_str());
int sel_start = std::min(ip_offset, sel_offset) + 1;
int sel_width = abs(ip_offset - sel_offset) + 3;
RECT selectRect = frame;
selectRect.left += sel_start;
selectRect.right = selectRect.left + sel_width;
fill_rect(*inWindow, selectRect, ipClr);
selectRect.right - 1;
fill_rect(*inWindow, selectRect, hiliteClr);
} else if(ip_timer.getElapsedTime().asMilliseconds() < 500) {
// printf("Blink on (%d); ", ip_timer.getElapsedTime().asMilliseconds());
RECT ipRect = frame;
ipRect.left += ip_offset + 2;
ipRect.right = ipRect.left + 1;
fill_rect(*inWindow, ipRect, ipClr);
} else if(ip_timer.getElapsedTime().asMilliseconds() > 1000) {
// printf("Blink off (%d); ", ip_timer.getElapsedTime().asMilliseconds());
ip_timer.restart();
}
}
// TODO: Update win_draw_string to take a std::string
win_draw_string(*inWindow, rect, contents.c_str(), 0, 14);
}
void cTextField::handleInput(cKey key) {
bool select = mod_contains(key.mod, mod_shift);
bool word = mod_contains(key.mod, mod_alt) || mod_contains(key.mod, mod_ctrl);
bool haveSelection = insertionPoint != selectionPoint;
int new_ip;
std::string contents = getText();
if(!key.spec) {
if(haveSelection) {
cKey deleteKey = key;
deleteKey.spec = true;
deleteKey.k = key_bsp;
handleInput(deleteKey);
contents = getText();
}
contents.insert(contents.begin() + insertionPoint, key.c);
selectionPoint = ++insertionPoint;
} else switch(key.k) {
// TODO: Implement all the other special keys
case key_left:
if(haveSelection && !select) {
selectionPoint = insertionPoint = std::min(selectionPoint,insertionPoint);
break;
}
new_ip = select ? selectionPoint : insertionPoint;
if(new_ip == 0) break;
if(word) {
new_ip--;
while(new_ip > 0 && contents[new_ip - 1] != ' ')
new_ip--;
} else new_ip--;
(select ? selectionPoint : insertionPoint) = new_ip;
if(!select) selectionPoint = insertionPoint;
break;
case key_right:
if(haveSelection && !select) {
selectionPoint = insertionPoint = std::max(selectionPoint,insertionPoint);
break;
}
new_ip = select ? selectionPoint : insertionPoint;
if(new_ip == contents.length()) break;
if(word) {
new_ip++;
while(new_ip < contents.length() && contents[new_ip + 1] != ' ')
new_ip++;
} else new_ip++;
(select ? selectionPoint : insertionPoint) = new_ip;
if(!select) selectionPoint = insertionPoint;
break;
case key_up:
case key_down:
break;
case key_enter:
key.spec = false;
key.c = '\n';
handleInput(key);
break;
case key_bsp:
if(haveSelection) {
auto begin = contents.begin() + std::min(selectionPoint, insertionPoint);
auto end = contents.begin() + std::max(selectionPoint, insertionPoint);
auto result = contents.erase(begin, end);
selectionPoint = insertionPoint = result - contents.begin();
} else if(word) {
cKey selectKey = key;
selectKey.k = key_left;
handleInput(selectKey);
if(selectionPoint != insertionPoint)
handleInput(key);
} else {
if(insertionPoint == 0) break;
contents.erase(insertionPoint - 1,1);
selectionPoint = --insertionPoint;
}
break;
case key_del:
if(haveSelection) {
auto begin = contents.begin() + std::min(selectionPoint, insertionPoint);
auto end = contents.begin() + std::max(selectionPoint, insertionPoint);
auto result = contents.erase(begin, end);
selectionPoint = insertionPoint = result - contents.begin();
} else if(word) {
cKey selectKey = key;
selectKey.k = key_left;
handleInput(selectKey);
if(selectionPoint != insertionPoint)
handleInput(key);
} else {
if(insertionPoint == contents.length()) break;
contents.erase(insertionPoint,1);
}
break;
case key_end:
case key_home:
case key_pgup:
case key_pgdn:
case key_copy:
case key_cut:
case key_paste:
break;
case key_selectall:
selectionPoint = 0;
insertionPoint = contents.length();
break;
case key_esc:
case key_tab:
case key_help:
break;
}
setText(contents);
}

View File

@@ -10,6 +10,12 @@
#define FIELD_H
#include <string>
#include "control.h"
enum eFldType {
FLD_NUM,
FLD_TEXT,
};
class cTextField : public cControl {
public:
@@ -18,19 +24,24 @@ public:
bool triggerFocusHandler(cDialog& me, std::string id, bool losingFocus);
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
short getFormat(eFormat prop) throw(xUnsupportedProp);
std::string getText();
void setText(std::string what);
void setColour(sf::Color clr) throw(xUnsupportedProp);
eFldType getInputType();
void setInputType(eFldType newType);
sf::Color getColour() throw(xUnsupportedProp);
explicit cTextField(cDialog* parent);
bool isClickable();
virtual ~cTextField();
void show();
void hide();
protected:
void draw();
bool hasFocus();
void handleInput(cKey key);
private:
friend class cDialog;
bool isNumericField;
focus_callback_t onFocus;
ControlRef theField;
bool haveFocus;
int insertionPoint;
int selectionPoint;
sf::Color color;
bool ip_visible;
sf::Clock ip_timer;
};
#endif

View File

@@ -6,45 +6,33 @@
*
*/
#include <Carbon/Carbon.h>
#include "message.h"
#include "graphtool.h"
#include "mathutil.h"
#include "dialog.h"
extern GWorldPtr bg_gworld;
extern sf::Texture bg_gworld;
void cTextMsg::attachClickHandler(click_callback_t f) throw(){
onClick = f;
clickable = onClick != NULL;
}
void cTextMsg::attachFocusHandler(focus_callback_t f __attribute__((unused))) throw(xHandlerNotSupported){
throw xHandlerNotSupported(true);
}
bool cTextMsg::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where){
bool cTextMsg::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where){
if(onClick != NULL) return onClick(me,id,mods);
return false;
}
void cTextMsg::setColour(sf::Color clr) {
color = clr;
}
void cTextMsg::setFormat(eFormat prop, short val) throw(xUnsupportedProp){
switch(prop){
case TXT_COLOR:
{ // TODO: Test this and see if it works as imagined
RGBColor clr;
unsigned char red, green, blue, bright;
red = (val & 0xF000) >> 12;
green = (val & 0x0F00) >> 8;
blue = (val & 0x00F0) >> 4;
bright = val & 0x000F;
red *= bright;
green *= bright;
blue *= bright;
clr.red = red * 257;
clr.green = green * 257;
clr.blue = blue * 257;
color = clr;
}
break;
case TXT_FRAME:
drawFramed = val;
break;
@@ -62,25 +50,12 @@ void cTextMsg::setFormat(eFormat prop, short val) throw(xUnsupportedProp){
}
}
sf::Color cTextMsg::getColour() {
return color;
}
short cTextMsg::getFormat(eFormat prop) throw(xUnsupportedProp){
switch(prop){
case TXT_COLOR:
{
unsigned char red, green, blue, bright;
short val;
red = color.red / 257;
green = color.green / 257;
blue = color.green / 257;
bright = gcd(red,gcd(green,blue));
red /= bright;
green /= bright;
blue /= bright;
val |= bright;
val |= blue << 4;
val |= green << 8;
val |= red << 12;
return val;
}
case TXT_FRAME:
return drawFramed;
case TXT_SIZE:
@@ -94,8 +69,8 @@ short cTextMsg::getFormat(eFormat prop) throw(xUnsupportedProp){
}
cTextMsg::cTextMsg(cDialog* parent) :
cControl(parent,CTRL_TEXT),
drawFramed(true),
cControl(CTRL_TEXT,*parent),
drawFramed(false),
textFont(SILOM),
textSize(10),
color(parent->defTextClr),
@@ -107,36 +82,32 @@ bool cTextMsg::isClickable(){
}
void cTextMsg::draw(){
GrafPtr old_port;
Rect to_rect = frame;
RECT to_rect = frame;
GetPort(&old_port);
SetPortWindowPort(parent->win);
tileImage(frame,bg_gworld,bg[parent->bg]);
inWindow->setActive();
if(visible){
TextFont(font_nums[textFont]);
if(textFont == SILOM && !foundSilom()) TextFace(bold);
else TextFace(normal);
TextSize(textSize);
TEXT.font = font_nums[textFont];
if(textFont == SILOM && !foundSilom()) TEXT.style = sf::Text::Bold;
else TEXT.style = sf::Text::Regular;
TEXT.pointSize = textSize;
// TODO: When should we pass 1 as the second parameter?
if(drawFramed) drawFrame(2,0);
RGBColor draw_color = color;
sf::Color draw_color = color;
if(clickable && depressed){
color.red = 65535 - color.red;
color.green = 65535 - color.green;
color.blue = 65535 - color.blue;
draw_color.r = 256 - draw_color.r;
draw_color.g = 256 - draw_color.g;
draw_color.b = 256 - draw_color.b;
}
RGBForeColor(&draw_color);
TEXT.colour = draw_color;
if (to_rect.bottom - to_rect.top < 20) { // essentially, it's a single line
to_rect.left += 3;
char_win_draw_string(parent->win,to_rect,lbl.c_str(),3,12);
win_draw_string(*inWindow,to_rect,lbl.c_str(),3,12);
}else {
InsetRect(&to_rect,4,4);
char_win_draw_string(parent->win,to_rect,lbl.c_str(),0,textSize + 2);
to_rect.inset(4,4);
win_draw_string(*inWindow,to_rect,lbl.c_str(),0,textSize + 2);
}
}
SetPort(old_port);
}
cTextMsg::~cTextMsg() {}

View File

@@ -9,26 +9,29 @@
#ifndef MESSAGE_H
#define MESSAGE_H
#include <SFML/Graphics.hpp>
#include <string>
#include "control.h"
class cTextMsg : public cControl {
public:
void attachClickHandler(click_callback_t f) throw();
void attachFocusHandler(focus_callback_t f) throw(xHandlerNotSupported);
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where);
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where);
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
short getFormat(eFormat prop) throw(xUnsupportedProp);
void setColour(sf::Color clr) throw(xUnsupportedProp);
sf::Color getColour() throw(xUnsupportedProp);
explicit cTextMsg(cDialog* parent);
bool isClickable();
virtual ~cTextMsg();
protected:
void draw();
private:
friend class cDialog;
bool drawFramed, clickable;
short textSize;
eTextFont textFont;
RGBColor color;
sf::Color color;
std::string fromList;
click_callback_t onClick;
};

File diff suppressed because it is too large Load Diff

View File

@@ -9,9 +9,12 @@
#ifndef PICT_H
#define PICT_H
#include <SFML/Graphics.hpp>
#include <vector>
#include <map>
#include "graphtool.h" // for pic_num_t
#include "control.h"
enum ePicType {
PIC_TER = 1, // 28x36 terrain graphic from the preset sheets
@@ -94,69 +97,66 @@ public:
static void init();
void attachClickHandler(click_callback_t f) throw();
void attachFocusHandler(focus_callback_t f) throw(xHandlerNotSupported);
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, Point where);
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where);
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
short getFormat(eFormat prop) throw(xUnsupportedProp);
static void setSheet(eSheetType type, GWorldPtr sheet, short n = 0);
static bool isSheetSet(eSheetType type, size_t n = 0);
void setColour(sf::Color clr) throw(xUnsupportedProp);
sf::Color getColour() throw(xUnsupportedProp);
void setPict(pic_num_t num, ePicType type);
void setPict(pic_num_t num);
pic_num_t getPicNum();
ePicType getPicType();
explicit cPict(cDialog* parent);
explicit cPict(cDialog& parent);
explicit cPict(sf::RenderWindow& parent);
bool isClickable();
static void advanceAnim();
virtual ~cPict();
protected:
void draw();
private:
static std::shared_ptr<sf::Texture> getSheet(eSheetType type, size_t n = 0);
static short animFrame;
short picNum;
ePicType picType;
bool clickable, drawFramed;
friend class cDialog;
static GWorldPtr teranim, dlog, talk, scen, largeScen, item, tinyItem, pc, field, boom, missile, save, header, map, status;
static std::vector<GWorldPtr> ter, monst, customSheets;
static std::map<size_t,GWorldPtr> largeSheets; // map instead of vector because it'll be a sparse array
static void drawPresetTer(short num, Rect to_rect);
static void drawPresetTerAnim(short num, Rect to_rect);
static void drawPresetMonstSm(short num, Rect to_rect);
static void drawPresetMonstWide(short num, Rect to_rect);
static void drawPresetMonstTall(short num, Rect to_rect);
static void drawPresetMonstLg(short num, Rect to_rect);
static void drawPresetDlog(short num, Rect to_rect);
static void drawPresetDlogLg(short num, Rect to_rect);
static void drawPresetTalk(short num, Rect to_rect);
static void drawPresetScen(short num, Rect to_rect);
static void drawPresetScenLg(short num, Rect to_rect);
static void drawPresetItem(short num, Rect to_rect);
static void drawPresetPc(short num, Rect to_rect);
static void drawPresetField(short num, Rect to_rect);
static void drawPresetBoom(short num, Rect to_rect);
static void drawPresetMissile(short num, Rect to_rect);
static void drawPresetTerMap(short num, Rect to_rect);
static void drawStatusIcon(short num, Rect to_rect);
static void drawFullSheet(short num, Rect to_rect);
static void drawCustomTer(short num, Rect to_rect);
static void drawCustomTerAnim(short num, Rect to_rect);
static void drawCustomMonstSm(short num, Rect to_rect);
static void drawCustomMonstWide(short num, Rect to_rect);
static void drawCustomMonstTall(short num, Rect to_rect);
static void drawCustomMonstLg(short num, Rect to_rect);
static void drawCustomDlog(short num, Rect to_rect);
static void drawCustomDlogLg(short num, Rect to_rect);
static void drawCustomTalk(short num, Rect to_rect);
static void drawCustomItem(short num, Rect to_rect);
static void drawCustomMissile(short num, Rect to_rect);
static void drawCustomTerMap(short num, Rect to_rect);
static void drawPartyMonstSm(short num, Rect to_rect);
static void drawPartyMonstWide(short num, Rect to_rect);
static void drawPartyMonstTall(short num, Rect to_rect);
static void drawPartyMonstLg(short num, Rect to_rect);
static void drawPartyScen(short num, Rect to_rect);
static void drawPartyItem(short num, Rect to_rect);
static void drawPartyPc(short num, Rect to_rect);
static std::map<ePicType,void(*)(short,Rect)>& drawPict();
//static void(* drawPict[NUM_PIC_TYPES])(short,GWorldPtr,Rect);
void drawPresetTer(short num, RECT to_rect);
void drawPresetTerAnim(short num, RECT to_rect);
void drawPresetMonstSm(short num, RECT to_rect);
void drawPresetMonstWide(short num, RECT to_rect);
void drawPresetMonstTall(short num, RECT to_rect);
void drawPresetMonstLg(short num, RECT to_rect);
void drawPresetDlog(short num, RECT to_rect);
void drawPresetDlogLg(short num, RECT to_rect);
void drawPresetTalk(short num, RECT to_rect);
void drawPresetScen(short num, RECT to_rect);
void drawPresetScenLg(short num, RECT to_rect);
void drawPresetItem(short num, RECT to_rect);
void drawPresetPc(short num, RECT to_rect);
void drawPresetField(short num, RECT to_rect);
void drawPresetBoom(short num, RECT to_rect);
void drawPresetMissile(short num, RECT to_rect);
void drawPresetTerMap(short num, RECT to_rect);
void drawStatusIcon(short num, RECT to_rect);
void drawFullSheet(short num, RECT to_rect);
void drawCustomTer(short num, RECT to_rect);
void drawCustomTerAnim(short num, RECT to_rect);
void drawCustomMonstSm(short num, RECT to_rect);
void drawCustomMonstWide(short num, RECT to_rect);
void drawCustomMonstTall(short num, RECT to_rect);
void drawCustomMonstLg(short num, RECT to_rect);
void drawCustomDlog(short num, RECT to_rect);
void drawCustomDlogLg(short num, RECT to_rect);
void drawCustomTalk(short num, RECT to_rect);
void drawCustomItem(short num, RECT to_rect);
void drawCustomMissile(short num, RECT to_rect);
void drawCustomTerMap(short num, RECT to_rect);
void drawPartyMonstSm(short num, RECT to_rect);
void drawPartyMonstWide(short num, RECT to_rect);
void drawPartyMonstTall(short num, RECT to_rect);
void drawPartyMonstLg(short num, RECT to_rect);
void drawPartyScen(short num, RECT to_rect);
void drawPartyItem(short num, RECT to_rect);
void drawPartyPc(short num, RECT to_rect);
static std::map<ePicType,void(cPict::*)(short,RECT)>& drawPict();
click_callback_t onClick;
};
@@ -167,14 +167,4 @@ ePicType operator - (ePicTypeMod lhs, ePicType rhs);
ePicType&operator +=(ePicType&lhs, ePicTypeMod rhs);
ePicType&operator -=(ePicType&lhs, ePicTypeMod rhs);
class xMissingSheet : std::exception {
static const char*const messages[NUM_SHEET_TYPES+1];
eSheetType type;
size_t num;
public:
explicit xMissingSheet(eSheetType t, size_t n = 0) throw();
~xMissingSheet() throw();
const char* what() throw();
};
#endif

View File

@@ -0,0 +1,68 @@
//
// scrollbar.cpp
// BoE
//
// Created by Celtic Minstrel on 14-03-28.
//
//
#include "scrollbar.h"
cScrollbar::cScrollbar(cDialog& parent) : cControl(CTRL_SCROLL, parent) {}
cScrollbar::cScrollbar(sf::RenderWindow& parent) : cControl(CTRL_SCROLL, parent) {}
bool cScrollbar::isClickable(){
return true;
}
void cScrollbar::setPosition(long newPos) {
if(newPos > max) pos = max;
else pos = newPos;
}
void cScrollbar::setMaximum(long newMax) {
max = newMax;
}
long cScrollbar::getPosition() {
return pos;
}
long cScrollbar::getMaximum() {
return max;
}
void cScrollbar::attachClickHandler(click_callback_t f) throw(xHandlerNotSupported) {
onClick = f;
}
void cScrollbar::attachFocusHandler(focus_callback_t f) throw(xHandlerNotSupported) {
throw xHandlerNotSupported(true);
}
bool cScrollbar::triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where) {
// TODO: Implement detection of scrolling stuff, maybe even dragging the thumb
if(onClick != NULL) return onClick(me,id,mods);
return false;
}
void cScrollbar::setFormat(eFormat prop, short val) throw(xUnsupportedProp) {
throw xUnsupportedProp(prop);
}
short cScrollbar::getFormat(eFormat prop) throw(xUnsupportedProp) {
throw xUnsupportedProp(prop);
}
void cScrollbar::setColour(sf::Color clr) throw(xUnsupportedProp) {
// TODO: Colour is unsupported
}
sf::Color cScrollbar::getColour() throw(xUnsupportedProp) {
// TODO: Colour is unsupported
}
void cScrollbar::draw() {
// TODO: Draw the scrollbar
}

35
osx/dialogxml/scrollbar.h Normal file
View File

@@ -0,0 +1,35 @@
//
// scrollbar.h
// BoE
//
// Created by Celtic Minstrel on 14-03-26.
//
//
#ifndef BoE_scrollbar_h
#define BoE_scrollbar_h
#include "control.h"
class cScrollbar : public cControl {
int pos, max;
click_callback_t onClick;
public:
explicit cScrollbar(sf::RenderWindow& parent);
explicit cScrollbar(cDialog& parent);
void attachClickHandler(click_callback_t f) throw(xHandlerNotSupported);
void attachFocusHandler(focus_callback_t f) throw(xHandlerNotSupported);
bool triggerClickHandler(cDialog& me, std::string id, eKeyMod mods, location where);
void setFormat(eFormat prop, short val) throw(xUnsupportedProp);
short getFormat(eFormat prop) throw(xUnsupportedProp);
void setColour(sf::Color clr) throw(xUnsupportedProp);
sf::Color getColour() throw(xUnsupportedProp);
bool isClickable();
long getPosition();
long getMaximum();
void setPosition(long to);
void setMaximum(long to);
void draw();
};
#endif