2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2008-08-14 17:19:13 +00:00
|
|
|
#include <base/system.h>
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/shared/config.h>
|
|
|
|
#include <engine/graphics.h>
|
|
|
|
#include <engine/textrender.h>
|
|
|
|
#include "ui.h"
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2014-06-16 11:29:18 +00:00
|
|
|
#if defined(__ANDROID__)
|
|
|
|
#include <SDL_screenkeyboard.h>
|
|
|
|
#endif
|
|
|
|
|
2007-05-22 15:03:32 +00:00
|
|
|
/********************************************************
|
2011-04-13 18:37:12 +00:00
|
|
|
UI
|
2007-05-22 15:03:32 +00:00
|
|
|
*********************************************************/
|
2009-10-27 14:38:53 +00:00
|
|
|
|
|
|
|
CUI::CUI()
|
|
|
|
{
|
|
|
|
m_pHotItem = 0;
|
|
|
|
m_pActiveItem = 0;
|
|
|
|
m_pLastActiveItem = 0;
|
|
|
|
m_pBecommingHotItem = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
m_MouseX = 0;
|
|
|
|
m_MouseY = 0;
|
|
|
|
m_MouseWorldX = 0;
|
|
|
|
m_MouseWorldY = 0;
|
|
|
|
m_MouseButtons = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
m_LastMouseButtons = 0;
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
m_Screen.x = 0;
|
|
|
|
m_Screen.y = 0;
|
|
|
|
m_Screen.w = 848.0f;
|
|
|
|
m_Screen.h = 480.0f;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int CUI::Update(float Mx, float My, float Mwx, float Mwy, int Buttons)
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
m_MouseX = Mx;
|
|
|
|
m_MouseY = My;
|
|
|
|
m_MouseWorldX = Mwx;
|
|
|
|
m_MouseWorldY = Mwy;
|
|
|
|
m_LastMouseButtons = m_MouseButtons;
|
|
|
|
m_MouseButtons = Buttons;
|
|
|
|
m_pHotItem = m_pBecommingHotItem;
|
|
|
|
if(m_pActiveItem)
|
|
|
|
m_pHotItem = m_pActiveItem;
|
|
|
|
m_pBecommingHotItem = 0;
|
|
|
|
return 0;
|
2007-05-22 15:03:32 +00:00
|
|
|
}
|
2009-10-27 14:38:53 +00:00
|
|
|
|
|
|
|
int CUI::MouseInside(const CUIRect *r)
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
if(m_MouseX >= r->x && m_MouseX <= r->x+r->w && m_MouseY >= r->y && m_MouseY <= r->y+r->h)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
2007-05-22 15:03:32 +00:00
|
|
|
}
|
|
|
|
|
2011-07-02 22:36:07 +00:00
|
|
|
void CUI::ConvertMouseMove(float *x, float *y)
|
|
|
|
{
|
2014-06-16 11:29:18 +00:00
|
|
|
#if defined(__ANDROID__)
|
|
|
|
//*x = *x * 500 / g_Config.m_GfxScreenWidth;
|
|
|
|
//*y = *y * 500 / g_Config.m_GfxScreenHeight;
|
|
|
|
#else
|
2011-07-02 22:36:07 +00:00
|
|
|
float Fac = (float)(g_Config.m_UiMousesens)/g_Config.m_InpMousesens;
|
|
|
|
*x = *x*Fac;
|
|
|
|
*y = *y*Fac;
|
2014-06-16 11:29:18 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CUI::AndroidShowScreenKeys(bool shown)
|
|
|
|
{
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
static bool ScreenKeyboardInitialized = false;
|
|
|
|
static bool ScreenKeyboardShown = true;
|
|
|
|
static SDL_Rect Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM];
|
|
|
|
static SDL_Rect ButtonHidden = { 0, 0, 0, 0 };
|
|
|
|
if( !ScreenKeyboardInitialized )
|
|
|
|
{
|
|
|
|
//dbg_msg("dbg", "CUI::AndroidShowScreenKeys: ScreenKeyboardInitialized");
|
|
|
|
ScreenKeyboardInitialized = true;
|
|
|
|
|
|
|
|
for( int i = 0; i < SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM; i++ )
|
|
|
|
SDL_ANDROID_GetScreenKeyboardButtonPos( i, &Buttons[i] );
|
|
|
|
|
|
|
|
if( !SDL_ANDROID_GetScreenKeyboardRedefinedByUser() )
|
|
|
|
{
|
|
|
|
int ScreenW = Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].x +
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].w;
|
|
|
|
int ScreenH = Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].y +
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].h;
|
|
|
|
// Weapnext button above right joystick
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_1].x =
|
|
|
|
ScreenW - Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_1].w;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_1].y =
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD3].y -
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_1].h;
|
|
|
|
// Hide Hook button(it was above Weapnext)
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_0].x =
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_1].x;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_0].y =
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_1].y -
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_0].h;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_0].w = 0;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_0].h = 0;
|
|
|
|
// Hide Weapprev button
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_2].x =
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_0].x;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_2].y =
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_1].y -
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_2].h;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_2].w = 0;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_2].h = 0;
|
|
|
|
// Scores button above left joystick
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_3].x = 0;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_3].y =
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD].y -
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_3].h * 2.0f;
|
|
|
|
// Text input button above scores
|
|
|
|
//Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT].w =
|
|
|
|
// Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_3].w;
|
|
|
|
//Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT].h =
|
|
|
|
// Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_3].h;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT].y =
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_3].y -
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT].h;
|
|
|
|
// Bigger joysticks
|
|
|
|
/*
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD].w *= 1.25;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD].h *= 1.25;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD].y =
|
|
|
|
ScreenH - Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD].h;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].w *= 1.25;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].h *= 1.25;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].x =
|
|
|
|
ScreenW - Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].w;
|
|
|
|
Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].y =
|
|
|
|
ScreenH - Buttons[SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2].h;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ScreenKeyboardShown == shown )
|
|
|
|
return;
|
|
|
|
ScreenKeyboardShown = shown;
|
|
|
|
//dbg_msg("dbg", "CUI::AndroidShowScreenKeys: shown %d", shown);
|
|
|
|
for( int i = 0; i < SDL_ANDROID_SCREENKEYBOARD_BUTTON_NUM; i++ )
|
|
|
|
SDL_ANDROID_SetScreenKeyboardButtonPos( i, shown ? &Buttons[i] : &ButtonHidden );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CUI::AndroidShowTextInput(const char *text, const char *hintText)
|
|
|
|
{
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
SDL_ANDROID_SetScreenKeyboardHintMesage(hintText);
|
|
|
|
SDL_ANDROID_ToggleScreenKeyboardTextInput(text);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CUI::AndroidBlockAndGetTextInput(char *text, int textLength, const char *hintText)
|
|
|
|
{
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
SDL_ANDROID_SetScreenKeyboardHintMesage(hintText);
|
|
|
|
SDL_ANDROID_GetScreenKeyboardTextInput(text, textLength);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CUI::AndroidTextInputShown()
|
|
|
|
{
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
return SDL_IsScreenKeyboardShown(NULL);
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2011-07-02 22:36:07 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
CUIRect *CUI::Screen()
|
2007-05-22 15:03:32 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
float Aspect = Graphics()->ScreenAspect();
|
|
|
|
float w, h;
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
h = 600;
|
|
|
|
w = Aspect*h;
|
2007-05-22 15:03:32 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
m_Screen.w = w;
|
|
|
|
m_Screen.h = h;
|
2007-05-27 18:14:24 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
return &m_Screen;
|
2007-05-22 15:03:32 +00:00
|
|
|
}
|
|
|
|
|
2012-01-10 22:13:19 +00:00
|
|
|
float CUI::PixelSize()
|
|
|
|
{
|
|
|
|
return Screen()->w/Graphics()->ScreenWidth();
|
|
|
|
}
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
void CUI::SetScale(float s)
|
2007-10-29 18:40:04 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
g_Config.m_UiScale = (int)(s*100.0f);
|
2007-10-29 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
2010-12-14 00:20:47 +00:00
|
|
|
float CUI::Scale()
|
2007-10-29 18:40:04 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
return g_Config.m_UiScale/100.0f;
|
2010-12-14 00:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float CUIRect::Scale() const
|
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
return g_Config.m_UiScale/100.0f;
|
2010-12-14 00:20:47 +00:00
|
|
|
}
|
2007-10-29 18:40:04 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
void CUI::ClipEnable(const CUIRect *r)
|
2007-10-29 18:40:04 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
float XScale = Graphics()->ScreenWidth()/Screen()->w;
|
|
|
|
float YScale = Graphics()->ScreenHeight()/Screen()->h;
|
|
|
|
Graphics()->ClipEnable((int)(r->x*XScale), (int)(r->y*YScale), (int)(r->w*XScale), (int)(r->h*YScale));
|
2007-10-29 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
void CUI::ClipDisable()
|
2007-10-29 18:40:04 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->ClipDisable();
|
2007-10-29 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-26 15:19:37 +00:00
|
|
|
void CUIRect::HSplitMid(CUIRect *pTop, CUIRect *pBottom) const
|
|
|
|
{
|
|
|
|
CUIRect r = *this;
|
2011-04-13 18:37:12 +00:00
|
|
|
float Cut = r.h/2;
|
|
|
|
|
|
|
|
if(pTop)
|
|
|
|
{
|
|
|
|
pTop->x = r.x;
|
|
|
|
pTop->y = r.y;
|
|
|
|
pTop->w = r.w;
|
|
|
|
pTop->h = Cut;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pBottom)
|
|
|
|
{
|
|
|
|
pBottom->x = r.x;
|
|
|
|
pBottom->y = r.y + Cut;
|
|
|
|
pBottom->w = r.w;
|
|
|
|
pBottom->h = r.h - Cut;
|
|
|
|
}
|
2011-03-26 15:19:37 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CUIRect::HSplitTop(float Cut, CUIRect *pTop, CUIRect *pBottom) const
|
2007-10-29 18:40:04 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
CUIRect r = *this;
|
|
|
|
Cut *= Scale();
|
|
|
|
|
|
|
|
if (pTop)
|
|
|
|
{
|
|
|
|
pTop->x = r.x;
|
|
|
|
pTop->y = r.y;
|
|
|
|
pTop->w = r.w;
|
|
|
|
pTop->h = Cut;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pBottom)
|
|
|
|
{
|
|
|
|
pBottom->x = r.x;
|
|
|
|
pBottom->y = r.y + Cut;
|
|
|
|
pBottom->w = r.w;
|
|
|
|
pBottom->h = r.h - Cut;
|
|
|
|
}
|
2007-10-29 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CUIRect::HSplitBottom(float Cut, CUIRect *pTop, CUIRect *pBottom) const
|
2007-10-29 18:40:04 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
CUIRect r = *this;
|
|
|
|
Cut *= Scale();
|
|
|
|
|
|
|
|
if (pTop)
|
|
|
|
{
|
|
|
|
pTop->x = r.x;
|
|
|
|
pTop->y = r.y;
|
|
|
|
pTop->w = r.w;
|
|
|
|
pTop->h = r.h - Cut;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pBottom)
|
|
|
|
{
|
|
|
|
pBottom->x = r.x;
|
|
|
|
pBottom->y = r.y + r.h - Cut;
|
|
|
|
pBottom->w = r.w;
|
|
|
|
pBottom->h = Cut;
|
|
|
|
}
|
2007-10-29 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CUIRect::VSplitMid(CUIRect *pLeft, CUIRect *pRight) const
|
2007-10-29 18:40:04 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
CUIRect r = *this;
|
|
|
|
float Cut = r.w/2;
|
|
|
|
// Cut *= Scale();
|
|
|
|
|
|
|
|
if (pLeft)
|
|
|
|
{
|
|
|
|
pLeft->x = r.x;
|
|
|
|
pLeft->y = r.y;
|
|
|
|
pLeft->w = Cut;
|
|
|
|
pLeft->h = r.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pRight)
|
|
|
|
{
|
|
|
|
pRight->x = r.x + Cut;
|
|
|
|
pRight->y = r.y;
|
|
|
|
pRight->w = r.w - Cut;
|
|
|
|
pRight->h = r.h;
|
|
|
|
}
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CUIRect::VSplitLeft(float Cut, CUIRect *pLeft, CUIRect *pRight) const
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
CUIRect r = *this;
|
|
|
|
Cut *= Scale();
|
|
|
|
|
|
|
|
if (pLeft)
|
|
|
|
{
|
|
|
|
pLeft->x = r.x;
|
|
|
|
pLeft->y = r.y;
|
|
|
|
pLeft->w = Cut;
|
|
|
|
pLeft->h = r.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pRight)
|
|
|
|
{
|
|
|
|
pRight->x = r.x + Cut;
|
|
|
|
pRight->y = r.y;
|
|
|
|
pRight->w = r.w - Cut;
|
|
|
|
pRight->h = r.h;
|
|
|
|
}
|
2007-10-29 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CUIRect::VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const
|
2007-10-29 18:40:04 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
CUIRect r = *this;
|
|
|
|
Cut *= Scale();
|
|
|
|
|
|
|
|
if (pLeft)
|
|
|
|
{
|
|
|
|
pLeft->x = r.x;
|
|
|
|
pLeft->y = r.y;
|
|
|
|
pLeft->w = r.w - Cut;
|
|
|
|
pLeft->h = r.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pRight)
|
|
|
|
{
|
|
|
|
pRight->x = r.x + r.w - Cut;
|
|
|
|
pRight->y = r.y;
|
|
|
|
pRight->w = Cut;
|
|
|
|
pRight->h = r.h;
|
|
|
|
}
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
2007-10-29 18:40:04 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CUIRect::Margin(float Cut, CUIRect *pOtherRect) const
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
CUIRect r = *this;
|
2010-05-29 07:25:38 +00:00
|
|
|
Cut *= Scale();
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
pOtherRect->x = r.x + Cut;
|
|
|
|
pOtherRect->y = r.y + Cut;
|
|
|
|
pOtherRect->w = r.w - 2*Cut;
|
|
|
|
pOtherRect->h = r.h - 2*Cut;
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CUIRect::VMargin(float Cut, CUIRect *pOtherRect) const
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
CUIRect r = *this;
|
2010-05-29 07:25:38 +00:00
|
|
|
Cut *= Scale();
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
pOtherRect->x = r.x + Cut;
|
|
|
|
pOtherRect->y = r.y;
|
|
|
|
pOtherRect->w = r.w - 2*Cut;
|
|
|
|
pOtherRect->h = r.h;
|
2007-10-29 18:40:04 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CUIRect::HMargin(float Cut, CUIRect *pOtherRect) const
|
2007-10-29 18:40:04 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
CUIRect r = *this;
|
2010-05-29 07:25:38 +00:00
|
|
|
Cut *= Scale();
|
2007-10-29 18:40:04 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
pOtherRect->x = r.x;
|
|
|
|
pOtherRect->y = r.y + Cut;
|
|
|
|
pOtherRect->w = r.w;
|
|
|
|
pOtherRect->h = r.h - 2*Cut;
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
int CUI::DoButtonLogic(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
// logic
|
|
|
|
int ReturnValue = 0;
|
|
|
|
int Inside = MouseInside(pRect);
|
2009-10-27 14:38:53 +00:00
|
|
|
static int ButtonUsed = 0;
|
|
|
|
|
|
|
|
if(ActiveItem() == pID)
|
|
|
|
{
|
|
|
|
if(!MouseButton(ButtonUsed))
|
|
|
|
{
|
|
|
|
if(Inside && Checked >= 0)
|
|
|
|
ReturnValue = 1+ButtonUsed;
|
|
|
|
SetActiveItem(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(HotItem() == pID)
|
|
|
|
{
|
|
|
|
if(MouseButton(0))
|
|
|
|
{
|
|
|
|
SetActiveItem(pID);
|
|
|
|
ButtonUsed = 0;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
if(MouseButton(1))
|
|
|
|
{
|
|
|
|
SetActiveItem(pID);
|
|
|
|
ButtonUsed = 1;
|
|
|
|
}
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
if(Inside)
|
|
|
|
SetHotItem(pID);
|
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
return ReturnValue;
|
2009-10-27 14:38:53 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
int CUI::DoButton(const void *id, const char *text, int checked, const CUIRect *r, ui_draw_button_func draw_func, const void *extra)
|
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
// logic
|
|
|
|
int ret = 0;
|
|
|
|
int inside = ui_MouseInside(r);
|
2008-01-13 22:03:32 +00:00
|
|
|
static int button_used = 0;
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
if(ui_ActiveItem() == id)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
if(!ui_MouseButton(button_used))
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
|
|
|
if(inside && checked >= 0)
|
2008-01-13 22:03:32 +00:00
|
|
|
ret = 1+button_used;
|
2009-10-27 14:38:53 +00:00
|
|
|
ui_SetActiveItem(0);
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-27 14:38:53 +00:00
|
|
|
else if(ui_HotItem() == id)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
if(ui_MouseButton(0))
|
2008-01-13 22:03:32 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
ui_SetActiveItem(id);
|
2008-01-13 22:03:32 +00:00
|
|
|
button_used = 0;
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
if(ui_MouseButton(1))
|
2008-01-13 22:03:32 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
ui_SetActiveItem(id);
|
2008-01-13 22:03:32 +00:00
|
|
|
button_used = 1;
|
|
|
|
}
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-01-12 12:27:55 +00:00
|
|
|
if(inside)
|
2009-10-27 14:38:53 +00:00
|
|
|
ui_SetHotItem(id);
|
2008-01-12 12:27:55 +00:00
|
|
|
|
|
|
|
if(draw_func)
|
2011-04-13 18:37:12 +00:00
|
|
|
draw_func(id, text, checked, r, extra);
|
|
|
|
return ret;
|
2009-10-27 14:38:53 +00:00
|
|
|
}*/
|
2008-01-12 12:27:55 +00:00
|
|
|
|
2010-10-20 19:33:48 +00:00
|
|
|
void CUI::DoLabel(const CUIRect *r, const char *pText, float Size, int Align, int MaxWidth)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2009-10-27 14:38:53 +00:00
|
|
|
// TODO: FIX ME!!!!
|
2011-04-13 18:37:12 +00:00
|
|
|
//Graphics()->BlendNormal();
|
|
|
|
if(Align == 0)
|
|
|
|
{
|
|
|
|
float tw = TextRender()->TextWidth(0, Size, pText, MaxWidth);
|
|
|
|
TextRender()->Text(0, r->x + r->w/2-tw/2, r->y - Size/10, Size, pText, MaxWidth);
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
else if(Align < 0)
|
2011-04-13 18:37:12 +00:00
|
|
|
TextRender()->Text(0, r->x, r->y - Size/10, Size, pText, MaxWidth);
|
2010-05-29 07:25:38 +00:00
|
|
|
else if(Align > 0)
|
2008-01-12 12:27:55 +00:00
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
float tw = TextRender()->TextWidth(0, Size, pText, MaxWidth);
|
|
|
|
TextRender()->Text(0, r->x + r->w-tw, r->y - Size/10, Size, pText, MaxWidth);
|
2008-01-12 12:27:55 +00:00
|
|
|
}
|
2007-10-29 18:40:04 +00:00
|
|
|
}
|
2010-12-14 00:20:47 +00:00
|
|
|
|
|
|
|
void CUI::DoLabelScaled(const CUIRect *r, const char *pText, float Size, int Align, int MaxWidth)
|
|
|
|
{
|
2011-04-13 18:37:12 +00:00
|
|
|
DoLabel(r, pText, Size*Scale(), Align, MaxWidth);
|
2014-01-15 23:46:13 +00:00
|
|
|
}
|