OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4MouseControl Class Reference

#include <C4MouseControl.h>

Collaboration diagram for C4MouseControl:
[legend]

Public Member Functions

 C4MouseControl ()
 
 ~C4MouseControl ()
 
void Default ()
 
void Clear ()
 
bool Init (int32_t iPlayer)
 
void Execute ()
 
void HideCursor ()
 
void ShowCursor ()
 
void Draw (C4TargetFacet &cgo, const ZoomData &GameZoom)
 
void Move (int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyFlags, bool fCenter=false)
 
void DoMoveInput ()
 
bool IsViewport (C4Viewport *pViewport)
 
void ClearPointers (C4Object *pObj)
 
void UpdateClip ()
 
void SetOwnedMouse (bool fToVal)
 
bool IsMouseOwned ()
 
bool IsActive ()
 
bool GetLastCursorPos (int32_t *x_out_gui, int32_t *y_out_gui, int32_t *x_out_game, int32_t *y_out_game) const
 
const char * GetCaption ()
 
void SetTooltipText (const StdStrBuf &text)
 
void SetTooltipRectangle (const C4Rect &rectangle)
 
bool IsDragging ()
 
bool IsLeftDown ()
 
int32_t GetPlayer ()
 

Protected Member Functions

void UpdateFogOfWar ()
 
void RightUpDragNone ()
 
void ButtonUpDragScript ()
 
void LeftUpDragNone ()
 
void DragScript ()
 
void Wheel (DWORD dwFlags)
 
void RightUp ()
 
void RightDown ()
 
void LeftDouble ()
 
void DragNone ()
 
void LeftUp ()
 
void LeftDown ()
 
void UpdateScrolling ()
 
void UpdateCursorTarget ()
 
int32_t UpdateSingleSelection ()
 
C4ObjectGetTargetObject ()
 
bool IsPassive ()
 
void ScrollView (float iX, float iY, float ViewWdt, float ViewHgt)
 

Protected Attributes

bool Active
 
bool fMouseOwned
 
int32_t Player
 
C4PlayerpPlayer
 
C4ViewportViewport
 
int32_t Cursor
 
int32_t VpX
 
int32_t VpY
 
float ViewX
 
float ViewY
 
float GameX
 
float GameY
 
float GuiX
 
float GuiY
 
C4Facet fctViewport
 
C4Facet fctViewportGame
 
C4Facet fctViewportGUI
 
float DownX
 
float DownY
 
int32_t ScrollSpeed
 
int32_t Drag
 
bool LeftButtonDown
 
bool RightButtonDown
 
bool LeftDoubleIgnoreUp
 
bool ButtonDownOnSelection
 
bool ControlDown
 
bool ShiftDown
 
bool AltDown
 
bool Scrolling
 
bool InitCentered
 
bool FogOfWar
 
bool Visible
 
C4ObjectList Selection
 
C4ObjectDragObject
 
C4ID DragID
 
C4DefDragImageDef
 
C4ObjectDragImageObject
 
StdCopyStrBuf Caption
 
StdCopyStrBuf TooltipText
 
int32_t CaptionBottomY
 
int32_t KeepCaption
 
int32_t TimeInTooltipRectangle
 
C4Rect ToolTipRectangle
 
C4ObjectTargetObject
 
C4ObjectDownTarget
 

Friends

class C4Viewport
 

Detailed Description

Definition at line 66 of file C4MouseControl.h.

Constructor & Destructor Documentation

C4MouseControl::C4MouseControl ( )

Definition at line 46 of file C4MouseControl.cpp.

References Default().

47 {
48  Default();
49 }

Here is the call graph for this function:

C4MouseControl::~C4MouseControl ( )

Definition at line 51 of file C4MouseControl.cpp.

References Clear().

52 {
53  Clear();
54 }

Here is the call graph for this function:

Member Function Documentation

void C4MouseControl::ButtonUpDragScript ( )
protected

Definition at line 759 of file C4MouseControl.cpp.

References C4Control::Add(), C4MC_Drag_None, C4MC_MD_DropTarget, CID_PlrMouseMove, Drag, C4ControlPlayerMouse::DragDrop(), DragID, DragImageDef, DragImageObject, DragObject, C4Player::Eliminated, Game, C4PlayerList::Get(), C4PropList::GetPropertyInt(), C4Game::Input, C4ID::None, P_MouseDrag, Player, Players, TargetObject, and UpdateCursorTarget().

Referenced by LeftUp(), and RightUp().

760 {
761  // Determine drag+drop targets
763  // Finish drag
766  DragImageObject = nullptr;
767  DragImageDef = nullptr;
768  C4Object *DragObject = this->DragObject;
769  this->DragObject = nullptr;
770  C4Object *DropObject = TargetObject;
771  // drag object must exist; drop object is optional
772  if (!DragObject) return;
773  if (DropObject && (~DropObject->GetPropertyInt(P_MouseDrag) & C4MC_MD_DropTarget))
774  DropObject = nullptr;
775  // no commands if player is eliminated or doesn't exist any more
776  C4Player *pPlr = ::Players.Get(Player);
777  if (!pPlr || pPlr->Eliminated) return;
778  // todo: Perform drag/drop validity check
779  // now drag/drop is handled by script
781 }
C4Game Game
Definition: C4Globals.cpp:52
C4Object * DragImageObject
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
C4Object * TargetObject
const int32_t C4MC_MD_DropTarget
C4Player * Get(int iPlayer) const
const int32_t C4MC_Drag_None
static const C4ID None
Definition: C4Id.h:42
C4Object * DragObject
C4PlayerList Players
C4Def * DragImageDef
int32_t Eliminated
Definition: C4Player.h:85
C4Control & Input
Definition: C4Game.h:84
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:863
static C4ControlPlayerMouse * DragDrop(const C4Player *player, const C4Object *target, const C4Object *drag)
Definition: C4Control.cpp:469

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::Clear ( )

Definition at line 92 of file C4MouseControl.cpp.

References Active, C4ObjectList::Clear(), Selection, and UpdateClip().

Referenced by C4Game::Clear(), Init(), and ~C4MouseControl().

93 {
94  Active = false;
95  Selection.Clear();
96  UpdateClip(); // reset mouse clipping!
97 }
C4ObjectList Selection
virtual void Clear()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::ClearPointers ( C4Object pObj)

Definition at line 125 of file C4MouseControl.cpp.

References C4MC_Drag_None, C4ObjectList::ClearPointers(), DownTarget, Drag, DragImageDef, DragImageObject, DragObject, Selection, and TargetObject.

Referenced by C4Game::ClearPointers().

126 {
127  if (TargetObject==pObj) TargetObject=nullptr;
128  if (DownTarget==pObj) DownTarget=nullptr;
129  if (DragObject==pObj)
130  {
131  DragObject=nullptr;
133  DragImageDef=nullptr;
134  DragImageObject=nullptr;
135  }
136  Selection.ClearPointers(pObj);
137 }
C4ObjectList Selection
C4Object * DragImageObject
C4Object * DownTarget
C4Object * TargetObject
const int32_t C4MC_Drag_None
C4Object * DragObject
C4Def * DragImageDef
int ClearPointers(C4Object *pObj)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::Default ( )

Definition at line 56 of file C4MouseControl.cpp.

References Active, AltDown, ButtonDownOnSelection, C4MC_Drag_None, Caption, CaptionBottomY, StdStrBuf::Clear(), ControlDown, Cursor, C4ObjectList::Default(), C4Facet::Default(), DownTarget, DownX, DownY, Drag, DragID, DragImageDef, DragImageObject, DragObject, fctViewport, fMouseOwned, FogOfWar, GameX, GameY, GuiX, GuiY, InitCentered, KeepCaption, LeftButtonDown, LeftDoubleIgnoreUp, NO_OWNER, C4ID::None, Player, pPlayer, RightButtonDown, Scrolling, ScrollSpeed, Selection, ShiftDown, TargetObject, Viewport, ViewX, ViewY, Visible, VpX, and VpY.

Referenced by C4MouseControl(), C4Game::Default(), and Init().

57 {
58  Active=false;
60  pPlayer=nullptr;
61  Viewport=nullptr;
62  Cursor=0;
63  Caption.Clear();
65  VpX=VpY=0;
66  DownX=DownY=0;
67  ViewX=ViewY=0;
68  GuiX=GuiY=GameX=GameY=0;
70  LeftDoubleIgnoreUp=false;
72  Visible=true;
73  InitCentered=false;
74  FogOfWar=false;
76  DragObject=nullptr;
77  KeepCaption=0;
80  TargetObject=DownTarget=nullptr;
81  ControlDown=false;
82  ShiftDown=false;
83  AltDown=false;
84  Scrolling=false;
85  ScrollSpeed=10;
86  DragImageDef=nullptr;
87  DragImageObject=nullptr;
88  fMouseOwned = true; // default mouse owned
90 }
C4ObjectList Selection
C4Player * pPlayer
void Clear()
Definition: StdBuf.h:474
C4Object * DragImageObject
C4Object * DownTarget
bool ButtonDownOnSelection
C4Object * TargetObject
const int32_t C4MC_Drag_None
void Default()
Definition: C4Facet.cpp:31
StdCopyStrBuf Caption
int32_t ScrollSpeed
static const C4ID None
Definition: C4Id.h:42
C4Object * DragObject
const int NO_OWNER
Definition: C4Constants.h:138
int32_t CaptionBottomY
C4Viewport * Viewport
C4Def * DragImageDef
C4Facet fctViewport
virtual void Default()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::DoMoveInput ( )

