mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r17502) -Codechange [FS#3184]: Extend QueryStringBaseWindow to support windows with nested widgets (by Terkhen with a few tweaks).
This commit is contained in:
parent
4cb6451507
commit
669b7d01ac
|
@ -1182,23 +1182,35 @@ void QueryString::HandleEditBox(Window *w, int wid)
|
||||||
|
|
||||||
void QueryString::DrawEditBox(Window *w, int wid)
|
void QueryString::DrawEditBox(Window *w, int wid)
|
||||||
{
|
{
|
||||||
const Widget *wi = &w->widget[wid];
|
int left;
|
||||||
|
int right;
|
||||||
|
int top;
|
||||||
|
int bottom;
|
||||||
|
if (w->widget == NULL) {
|
||||||
|
const NWidgetCore *wi = w->nested_array[wid];
|
||||||
|
|
||||||
assert((wi->type & WWT_MASK) == WWT_EDITBOX);
|
assert((wi->type & WWT_MASK) == WWT_EDITBOX);
|
||||||
|
|
||||||
GfxFillRect(wi->left + 1, wi->top + 1, wi->right - 1, wi->bottom - 1, 215);
|
left = wi->pos_x;
|
||||||
|
right = wi->pos_x + wi->current_x - 1;
|
||||||
|
top = wi->pos_y;
|
||||||
|
bottom = wi->pos_y + wi->current_y - 1;
|
||||||
|
} else {
|
||||||
|
const Widget *wi = &w->widget[wid];
|
||||||
|
|
||||||
DrawPixelInfo dpi;
|
assert((wi->type & WWT_MASK) == WWT_EDITBOX);
|
||||||
int delta;
|
|
||||||
|
left = wi->left;
|
||||||
|
right = wi->right;
|
||||||
|
top = wi->top;
|
||||||
|
bottom = wi->bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, 215);
|
||||||
|
|
||||||
/* Limit the drawing of the string inside the widget boundaries */
|
/* Limit the drawing of the string inside the widget boundaries */
|
||||||
if (!FillDrawPixelInfo(&dpi,
|
DrawPixelInfo dpi;
|
||||||
wi->left + 4,
|
if (!FillDrawPixelInfo(&dpi, left + WD_FRAMETEXT_LEFT, top + WD_FRAMERECT_TOP, right - left - WD_FRAMETEXT_RIGHT, bottom - top - WD_FRAMERECT_BOTTOM)) return;
|
||||||
wi->top + 1,
|
|
||||||
wi->right - wi->left - 4,
|
|
||||||
wi->bottom - wi->top - 1)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawPixelInfo *old_dpi = _cur_dpi;
|
DrawPixelInfo *old_dpi = _cur_dpi;
|
||||||
_cur_dpi = &dpi;
|
_cur_dpi = &dpi;
|
||||||
|
@ -1206,9 +1218,7 @@ void QueryString::DrawEditBox(Window *w, int wid)
|
||||||
/* We will take the current widget length as maximum width, with a small
|
/* We will take the current widget length as maximum width, with a small
|
||||||
* space reserved at the end for the caret to show */
|
* space reserved at the end for the caret to show */
|
||||||
const Textbuf *tb = &this->text;
|
const Textbuf *tb = &this->text;
|
||||||
|
int delta = min(0, (right - left) - tb->width - 10);
|
||||||
delta = (wi->right - wi->left) - tb->width - 10;
|
|
||||||
if (delta > 0) delta = 0;
|
|
||||||
|
|
||||||
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
|
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,13 @@ struct OskWindow : public Window {
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
assert(parent != NULL);
|
assert(parent != NULL);
|
||||||
|
|
||||||
this->caption = (parent->widget[button].data != STR_NULL) ? parent->widget[button].data : parent->caption;
|
if (parent->widget != NULL) {
|
||||||
|
this->caption = (parent->widget[button].data != STR_NULL) ? parent->widget[button].data : parent->caption;
|
||||||
|
}
|
||||||
|
if (parent->nested_array != NULL) {
|
||||||
|
assert(parent->nested_array[button] != NULL);
|
||||||
|
this->caption = (parent->nested_array[button]->widget_data != STR_NULL) ? parent->nested_array[button]->widget_data : parent->caption;
|
||||||
|
}
|
||||||
|
|
||||||
this->qs = parent;
|
this->qs = parent;
|
||||||
this->text_btn = button;
|
this->text_btn = button;
|
||||||
|
|
|
@ -62,6 +62,12 @@ struct QueryStringBaseWindow : public Window, public QueryString {
|
||||||
char *orig_str_buf;
|
char *orig_str_buf;
|
||||||
const uint16 edit_str_size; ///< maximum length of string (in bytes), including terminating '\0'
|
const uint16 edit_str_size; ///< maximum length of string (in bytes), including terminating '\0'
|
||||||
|
|
||||||
|
QueryStringBaseWindow(uint16 size) : Window(), edit_str_size(size)
|
||||||
|
{
|
||||||
|
assert(size != 0);
|
||||||
|
this->edit_str_buf = CallocT<char>(size);
|
||||||
|
}
|
||||||
|
|
||||||
QueryStringBaseWindow(uint16 size, const WindowDesc *desc, WindowNumber window_number = 0) : Window(desc, window_number), edit_str_size(size)
|
QueryStringBaseWindow(uint16 size, const WindowDesc *desc, WindowNumber window_number = 0) : Window(desc, window_number), edit_str_size(size)
|
||||||
{
|
{
|
||||||
assert(size != 0);
|
assert(size != 0);
|
||||||
|
|
Loading…
Reference in New Issue