diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2009-10-27 14:38:53 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2009-10-27 14:38:53 +0000 |
| commit | 878ede3080ab2cfb627aca505c397d9765052996 (patch) | |
| tree | 98bff371070e1dca0295f0ca58d64ac4ee8042ce /src/game/client/ui.cpp | |
| parent | 9b99ec0e60b60134e46f2f71d707230948f7db03 (diff) | |
| download | zcatch-878ede3080ab2cfb627aca505c397d9765052996.tar.gz zcatch-878ede3080ab2cfb627aca505c397d9765052996.zip | |
major update with stuff
Diffstat (limited to 'src/game/client/ui.cpp')
| -rw-r--r-- | src/game/client/ui.cpp | 225 |
1 files changed, 128 insertions, 97 deletions
diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index 1361b85c..4aaaf32f 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -3,101 +3,95 @@ #include <engine/e_client_interface.h> #include <engine/e_config.h> +#include <engine/client/graphics.h> #include "ui.hpp" /******************************************************** UI *********************************************************/ -static const void *hot_item = 0; -static const void *active_item = 0; -static const void *last_active_item = 0; -static const void *becomming_hot_item = 0; -static float mouse_x, mouse_y; /* in gui space */ -static float mouse_wx, mouse_wy; /* in world space */ -static unsigned mouse_buttons = 0; -static unsigned last_mouse_buttons = 0; - -float ui_mouse_x() { return mouse_x; } -float ui_mouse_y() { return mouse_y; } -float ui_mouse_world_x() { return mouse_wx; } -float ui_mouse_world_y() { return mouse_wy; } -int ui_mouse_button(int index) { return (mouse_buttons>>index)&1; } -int ui_mouse_button_clicked(int index) { return ui_mouse_button(index) && !((last_mouse_buttons>>index)&1) ; } - -void ui_set_hot_item(const void *id) { becomming_hot_item = id; } -void ui_set_active_item(const void *id) { active_item = id; if (id) last_active_item = id; } -void ui_clear_last_active_item() { last_active_item = 0; } -const void *ui_hot_item() { return hot_item; } -const void *ui_next_hot_item() { return becomming_hot_item; } -const void *ui_active_item() { return active_item; } -const void *ui_last_active_item() { return last_active_item; } - -int ui_update(float mx, float my, float mwx, float mwy, int buttons) + +CUI::CUI() +{ + m_pHotItem = 0; + m_pActiveItem = 0; + m_pLastActiveItem = 0; + m_pBecommingHotItem = 0; + + m_MouseX = 0; + m_MouseY = 0; + m_MouseWorldX = 0; + m_MouseWorldY = 0; + m_MouseButtons = 0; + m_LastMouseButtons = 0; + + m_Screen.x = 0; + m_Screen.y = 0; + m_Screen.w = 848.0f; + m_Screen.h = 480.0f; +} + +int CUI::Update(float mx, float my, float mwx, float mwy, int Buttons) { - mouse_x = mx; - mouse_y = my; - mouse_wx = mwx; - mouse_wy = mwy; - last_mouse_buttons = mouse_buttons; - mouse_buttons = buttons; - hot_item = becomming_hot_item; - if(active_item) - hot_item = active_item; - becomming_hot_item = 0; + 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; } -/* -bool ui_ -*/ -int ui_mouse_inside(const RECT *r) + +int CUI::MouseInside(const CUIRect *r) { - if(mouse_x >= r->x && mouse_x <= r->x+r->w && mouse_y >= r->y && mouse_y <= r->y+r->h) + 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; } -static RECT screen = { 0.0f, 0.0f, 848.0f, 480.0f }; - -RECT *ui_screen() +CUIRect *CUI::Screen() { - float aspect = gfx_screenaspect(); + float aspect = Graphics()->ScreenAspect(); float w, h; h = 600; w = aspect*h; - screen.w = w; - screen.h = h; + m_Screen.w = w; + m_Screen.h = h; - return &screen; + return &m_Screen; } -void ui_set_scale(float s) +void CUI::SetScale(float s) { - config.ui_scale = (int)(s*100.0f); + //config.UI()->Scale = (int)(s*100.0f); } -float ui_scale() +/*float CUI::Scale() { - return config.ui_scale/100.0f; -} + return config.UI()->Scale/100.0f; +}*/ -void ui_clip_enable(const RECT *r) +void CUI::ClipEnable(const CUIRect *r) { - float xscale = gfx_screenwidth()/ui_screen()->w; - float yscale = gfx_screenheight()/ui_screen()->h; - gfx_clip_enable((int)(r->x*xscale), (int)(r->y*yscale), (int)(r->w*xscale), (int)(r->h*yscale)); + 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)); } -void ui_clip_disable() +void CUI::ClipDisable() { - gfx_clip_disable(); + Graphics()->ClipDisable(); } -void ui_hsplit_t(const RECT *original, float cut, RECT *top, RECT *bottom) +void CUIRect::HSplitTop(float cut, CUIRect *top, CUIRect *bottom) const { - RECT r = *original; - cut *= ui_scale(); + CUIRect r = *this; + cut *= Scale(); if (top) { @@ -116,10 +110,10 @@ void ui_hsplit_t(const RECT *original, float cut, RECT *top, RECT *bottom) } } -void ui_hsplit_b(const RECT *original, float cut, RECT *top, RECT *bottom) +void CUIRect::HSplitBottom(float cut, CUIRect *top, CUIRect *bottom) const { - RECT r = *original; - cut *= ui_scale(); + CUIRect r = *this; + cut *= Scale(); if (top) { @@ -139,9 +133,9 @@ void ui_hsplit_b(const RECT *original, float cut, RECT *top, RECT *bottom) } -void ui_vsplit_mid(const RECT *original, RECT *left, RECT *right) +void CUIRect::VSplitMid(CUIRect *left, CUIRect *right) const { - RECT r = *original; + CUIRect r = *this; float cut = r.w/2; if (left) @@ -161,10 +155,10 @@ void ui_vsplit_mid(const RECT *original, RECT *left, RECT *right) } } -void ui_vsplit_l(const RECT *original, float cut, RECT *left, RECT *right) +void CUIRect::VSplitLeft(float cut, CUIRect *left, CUIRect *right) const { - RECT r = *original; - cut *= ui_scale(); + CUIRect r = *this; + cut *= Scale(); if (left) { @@ -183,10 +177,10 @@ void ui_vsplit_l(const RECT *original, float cut, RECT *left, RECT *right) } } -void ui_vsplit_r(const RECT *original, float cut, RECT *left, RECT *right) +void CUIRect::VSplitRight(float cut, CUIRect *left, CUIRect *right) const { - RECT r = *original; - cut *= ui_scale(); + CUIRect r = *this; + cut *= Scale(); if (left) { @@ -205,10 +199,10 @@ void ui_vsplit_r(const RECT *original, float cut, RECT *left, RECT *right) } } -void ui_margin(const RECT *original, float cut, RECT *other_rect) +void CUIRect::Margin(float cut, CUIRect *other_rect) const { - RECT r = *original; - cut *= ui_scale(); + CUIRect r = *this; + cut *= Scale(); other_rect->x = r.x + cut; other_rect->y = r.y + cut; @@ -216,10 +210,10 @@ void ui_margin(const RECT *original, float cut, RECT *other_rect) other_rect->h = r.h - 2*cut; } -void ui_vmargin(const RECT *original, float cut, RECT *other_rect) +void CUIRect::VMargin(float cut, CUIRect *other_rect) const { - RECT r = *original; - cut *= ui_scale(); + CUIRect r = *this; + cut *= Scale(); other_rect->x = r.x + cut; other_rect->y = r.y; @@ -227,10 +221,10 @@ void ui_vmargin(const RECT *original, float cut, RECT *other_rect) other_rect->h = r.h; } -void ui_hmargin(const RECT *original, float cut, RECT *other_rect) +void CUIRect::HMargin(float cut, CUIRect *other_rect) const { - RECT r = *original; - cut *= ui_scale(); + CUIRect r = *this; + cut *= Scale(); other_rect->x = r.x; other_rect->y = r.y + cut; @@ -238,50 +232,87 @@ void ui_hmargin(const RECT *original, float cut, RECT *other_rect) other_rect->h = r.h - 2*cut; } - -int ui_do_button(const void *id, const char *text, int checked, const RECT *r, ui_draw_button_func draw_func, const void *extra) +int CUI::DoButtonLogic(const void *pID, const char *pText, int Checked, const CUIRect *pRect) { /* logic */ + int ReturnValue = 0; + int Inside = MouseInside(pRect); + 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; + } + + if(MouseButton(1)) + { + SetActiveItem(pID); + ButtonUsed = 1; + } + } + + if(Inside) + SetHotItem(pID); + + return ReturnValue; +} +/* +int CUI::DoButton(const void *id, const char *text, int checked, const CUIRect *r, ui_draw_button_func draw_func, const void *extra) +{ + // logic int ret = 0; - int inside = ui_mouse_inside(r); + int inside = ui_MouseInside(r); static int button_used = 0; - if(ui_active_item() == id) + if(ui_ActiveItem() == id) { - if(!ui_mouse_button(button_used)) + if(!ui_MouseButton(button_used)) { if(inside && checked >= 0) ret = 1+button_used; - ui_set_active_item(0); + ui_SetActiveItem(0); } } - else if(ui_hot_item() == id) + else if(ui_HotItem() == id) { - if(ui_mouse_button(0)) + if(ui_MouseButton(0)) { - ui_set_active_item(id); + ui_SetActiveItem(id); button_used = 0; } - if(ui_mouse_button(1)) + if(ui_MouseButton(1)) { - ui_set_active_item(id); + ui_SetActiveItem(id); button_used = 1; } } if(inside) - ui_set_hot_item(id); + ui_SetHotItem(id); if(draw_func) draw_func(id, text, checked, r, extra); return ret; -} +}*/ -void ui_do_label(const RECT *r, const char *text, float size, int align, int max_width) +void CUI::DoLabel(const CUIRect *r, const char *text, float size, int align, int max_width) { - gfx_blend_normal(); - size *= ui_scale(); + // TODO: FIX ME!!!! + //Graphics()->BlendNormal(); + size *= Scale(); if(align == 0) { float tw = gfx_text_width(0, size, text, max_width); |