Definition at line 326 of file C4MouseControl.cpp.

References Active, AltDown, C4MC_Button_None, C4Player::Control, ControlDown, C4Player::ControlSet, C4PlayerControl::DoMouseInput(), fMouseOwned, GameX, GameY, C4PlayerList::Get(), GuiX, GuiY, C4PlayerControlAssignmentSet::IsMouseControlAssigned(), Player, Players, pPlayer, and ShiftDown.

Referenced by C4GameControl::PrepareInput().

327 {
328  // current mouse move to input queue
329  // do sanity checks
330  if (!Active || !fMouseOwned) return;
331  if (!(pPlayer=::Players.Get(Player))) return;
332  if (!pPlayer->ControlSet) return;
334  pPlayer->Control.DoMouseInput(0 /* only 1 mouse supported so far */, C4MC_Button_None, GameX, GameY, GuiX, GuiY, ControlDown, ShiftDown, AltDown, 0);
335 }
C4Player * pPlayer
C4PlayerControl Control
Definition: C4Player.h:131
bool DoMouseInput(uint8_t mouse_id, int32_t mouseevent, float game_x, float game_y, float gui_x, float gui_y, bool is_ctrl_down, bool is_shift_down, bool is_alt_down, int wheel_dir)
C4Player * Get(int iPlayer) const
class C4PlayerControlAssignmentSet * ControlSet
Definition: C4Player.h:92
C4PlayerList Players
bool IsMouseControlAssigned(int32_t mouseevent) const
const int32_t C4MC_Button_None

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::DragNone ( )
protected

Definition at line 644 of file C4MouseControl.cpp.

References Abs(), C4D_IgnoreFoW, C4MC_Drag_None, C4MC_Drag_Script, C4MC_Drag_Unhandled, C4MC_DragSensitivity, C4MC_MD_DragSource, C4Object::Category, DownTarget, DownX, DownY, Drag, DragImageDef, DragImageObject, DragObject, FogOfWar, GameX, GameY, C4Object::GetDragImage(), C4PropList::GetPropertyInt(), LeftButtonDown, P_MouseDrag, RightButtonDown, UpdateCursorTarget(), and UpdateSingleSelection().

Referenced by Move().

645 {
646  // Cursor movement
648  // Update selection
650 
651  // Button down: begin drag
654  {
655  bool fAllowDrag = true;
656  // check if target object allows scripted dragging
657  if (fAllowDrag && DownTarget && (!FogOfWar || (DownTarget->Category & C4D_IgnoreFoW)))
658  {
659  C4Object *drag_image_obj; C4Def * drag_image_def;
660 
661  // Drag only if MD_SOURCE is set and drag image is present
663  DownTarget->GetDragImage(&drag_image_obj, &drag_image_def))
664  {
666 
667  if(drag_image_obj) DragImageObject = drag_image_obj;
668  else DragImageDef = drag_image_def;
669 
671  }
672  }
673 
674  // dragging somewhere unhandled - mark drag process so moving over a draggable object won't start a drag
675  if (Drag == C4MC_Drag_None)
676  {
678  }
679  }
680 }
const int32_t C4MC_Drag_Script
bool GetDragImage(C4Object **drag_object, C4Def **drag_id) const
Definition: C4Object.cpp:4298
C4Object * DragImageObject
int32_t UpdateSingleSelection()
const int32_t C4MC_DragSensitivity
C4Object * DownTarget
const int32_t C4D_IgnoreFoW
Definition: C4Def.h:57
const int32_t C4MC_Drag_None
C4Object * DragObject
Definition: C4Def.h:100
C4Def * DragImageDef
int32_t Category
Definition: C4Object.h:113
const int32_t C4MC_Drag_Unhandled
const int32_t C4MC_MD_DragSource
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:863
T Abs(T val)
Definition: Standard.h:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::DragScript ( )
protected

Definition at line 729 of file C4MouseControl.cpp.

References C4MC_Cursor_DragDrop, Cursor, UpdateCursorTarget(), and UpdateSingleSelection().

Referenced by Move().

730 {
731  // script drag should update target and selection so selection highlight on drop target is visible
732  // Cursor movement
734  // Update selection
737 }
const int32_t C4MC_Cursor_DragDrop
int32_t UpdateSingleSelection()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::Draw ( C4TargetFacet cgo,
const ZoomData GameZoom 
)

Definition at line 337 of file C4MouseControl.cpp.

References C4Draw::ActivateBlitModulation(), C4Object::BlitMode, C4D_Foreground, C4GFXBLIT_MOD2, C4MC_Cursor_Down, C4MC_Cursor_DownLeft, C4MC_Cursor_DownRight, C4MC_Cursor_Left, C4MC_Cursor_Right, C4MC_Cursor_Up, C4MC_Cursor_UpLeft, C4MC_Cursor_UpRight, C4MC_Drag_None, C4MC_Drag_Script, C4MC_Drag_Unhandled, Caption, C4Object::Category, C4Player::ColorDw, C4Object::ColorMod, Config, Cursor, C4Draw::DeactivateBlitModulation(), C4Object::Def, Drag, DragImageDef, DragImageObject, DragObject, C4Def::Draw(), C4Object::DrawPicture(), C4ObjectList::DrawSelectMark(), C4GUI::Screen::DrawToolTip(), fMouseOwned, GameX, GameY, StdStrBuf::getData(), C4Object::GetGraphics(), C4Draw::GetZoom(), GfxR, C4Def::Graphics, C4Config::Graphics, GuiX, GuiY, C4Rect::Hgt, IsPassive(), C4ConfigGraphics::MouseCursorSize, pDraw, pGUI, C4Def::PictureRect, pPlayer, Selection, C4TargetFacet::Set(), C4Draw::SetBlitMode(), C4Draw::SetZoom(), C4Facet::Surface, C4DefGraphics::Type, C4DefGraphics::TYPE_Bitmap, C4DefGraphics::TYPE_Mesh, Visible, C4Rect::Wdt, C4Facet::X, and C4Facet::Y.

Referenced by C4Viewport::DrawOverlay().

