From 6027e777c85c94f009e8ecd27ed1cce525359c61 Mon Sep 17 00:00:00 2001 From: dominik Date: Sat, 22 Jan 2005 23:13:20 +0000 Subject: (svn r1598) Feature: Message history now is stickyable and resizeable The news messages are now precisely cropped according to pixel width to fit optimal into the window. Introduced a new date format: DATE_TINY, which is ISOish. --- lang/english.txt | 2 ++ news_gui.c | 35 ++++++++++++++++++++++++----------- strgen/strgen.c | 1 + strings.c | 17 +++++++++++++++++ 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/lang/english.txt b/lang/english.txt index 5c079d97c..a38c90c38 100644 --- a/lang/english.txt +++ b/lang/english.txt @@ -2785,6 +2785,8 @@ STR_REPLACE_HELP_RAILTYPE :{BLACK}Choose the railtype you want to replace en STR_REPLACE_HELP_REPLACE_INFO_TAB :{BLACK}Displays which engine the left selected engine is being replaced with, if any STR_REPLACE_HELP :{BLACK}This allows you to replace one engine type with another type, when trains of the original type enter a depot +STR_SHORT_DATE :{WHITE}{DATE_TINY} + ############ Lists rail types STR_RAIL_VEHICLES :Rail Vehicles diff --git a/news_gui.c b/news_gui.c index e51935f3d..a17946c90 100644 --- a/news_gui.c +++ b/news_gui.c @@ -501,10 +501,12 @@ static byte getNews(byte i) return i; } -static void GetNewsString(NewsItem *ni, byte *buffer) +// cut string after len pixels +static void GetNewsString(NewsItem *ni, byte *buffer, uint max) { StringID str; byte *s, *d; + uint len = 0; if (ni->display_mode == 3) { str = _get_news_string_callback[ni->callback](ni); @@ -521,7 +523,7 @@ static void GetNewsString(NewsItem *ni, byte *buffer) for (;; s++) { // cut strings that are too long - if (s >= str_buffr + 55) { + if (len >= max-24) { // add 3x "." at the end d[0] = d[1] = d[2] = '.'; d += 3; *d = '\0'; @@ -535,6 +537,7 @@ static void GetNewsString(NewsItem *ni, byte *buffer) d[0] = d[1] = d[2] = d[3] = ' '; d += 4; } else if (*s >= ' ' && (*s < 0x88 || *s >= 0x99)) { + len += _stringwidth_table[*s - 32]; *d++ = *s; } } @@ -553,17 +556,17 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e) DrawWindowWidgets(w); if (_total_news == 0) break; - show = min(_total_news, 10); + show = min(_total_news, w->vscroll.cap); for (p = w->vscroll.pos; p < w->vscroll.pos + show; p++) { // get news in correct order ni = &_news_items[getNews(p)]; SetDParam(0, ni->date); - DrawString(4, y, STR_00AF, 16); + DrawString(4, y, STR_SHORT_DATE, 16); - GetNewsString(ni, buffer); - DoDrawString(buffer, 85, y, 16); + GetNewsString(ni, buffer, w->width-90); + DoDrawString(buffer, 82, y, 16); y += 12; } @@ -572,7 +575,7 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e) case WE_CLICK: switch (e->click.widget) { - case 2: { + case 3: { int y = (e->click.pt.y - 19) / 12; byte p, q; @@ -601,21 +604,27 @@ static void MessageHistoryWndProc(Window *w, WindowEvent *e) } } break; + + case WE_RESIZE: + w->vscroll.cap += e->sizing.diff.y / 12; + break; } } static const Widget _message_history_widgets[] = { { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, -{ WWT_CAPTION, RESIZE_NONE, 13, 11, 399, 0, 13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS}, -{ WWT_IMGBTN, RESIZE_NONE, 13, 0, 387, 14, 139, 0x0, STR_MESSAGE_HISTORY_TIP}, -{ WWT_SCROLLBAR, RESIZE_NONE, 13, 388, 399, 14, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, +{ WWT_CAPTION, RESIZE_RIGHT, 13, 11, 387, 0, 13, STR_MESSAGE_HISTORY, STR_018C_WINDOW_TITLE_DRAG_THIS}, +{ WWT_STICKYBOX, RESIZE_LR, 13, 388, 399, 0, 13, 0x0, STR_STICKY_BUTTON}, +{ WWT_IMGBTN, RESIZE_RB, 13, 0, 387, 14, 139, 0x0, STR_MESSAGE_HISTORY_TIP}, +{ WWT_SCROLLBAR, RESIZE_LRB, 13, 388, 399, 14, 127, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, +{ WWT_RESIZEBOX, RESIZE_LRTB, 13, 388, 399, 128, 139, 0x0, STR_RESIZE_BUTTON}, { WIDGETS_END}, }; static const WindowDesc _message_history_desc = { 240, 22, 400, 140, WC_MESSAGE_HISTORY, 0, - WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, + WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, _message_history_widgets, MessageHistoryWndProc }; @@ -630,6 +639,10 @@ void ShowMessageHistory(void) if (w != NULL) { w->vscroll.cap = 10; w->vscroll.count = _total_news; + w->resize.step_height = 12; + w->resize.height = w->height - 12 * 6; // minimum of 4 items in the list, each item 12 high + w->resize.step_width = 1; + w->resize.width = 200; // can't make window any smaller than 200 pixel SetWindowDirty(w); } } diff --git a/strgen/strgen.c b/strgen/strgen.c index 8734c5b4f..481640643 100644 --- a/strgen/strgen.c +++ b/strgen/strgen.c @@ -266,6 +266,7 @@ static const CmdStruct _cmd_structs[] = { {"TOWN", EmitSingleByte, 0x9B}, {"CURRENCY64", EmitSingleByte, 0x9C}, {"WAYPOINT", EmitSingleByte, 0x9D}, // waypoint name + {"DATE_TINY", EmitSingleByte, 0x9E}, // 0x9E=158 is the LAST special character we may use. {"UPARROW", EmitSingleByte, 0xA0}, diff --git a/strings.c b/strings.c index c9fa18196..db29c71f8 100644 --- a/strings.c +++ b/strings.c @@ -259,6 +259,17 @@ static byte *FormatMonthAndYear(byte *buff, uint16 number) return FormatNoCommaNumber(buff, ymd.year + MAX_YEAR_BEGIN_REAL); } +static byte *FormatTinyDate(byte *buff, uint16 number) +{ + const char *src; + YearMonthDay ymd; + + ConvertDayToYMD(&ymd, number); + buff += sprintf(buff, " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year + MAX_YEAR_BEGIN_REAL); + + return buff; +} + uint GetCurrentCurrencyRate(void) { return (&_currency_specs[_opt.currency])->rate; @@ -478,6 +489,12 @@ static byte *DecodeString(byte *buff, const byte *str) buff = GetString(buff, str); } break; + + case 0x9E: { // {DATE_TINY} + buff = FormatTinyDate(buff, GetParamUint16()); + break; + } + // case 0x88..0x98: // {COLORS} // case 0xE: // {TINYFONT} // case 0xF: // {BIGFONT} -- cgit v1.2.3-70-g09d2