| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- #include "BaseGUICursor.h"
- #include "..\..\..\common_h\InputSrvCmds.h"
- const float max_time = 0.1f;
- BaseGUICursor:: BaseGUICursor()
- {
- cursor.Reset();
- // m_hided = true;
- m_hided = false;
- m_time = 0.0f;
- m_px = m_x = 0.5f;
- m_py = m_y = 0.5f;
- m_moved = false;
- m_clicked = false;
- m_active = null;
- m_show = false;
- }
- BaseGUICursor::~BaseGUICursor()
- {
- if( m_active )
- m_active->Release();
- }
- void BaseGUICursor::Restart()
- {
- // m_px = m_x = 0.5f;
- // m_py = m_y = 0.5f;
- m_moved = false;
- m_clicked = false;
- m_cnt = 0;
- // m_init = true; m_nomove = true;
- m_hide = true;
- Show(m_show);
- // SetUpdate(&BaseGUICursor::InitFn,ML_FIRST);
- SetUpdate(&BaseGUICursor::InitFn,ML_FIRST + 2);
- }
- void _cdecl BaseGUICursor::InitFn(float dltTime, long level)
- {
- BaseGUIElement *cur = (BaseGUIElement *)cursor.Ptr();
- if( cur )
- {
- if( m_hide )
- {
- cur->Show(false);
- m_hide = false;
- }
- }
- DelUpdate(&BaseGUICursor::InitFn);
- }
- bool BaseGUICursor::Create (MOPReader &reader)
- {
- InitParams(reader);
- return true;
- }
- bool BaseGUICursor::EditMode_Update(MOPReader &reader)
- {
- InitParams(reader);
- return true;
- }
- void BaseGUICursor::Show(bool isShow)
- {
- MissionObject::Show(isShow);
- #ifndef _XBOX
- if( isShow )
- {
- // SetUpdate(&BaseGUICursor::Update,ML_FIRST);
- SetUpdate(&BaseGUICursor::Update,ML_FIRST + 2);
- SetUpdate(&BaseGUICursor::Redraw,ML_LAST);
- }
- else
- {
- DelUpdate(&BaseGUICursor::Update);
- DelUpdate(&BaseGUICursor::Redraw);
- }
- #endif
- }
- void _cdecl BaseGUICursor::Update(float dltTime, long level)
- {
- if( EditMode_IsOn())
- return;
- long active = m_active ? m_active->Get(1) : 1;
- if( !active )
- {
- m_nomove = true;
- m_nodraw = 2;
- return;
- }
- BaseGUIElement *cur = (BaseGUIElement *)cursor.Ptr();
- if( cur )
- {
- Controls().FreeMouse();
- bool clicked = (
- Controls().GetControlStateType(m_lb) != CST_INACTIVE ||
- Controls().GetControlStateType(m_rb) != CST_INACTIVE);
- if( clicked )
- {
- m_clicked = true; m_cnt = 5;
- }
- else
- {
- if( m_clicked )
- {
- if( --m_cnt > 0 )
- m_clicked = true;
- else
- m_clicked = false;
- }
- }
- if( dltTime <= 0.0f )
- {
- if( m_drawOnPause )
- cur->Draw();
- return;
- }
- float x = Controls().GetControlStateFloat(m_mh)/Render().GetScreenInfo2D().dwWidth;
- float y = Controls().GetControlStateFloat(m_mv)/Render().GetScreenInfo2D().dwHeight;
- if( m_nomove )
- {
- m_nomove = false;
- x = 0.5f;
- y = 0.5f;
- }
- /* m_x += x - 0.5f;
- m_y += y - 0.5f;
- if( m_x < 0.0f )
- m_x = 0.0f;
- if( m_x > 1.0f )
- m_x = 1.0f;
- if( m_y < 0.0f )
- m_y = 0.0f;
- if( m_y > 1.0f )
- m_y = 1.0f;*/
- m_x = x;
- m_y = y;
- if( m_x < 0.0f ) m_x = -1.0f;
- if( m_x > 1.0f ) m_x = 2.0f;
- if( m_y < 0.0f ) m_y = -1.0f;
- if( m_y > 1.0f ) m_y = 2.0f;
- //// прячем курсор при активации клавиатуры ////
- const char *s = Controls().GetPressedControl(null);
- // if( s && strncmp(s,"Mouse",5))
- // m_hided = true;
- ////////////////////////////////////////////////
- if( m_hide )
- {
- cur->Show(false);
- m_hide = false;
- }
- if( m_init )
- {
- m_init = false;
- m_px = m_x = 0.5f;
- m_py = m_y = 0.5f;
- }
- if( m_px == m_x &&
- m_py == m_y )
- {
- m_moved = false;
- }
- else
- {
- /* if( m_init )
- {
- m_init = false;
- }
- else
- {
- m_hided = false;
- }*/
- m_hided = false;
- m_moved = true;
- }
- m_px = m_x;
- m_py = m_y;
- if( m_hided )
- {
- m_time -= dltTime;
- if( m_time < 0.0f )
- m_time = 0.0f;
- }
- else
- {
- m_time += dltTime;
- if( m_time > max_time )
- m_time = max_time;
- }
- }
- }
- void _cdecl BaseGUICursor::Redraw(float dltTime, long level)
- {
- if( EditMode_IsOn())
- return;
- if( m_nodraw > 0 )
- {
- m_nodraw--;
- return;
- }
- BaseGUIElement *cur = (BaseGUIElement *)cursor.Ptr();
- if( cur )
- {
- /* cur->Draw(
- m_x + m_dx,
- m_y + m_dy,m_time/max_time*cursor->GetAlpha());*/
- float w,h; cur->GetSize(w,h);
- float asp = cur->GetAspect();
- cur->SetAlign(IGUIElement::OnLeft);
- cur->SetPosition(
- (m_x + m_dx)/asp - w*0.5f - w*m_off_x,
- (m_y + m_dy) - h*0.5f - h*m_off_y);
- cur->SetAlpha(m_time/max_time);
- cur->Draw();
- cur->Update(dltTime);
- }
- }
- /*
- void BaseGUICursor::PostCreate()
- {
- if( !cursor )
- {
- cursor = (BaseGUIElement *)FindObject(cursorName);
- if( cursor )
- {
- BaseGUIElement::Rect r; cursor->GetRect(r);
- m_dx = (r.r - r.l)*0.5f*0.01f;
- m_dy = (r.b - r.t)*0.5f*0.01f;
- }
- else
- {
- m_dx = 0.0f;
- m_dy = 0.0f;
- }
- if( cursor && !EditMode_IsOn())
- cursor->Show(false);
- }
- }
- */
- void BaseGUICursor::InitParams(MOPReader &reader)
- {
- m_px = m_x = 0.5f;
- m_py = m_y = 0.5f;
- m_moved = false;
- m_clicked = false;
- m_cnt = 0;
- m_lb = Controls().FindControlByName( "LeftMouseButton");
- m_rb = Controls().FindControlByName("RightMouseButton");
- m_mh = Controls().FindControlByName("MouseH");
- m_mv = Controls().FindControlByName("MouseV");
- ConstString t = reader.String();
- if( !cursor.Validate() || t != cursor.Ptr()->GetObjectID() )
- {
- FindObject(t,cursor);
- BaseGUIElement *cur = (BaseGUIElement *)cursor.Ptr();
- if( cur )
- {
- BaseGUIElement::Rect r; cur->GetRect(r);
- m_dx = (r.r - r.l)*0.5f*0.01f;
- m_dy = (r.b - r.t)*0.5f*0.01f;
- }
- else
- {
- m_dx = 0.0f;
- m_dy = 0.0f;
- }
- if( cur && !EditMode_IsOn())
- cur->Show(false);
- }
- // cursorName = t;
- m_px = m_x = 0.5f;
- m_py = m_y = 0.5f;
- m_init = true; m_nomove = true;
- m_hide = true;
- m_nodraw = 0;
- m_off_x = reader.Float();
- m_off_y = reader.Float();
- m_drawOnPause = reader.Bool();
- Show(m_show = reader.Bool());
- }
- MOP_BEGINLISTCG(BaseGUICursor, "GUI Cursor", '1.00', 2000/*0*/, "GUI Cursor\n\n Use to manage screen cursor", "Interface")
- MOP_STRING("Face widget", "")
- MOP_FLOATEX("Face hor offset",0.0f,0.0f,1.0f)
- MOP_FLOATEX("Face ver offset",0.0f,0.0f,1.0f)
- MOP_BOOL("Draw on pause", true)
- MOP_BOOL("Show", false)
- MOP_ENDLIST(BaseGUICursor)
|