338 {
339  int32_t iOffsetX,iOffsetY;
340  float wdt = GfxR->fctMouseCursor.Wdt, hgt = GfxR->fctMouseCursor.Hgt;
341  // Cursor size relative to height - does not matter with current square graphics.
342  float zoom = Config.Graphics.MouseCursorSize / hgt;
343  hgt *= zoom;
344  wdt *= zoom;
345 
346  ZoomData GuiZoom;
347  pDraw->GetZoom(&GuiZoom);
348 
349  // Hidden
350  if (!Visible || !fMouseOwned) return;
351 
352  // Draw selection
353  if (!IsPassive())
354  {
356  }
357 
358  // Draw control
359  switch (Drag)
360  {
361  //------------------------------------------------------------------------------------------
363  // Hotspot offset: Usually, hotspot is in center
364  iOffsetX = wdt/2;
365  iOffsetY = hgt/2;
366  // calculate the hotspot for the scrolling cursors
367  switch (Cursor)
368  {
369  case C4MC_Cursor_Up: iOffsetY += -hgt/2; break;
370  case C4MC_Cursor_Down:iOffsetY += +hgt/2; break;
371  case C4MC_Cursor_Left: iOffsetX += -wdt/2; break;
372  case C4MC_Cursor_Right: iOffsetX += +wdt/2; break;
373  case C4MC_Cursor_UpLeft: iOffsetX += -wdt/2; iOffsetY += -hgt/2; break;
374  case C4MC_Cursor_UpRight: iOffsetX += +wdt/2; iOffsetY += -hgt/2; break;
375  case C4MC_Cursor_DownLeft: iOffsetX += -wdt/2; iOffsetY += +hgt/2; break;
376  case C4MC_Cursor_DownRight: iOffsetX += +wdt/2; iOffsetY += +hgt/2; break;
377  }
378  // Drag image
380  {
381  C4DefGraphics* pGfx;
382  if(DragImageObject)
383  pGfx = DragImageObject->GetGraphics();
384  else
385  pGfx = &DragImageDef->Graphics;
386 
387  // Determine image boundaries
388  float ImageWdt;
389  float ImageHgt;
390  if (pGfx->Type == C4DefGraphics::TYPE_Bitmap)
391  {
393  ImageWdt = Def->PictureRect.Wdt;
394  ImageHgt = Def->PictureRect.Hgt;
395  }
396  else if (pGfx->Type == C4DefGraphics::TYPE_Mesh)
397  {
398  // Note bounding box is in OGRE coordinate system
399  ImageWdt = pGfx->Mesh->GetBoundingBox().y2 - pGfx->Mesh->GetBoundingBox().y1;
400  ImageHgt = pGfx->Mesh->GetBoundingBox().z2 - pGfx->Mesh->GetBoundingBox().z1;
401  }
402  else
403  {
404  ImageWdt = ImageHgt = 1.0f;
405  }
406 
407  // zoom mode: Drag in GUI or Game depending on source object
408  bool fIsGameZoom = true;
410  fIsGameZoom = false;
411  // drag image in game zoom
412  float XDraw, YDraw, ZoomDraw;
413  if (fIsGameZoom)
414  {
415  pDraw->SetZoom(GameZoom);
416  XDraw = GameX; YDraw = GameY;
417  ZoomDraw = 1.0f;
418  }
419  else
420  {
421  ZoomDraw = std::min(64.0f / ImageWdt, 64.0f / ImageHgt);
422  XDraw = GuiX; YDraw = GuiY;
423  }
424 
425  iOffsetX=int(ZoomDraw*ImageWdt/2);
426  iOffsetY=int(ZoomDraw*ImageHgt/2);
427 
428  C4TargetFacet ccgo;
429  ccgo.Set(cgo.Surface, XDraw + cgo.X - iOffsetX, YDraw + cgo.Y - iOffsetY, float(ImageWdt)*ZoomDraw, float(ImageHgt)*ZoomDraw);
430 
431  if (DragImageObject)
432  {
433  uint32_t ColorMod = DragImageObject->ColorMod;
434  uint32_t BlitMode = DragImageObject->BlitMode;
435  DragImageObject->ColorMod = (Drag == C4MC_Drag_Script) ? 0x7fffffff : (/*DragImagePhase*/0 ? 0x8f7f0000 : 0x1f007f00);
437 
438  DragImageObject->DrawPicture(ccgo, false, nullptr);
439 
440  DragImageObject->ColorMod = ColorMod;
441  DragImageObject->BlitMode = BlitMode;
442  }
443  else
444  {
445  // draw in special modulation mode
447  // draw DragImage in red or green, according to the phase to be used
448  pDraw->ActivateBlitModulation((Drag == C4MC_Drag_Script) ? 0x7fffffff : (/*DragImagePhase*/0 ? 0x8f7f0000 : 0x1f007f00));
449 
450  DragImageDef->Draw(ccgo, false, pPlayer ? pPlayer->ColorDw : 0xff0000ff, nullptr, 0, 0, nullptr);
451 
452  // reset color
454  pDraw->SetBlitMode(0);
455  }
456 
457  if (fIsGameZoom) pDraw->SetZoom(GuiZoom);
458  // reset cursor hotspot offset for script drawing
459  iOffsetX = wdt/2;
460  iOffsetY = hgt/2;
461  }
462  // Cursor
464  {
465  GfxR->fctMouseCursor.DrawX(cgo.Surface, cgo.X+GuiX-iOffsetX, cgo.Y+GuiY-iOffsetY, wdt, hgt, Cursor);
466  }
467  break;
468  //------------------------------------------------------------------------------------------
469  }
470 
471  // Draw caption
472  if (Caption && ::pGUI)
473  {
474  C4TargetFacet cgoTip;
475  cgoTip = static_cast<const C4Facet &>(cgo);
476  C4GUI::Screen::DrawToolTip(Caption.getData(), cgoTip, cgo.X+GuiX, cgo.Y+GuiY);
477  }
478 
479 }
const char * getData() const
Definition: StdBuf.h:450
C4ObjectList Selection
C4Config Config
Definition: C4Config.cpp:837
float Y
Definition: C4Facet.h:120
#define C4GFXBLIT_MOD2
Definition: C4Surface.h:29
#define GfxR
C4Player * pPlayer
const int32_t C4MC_Drag_Script
C4Rect PictureRect
Definition: C4Def.h:109
const int32_t C4MC_Cursor_Right
void DrawPicture(C4Facet &cgo, bool fSelected=false, C4DrawTransform *transform=nullptr)
Definition: C4Object.cpp:2351
C4Object * DragImageObject
int32_t MouseCursorSize
Definition: C4Config.h:119
const int32_t C4MC_Cursor_Down
static void DrawToolTip(const char *szTip, C4TargetFacet &cgo, float guix, float guiy)
Definition: C4Gui.cpp:1012
void SetBlitMode(DWORD dwBlitMode)
Definition: C4Draw.h:191
uint32_t ColorDw
Definition: C4Player.h:91
C4ConfigGraphics Graphics
Definition: C4Config.h:254
int32_t Wdt
Definition: C4Rect.h:32
const int32_t C4MC_Drag_None
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
C4Def * Def
Definition: C4Object.h:143
StdCopyStrBuf Caption
const int32_t C4MC_Cursor_Left
C4DefGraphics * GetGraphics() const
Definition: C4Object.h:340
const int32_t C4MC_Cursor_DownLeft
void Set(const C4Facet &cpy)
Definition: C4Facet.h:184
C4Object * DragObject
void Draw(C4Facet &cgo, bool fSelected=false, DWORD iColor=0, C4Object *pObj=nullptr, int32_t iPhaseX=0, int32_t iPhaseY=0, C4DrawTransform *trans=nullptr, const char *graphicsName=nullptr)
Definition: C4Def.cpp:601
Definition: C4Def.h:100
C4Draw * pDraw
Definition: C4Draw.cpp:45
C4Def * DragImageDef
int32_t Category
Definition: C4Object.h:113
const int32_t C4MC_Cursor_Up
const int32_t C4MC_Drag_Unhandled
uint32_t ColorMod
Definition: C4Object.h:161
void GetZoom(ZoomData *r)
Definition: C4Draw.h:197
const int32_t C4MC_Cursor_UpLeft
GraphicsType Type
Definition: C4DefGraphics.h:48
void DeactivateBlitModulation()
Definition: C4Draw.h:189
void DrawSelectMark(C4TargetFacet &cgo) const
uint32_t BlitMode
Definition: C4Object.h:162
const int32_t C4MC_Cursor_DownRight
void ActivateBlitModulation(DWORD dwWithClr)
Definition: C4Draw.h:188
int32_t Hgt
Definition: C4Rect.h:32
const int32_t C4MC_Cursor_UpRight
C4Surface * Surface
Definition: C4Facet.h:119
void SetZoom(float X, float Y, float Zoom)
Definition: C4Draw.cpp:782
C4DefGraphics Graphics
Definition: C4Def.h:194
float X
Definition: C4Facet.h:120
const int32_t C4D_Foreground
Definition: C4Def.h:55

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::Execute ( )

Definition at line 99 of file C4MouseControl.cpp.

References Active, C4MC_Button_None, ControlDown, fMouseOwned, Game, C4Game::iTick5, Move(), Scrolling, ShiftDown, VpX, and VpY.

Referenced by C4Game::Execute().

100 {
101 
102  if (!Active || !fMouseOwned) return;
103 
104  // Scrolling/continuous update
105  if (Scrolling || !::Game.iTick5)
106  {
107  WORD wKeyState=0;
108  if (ControlDown) wKeyState|=MK_CONTROL;
109  if (ShiftDown) wKeyState|=MK_SHIFT;
110  Move(C4MC_Button_None, VpX, VpY, wKeyState);
111  }
112 }
int32_t iTick5
Definition: C4Game.h:131
C4Game Game
Definition: C4Globals.cpp:52
void Move(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyFlags, bool fCenter=false)
const int32_t C4MC_Button_None
uint16_t WORD

Here is the call graph for this function:

Here is the caller graph for this function:

const char * C4MouseControl::GetCaption ( )

Definition at line 825 of file C4MouseControl.cpp.

References Caption, and StdStrBuf::getData().

Referenced by C4EditCursor::UpdateStatusBar().

826 {
827  return Caption.getData();
828 }
const char * getData() const
Definition: StdBuf.h:450
StdCopyStrBuf Caption

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MouseControl::GetLastCursorPos ( int32_t *  x_out_gui,
int32_t *  y_out_gui,
int32_t *  x_out_game,
int32_t *  y_out_game 
) const

Definition at line 876 of file C4MouseControl.cpp.

References Active, fMouseOwned, GameX, GameY, GuiX, and GuiY.

