|
@@ -503,67 +503,75 @@ struct NewGRFTextfileWindow : public Win
|
|
|
}
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
|
|
{
|
|
|
switch (widget) {
|
|
|
case GTW_WIDGET_BACKGROUND:
|
|
|
this->line_height = FONT_HEIGHT_NORMAL + 2;
|
|
|
resize->height = this->line_height;
|
|
|
|
|
|
size->height = 4 * resize->height + TOP_SPACING + BOTTOM_SPACING; // At least 4 lines are visible.
|
|
|
size->width = max(200u, size->width); // At least 200 pixels wide.
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
virtual void SetStringParameters(int widget) const
|
|
|
{
|
|
|
if (widget == GTW_WIDGET_CAPTION) SetDParamStr(0, this->grf_config->GetName());
|
|
|
}
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
{
|
|
|
if (widget != GTW_WIDGET_BACKGROUND) return;
|
|
|
|
|
|
int width = r.right - r.left + 1 - WD_BEVEL_LEFT - WD_BEVEL_RIGHT;
|
|
|
int height = r.bottom - r.top + 1 - WD_BEVEL_LEFT - WD_BEVEL_RIGHT;
|
|
|
|
|
|
DrawPixelInfo new_dpi;
|
|
|
if (!FillDrawPixelInfo(&new_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) return;
|
|
|
|
|
|
if (!FillDrawPixelInfo(&new_dpi, r.left + WD_BEVEL_LEFT, r.top, width, height)) return;
|
|
|
DrawPixelInfo *old_dpi = _cur_dpi;
|
|
|
_cur_dpi = &new_dpi;
|
|
|
|
|
|
int left = WD_FRAMETEXT_LEFT - this->hscroll->GetPosition();
|
|
|
int right = r.right - r.left - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT;
|
|
|
int left, right;
|
|
|
if (_current_text_dir == TD_RTL) {
|
|
|
left = width + WD_BEVEL_RIGHT - WD_FRAMETEXT_RIGHT - this->hscroll->GetCount();
|
|
|
right = width + WD_BEVEL_RIGHT - WD_FRAMETEXT_RIGHT - 1 + this->hscroll->GetPosition();
|
|
|
} else {
|
|
|
left = WD_FRAMETEXT_LEFT - WD_BEVEL_LEFT - this->hscroll->GetPosition();
|
|
|
right = WD_FRAMETEXT_LEFT - WD_BEVEL_LEFT + this->hscroll->GetCount() - 1;
|
|
|
}
|
|
|
int top = TOP_SPACING;
|
|
|
for (uint i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->lines.Length(); i++) {
|
|
|
DrawString(left, right, top + i * this->line_height, this->lines[i + this->vscroll->GetPosition()], TC_WHITE);
|
|
|
}
|
|
|
|
|
|
_cur_dpi = old_dpi;
|
|
|
}
|
|
|
|
|
|
virtual void OnResize()
|
|
|
{
|
|
|
this->vscroll->SetCapacityFromWidget(this, GTW_WIDGET_BACKGROUND, this->line_height);
|
|
|
this->vscroll->SetCapacityFromWidget(this, GTW_WIDGET_BACKGROUND, TOP_SPACING + BOTTOM_SPACING);
|
|
|
this->hscroll->SetCapacityFromWidget(this, GTW_WIDGET_BACKGROUND);
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
|
|
|
/**
|
|
|
* Load the NewGRF's textfile text from file, and setup #lines, #max_length, and both scrollbars.
|
|
|
*/
|
|
|
void LoadTextfile()
|
|
|
{
|
|
|
this->lines.Clear();
|
|
|
|
|
|
/* Does GRF have a file of the demanded type? */
|
|
|
const char *textfile = this->grf_config->GetTextfile(file_type);
|
|
|
if (textfile == NULL) return;
|
|
|
|
|
|
/* Get text from file */
|
|
|
size_t filesize;
|
|
|
FILE *handle = FioFOpenFile(textfile, "rb", NEWGRF_DIR, &filesize);
|
|
|
if (handle == NULL) return;
|
|
|
|
|
|
this->text = ReallocT(this->text, filesize + 1);
|
|
|
size_t read = fread(this->text, 1, filesize, handle);
|
|
|
fclose(handle);
|