OpenClonk
C4GUI::CMouse Class Reference

#include <C4Gui.h>

Collaboration diagram for C4GUI::CMouse:
[legend]

Public Types

enum  TooltipShowState { TTST_None = 0 , TTST_Immediate = 1 , TTST_All = 2 }
 

Public Member Functions

 CMouse (int32_t iX, int32_t iY)
 
 ~CMouse ()
 
void Draw (C4TargetFacet &cgo, TooltipShowState draw_tool_tips)
 
void Input (int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam)
 
bool IsLDown ()
 
void GetLastXY (int32_t &rX, int32_t &rY, DWORD &rdwKeys)
 
void ResetElements ()
 
void ReleaseElements ()
 
void OnElementGetsInvisible (Element *pChild)
 
void RemoveElement (Element *pChild)
 
void SetOwnedMouse (bool fToVal)
 
void ResetToolTipTime ()
 
bool IsMouseStill ()
 
void ResetActiveInput ()
 
bool IsActiveInput ()
 
void ReleaseButtons ()
 

Public Attributes

int32_t x
 
int32_t y
 
bool LDown
 
bool MDown
 
bool RDown
 
int32_t LDownX
 
int32_t LDownY
 
DWORD dwKeys
 
bool fActive
 
C4TimeMilliseconds tLastMovementTime
 
bool fActiveInput
 
ElementpMouseOverElement
 
ElementpPrevMouseOverElement
 
ElementpDragElement
 

Detailed Description

Definition at line 2532 of file C4Gui.h.

Member Enumeration Documentation

◆ TooltipShowState

Enumerator
TTST_None 
TTST_Immediate 
TTST_All 

Definition at line 2547 of file C4Gui.h.

2548  {
2549  TTST_None = 0, // show no tooltips
2550  TTST_Immediate = 1, // show only tooltips of elements that require immediate show (i.e. otherwise unlabeled buttons)
2551  TTST_All = 2, // show all tooltips (mouse hovered on same element for some time)
2552  };
@ TTST_Immediate
Definition: C4Gui.h:2550

Constructor & Destructor Documentation

◆ CMouse()

C4GUI::CMouse::CMouse ( int32_t  iX,
int32_t  iY 
)

Definition at line 448 of file C4Gui.cpp.

448  : fActive(true), fActiveInput(false)
449  {
450  // set pos
451  x=iX; y=iY;
452  // reset fields
453  LDown=MDown=RDown=false;
454  dwKeys=0;
456  pDragElement = nullptr;
458  // LDownX/Y initialized upon need
459  }
bool LDown
Definition: C4Gui.h:2536
bool fActive
Definition: C4Gui.h:2539
bool MDown
Definition: C4Gui.h:2536
void ResetToolTipTime()
Definition: C4Gui.h:2578
Element * pMouseOverElement
Definition: C4Gui.h:2555
Element * pDragElement
Definition: C4Gui.h:2556
int32_t y
Definition: C4Gui.h:2535
Element * pPrevMouseOverElement
Definition: C4Gui.h:2555
int32_t x
Definition: C4Gui.h:2535
bool fActiveInput
Definition: C4Gui.h:2545
bool RDown
Definition: C4Gui.h:2536
DWORD dwKeys
Definition: C4Gui.h:2538

References dwKeys, LDown, MDown, pDragElement, pMouseOverElement, pPrevMouseOverElement, RDown, ResetToolTipTime(), x, and y.

Here is the call graph for this function:

◆ ~CMouse()

C4GUI::CMouse::~CMouse ( )
default

Member Function Documentation

◆ Draw()

void C4GUI::CMouse::Draw ( C4TargetFacet cgo,
TooltipShowState  draw_tool_tips 
)

Definition at line 485 of file C4Gui.cpp.

486  {
487  // only if owned
488  if (!fActive) return;
489 
490  // Make sure to draw the cursor without zoom.
491  ZoomData GuiZoom;
492  pDraw->GetZoom(&GuiZoom);
493  const float oldZoom = GuiZoom.Zoom;
494  GuiZoom.Zoom = 1.0;
495  pDraw->SetZoom(GuiZoom);
496 
497  int32_t iOffsetX = -GfxR->fctMouseCursor.Wdt/2;
498  int32_t iOffsetY = -GfxR->fctMouseCursor.Hgt/2;
499  GfxR->fctMouseCursor.Draw(cgo.Surface,x+iOffsetX,y+iOffsetY,0);
500  // ToolTip
501  if (pMouseOverElement && draw_tool_tips != TTST_None)
502  {
503  if (draw_tool_tips == TTST_All || pMouseOverElement->IsImmediateToolTip())
504  {
505  const char *szTip = pMouseOverElement->GetToolTip();
506  if (szTip && *szTip)
507  {
508  C4TargetFacet cgoTip; cgoTip.Set(cgo.Surface, cgo.X, cgo.Y, cgo.Wdt, cgo.Hgt);
509  Screen::DrawToolTip(szTip, cgoTip, x, y);
510  }
511  }
512  }
513 
514  // And restore old zoom settings.
515  GuiZoom.Zoom = oldZoom;
516  pDraw->SetZoom(GuiZoom);
517  }
C4Draw * pDraw
Definition: C4Draw.cpp:42
#define GfxR
void GetZoom(ZoomData *r)
Definition: C4Draw.h:197
void SetZoom(float X, float Y, float Zoom)
Definition: C4Draw.cpp:773
C4Surface * Surface
Definition: C4Facet.h:117
float Hgt
Definition: C4Facet.h:118
float Wdt
Definition: C4Facet.h:118
float Y
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
const char * GetToolTip()
Definition: C4Gui.cpp:423
bool IsImmediateToolTip() const
Definition: C4Gui.h:441
static void DrawToolTip(const char *szTip, C4TargetFacet &cgo, float guix, float guiy)
Definition: C4Gui.cpp:1009
void Set(const C4Facet &cpy)
Definition: C4Facet.h:182
float Zoom
Definition: C4Draw.h:70