877 {
878  // safety
879  if (!Active || !fMouseOwned) return false;
880  // OK; assign last known pos
881  *x_out_gui = GuiX; *y_out_gui = GuiY;
882  *x_out_game = GameX; *y_out_game = GameY;
883  return true;
884 }
int32_t C4MouseControl::GetPlayer ( )
inline

Definition at line 167 of file C4MouseControl.h.

References Player.

Referenced by C4ObjectMenu::IsReadOnly(), C4MenuItem::MouseEnter(), C4ScriptGuiWindow::MouseEnter(), C4MenuItem::MouseInput(), C4ScriptGuiWindow::MouseInput(), C4ScriptGuiWindow::MouseLeave(), C4ObjectMenu::OnUserClose(), and C4ScriptGuiWindow::ProcessMouseInput().

167 { return Player; }

Here is the caller graph for this function:

C4Object * C4MouseControl::GetTargetObject ( )
protected

Definition at line 844 of file C4MouseControl.cpp.

References C4D_MouseSelect, fctViewportGame, fctViewportGUI, C4Game::FindVisObject(), Game, GameX, GameY, GuiX, GuiY, Player, ViewX, ViewY, C4Facet::X, and C4Facet::Y.

Referenced by UpdateCursorTarget().

845 {
846  // find object
847  // gui object position currently wrong...will fall apart once GUIZoom is activated
849  if (!pObj) return nullptr;
850  return pObj;
851 }
float Y
Definition: C4Facet.h:120
C4Game Game
Definition: C4Globals.cpp:52
C4Facet fctViewportGame
const int32_t C4D_MouseSelect
Definition: C4Def.h:54
C4Facet fctViewportGUI
C4Object * FindVisObject(float tx, float ty, int32_t iPlr, const C4Facet &fctViewportGame, const C4Facet &fctViewportGUI, float iX, float iY, DWORD category, float gui_x, float gui_y)
Definition: C4Game.cpp:1229
float X
Definition: C4Facet.h:120

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::HideCursor ( )

Definition at line 820 of file C4MouseControl.cpp.

References Visible.

Referenced by C4EditCursor::SetMode().

821 {
822  Visible=false;
823 }

Here is the caller graph for this function:

bool C4MouseControl::Init ( int32_t  iPlayer)

Definition at line 114 of file C4MouseControl.cpp.

References Active, Clear(), Default(), InitCentered, Player, and UpdateClip().

Referenced by C4FullScreen::ViewportCheck().

