mirror of https://github.com/OpenRCT2/OpenRCT2.git
Chat: Improve 3d edge style + initial test for clipping the text.
This commit is contained in:
parent
9ec3fbc39b
commit
c52747bc93
|
@ -25,7 +25,7 @@
|
||||||
#include "../interface/themes.h"
|
#include "../interface/themes.h"
|
||||||
|
|
||||||
#define CHAT_HISTORY_SIZE 10
|
#define CHAT_HISTORY_SIZE 10
|
||||||
#define CHAT_INPUT_SIZE 256
|
#define CHAT_INPUT_SIZE 150
|
||||||
|
|
||||||
bool gChatOpen = false;
|
bool gChatOpen = false;
|
||||||
char _chatCurrentLine[CHAT_INPUT_SIZE];
|
char _chatCurrentLine[CHAT_INPUT_SIZE];
|
||||||
|
@ -81,8 +81,13 @@ void chat_draw(rct_drawpixelinfo * dpi)
|
||||||
gChatOpen = false;
|
gChatOpen = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_chatLeft = 10;
|
_chatLeft = 10;
|
||||||
_chatTop = gScreenHeight - 45;
|
_chatTop = gScreenHeight - 45;
|
||||||
|
_chatRight = gScreenWidth - 10;
|
||||||
|
_chatBottom = gScreenHeight - 45;
|
||||||
|
|
||||||
|
//Dynamic background (auto-resizable, depending of the chat history).
|
||||||
if (_chatHistoryIndex < CHAT_HISTORY_SIZE && _chatHistoryIndex > 5) {
|
if (_chatHistoryIndex < CHAT_HISTORY_SIZE && _chatHistoryIndex > 5) {
|
||||||
_chatTop -= ((_chatHistoryIndex + 1) * 15);
|
_chatTop -= ((_chatHistoryIndex + 1) * 15);
|
||||||
} else if (_chatHistoryIndex <= 5) {
|
} else if (_chatHistoryIndex <= 5) {
|
||||||
|
@ -90,17 +95,17 @@ void chat_draw(rct_drawpixelinfo * dpi)
|
||||||
} else {
|
} else {
|
||||||
_chatTop -= ((CHAT_HISTORY_SIZE + 1) * 15);
|
_chatTop -= ((CHAT_HISTORY_SIZE + 1) * 15);
|
||||||
}
|
}
|
||||||
_chatRight = gScreenWidth - 10;
|
|
||||||
_chatBottom = gScreenHeight - 45;
|
//Max width
|
||||||
char lineBuffer[CHAT_INPUT_SIZE + 10];
|
if (_chatRight > 500) {
|
||||||
char* lineCh = lineBuffer;
|
_chatRight = 500;
|
||||||
int x = _chatLeft + 5;
|
}
|
||||||
int y = _chatBottom - (15 * 2);
|
|
||||||
uint8 chatBackgroundColor = theme_get_colour(WC_CHAT, 0);
|
uint8 chatBackgroundColor = theme_get_colour(WC_CHAT, 0);
|
||||||
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
|
||||||
gCurrentFontFlags = 0;
|
|
||||||
if (gChatOpen) {
|
if (gChatOpen) {
|
||||||
gfx_set_dirty_blocks(_chatLeft, _chatTop - 5, _chatRight, _chatBottom + 5); //Background area + Textbox
|
gfx_set_dirty_blocks(_chatLeft, _chatTop - 5, _chatRight, _chatBottom + 5); //Background area + Textbox
|
||||||
|
//TODO: Cleanup
|
||||||
gfx_fill_rect(
|
gfx_fill_rect(
|
||||||
dpi,
|
dpi,
|
||||||
_chatLeft,
|
_chatLeft,
|
||||||
|
@ -108,7 +113,7 @@ void chat_draw(rct_drawpixelinfo * dpi)
|
||||||
_chatRight,
|
_chatRight,
|
||||||
_chatBottom + 5,
|
_chatBottom + 5,
|
||||||
0x2000000 | 51
|
0x2000000 | 51
|
||||||
); //Simulate window background (gray background).
|
);
|
||||||
gfx_fill_rect_inset(
|
gfx_fill_rect_inset(
|
||||||
dpi,
|
dpi,
|
||||||
_chatLeft,
|
_chatLeft,
|
||||||
|
@ -127,30 +132,55 @@ void chat_draw(rct_drawpixelinfo * dpi)
|
||||||
chatBackgroundColor,
|
chatBackgroundColor,
|
||||||
0x20
|
0x20
|
||||||
);
|
);
|
||||||
|
gfx_fill_rect_inset(
|
||||||
|
dpi,
|
||||||
|
_chatLeft + 1,
|
||||||
|
_chatTop - 4,
|
||||||
|
_chatRight - 1,
|
||||||
|
_chatBottom - 16,
|
||||||
|
chatBackgroundColor,
|
||||||
|
0x30
|
||||||
|
);
|
||||||
gfx_fill_rect_inset(
|
gfx_fill_rect_inset(
|
||||||
dpi,
|
dpi,
|
||||||
x - 1,
|
_chatLeft + 1,
|
||||||
_chatBottom - 15,
|
_chatBottom - 15,
|
||||||
_chatRight + 1,
|
_chatRight - 1,
|
||||||
_chatBottom + 1,
|
_chatBottom + 4,
|
||||||
chatBackgroundColor,
|
chatBackgroundColor,
|
||||||
0x20
|
0x30
|
||||||
); //Textbox
|
); //Textbox
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char lineBuffer[CHAT_INPUT_SIZE + 10];
|
||||||
|
char* lineCh = lineBuffer;
|
||||||
|
int x = _chatLeft + 5;
|
||||||
|
int y = _chatBottom - (15 * 2);
|
||||||
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
||||||
|
gCurrentFontFlags = 0;
|
||||||
|
|
||||||
for (int i = 0; i < CHAT_HISTORY_SIZE; i++, y -= 15) {
|
for (int i = 0; i < CHAT_HISTORY_SIZE; i++, y -= 15) {
|
||||||
if (!gChatOpen && SDL_TICKS_PASSED(SDL_GetTicks(), chat_history_get_time(i) + 10000)) {
|
if (!gChatOpen && SDL_TICKS_PASSED(SDL_GetTicks(), chat_history_get_time(i) + 10000)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_strcpy(lineBuffer, chat_history_get(i), CHAT_INPUT_SIZE + 10);
|
safe_strcpy(lineBuffer, chat_history_get(i), CHAT_INPUT_SIZE + 10);
|
||||||
gfx_set_dirty_blocks(x, y, x + gfx_get_string_width(lineBuffer), y + 12);
|
|
||||||
|
gfx_clip_string(lineBuffer, _chatRight - _chatLeft - 10);
|
||||||
|
|
||||||
|
gfx_set_dirty_blocks(x, y, x + gfx_get_string_width(lineBuffer), y + 12); //clipping text not yet implemented, this is still required
|
||||||
gfx_draw_string(dpi, lineBuffer, 255, x, y);
|
gfx_draw_string(dpi, lineBuffer, 255, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gChatOpen) {
|
if (gChatOpen) {
|
||||||
lineCh = utf8_write_codepoint(lineCh, FORMAT_OUTLINE);
|
lineCh = utf8_write_codepoint(lineCh, FORMAT_OUTLINE);
|
||||||
lineCh = utf8_write_codepoint(lineCh, FORMAT_CELADON);
|
lineCh = utf8_write_codepoint(lineCh, FORMAT_CELADON);
|
||||||
safe_strcpy(lineCh, _chatCurrentLine, CHAT_INPUT_SIZE);
|
safe_strcpy(lineCh, _chatCurrentLine, CHAT_INPUT_SIZE);
|
||||||
y = _chatBottom - 15;
|
y = _chatBottom - 15;
|
||||||
|
|
||||||
|
gfx_set_dirty_blocks(x, y, x + gfx_get_string_width(lineBuffer), y + 12);
|
||||||
gfx_draw_string(dpi, lineBuffer, 255, x, y + 3);
|
gfx_draw_string(dpi, lineBuffer, 255, x, y + 3);
|
||||||
|
|
||||||
if (_chatCaretTicks < 15) {
|
if (_chatCaretTicks < 15) {
|
||||||
memcpy(lineBuffer, _chatCurrentLine, gTextInput.selection_offset);
|
memcpy(lineBuffer, _chatCurrentLine, gTextInput.selection_offset);
|
||||||
lineBuffer[gTextInput.selection_offset] = 0;
|
lineBuffer[gTextInput.selection_offset] = 0;
|
||||||
|
|
Loading…
Reference in New Issue