References C4GUI::Screen::DrawToolTip(), fActive, C4GUI::Element::GetToolTip(), C4Draw::GetZoom(), GfxR, C4Facet::Hgt, C4GUI::Element::IsImmediateToolTip(), pDraw, pMouseOverElement, C4TargetFacet::Set(), C4Draw::SetZoom(), C4Facet::Surface, TTST_All, TTST_None, C4Facet::Wdt, C4Facet::X, x, C4Facet::Y, y, and ZoomData::Zoom.

Referenced by C4GUI::Screen::RenderMouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLastXY()

void C4GUI::CMouse::GetLastXY ( int32_t &  rX,
int32_t &  rY,
DWORD rdwKeys 
)
inline

Definition at line 2567 of file C4Gui.h.

2567 { rX=x; rY=y; rdwKeys=dwKeys; }

References dwKeys, x, and y.

Referenced by ReleaseElements().

Here is the caller graph for this function:

◆ Input()

void C4GUI::CMouse::Input ( int32_t  iButton,
int32_t  iX,
int32_t  iY,
DWORD  dwKeyParam 
)

Definition at line 463 of file C4Gui.cpp.

464  {
465  // pos changed or click issued?
466  if (iButton || iX!=x || iY!=y)
467  {
468  // then hide tooltips for a while
470  // and mark as active input device
471  fActiveInput = true;
472  }
473  // copy fields
474  x=iX; y=iY; dwKeys=dwKeyParam;
475  // update buttons
476  switch (iButton)
477  {
478  case C4MC_Button_LeftDown: LDown=true; LDownX=x; LDownY=y; break;
479  case C4MC_Button_LeftUp: LDown=false; break;
480  case C4MC_Button_RightDown: RDown=true; break;
481  case C4MC_Button_RightUp: RDown=false; break;
482  }
483  }
const int32_t C4MC_Button_RightDown
const int32_t C4MC_Button_RightUp
const int32_t C4MC_Button_LeftUp
const int32_t C4MC_Button_LeftDown
int32_t LDownX
Definition: C4Gui.h:2537
int32_t LDownY
Definition: C4Gui.h:2537

References C4MC_Button_LeftDown, C4MC_Button_LeftUp, C4MC_Button_RightDown, C4MC_Button_RightUp, dwKeys, fActiveInput, LDown, LDownX, LDownY, RDown, ResetToolTipTime(), x, and y.

Referenced by C4GUI::Screen::MouseInput().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsActiveInput()

bool C4GUI::CMouse::IsActiveInput ( )
inline

Definition at line 2581 of file C4Gui.h.

2581 { return fActiveInput; }

References fActiveInput.

Referenced by C4Menu::Draw(), and C4GUI::Screen::RenderMouse().

Here is the caller graph for this function:

◆ IsLDown()

bool C4GUI::CMouse::IsLDown ( )
inline

Definition at line 2565 of file C4Gui.h.

2565 { return LDown; }

References LDown.

Referenced by C4GUI::ScrollBar::MouseInput(), and C4GUI::Screen::MouseInput().

Here is the caller graph for this function:

◆ IsMouseStill()

bool C4GUI::CMouse::IsMouseStill ( )
inline

Definition at line 2579 of file C4Gui.h.

#define C4GUI_ToolTipShowTime
Definition: C4Gui.h:143
C4TimeMilliseconds tLastMovementTime
Definition: C4Gui.h:2540
static C4TimeMilliseconds Now()

References C4GUI_ToolTipShowTime, C4TimeMilliseconds::Now(), and tLastMovementTime.

Referenced by C4GUI::Screen::RenderMouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnElementGetsInvisible()

void C4GUI::CMouse::OnElementGetsInvisible ( Element pChild)

Definition at line 546 of file C4Gui.cpp.

547  {
548  // clear ptr
549  RemoveElement(pChild);
550  }
void RemoveElement(Element *pChild)
Definition: C4Gui.cpp:534

References RemoveElement().

Referenced by C4GUI::Element::SetVisibility().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReleaseButtons()

void C4GUI::CMouse::ReleaseButtons ( )
inline

Definition at line 2583 of file C4Gui.h.

2583 { LDown = RDown = MDown = false; }

References LDown, MDown, and RDown.