115 {
116  Clear();
117  Default();
118  Active = true;
119  Player = iPlayer;
120  InitCentered = false;
121  UpdateClip();
122  return true;
123 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MouseControl::IsActive ( )
inline

Definition at line 138 of file C4MouseControl.h.

References Active.

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

138 { return !!Active; }

Here is the caller graph for this function:

bool C4MouseControl::IsDragging ( )

Definition at line 871 of file C4MouseControl.cpp.

References Active, C4MC_Drag_Script, and Drag.

Referenced by C4Viewport::DrawMenu(), and C4GUI::Screen::MouseMove().

872 {
873  return Active && Drag == C4MC_Drag_Script;
874 }
const int32_t C4MC_Drag_Script

Here is the caller graph for this function:

bool C4MouseControl::IsLeftDown ( )
inline

Definition at line 166 of file C4MouseControl.h.

References LeftButtonDown.

Referenced by C4ScriptGuiWindow::ProcessMouseInput().

166 { return LeftButtonDown; }

Here is the caller graph for this function:

bool C4MouseControl::IsMouseOwned ( )
inline

Definition at line 137 of file C4MouseControl.h.

References fMouseOwned.

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

137 { return fMouseOwned; }

Here is the caller graph for this function:

bool C4MouseControl::IsPassive ( )
protected

Definition at line 853 of file C4MouseControl.cpp.

References Control, C4GameControl::isReplay(), NO_OWNER, and Player.

Referenced by Draw(), LeftUpDragNone(), Move(), RightUpDragNone(), and UpdateCursorTarget().

854 {
856 }
C4GameControl Control
const int NO_OWNER
Definition: C4Constants.h:138
bool isReplay() const
Definition: C4GameControl.h:98

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4MouseControl::IsViewport ( C4Viewport pViewport)

Definition at line 139 of file C4MouseControl.cpp.

References Viewport.

Referenced by C4Viewport::DrawMenu(), C4Viewport::DrawOverlay(), C4ViewportList::MouseMoveToViewport(), and ViewportWinProc().

140 {
141  return (Viewport==pViewport);
142 }
C4Viewport * Viewport

Here is the caller graph for this function:

void C4MouseControl::LeftDouble ( )
protected

Definition at line 682 of file C4MouseControl.cpp.

References C4MC_Drag_None, Drag, LeftButtonDown, and LeftDoubleIgnoreUp.

Referenced by Move().

683 {
684  // Update status flag
685  LeftButtonDown=false;
686  // Set ignore flag for next left up
687  LeftDoubleIgnoreUp=true;
688  // Evaluate left double by drag status (can only be C4MC_Drag_None really)
689  switch (Drag)
690  {
691  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
692  case C4MC_Drag_None:
693  // Double left click (might be on a target)
694  break;
695  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
696  }
697 }
const int32_t C4MC_Drag_None

Here is the caller graph for this function:

void C4MouseControl::LeftDown ( )
protected

Definition at line 610 of file C4MouseControl.cpp.

References DownTarget, DownX, DownY, GameX, GameY, LeftButtonDown, and TargetObject.

Referenced by Move().

611 {
612  // Set flag
613  LeftButtonDown=true;
614  // Store down values (same MoveRightDown -> use StoreDown)
617 }
C4Object * DownTarget
C4Object * TargetObject

Here is the caller graph for this function:

void C4MouseControl::LeftUp ( )
protected

Definition at line 619 of file C4MouseControl.cpp.

References ButtonUpDragScript(), C4MC_Drag_None, C4MC_Drag_Script, C4MC_Drag_Unhandled, DownTarget, Drag, LeftButtonDown, LeftDoubleIgnoreUp, LeftUpDragNone(), and RightButtonDown.

Referenced by Move().

620 {
621  // Ignore left up after double click
622  if (LeftDoubleIgnoreUp)
623  {
624  LeftDoubleIgnoreUp=false;
625  }
626  else
627  {
628  // Evaluate by drag status
629  switch (Drag)
630  {
631  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
632  case C4MC_Drag_Unhandled: // nobreak
633  case C4MC_Drag_None: LeftUpDragNone(); break;
634  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
635  case C4MC_Drag_Script: ButtonUpDragScript(); break;
636  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
637  }
638  }
639  // Update status flag
640  LeftButtonDown=false;
641  if(!RightButtonDown) DownTarget = nullptr;
642 }
const int32_t C4MC_Drag_Script
C4Object * DownTarget
const int32_t C4MC_Drag_None
const int32_t C4MC_Drag_Unhandled

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::LeftUpDragNone ( )
protected

Definition at line 739 of file C4MouseControl.cpp.

References C4Control::Add(), C4MC_Cursor_Select, C4MC_Drag_None, CID_PlrSelect, C4ObjectList::Clear(), Cursor, DownTarget, Drag, Game, C4ObjectList::GetObject(), C4Game::Input, IsPassive(), Player, and Selection.

Referenced by LeftUp().

740 {
741  // might be in Drag_Unknown
743  // Single left click (might be on a target)
744  switch (Cursor)
745  {
746  case C4MC_Cursor_Select:
747  // Object selection to control queue
748  if (!IsPassive() && Selection.GetObject() == DownTarget)
750  break;
751  default:
752  // done in script
753  break;
754  }
755  // Clear selection
756  Selection.Clear();
757 }
C4ObjectList Selection
C4Game Game
Definition: C4Globals.cpp:52
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
C4Object * DownTarget
const int32_t C4MC_Drag_None
const int32_t C4MC_Cursor_Select
C4Object * GetObject(int Index=0) const
C4Control & Input
Definition: C4Game.h:84
virtual void Clear()

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::Move ( int32_t  iButton,
int32_t  iX,
int32_t  iY,
DWORD  dwKeyFlags,
bool  fCenter = false 
)

Definition at line 175 of file C4MouseControl.cpp.

References Active, AltDown, Application, C4MC_Button_LeftDouble, C4MC_Button_LeftDown, C4MC_Button_LeftUp, C4MC_Button_None, C4MC_Button_RightDown, C4MC_Button_RightUp, C4MC_Button_Wheel, C4MC_Cursor_Select, C4MC_Drag_None, C4MC_Drag_Script, C4MC_Drag_Unhandled, Caption, CaptionBottomY, StdStrBuf::Clear(), C4Player::Control, ControlDown, C4Player::ControlSet, Cursor, C4PlayerControl::DoMouseInput(), Drag, DragNone(), DragScript(), fctViewport, fctViewportGame, fctViewportGUI, fMouseOwned, FogOfWar, Game, GameX, GameY, C4PlayerList::Get(), C4Viewport::GetGUIZoom(), C4Viewport::GetOutputRect(), C4ViewportList::GetViewport(), C4Viewport::GetViewX(), C4Viewport::GetViewY(), GuiX, GuiY, C4Rect::Hgt, InitCentered, C4Application::isEditor, C4PlayerControlAssignmentSet::IsMouseControlAssigned(), IsPassive(), KeepCaption, C4Viewport::last_game_draw_cgo, C4Viewport::last_gui_draw_cgo, LeftButtonDown, LeftDouble(), LeftDown(), LeftUp(), NO_OWNER, C4Viewport::OutX, C4Viewport::OutY, Player, Players, pPlayer, C4AbstractApp::pWindow, RightButtonDown, RightDown(), RightUp(), C4Game::ScriptGuiRoot, C4Facet::Set(), ShiftDown, TargetObject, UpdateCursorTarget(), UpdateFogOfWar(), UpdateScrolling(), C4Viewport::ViewHgt, Viewport, Viewports, C4Viewport::ViewWdt, ViewX, ViewY, VpX, VpY, C4Rect::Wdt, Wheel(), C4Rect::x, C4Rect::y, and C4Viewport::Zoom.

Referenced by Execute(), and C4ViewportList::MouseMoveToViewport().

176 {
177  // Control state
178  ControlDown=false; if (dwKeyFlags & MK_CONTROL) ControlDown=true;
179  ShiftDown=false; if (dwKeyFlags & MK_SHIFT) ShiftDown=true;
180  AltDown=false; if(dwKeyFlags & MK_ALT) AltDown=true;
181  // Active
182  if (!Active || !fMouseOwned) return;
183  // Execute caption
184  if (KeepCaption) KeepCaption--; else { Caption.Clear(); CaptionBottomY=0; }
185  // Check player
186  if (Player>NO_OWNER)
187  {
189  if (!pPlayer) { Active=false; return; }
190  }
191  else
192  pPlayer = nullptr;
193  // Check viewport
194  if (!(Viewport=::Viewports.GetViewport(Player))) return;
195  // get view position
196  C4Rect rcViewport = Viewport->GetOutputRect();
197  fctViewport.Set(nullptr, rcViewport.x, rcViewport.y, rcViewport.Wdt, rcViewport.Hgt);
201  // First time viewport attachment: center mouse
202 #ifdef USE_WIN32_WINDOWS
203  if (!InitCentered || fCenter)
204  {
205  iX = Viewport->ViewWdt/2;
206  iY = Viewport->ViewHgt/2;
207  if (!Application.isEditor)
208  {
209  int32_t iMidX = Viewport->OutX + iX;
210  int32_t iMidY = Viewport->OutY + iY;
211  RECT rtWindow;
212  if (GetWindowRect(Application.pWindow->hWindow, &rtWindow))
213  {
214  iMidX += rtWindow.left; iMidY += rtWindow.top;
215  }
216  SetCursorPos(iMidX, iMidY);
217  }
218  InitCentered = true;
219  }
220 #else
221  if (!InitCentered || fCenter)
222  {
223  iX = Viewport->ViewWdt/2;
224  iY = Viewport->ViewHgt/2;
225  InitCentered = true;
226  }
227 #endif
228  // passive mode: scrolling and player buttons only
229  if (IsPassive())
230  {
231  if (iButton != C4MC_Button_Wheel)
232  {
233  VpX=iX; VpY=iY;
235  GuiX=float(VpX)/Viewport->GetGUIZoom(); GuiY=float(VpY)/Viewport->GetGUIZoom();
236  }
237  UpdateScrolling();
238  if (iButton == C4MC_Button_LeftDown) LeftDown();
239  else if (iButton == C4MC_Button_LeftUp) LeftUp();
240  else UpdateCursorTarget();
241  return;
242  }
243 
244  if (iButton != C4MC_Button_Wheel)
245  {
246  // Position
247  VpX=iX; VpY=iY;
249  GuiX=float(VpX)/Viewport->GetGUIZoom(); GuiY=float(VpY)/Viewport->GetGUIZoom();
250  // Scrolling
251  UpdateScrolling();
252  // Fog of war
253  UpdateFogOfWar();
254 
255  // Blocked by fog of war: evaluate button up, dragging and region controls only
256  if (FogOfWar && Drag == C4MC_Drag_None)
257  {
258  // Left button up
259  if (iButton==C4MC_Button_LeftUp)
260  {
261  LeftButtonDown=false;
262  // End any drag
264  }
265  // Right button up
266  if (iButton==C4MC_Button_RightUp)
267  {
268  RightButtonDown=false;
269  }
270  }
271  }
272 
273  // Move execution by button/drag status
274  switch (iButton)
275  {
276  //------------------------------------------------------------------------------------------
277  case C4MC_Button_None:
278  switch (Drag)
279  {
280  case C4MC_Drag_Unhandled: break; // nothing to do
281  case C4MC_Drag_None: DragNone(); break;
282  case C4MC_Drag_Script: DragScript(); break;
283  }
284  break;
285  //------------------------------------------------------------------------------------------
286  case C4MC_Button_LeftDown: LeftDown(); break;
287  //------------------------------------------------------------------------------------------
288  case C4MC_Button_LeftUp: LeftUp(); break;
289  //------------------------------------------------------------------------------------------
290  case C4MC_Button_LeftDouble: LeftDouble(); break;
291  //------------------------------------------------------------------------------------------
292  case C4MC_Button_RightDown: RightDown(); break;
293  //------------------------------------------------------------------------------------------
294  case C4MC_Button_RightUp: RightUp(); break;
295  //------------------------------------------------------------------------------------------
296  case C4MC_Button_Wheel: Wheel(dwKeyFlags); break;
297  }
298 
299  // are custom menus active?
300  bool menuProcessed = false;
301  if (pPlayer)
302  // adjust by viewport X/Y because the GUI windows calculate their positions (and thus check input) based on that
303  menuProcessed = ::Game.ScriptGuiRoot->MouseInput(iButton, iX, iY, dwKeyFlags);
304 
305  if (menuProcessed)
307 
308  // if not caught by a menu
309  if (!menuProcessed)
310  // script handling of mouse control for everything but regular movement (which is sent at control frame intervals only)
311  if (iButton != C4MC_Button_None)
312  // not if blocked by selection object
313  if (!TargetObject)
314  // safety (can't really happen in !IsPassive, but w/e
315  if (pPlayer && pPlayer->ControlSet)
316  {
317  if (!menuProcessed && pPlayer->ControlSet->IsMouseControlAssigned(iButton))
318  {
319  int wheel_dir = 0;
320  if (iButton == C4MC_Button_Wheel) wheel_dir = (short)(dwKeyFlags >> 16);
321  pPlayer->Control.DoMouseInput(0 /* only 1 mouse supported so far */, iButton, GameX, GameY, GuiX, GuiY, (dwKeyFlags & MK_CONTROL) != 0, (dwKeyFlags & MK_SHIFT) != 0, (dwKeyFlags & MK_ALT) != 0, wheel_dir);
322  }
323  }
324 }
int32_t OutX
Definition: C4Viewport.h:107
const int32_t C4MC_Button_LeftDown
int32_t OutY
Definition: C4Viewport.h:107
C4Player * pPlayer
const int32_t C4MC_Drag_Script
C4Game Game
Definition: C4Globals.cpp:52
void Clear()
Definition: StdBuf.h:474
const int32_t C4MC_Button_RightUp
Definition: C4Rect.h:29
C4Viewport * GetViewport(int32_t iPlayer, C4Viewport *pPrev=nullptr)
C4PlayerControl Control
Definition: C4Player.h:131
C4Object * TargetObject
void Set(C4Surface &rSfc)
Definition: C4Facet.cpp:459
C4TargetFacet last_gui_draw_cgo
Definition: C4Viewport.h:41
C4Facet fctViewportGame
const int32_t C4MC_Button_LeftDouble
int32_t ViewHgt
Definition: C4Viewport.h:36
int32_t Wdt
Definition: C4Rect.h:32
bool DoMouseInput(uint8_t mouse_id, int32_t mouseevent, float game_x, float game_y, float gui_x, float gui_y, bool is_ctrl_down, bool is_shift_down, bool is_alt_down, int wheel_dir)
C4Player * Get(int iPlayer) const
const int32_t C4MC_Drag_None
class C4PlayerControlAssignmentSet * ControlSet
Definition: C4Player.h:92
const int32_t C4MC_Button_LeftUp
int32_t ViewWdt
Definition: C4Viewport.h:36
int32_t y
Definition: C4Rect.h:32
StdCopyStrBuf Caption
C4PlayerList Players
const int NO_OWNER
Definition: C4Constants.h:138
int32_t CaptionBottomY
C4Rect GetOutputRect()
Definition: C4Viewport.h:64
const int32_t C4MC_Cursor_Select
C4Viewport * Viewport
bool IsMouseControlAssigned(int32_t mouseevent) const
float Zoom
Definition: C4Viewport.h:101
C4Facet fctViewportGUI
const int32_t C4MC_Button_RightDown
C4TargetFacet last_game_draw_cgo
Definition: C4Viewport.h:41
int32_t x
Definition: C4Rect.h:32
void Wheel(DWORD dwFlags)
const int32_t C4MC_Button_Wheel
const int32_t C4MC_Drag_Unhandled
C4ViewportList Viewports
Definition: C4Viewport.cpp:841
float GetViewY()
Definition: C4Viewport.h:75
const int32_t C4MC_Button_None
float GetGUIZoom() const
Definition: C4Viewport.h:47
C4Facet fctViewport
int32_t Hgt
Definition: C4Rect.h:32
std::unique_ptr< C4ScriptGuiWindow > ScriptGuiRoot
Definition: C4Game.h:235
float GetViewX()
Definition: C4Viewport.h:73
C4Window * pWindow
Definition: C4App.h:80
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::RightDown ( )
protected

Definition at line 699 of file C4MouseControl.cpp.

References DownTarget, DownX, DownY, GameX, GameY, RightButtonDown, and TargetObject.

Referenced by Move().

700 {
701  // Update status flag
702  RightButtonDown=true;
703  // Store down values (same MoveLeftDown -> use StoreDown)
706 }
C4Object * DownTarget
C4Object * TargetObject

Here is the caller graph for this function:

void C4MouseControl::RightUp ( )
protected

Definition at line 708 of file C4MouseControl.cpp.

References ButtonUpDragScript(), C4MC_Drag_None, C4MC_Drag_Script, C4MC_Drag_Unhandled, DownTarget, Drag, LeftButtonDown, RightButtonDown, and RightUpDragNone().

Referenced by Move().

709 {
710  // Evaluate by drag status
711  switch (Drag)
712  {
713  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
714  case C4MC_Drag_Unhandled: // nobreak
715  case C4MC_Drag_None: RightUpDragNone(); break;
716  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
717  case C4MC_Drag_Script: ButtonUpDragScript(); break;
718  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
719  }
720  // Update status flag
721  RightButtonDown=false;
722  if(!LeftButtonDown) DownTarget = nullptr;
723 }
const int32_t C4MC_Drag_Script
C4Object * DownTarget
const int32_t C4MC_Drag_None
const int32_t C4MC_Drag_Unhandled

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::RightUpDragNone ( )
protected

Definition at line 783 of file C4MouseControl.cpp.

References C4Control::Add(), C4MC_Cursor_Select, C4MC_Drag_None, CID_PlrSelect, Cursor, DownTarget, Drag, Game, C4ObjectList::GetObject(), C4Game::Input, IsPassive(), Player, and Selection.

Referenced by RightUp().

784 {
785 
786  // might be in Drag_Unknown
788 
789  // Alternative object selection
792 
793  // TODO: Evaluate right click
794 
795 }
C4ObjectList Selection
C4Game Game
Definition: C4Globals.cpp:52
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
C4Object * DownTarget
const int32_t C4MC_Drag_None
const int32_t C4MC_Cursor_Select
C4Object * GetObject(int Index=0) const
C4Control & Input
Definition: C4Game.h:84

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::ScrollView ( float  iX,
float  iY,
float  ViewWdt,
float  ViewHgt 
)
protected

Definition at line 858 of file C4MouseControl.cpp.

References pPlayer, C4Viewport::ScrollView(), C4Player::ScrollView(), and Viewport.

Referenced by UpdateScrolling().

859 {
860  // player assigned: scroll player view
861  if (pPlayer)
862  pPlayer->ScrollView(iX, iY, ViewWdt, ViewHgt);
863  else if (Viewport)
864  {
865  // no player: Scroll fullscreen viewport
866  Viewport->ScrollView(iX, iY);
867  }
868 
869 }
C4Player * pPlayer
void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt)
Definition: C4Player.cpp:1368
void ScrollView(float byX, float byY)
Definition: C4Viewport.cpp:734
C4Viewport * Viewport

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::SetOwnedMouse ( bool  fToVal)
inline

