ddnet/src/game/client/ui.h

103 lines
3.3 KiB
C
Raw Normal View History

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. */
2010-05-29 07:25:38 +00:00
#ifndef GAME_CLIENT_UI_H
#define GAME_CLIENT_UI_H
2009-10-27 14:38:53 +00:00
class CUIRect
2008-01-12 12:27:55 +00:00
{
2009-10-27 14:38:53 +00:00
// TODO: Refactor: Redo UI scaling
float Scale() const;
2009-10-27 14:38:53 +00:00
public:
float x, y, w, h;
2011-03-26 15:19:37 +00:00
void HSplitMid(CUIRect *pTop, CUIRect *pBottom) const;
2009-10-27 14:38:53 +00:00
void HSplitTop(float Cut, CUIRect *pTop, CUIRect *pBottom) const;
void HSplitBottom(float Cut, CUIRect *pTop, CUIRect *pBottom) const;
void VSplitMid(CUIRect *pLeft, CUIRect *pRight) const;
void VSplitLeft(float Cut, CUIRect *pLeft, CUIRect *pRight) const;
void VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const;
void Margin(float Cut, CUIRect *pOtherRect) const;
void VMargin(float Cut, CUIRect *pOtherRect) const;
void HMargin(float Cut, CUIRect *pOtherRect) const;
2009-10-27 14:38:53 +00:00
};
2008-01-12 12:27:55 +00:00
2009-10-27 14:38:53 +00:00
class CUI
2008-01-12 12:27:55 +00:00
{
2009-10-27 14:38:53 +00:00
const void *m_pHotItem;
const void *m_pActiveItem;
const void *m_pLastActiveItem;
const void *m_pBecommingHotItem;
2010-05-29 07:25:38 +00:00
float m_MouseX, m_MouseY; // in gui space
float m_MouseWorldX, m_MouseWorldY; // in world space
2009-10-27 14:38:53 +00:00
unsigned m_MouseButtons;
unsigned m_LastMouseButtons;
2009-10-27 14:38:53 +00:00
CUIRect m_Screen;
class IGraphics *m_pGraphics;
2010-05-29 07:25:38 +00:00
class ITextRender *m_pTextRender;
2009-10-27 14:38:53 +00:00
public:
// TODO: Refactor: Fill this in
2010-05-29 07:25:38 +00:00
void SetGraphics(class IGraphics *pGraphics, class ITextRender *pTextRender) { m_pGraphics = pGraphics; m_pTextRender = pTextRender;}
2009-10-27 14:38:53 +00:00
class IGraphics *Graphics() { return m_pGraphics; }
2010-05-29 07:25:38 +00:00
class ITextRender *TextRender() { return m_pTextRender; }
2008-01-12 12:27:55 +00:00
2009-10-27 14:38:53 +00:00
CUI();
2007-05-22 15:03:32 +00:00
2009-10-27 14:38:53 +00:00
enum
{
CORNER_TL=1,
CORNER_TR=2,
CORNER_BL=4,
CORNER_BR=8,
2009-10-27 14:38:53 +00:00
CORNER_T=CORNER_TL|CORNER_TR,
CORNER_B=CORNER_BL|CORNER_BR,
CORNER_R=CORNER_TR|CORNER_BR,
CORNER_L=CORNER_TL|CORNER_BL,
2009-10-27 14:38:53 +00:00
CORNER_ALL=CORNER_T|CORNER_B
};
2007-05-22 15:03:32 +00:00
2010-05-29 07:25:38 +00:00
int Update(float mx, float my, float Mwx, float Mwy, int m_Buttons);
2007-05-22 15:03:32 +00:00
2009-10-27 14:38:53 +00:00
float MouseX() const { return m_MouseX; }
float MouseY() const { return m_MouseY; }
float MouseWorldX() const { return m_MouseWorldX; }
float MouseWorldY() const { return m_MouseWorldY; }
int MouseButton(int Index) const { return (m_MouseButtons>>Index)&1; }
int MouseButtonClicked(int Index) { return MouseButton(Index) && !((m_LastMouseButtons>>Index)&1) ; }
2008-01-12 12:27:55 +00:00
2009-10-27 14:38:53 +00:00
void SetHotItem(const void *pID) { m_pBecommingHotItem = pID; }
void SetActiveItem(const void *pID) { m_pActiveItem = pID; if (pID) m_pLastActiveItem = pID; }
void ClearLastActiveItem() { m_pLastActiveItem = 0; }
const void *HotItem() const { return m_pHotItem; }
const void *NextHotItem() const { return m_pBecommingHotItem; }
const void *ActiveItem() const { return m_pActiveItem; }
const void *LastActiveItem() const { return m_pLastActiveItem; }
2008-01-12 12:27:55 +00:00
2010-05-29 07:25:38 +00:00
int MouseInside(const CUIRect *pRect);
void ConvertMouseMove(float *x, float *y);
2008-01-12 12:27:55 +00:00
2009-10-27 14:38:53 +00:00
CUIRect *Screen();
float PixelSize();
2010-05-29 07:25:38 +00:00
void ClipEnable(const CUIRect *pRect);
2009-10-27 14:38:53 +00:00
void ClipDisable();
2009-10-27 14:38:53 +00:00
// TODO: Refactor: Redo UI scaling
void SetScale(float s);
float Scale();
2007-05-22 15:03:32 +00:00
2009-10-27 14:38:53 +00:00
int DoButtonLogic(const void *pID, const char *pText /* TODO: Refactor: Remove */, int Checked, const CUIRect *pRect);
int DoPickerLogic(const void *pID, const CUIRect *pRect, float *pX, float *pY);
2009-10-27 14:38:53 +00:00
// TODO: Refactor: Remove this?
2010-05-29 07:25:38 +00:00
void DoLabel(const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1);
void DoLabelScaled(const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth = -1);
2009-10-27 14:38:53 +00:00
};
2007-05-22 15:03:32 +00:00
#endif