Skip to content

Commit

Permalink
Merge pull request #51 from taiyu-len/gui_replace_printex
Browse files Browse the repository at this point in the history
gui: replace deprecated printEx with printf
  • Loading branch information
HexDecimal committed Apr 15, 2020
2 parents a725248 + 2460e7a commit 1e0675a
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions samples/hmtool/hmtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ void render() {
sprintf(maxZTxt,"max z : %.2f",mapmax);
sprintf(seedTxt,"seed : %X",seed);
float landProportion=100.0f - 100.0f*backup.countCells(0.0f,sandHeight) / (hm->w*hm->h);
sprintf(landMassTxt,"landMass : %d %%%%",(int)landProportion);
if ( ! isNormalized ) TCODConsole::root->printEx(HM_WIDTH/2,HM_HEIGHT-1,TCOD_BKGND_NONE,TCOD_CENTER,"the map is not normalized !");
sprintf(landMassTxt,"landMass : %d %%",(int)landProportion);
if ( ! isNormalized ) TCODConsole::root->printf(HM_WIDTH/2,HM_HEIGHT-1,TCOD_BKGND_NONE,TCOD_CENTER,"the map is not normalized !");
// message
msgDelay-=TCODSystem::getLastFrameLength();
if ( msg[0] != 0 && msgDelay > 0.0f ) {
Expand Down
2 changes: 1 addition & 1 deletion samples/hmtool/operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const char *Operation::names[]= {
"+fbm",
"*fbm",
"hill",
"\x18\x19 z",
"\u2191\u2193 z",
"smooth",
"rain",
"lerp fbm",
Expand Down
1 change: 1 addition & 0 deletions src/libtcod/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ public :
@Param fmt if NULL, the function only draws a rectangle.
Else, printf-like format string, eventually followed by parameters. You can use control codes to change the colors inside the string.
*/
TCODLIB_FORMAT(8, 9)
void printFrame(int x,int y,int w,int h, bool clear=true, TCOD_bkgnd_flag_t flag = TCOD_BKGND_DEFAULT, const char *fmt=NULL, ...);

/**
Expand Down
4 changes: 2 additions & 2 deletions src/libtcod/gui/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ void Button::render() {
if (w > 0 && h > 0) { con->rect(x, y, w, h, true, TCOD_BKGND_SET); }
if (label) {
if (pressed && mouseIn) {
con->printEx(x + w / 2, y, TCOD_BKGND_NONE, TCOD_CENTER, "-%s-", label);
con->printf(x + w / 2, y, TCOD_BKGND_NONE, TCOD_CENTER, "-%s-", label);
} else {
con->printEx(x + w / 2, y, TCOD_BKGND_NONE, TCOD_CENTER, label);
con->printf(x + w / 2, y, TCOD_BKGND_NONE, TCOD_CENTER, "%s", label);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libtcod/gui/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Label::Label(int x, int y, const char *label, const char *tip)
void Label::render() {
con->setDefaultBackground(back);
con->setDefaultForeground(fore);
con->printEx(x, y, TCOD_BKGND_NONE, TCOD_LEFT, label);
con->printf(x, y, TCOD_BKGND_NONE, TCOD_LEFT, "%s", label);
}
void Label::computeSize() {
w = label ? static_cast<int>(strlen(label)) : 0;
Expand Down
4 changes: 2 additions & 2 deletions src/libtcod/gui/textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ void TextBox::render() {
con->setDefaultBackground(back);
con->setDefaultForeground(fore);
con->rect(x,y,w,h,true,TCOD_BKGND_SET);
if ( label ) con->printEx(x,y,TCOD_BKGND_NONE,TCOD_LEFT,label);
if ( label ) con->printf(x,y,TCOD_BKGND_NONE,TCOD_LEFT, "%s", label);

con->setDefaultBackground(keyboardFocus == this ? foreFocus : fore);
con->setDefaultForeground(keyboardFocus == this ? backFocus : back);
con->rect(x+boxx,y,boxw,h,false,TCOD_BKGND_SET);
int len = static_cast<int>(strlen(txt) - offset);
if (len > boxw) len = boxw;
if ( txt ) con->printEx(x+boxx,y,TCOD_BKGND_NONE,TCOD_LEFT,"%.*s",len,&txt[offset]);
if ( txt ) con->printf(x+boxx,y,TCOD_BKGND_NONE,TCOD_LEFT,"%.*s",len,&txt[offset]);
if (keyboardFocus == this && blink > 0.0f) {
if (insert) {
con->setCharBackground(x+boxx+pos-offset,y,fore);
Expand Down
5 changes: 3 additions & 2 deletions src/libtcod/gui/togglebutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ void ToggleButton::render() {
con->setDefaultBackground(mouseIn ? backFocus : back);
con->setDefaultForeground(mouseIn ? foreFocus : fore);
con->rect(x,y,w,h,true,TCOD_BKGND_SET);
const char* check = pressed ? "\u2611" : "\u2610";
if ( label ) {
con->printEx(x,y,TCOD_BKGND_NONE,TCOD_LEFT,"%c %s",pressed ? TCOD_CHAR_CHECKBOX_SET : TCOD_CHAR_CHECKBOX_UNSET, label);
con->printf(x,y,TCOD_BKGND_NONE,TCOD_LEFT,"%s %s", check, label);
} else {
con->printEx(x,y,TCOD_BKGND_NONE,TCOD_LEFT,"%c",pressed ? TCOD_CHAR_CHECKBOX_SET : TCOD_CHAR_CHECKBOX_UNSET);
con->printf(x,y,TCOD_BKGND_NONE,TCOD_LEFT,"%s", check);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/libtcod/gui/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public :
con->setChar(x+w,y,TCOD_CHAR_TEEW);
con->setDefaultBackground(fore);
con->setDefaultForeground(back);
con->printEx(x+w/2,y,TCOD_BKGND_SET,TCOD_CENTER," %s ",txt);
con->printf(x+w/2,y,TCOD_BKGND_SET,TCOD_CENTER," %s ",txt);
}
char *txt;
};
Expand Down Expand Up @@ -103,7 +103,7 @@ void ToolBar::setName(const char *name) {
void ToolBar::render() {
con->setDefaultBackground(back);
con->setDefaultForeground(fore);
con->printFrame(x,y,w,h,true,TCOD_BKGND_SET,name);
TCOD_console_printf_frame(con->get_data(), x, y, w, h, true, TCOD_BKGND_SET, "%s", name);
Container::render();
}

Expand Down

0 comments on commit 1e0675a

Please sign in to comment.