From: fgsfds Date: Fri, 9 Feb 2018 14:37:36 +0000 (+0300) Subject: added word wrap to center messages; fixed e_CharFont_GetSizeFmt X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=d3967cf39bf31bc5573af05576457ccfce96e9ea;p=d2df-sdl.git added word wrap to center messages; fixed e_CharFont_GetSizeFmt --- diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas index 47e69d6..bb805da 100644 --- a/src/engine/e_graphics.pas +++ b/src/engine/e_graphics.pas @@ -1447,11 +1447,12 @@ end; procedure e_CharFont_GetSizeFmt(FontID: DWORD; Text: string; var w, h: Word); var a, lines, len: Integer; - h2, w2: Word; + h2, w2, tw, th: Word; begin w2 := 0; - w := 0; - h := 0; + h2 := 0; + tw := 0; + th := 0; if Text = '' then Exit; if e_CharFonts = nil then Exit; @@ -1467,29 +1468,26 @@ begin if Text[a] = #10 then begin Inc(lines); - if w2 > w then - begin - w := w2; - w2 := 0; - end; - continue; - end - else if Text[a] in [#1, #2, #3, #4, #18, #19, #20, #21] then + if w2 > tw then tw := w2; + w2 := 0; continue; + end; with Chars[Ord(Text[a])] do - if TextureID <> -1 then - begin - w2 := w2 + Width + IfThen(a = len, 0, Space); - e_GetTextureSize(TextureID, nil, @h2); - if h2 > h then h := h2; - end; + if TextureID <> -1 then + begin + w2 := w2 + Width + IfThen(a = len, 0, Space); + e_GetTextureSize(TextureID, nil, @h2); + if h2 > th then th := h2; + end; end; end; - if w2 > w then - w := w2; - h := h * lines; + if w2 > tw then + tw := w2; + + w := tw; + h := th * lines; end; function e_CharFont_GetMaxWidth(FontID: DWORD): Word; diff --git a/src/game/g_basic.pas b/src/game/g_basic.pas index eba4094..e5ef3d9 100644 --- a/src/game/g_basic.pas +++ b/src/game/g_basic.pas @@ -89,7 +89,7 @@ function g_SetFileTime(fileName: String; time: Integer): Boolean; procedure SortSArray(var S: SSArray); function b_Text_Format(S: string): string; function b_Text_Unformat(S: string): string; - +function b_Text_Wrap(S: string; LineLen: Integer): string; var gmon_dbg_los_enabled: Boolean = true; @@ -1175,4 +1175,9 @@ begin end; end; +function b_Text_Wrap(S: string; LineLen: Integer): string; +begin + Result := WrapText(S, ''#10, [#10, ' ', '-'], LineLen); +end; + end. diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 918a947..345f112 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -556,6 +556,7 @@ var EndingGameCounter: Byte = 0; MessageText: String; MessageTime: Word; + MessageLineLength: Integer = 80; MapList: SSArray = nil; MapIndex: Integer = -1; MegaWAD: record @@ -6975,7 +6976,8 @@ end; procedure g_Game_Message(Msg: string; Time: Word); begin - MessageText := b_Text_Format(Msg); + MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont); + MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength); MessageTime := Time; end;