Definition at line 136 of file C4MouseControl.h.

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

136 { fMouseOwned = fToVal; }

Here is the caller graph for this function:

void C4MouseControl::SetTooltipRectangle ( const C4Rect rectangle)

Definition at line 830 of file C4MouseControl.cpp.

References C4Rect::Hgt, TimeInTooltipRectangle, ToolTipRectangle, C4Rect::Wdt, C4Rect::x, and C4Rect::y.

Referenced by C4ScriptGuiWindow::OnMouseIn(), and UpdateCursorTarget().

831 {
832  // Set the tooltip rectangle slightly larger than originally requested.
833  // The tooltip will be removed when the cursor leaves the rectangle, so make sure that the tooltip is not already disabled when the cursor moves to the border-pixel of the GUI item
834  // in case the GUI item uses a different check for bounds (< vs <=) than the tooltip rectangle.
835  ToolTipRectangle = C4Rect(rectangle.x - 2, rectangle.y - 2, rectangle.Wdt + 4, rectangle.Hgt + 4);
837 }
C4Rect ToolTipRectangle
int32_t TimeInTooltipRectangle
Definition: C4Rect.h:29
int32_t Wdt
Definition: C4Rect.h:32
int32_t y
Definition: C4Rect.h:32
int32_t x
Definition: C4Rect.h:32
int32_t Hgt
Definition: C4Rect.h:32

Here is the caller graph for this function:

void C4MouseControl::SetTooltipText ( const StdStrBuf text)

Definition at line 839 of file C4MouseControl.cpp.

References text, and TooltipText.

Referenced by C4ScriptGuiWindow::OnMouseIn(), and UpdateCursorTarget().

840 {
841  TooltipText = text;
842 }
StdCopyStrBuf TooltipText

Here is the caller graph for this function:

void C4MouseControl::ShowCursor ( )

Definition at line 815 of file C4MouseControl.cpp.

References Visible.

Referenced by C4EditCursor::SetMode().

816 {
817  Visible=true;
818 }

Here is the caller graph for this function:

void C4MouseControl::UpdateClip ( )

Definition at line 144 of file C4MouseControl.cpp.

References C4AbstractApp::Active, Active, Application, FullScreen, C4ViewportList::GetViewport(), C4GUI::Screen::HasMouseFocus(), C4Application::isEditor, C4Viewport::OutX, C4Viewport::OutY, pGUI, Player, C4GUI::Screen::SetPreferredDlgRect(), C4Viewport::ViewHgt, Viewports, and C4Viewport::ViewWdt.

Referenced by Clear(), FullScreenWinProc(), Init(), C4Viewport::SetOutputSize(), and C4GUI::Screen::UpdateMouseFocus().

145 {
146 #ifdef _DEBUG
147  // never in debug
148  return;
149 #endif
150 #ifdef USE_WIN32_WINDOWS
151  // fullscreen only
152  if (Application.isEditor) return;
153  // application or mouse control not active? remove any clips
154  if (!Active || !Application.Active || ::pGUI->HasMouseFocus()) { ClipCursor(nullptr); return; }
155  // get controlled viewport
157  if (!pVP) { ClipCursor(nullptr); return; }
158  // adjust size by viewport size
159  RECT vpRct;
160  vpRct.left=pVP->OutX; vpRct.top=pVP->OutY; vpRct.right=pVP->OutX+pVP->ViewWdt; vpRct.bottom=pVP->OutY+pVP->ViewHgt;
161  // adjust by window pos
162  RECT rtWindow;
163  if (GetWindowRect(FullScreen.hWindow, &rtWindow))
164  {
165  vpRct.left += rtWindow.left; vpRct.top += rtWindow.top;
166  vpRct.right += rtWindow.left; vpRct.bottom+= rtWindow.top;
167  }
168  ClipCursor(&vpRct);
169  // and inform GUI
170  ::pGUI->SetPreferredDlgRect(C4Rect(pVP->OutX, pVP->OutY, pVP->ViewWdt, pVP->ViewHgt));
171 #endif
172  //StdWindow manages this.
173 }
int32_t OutX
Definition: C4Viewport.h:107
int32_t OutY
Definition: C4Viewport.h:107
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
Definition: C4Rect.h:29
C4Viewport * GetViewport(int32_t iPlayer, C4Viewport *pPrev=nullptr)
void SetPreferredDlgRect(const C4Rect &rtNewPref)
Definition: C4Gui.h:2648
int32_t ViewHgt
Definition: C4Viewport.h:36
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
bool Active
Definition: C4App.h:63
int32_t ViewWdt
Definition: C4Viewport.h:36
C4ViewportList Viewports
Definition: C4Viewport.cpp:841
bool HasMouseFocus()
Definition: C4Gui.h:2675
C4Application Application
Definition: C4Globals.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::UpdateCursorTarget ( )
protected