◆ ReleaseElements()

void C4GUI::CMouse::ReleaseElements ( )

Definition at line 519 of file C4Gui.cpp.

520  {
521  // release MouseOver
523  // release drag
524  if (pDragElement)
525  {
526  int32_t iX, iY; DWORD dwKeys;
527  GetLastXY(iX, iY, dwKeys);
529  pDragElement->StopDragging(*this, iX, iY, dwKeys);
530  }
532  }
uint32_t DWORD
void GetLastXY(int32_t &rX, int32_t &rY, DWORD &rdwKeys)
Definition: C4Gui.h:2567
virtual void StopDragging(CMouse &rMouse, int32_t iX, int32_t iY, DWORD dwKeyParam)
Definition: C4Gui.cpp:282
virtual void MouseLeave(CMouse &rMouse)
Definition: C4Gui.h:414
void ScreenPos2ClientPos(int32_t &riX, int32_t &riY)
Definition: C4Gui.cpp:218

References dwKeys, GetLastXY(), C4GUI::Element::MouseLeave(), pDragElement, pMouseOverElement, pPrevMouseOverElement, C4GUI::Element::ScreenPos2ClientPos(), and C4GUI::Element::StopDragging().

Referenced by C4GUI::Screen::ActivateDialog(), C4GUI::Screen::CloseDialog(), and C4GUI::Screen::RecheckActiveDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveElement()

void C4GUI::CMouse::RemoveElement ( Element pChild)

Definition at line 534 of file C4Gui.cpp.

535  {
536  // clear ptr
537  if (pMouseOverElement == pChild)
538  {
539  pMouseOverElement->MouseLeave(*this); // do leave callback so any tooltip is cleared!
540  pMouseOverElement = nullptr;
541  }
542  if (pPrevMouseOverElement == pChild) pPrevMouseOverElement = nullptr;
543  if (pDragElement == pChild) pDragElement = nullptr;
544  }

References C4GUI::Element::MouseLeave(), pDragElement, pMouseOverElement, and pPrevMouseOverElement.

Referenced by OnElementGetsInvisible(), C4GUI::ContextMenu::RemoveElement(), and C4GUI::Screen::RemoveElement().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetActiveInput()

void C4GUI::CMouse::ResetActiveInput ( )
inline

Definition at line 2580 of file C4Gui.h.

2580 { fActiveInput = false; }

References fActiveInput.

Referenced by C4GUI::Screen::CharIn(), and C4GUI::Screen::KeyAny().

Here is the caller graph for this function:

◆ ResetElements()

void C4GUI::CMouse::ResetElements ( )
inline

Definition at line 2569 of file C4Gui.h.

References pDragElement, pMouseOverElement, and pPrevMouseOverElement.

Referenced by C4GUI::Screen::RemoveElement().

Here is the caller graph for this function:

◆ ResetToolTipTime()

void C4GUI::CMouse::ResetToolTipTime ( )
inline

Definition at line 2578 of file C4Gui.h.

References C4TimeMilliseconds::Now(), and tLastMovementTime.

Referenced by CMouse(), and Input().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetOwnedMouse()

void C4GUI::CMouse::SetOwnedMouse ( bool  fToVal)
inline

Definition at line 2576 of file C4Gui.h.

2576 { fActive=fToVal; }

References fActive.

Referenced by C4GUI::Screen::SetExclusive(), and C4GUI::Screen::SetMouseInGUI().

Here is the caller graph for this function:

Member Data Documentation

◆ dwKeys

DWORD C4GUI::CMouse::dwKeys

◆ fActive

bool C4GUI::CMouse::fActive

Definition at line 2539 of file C4Gui.h.

Referenced by Draw(), and SetOwnedMouse().

◆ fActiveInput

bool C4GUI::CMouse::fActiveInput

Definition at line 2545 of file C4Gui.h.

Referenced by Input(), IsActiveInput(), and ResetActiveInput().

◆ LDown

bool C4GUI::CMouse::LDown

◆ LDownX

int32_t C4GUI::CMouse::LDownX

Definition at line 2537 of file C4Gui.h.

Referenced by Input().

◆ LDownY

int32_t C4GUI::CMouse::LDownY

Definition at line 2537 of file C4Gui.h.

Referenced by Input().

◆ MDown

bool C4GUI::CMouse::MDown

Definition at line 2536 of file C4Gui.h.

Referenced by CMouse(), and ReleaseButtons().

◆ pDragElement

◆ pMouseOverElement

Element* C4GUI::CMouse::pMouseOverElement

◆ pPrevMouseOverElement

Element * C4GUI::CMouse::pPrevMouseOverElement

◆ RDown

bool C4GUI::CMouse::RDown

Definition at line 2536 of file C4Gui.h.

Referenced by CMouse(), Input(), and ReleaseButtons().

◆ tLastMovementTime

C4TimeMilliseconds C4GUI::CMouse::tLastMovementTime

Definition at line 2540 of file C4Gui.h.

Referenced by IsMouseStill(), and ResetToolTipTime().

◆ x

◆ y

int32_t C4GUI::CMouse::y

The documentation for this class was generated from the following files: