diff options
| author | Tom Adams <Tom_Adams@web.de> | 2010-05-29 15:53:57 +0000 |
|---|---|---|
| committer | Tom Adams <Tom_Adams@web.de> | 2010-05-29 15:53:57 +0000 |
| commit | e16fdc3f3edc4f66cda9a44679af2ebe1b235612 (patch) | |
| tree | 8c9d3c5881e3d7af37188937dac8a7cb82bcc359 | |
| parent | f96fccb6e79cf2f691b67ae4152f3031863faec8 (diff) | |
| download | zcatch-e16fdc3f3edc4f66cda9a44679af2ebe1b235612.tar.gz zcatch-e16fdc3f3edc4f66cda9a44679af2ebe1b235612.zip | |
added clipping to editboxes (#773) and made their cursors blink
| -rw-r--r-- | src/game/client/components/menus.cpp | 46 | ||||
| -rw-r--r-- | src/game/client/components/menus.h | 2 | ||||
| -rw-r--r-- | src/game/client/components/menus_browser.cpp | 12 | ||||
| -rw-r--r-- | src/game/client/components/menus_settings.cpp | 6 |
4 files changed, 51 insertions, 15 deletions
diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 76ee2e5e..763e33b4 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -210,7 +210,7 @@ int CMenus::DoButton_CheckBox_Number(const void *pID, const char *pText, int Che return DoButton_CheckBox_Common(pID, pText, aBuf, pRect); } -int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, bool Hidden, int Corners) +int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners) { int Inside = UI()->MouseInside(pRect); bool ReturnValue = false; @@ -228,7 +228,7 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS for(int i = 1; i <= Len; i++) { - if(TextRender()->TextWidth(0, FontSize, pStr, i) + 10 > MxRel) + if(TextRender()->TextWidth(0, FontSize, pStr, i) - *Offset + 10 > MxRel) { s_AtIndex = i - 1; break; @@ -284,19 +284,47 @@ int CMenus::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrS pDisplayStr = aStars; } + // check if the text has to be moved + if(UI()->LastActiveItem() == pID && !JustGotActive && m_NumInputEvents) + { + float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex)*UI()->Scale(); + if(w-*Offset > Textbox.w) + { + // move to the left + float wt = TextRender()->TextWidth(0, FontSize, pDisplayStr, -1)*UI()->Scale(); + do + { + *Offset += min(wt-*Offset-Textbox.w, Textbox.w/3); + } + while(w-*Offset > Textbox.w); + } + else if(w-*Offset < 0.0f) + { + // move to the right + do + { + *Offset = max(0.0f, *Offset-Textbox.w/3); + } + while(w-*Offset < 0.0f); + } + } + UI()->ClipEnable(pRect); + Textbox.x -= *Offset*UI()->Scale(); + UI()->DoLabel(&Textbox, pDisplayStr, FontSize, -1); - //TODO: make it blink + // render the cursor if(UI()->LastActiveItem() == pID && !JustGotActive) { float w = TextRender()->TextWidth(0, FontSize, pDisplayStr, s_AtIndex); Textbox = *pRect; Textbox.VSplitLeft(2.0f, 0, &Textbox); - Textbox.x += w*UI()->Scale(); + Textbox.x += (w-*Offset)*UI()->Scale(); Textbox.y -= FontSize/10.f; - - UI()->DoLabel(&Textbox, "|", FontSize*1.1f, -1); + if((2*time_get()/time_freq()) % 2) // make it blink + UI()->DoLabel(&Textbox, "|", FontSize*1.1f, -1); } + UI()->ClipDisable(); return ReturnValue; } @@ -899,7 +927,8 @@ int CMenus::Render() TextBox.VSplitLeft(20.0f, 0, &TextBox); TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("Password"), 18.0f, -1); - DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, true); + static float Offset = 0.0f; + DoEditBox(&g_Config.m_Password, &TextBox, g_Config.m_Password, sizeof(g_Config.m_Password), 12.0f, &Offset, true); } else if(m_Popup == POPUP_FIRST_LAUNCH) { @@ -921,7 +950,8 @@ int CMenus::Render() TextBox.VSplitLeft(20.0f, 0, &TextBox); TextBox.VSplitRight(60.0f, &TextBox, 0); UI()->DoLabel(&Label, Localize("Nickname"), 18.0f, -1); - DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f); + static float Offset = 0.0f; + DoEditBox(&g_Config.m_PlayerName, &TextBox, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 12.0f, &Offset); } else { diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 3055e661..c09e6e96 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -58,7 +58,7 @@ class CMenus : public CComponent static void ui_draw_checkbox(const void *id, const char *text, int checked, const CUIRect *r, const void *extra); static void ui_draw_checkbox_number(const void *id, const char *text, int checked, const CUIRect *r, const void *extra); */ - int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, bool Hidden=false, int Corners=CUI::CORNER_ALL); + int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden=false, int Corners=CUI::CORNER_ALL); //static int ui_do_edit_box(void *id, const CUIRect *rect, char *str, unsigned str_size, float font_size, bool hidden=false); float DoScrollbarV(const void *pID, const CUIRect *pRect, float Current); diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 0a737052..f2437107 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -360,7 +360,8 @@ void CMenus::RenderServerbrowserServerList(CUIRect View) QuickSearch.VSplitLeft(TextRender()->TextWidth(0, 12.0f, pLabel, -1), 0, &QuickSearch); QuickSearch.VSplitLeft(5.0f, 0, &QuickSearch); QuickSearch.VSplitLeft(155.0f, &QuickSearch, &Button); - DoEditBox(&g_Config.m_BrFilterString, &QuickSearch, g_Config.m_BrFilterString, sizeof(g_Config.m_BrFilterString), 12.0f, false, CUI::CORNER_L); + static float Offset = 0.0f; + DoEditBox(&g_Config.m_BrFilterString, &QuickSearch, g_Config.m_BrFilterString, sizeof(g_Config.m_BrFilterString), 12.0f, &Offset, false, CUI::CORNER_L); // clear button { static int s_ClearButton = 0; @@ -422,7 +423,8 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) UI()->DoLabel(&Button, Localize("Game types:"), 12.0f, -1); Button.VSplitLeft(95.0f, 0, &Button); View.HSplitTop(3.0f, 0, &View); - DoEditBox(&g_Config.m_BrFilterGametype, &Button, g_Config.m_BrFilterGametype, sizeof(g_Config.m_BrFilterGametype), 12.0f); + static float Offset = 0.0f; + DoEditBox(&g_Config.m_BrFilterGametype, &Button, g_Config.m_BrFilterGametype, sizeof(g_Config.m_BrFilterGametype), 12.0f, &Offset); { View.HSplitTop(19.0f, &Button, &View); @@ -434,7 +436,8 @@ void CMenus::RenderServerbrowserFilters(CUIRect View) char aBuf[5]; str_format(aBuf, sizeof(aBuf), "%d", g_Config.m_BrFilterPing); - DoEditBox(&g_Config.m_BrFilterPing, &EditBox, aBuf, sizeof(aBuf), 12.0f); + static float Offset = 0.0f; + DoEditBox(&g_Config.m_BrFilterPing, &EditBox, aBuf, sizeof(aBuf), 12.0f, &Offset); g_Config.m_BrFilterPing = str_toint(aBuf); } @@ -691,7 +694,8 @@ void CMenus::RenderServerbrowser(CUIRect MainView) ButtonBox.HSplitBottom(5.0f, &ButtonBox, &Button); ButtonBox.HSplitBottom(20.0f, &ButtonBox, &Button); - DoEditBox(&g_Config.m_UiServerAddress, &Button, g_Config.m_UiServerAddress, sizeof(g_Config.m_UiServerAddress), 14.0f); + static float Offset = 0.0f; + DoEditBox(&g_Config.m_UiServerAddress, &Button, g_Config.m_UiServerAddress, sizeof(g_Config.m_UiServerAddress), 14.0f, &Offset); ButtonBox.HSplitBottom(20.0f, &ButtonBox, &Button); UI()->DoLabel(&Button, Localize("Host address"), 14.0f, -1); } diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index a612ed77..dc5451b2 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -60,7 +60,8 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView) UI()->DoLabel(&Button, aBuf, 14.0, -1); Button.VSplitLeft(80.0f, 0, &Button); Button.VSplitLeft(180.0f, &Button, 0); - if(DoEditBox(g_Config.m_PlayerName, &Button, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 14.0f)) + static float Offset = 0.0f; + if(DoEditBox(g_Config.m_PlayerName, &Button, g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName), 14.0f, &Offset)) m_NeedSendinfo = true; // extra spacing @@ -598,7 +599,8 @@ void CMenus::RenderSettingsSound(CUIRect MainView) UI()->DoLabel(&Button, Localize("Sample rate"), 14.0f, -1); Button.VSplitLeft(110.0f, 0, &Button); Button.VSplitLeft(180.0f, &Button, 0); - DoEditBox(&g_Config.m_SndRate, &Button, aBuf, sizeof(aBuf), 14.0f); + static float Offset = 0.0f; + DoEditBox(&g_Config.m_SndRate, &Button, aBuf, sizeof(aBuf), 14.0f, &Offset); int Before = g_Config.m_SndRate; g_Config.m_SndRate = str_toint(aBuf); |