Definition at line 481 of file C4MouseControl.cpp.

References C4Control::Add(), C4Object::addtop(), C4D_IgnoreFoW, C4D_MouseSelect, C4MC_Cursor_Crosshair, C4MC_Cursor_Passive, C4MC_Cursor_Select, C4MC_Drag_Script, C4MC_MD_DropTarget, C4MC_MD_NoClick, C4MC_Tooltip_Delay, Caption, C4Object::Category, CID_PlrMouseMove, Cursor, Drag, DragObject, fctViewportGUI, FogOfWar, Game, C4PlayerList::Get(), C4String::GetCStr(), C4PropList::GetPropertyInt(), C4PropList::GetPropertyStr(), GetTargetObject(), C4Object::GetViewPos(), GuiX, GuiY, C4Rect::Hgt, C4ControlPlayerMouse::Hover(), C4Game::Input, Inside(), IsPassive(), KeepCaption, P_MouseDrag, P_Tooltip, Player, Players, Scrolling, SetTooltipRectangle(), SetTooltipText(), C4Object::Shape, TargetObject, TimeInTooltipRectangle, ToolTipRectangle, TooltipText, C4Rect::Wdt, C4Rect::x, C4Facet::X, C4Rect::y, and C4Facet::Y.

Referenced by ButtonUpDragScript(), DragNone(), DragScript(), and Move().

482 {
483  C4Object* OldTargetObject = TargetObject;
484 
485  if (Scrolling)
486  {
487  // Scrolling: no other target
488  TargetObject=nullptr;
489  }
490  else
491  {
492  // Target object
495 
496  // Movement
498 
499  // Target action
500  if (TargetObject && !IsPassive())
501  {
502  // default cursor for object; also set if not in FoW
504 
505  // select custom region. Can select an object if it does not have the MD_NoClick
506  // flag set. If we are currently dragging then selection depends on it being a drop target.
507  bool CanSelect;
508  if(Drag == C4MC_Drag_Script)
510  else
512 
513  if ( (TargetObject->Category & C4D_MouseSelect) && CanSelect)
515  else
516  TargetObject = nullptr;
517  }
518 
519  // passive cursor
520  if (IsPassive())
522 
523  // update tooltip information
524  if (OldTargetObject != TargetObject)
525  {
526  C4String *newTooltip = nullptr;
528  {
529  float objX, objY;
531  objX += TargetObject->Shape.x;
532  objY += TargetObject->Shape.y - TargetObject->addtop();
534  SetTooltipText(StdStrBuf(newTooltip->GetCStr()));
535  }
536  else
537  {
538  SetTooltipRectangle(C4Rect(0, 0, 0, 0));
539  }
540  }
541 
542  if (!KeepCaption
543  && ToolTipRectangle.Wdt != 0
546  {
548 
550  {
552  }
553  }
554  else
555  {
556  // disable tooltip pop-up; whatever set it in the first place will set it again on the next mouse-enter
558  ToolTipRectangle.Wdt = 0;
559  }
560  }
561 
562  // Make a script callback if the object being hovered changes
563  if(!IsPassive() && OldTargetObject != TargetObject)
564  {
565  // TODO: This might put a heavy load on the network, depending on the number of
566  // selectable objects around. If it turns out to be a problem we might want to
567  // deduce these hover callbacks client-side instead.
568  // Or, make sure to send this at most once per control frame.
570  }
571 }
void SetTooltipRectangle(const C4Rect &rectangle)
float Y
Definition: C4Facet.h:120
C4Rect ToolTipRectangle
const int32_t C4MC_Drag_Script
C4Game Game
Definition: C4Globals.cpp:52
int32_t TimeInTooltipRectangle
void GetViewPos(float &riX, float &riY, float tx, float ty, const C4Facet &fctViewport) const
Definition: C4Object.cpp:4340
const int32_t C4MC_Cursor_Passive
StdCopyStrBuf TooltipText
const char * GetCStr() const
Definition: C4StringTable.h:49
void Add(C4PacketType eType, C4ControlPacket *pCtrl)
Definition: C4Control.h:82
Definition: C4Rect.h:29
C4Object * TargetObject
const int32_t C4MC_MD_NoClick
const int32_t C4MC_MD_DropTarget
int32_t Wdt
Definition: C4Rect.h:32
const int32_t C4D_IgnoreFoW
Definition: C4Def.h:57
void SetTooltipText(const StdStrBuf &text)
const int32_t C4D_MouseSelect
Definition: C4Def.h:54
C4Player * Get(int iPlayer) const
int32_t y
Definition: C4Rect.h:32
StdCopyStrBuf Caption
C4Object * DragObject
C4PlayerList Players
const int32_t C4MC_Tooltip_Delay
const int32_t C4MC_Cursor_Select
static C4ControlPlayerMouse * Hover(const C4Player *player, const C4Object *target, const C4Object *old_target, const C4Object *drag=nullptr)
Definition: C4Control.cpp:456
C4Facet fctViewportGUI
int32_t Category
Definition: C4Object.h:113
C4Control & Input
Definition: C4Game.h:84
int32_t x
Definition: C4Rect.h:32
int32_t GetPropertyInt(C4PropertyName k, int32_t default_val=0) const
Definition: C4PropList.cpp:863
int32_t Hgt
Definition: C4Rect.h:32
C4Shape Shape
Definition: C4Object.h:148
C4Object * GetTargetObject()
C4String * GetPropertyStr(C4PropertyName k) const
Definition: C4PropList.cpp:752
bool Inside(T ival, U lbound, V rbound)
Definition: Standard.h:45
float X
Definition: C4Facet.h:120
const int32_t C4MC_Cursor_Crosshair
int32_t addtop() const
Definition: C4Object.h:281

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::UpdateFogOfWar ( )
protected

Definition at line 797 of file C4MouseControl.cpp.

References C4D_IgnoreFoW, C4MC_Cursor_Passive, C4Object::Category, Cursor, FogOfWar, GameX, GameY, C4Landscape::GetHeight(), C4Landscape::GetWidth(), Landscape, Scrolling, and TargetObject.

Referenced by Move().

798 {
799  // Assume no fog of war
800  FogOfWar=false;
801  // Check for fog of war
802  // TODO: Check C4FoWRegion... should maybe be passed as a parameter?
803  // pDraw->GetFoW() might not be current at this time.
804  if (/*(pPlayer->fFogOfWar && !pPlayer->FoWIsVisible(int32_t(GameX),int32_t(GameY))) || */GameX<0 || GameY<0 || int32_t(GameX)>=::Landscape.GetWidth() || int32_t(GameY)>=::Landscape.GetHeight())
805  {
806  FogOfWar=true;
807  // allow dragging, scrolling, region selection and manipulations of objects not affected by FoW
809  {
811  }
812  }
813 }
const int32_t C4MC_Cursor_Passive
C4Object * TargetObject
const int32_t C4D_IgnoreFoW
Definition: C4Def.h:57
C4Landscape Landscape
int32_t Category
Definition: C4Object.h:113
int32_t GetHeight() const
int32_t GetWidth() const

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::UpdateScrolling ( )
protected

Definition at line 588 of file C4MouseControl.cpp.

References C4MC_Cursor_Down, C4MC_Cursor_DownLeft, C4MC_Cursor_DownRight, C4MC_Cursor_Left, C4MC_Cursor_Right, C4MC_Cursor_Up, C4MC_Cursor_UpLeft, C4MC_Cursor_UpRight, Cursor, C4Player::IsViewLocked(), pPlayer, Scrolling, ScrollSpeed, ScrollView(), C4Viewport::ViewHgt, Viewport, C4Viewport::ViewWdt, VpX, VpY, and C4Viewport::Zoom.

Referenced by Move().

589 {
590  // Assume no scrolling
591  Scrolling=false;
592  // No scrolling if disabled by player
593  if (pPlayer) if (pPlayer->IsViewLocked()) return;
594  // Scrolling on border
595  if (VpX==0)
597  if (VpY==0)
599  if (VpX==Viewport->ViewWdt-1)
601  if (VpY==Viewport->ViewHgt-1)
603  // Set correct cursor
604  if ((VpX==0) && (VpY==0)) Cursor=C4MC_Cursor_UpLeft;
605  if ((VpX==Viewport->ViewWdt-1) && (VpY==0)) Cursor=C4MC_Cursor_UpRight;
606  if ((VpX==0) && (VpY==Viewport->ViewHgt-1)) Cursor=C4MC_Cursor_DownLeft;
608 }
C4Player * pPlayer
const int32_t C4MC_Cursor_Right
const int32_t C4MC_Cursor_Down
bool IsViewLocked() const
Definition: C4Player.h:206
void ScrollView(float iX, float iY, float ViewWdt, float ViewHgt)
int32_t ViewHgt
Definition: C4Viewport.h:36
int32_t ViewWdt
Definition: C4Viewport.h:36
const int32_t C4MC_Cursor_Left
int32_t ScrollSpeed
const int32_t C4MC_Cursor_DownLeft
C4Viewport * Viewport
float Zoom
Definition: C4Viewport.h:101
const int32_t C4MC_Cursor_Up
const int32_t C4MC_Cursor_UpLeft
const int32_t C4MC_Cursor_DownRight
const int32_t C4MC_Cursor_UpRight

Here is the call graph for this function:

Here is the caller graph for this function:

int32_t C4MouseControl::UpdateSingleSelection ( )
protected

Definition at line 573 of file C4MouseControl.cpp.

References C4ObjectList::Add(), C4D_MouseSelect, C4MC_Cursor_Select, C4Object::Category, C4ObjectList::Clear(), Cursor, C4PlayerList::Get(), C4ObjectList::GetObject(), C4ObjectList::ObjectCount(), C4Player::ObjectInCrew(), Player, Players, Selection, C4ObjectList::stNone, and TargetObject.

Referenced by DragNone(), and DragScript().

574 {
575  // Set single selection if cursor on selection object (clear prior object selection)
578 
579  // Cursor has moved off single object (or target object) selection: clear selection
580  else if (Selection.GetObject())
583  Selection.Clear();
584 
585  return Selection.ObjectCount();
586 }
C4ObjectList Selection
virtual bool Add(C4Object *nObj, SortType eSort, C4ObjectList *pLstSorted=nullptr)
C4Object * TargetObject
const int32_t C4D_MouseSelect
Definition: C4Def.h:54
C4Player * Get(int iPlayer) const
C4PlayerList Players
const int32_t C4MC_Cursor_Select
C4Object * GetObject(int Index=0) const
int32_t Category
Definition: C4Object.h:113
int ObjectCount(C4ID id=C4ID::None) const
virtual void Clear()
bool ObjectInCrew(C4Object *tobj)
Definition: C4Player.cpp:92

Here is the call graph for this function:

Here is the caller graph for this function:

void C4MouseControl::Wheel ( DWORD  dwFlags)
protected

Definition at line 725 of file C4MouseControl.cpp.

Referenced by Move().

726 {
727 }

Here is the caller graph for this function:

Friends And Related Function Documentation

friend class C4Viewport
friend

Definition at line 68 of file C4MouseControl.h.

Member Data Documentation

bool C4MouseControl::Active
protected
bool C4MouseControl::AltDown
protected

Definition at line 96 of file C4MouseControl.h.

Referenced by Default(), DoMoveInput(), and Move().

bool C4MouseControl::ButtonDownOnSelection
protected

Definition at line 93 of file C4MouseControl.h.

Referenced by Default().

StdCopyStrBuf C4MouseControl::Caption
protected

Definition at line 112 of file C4MouseControl.h.

Referenced by Default(), Draw(), GetCaption(), Move(), and UpdateCursorTarget().

int32_t C4MouseControl::CaptionBottomY
protected

Definition at line 115 of file C4MouseControl.h.

Referenced by Default(), and Move().

bool C4MouseControl::ControlDown
protected

Definition at line 94 of file C4MouseControl.h.

Referenced by Default(), DoMoveInput(), Execute(), and Move().

int32_t C4MouseControl::Cursor
protected
C4Object* C4MouseControl::DownTarget
protected
float C4MouseControl::DownX
protected

Definition at line 87 of file C4MouseControl.h.

Referenced by Default(), DragNone(), LeftDown(), and RightDown().

float C4MouseControl::DownY
protected

Definition at line 87 of file C4MouseControl.h.

Referenced by Default(), DragNone(), LeftDown(), and RightDown().

C4ID C4MouseControl::DragID
protected

Definition at line 105 of file C4MouseControl.h.

Referenced by ButtonUpDragScript(), and Default().

C4Def* C4MouseControl::DragImageDef
protected

Definition at line 106 of file C4MouseControl.h.

Referenced by ButtonUpDragScript(), ClearPointers(), Default(), DragNone(), and Draw().

C4Object* C4MouseControl::DragImageObject
protected

Definition at line 107 of file C4MouseControl.h.

Referenced by ButtonUpDragScript(), ClearPointers(), Default(), DragNone(), and Draw().

C4Object* C4MouseControl::DragObject
protected
C4Facet C4MouseControl::fctViewport
protected

Definition at line 85 of file C4MouseControl.h.

Referenced by Default(), and Move().

C4Facet C4MouseControl::fctViewportGame
protected

Definition at line 85 of file C4MouseControl.h.

Referenced by GetTargetObject(), and Move().

C4Facet C4MouseControl::fctViewportGUI
protected

Definition at line 85 of file C4MouseControl.h.

Referenced by GetTargetObject(), Move(), and UpdateCursorTarget().

bool C4MouseControl::fMouseOwned
protected

Definition at line 74 of file C4MouseControl.h.

Referenced by Default(), DoMoveInput(), Draw(), Execute(), GetLastCursorPos(), IsMouseOwned(), and Move().

bool C4MouseControl::FogOfWar
protected

Definition at line 99 of file C4MouseControl.h.

Referenced by Default(), DragNone(), Move(), UpdateCursorTarget(), and UpdateFogOfWar().

float C4MouseControl::GameX
protected
float C4MouseControl::GameY
protected
float C4MouseControl::GuiX
protected
float C4MouseControl::GuiY
protected
bool C4MouseControl::InitCentered
protected

Definition at line 98 of file C4MouseControl.h.

Referenced by C4Viewport::AdjustPosition(), Default(), Init(), and Move().

int32_t C4MouseControl::KeepCaption
protected

Definition at line 116 of file C4MouseControl.h.

Referenced by Default(), Move(), and UpdateCursorTarget().

bool C4MouseControl::LeftButtonDown
protected

Definition at line 92 of file C4MouseControl.h.

Referenced by Default(), DragNone(), IsLeftDown(), LeftDouble(), LeftDown(), LeftUp(), Move(), and RightUp().

bool C4MouseControl::LeftDoubleIgnoreUp
protected

Definition at line 92 of file C4MouseControl.h.

Referenced by Default(), LeftDouble(), and LeftUp().

C4Player* C4MouseControl::pPlayer
protected

Definition at line 76 of file C4MouseControl.h.

Referenced by Default(), DoMoveInput(), Draw(), Move(), ScrollView(), and UpdateScrolling().

bool C4MouseControl::RightButtonDown
protected

Definition at line 92 of file C4MouseControl.h.

Referenced by Default(), DragNone(), LeftUp(), Move(), RightDown(), and RightUp().

bool C4MouseControl::Scrolling
protected
int32_t C4MouseControl::ScrollSpeed
protected

Definition at line 89 of file C4MouseControl.h.

Referenced by Default(), and UpdateScrolling().

C4ObjectList C4MouseControl::Selection
protected
bool C4MouseControl::ShiftDown
protected

Definition at line 95 of file C4MouseControl.h.

Referenced by Default(), DoMoveInput(), Execute(), and Move().

C4Object* C4MouseControl::TargetObject
protected
int32_t C4MouseControl::TimeInTooltipRectangle
protected

Definition at line 117 of file C4MouseControl.h.

Referenced by SetTooltipRectangle(), and UpdateCursorTarget().

C4Rect C4MouseControl::ToolTipRectangle
protected

Definition at line 118 of file C4MouseControl.h.

Referenced by SetTooltipRectangle(), and UpdateCursorTarget().

StdCopyStrBuf C4MouseControl::TooltipText
protected

Definition at line 114 of file C4MouseControl.h.

Referenced by SetTooltipText(), and UpdateCursorTarget().

C4Viewport* C4MouseControl::Viewport
protected

Definition at line 77 of file C4MouseControl.h.

Referenced by Default(), IsViewport(), Move(), ScrollView(), and UpdateScrolling().

float C4MouseControl::ViewX
protected

Definition at line 82 of file C4MouseControl.h.

Referenced by Default(), GetTargetObject(), and Move().

float C4MouseControl::ViewY
protected

Definition at line 82 of file C4MouseControl.h.

Referenced by Default(), GetTargetObject(), and Move().

bool C4MouseControl::Visible
protected

Definition at line 100 of file C4MouseControl.h.

Referenced by Default(), Draw(), HideCursor(), and ShowCursor().

int32_t C4MouseControl::VpX
protected

Definition at line 81 of file C4MouseControl.h.

Referenced by C4Viewport::AdjustPosition(), Default(), Execute(), Move(), and UpdateScrolling().

int32_t C4MouseControl::VpY
protected

Definition at line 81 of file C4MouseControl.h.

Referenced by C4Viewport::AdjustPosition(), Default(), Execute(), Move(), and UpdateScrolling().


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