Skip to content

Commit 1fcd096

Browse files
committed
DragDrop: small code reorg
1 parent 97b6c2b commit 1fcd096

4 files changed

Lines changed: 44 additions & 46 deletions

File tree

scripts/ui/DragDrop/DragDrop.asc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ struct DragDropSettings
88

99
eKeyCode HookKey; // default hook key
1010
MouseButton HookMBtn; // default hook mouse button
11+
bool AutoTrackHookKey; // track hook key press and release
1112
int DragMinDistance; // minimal number of pixels to start drag
1213
int DragMinTime; // minimal time to start drag
13-
14-
bool AutoTrackHookKey; // track hook key press and release
1514
DragDropUnhookAction DefaultUnhookAction; // what to do by default when the hook key is up
1615
};
1716

@@ -267,26 +266,26 @@ static void DragDrop::HookKeyDown(int user_key, MouseButton mbut)
267266

268267
//===========================================================================
269268
//
270-
// DragDrop::SetDragObject()
269+
// DragDrop::DragKeyUp()
271270
//
272271
//===========================================================================
273-
static void DragDrop::HookObject(int user_mode, int obj_x, int obj_y, int tag, String stag)
272+
static void DragDrop::HookKeyUp()
274273
{
275-
if (DDState.IsWantingObject())
276-
DDState.SetDragObject(user_mode, obj_x, obj_y, tag, stag);
274+
if (DDState.IsDragging())
275+
DDState.StartDropping();
276+
else
277+
DDState.Reset();
277278
}
278279

279280
//===========================================================================
280281
//
281-
// DragDrop::DragKeyUp()
282+
// DragDrop::SetDragObject()
282283
//
283284
//===========================================================================
284-
static void DragDrop::HookKeyUp()
285+
static void DragDrop::HookObject(int user_mode, int obj_x, int obj_y, int tag, String stag)
285286
{
286-
if (DDState.IsDragging())
287-
DDState.StartDropping();
288-
else
289-
DDState.Reset();
287+
if (DDState.IsWantingObject())
288+
DDState.SetDragObject(user_mode, obj_x, obj_y, tag, stag);
290289
}
291290

292291
//===========================================================================

scripts/ui/DragDrop/DragDrop.ash

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,12 @@ struct DragDrop
6060
import static attribute eKeyCode DefaultHookKey;
6161
/// Get/set default hook mouse button
6262
import static attribute MouseButton DefaultHookMouseButton;
63+
/// Get/set if the module should automatically track hook key press and release
64+
import static attribute bool AutoTrackHookKey;
6365
/// Get/set minimal number of pixels the mouse should move before it is considered to be dragging
6466
import static attribute int DragMinDistance;
65-
/// Get/set minimal time (in milliseconds) the mouse should move before it is considered to be dragging
67+
/// Get/set minimal time (in milliseconds) the hook key should be pressed down before it is considered to be dragging
6668
import static attribute int DragMinTime;
67-
68-
/// Get/set if the module should automatically track hook key press and release
69-
import static attribute bool AutoTrackHookKey;
7069
/// Get/set the default action that should be done to dragged object when the hook key is released;
7170
/// this action may be overriden by user by explicitly calling Drop() or Revert()
7271
import static attribute DragDropUnhookAction DefaultUnhookAction;
@@ -140,10 +139,10 @@ struct DragDrop
140139

141140
/// Notify hook key push down; this does not have to be real keycode
142141
import static void HookKeyDown(int user_key = 0, MouseButton mbtn = 0);
143-
/// Assign a draggable object for the module when it expects to find one under the mouse cursor
144-
import static void HookObject(int user_mode, int obj_x, int obj_y, int tag = 0, String stag = 0);
145142
/// Notify hook key release
146143
import static void HookKeyUp();
144+
/// Assign a draggable object for the module when it expects to find one under the mouse cursor
145+
import static void HookObject(int user_mode, int obj_x, int obj_y, int tag = 0, String stag = 0);
147146

148147
/// Drop the object now
149148
import static void Drop();

scripts/ui/DragDrop/DragDropCommon.asc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ struct DragDropSettings
88
bool PixelPerfect; // pixel-perfect hit mode for AGS objects
99
bool TestClickable; // test Clickable property for AGS objects
1010
DragDropCommonMove Move; // whether object is dragged itself, or overlay with object's image on it
11+
GUI* GhostGUI; // GUI to use for dragged object representation
1112
int GhostTransparency; // transparency value of the overlay
1213
bool GhostAlpha; // keep alpha channel when creating translucent overlays
13-
GUI* GhostGUI; // GUI to use for dragged object representation
1414
};
1515

1616
DragDropSettings DDSet;
@@ -53,9 +53,9 @@ void Reset(this DragDropSettings*)
5353
this.PixelPerfect = false;
5454
this.TestClickable = false;
5555
this.Move = eDDCmnMoveSelf;
56+
this.GhostGUI = null;
5657
this.GhostTransparency = 33;
5758
this.GhostAlpha = true;
58-
this.GhostGUI = null;
5959
}
6060

6161
//===========================================================================
@@ -390,47 +390,47 @@ void set_DragMove(this DragDropCommon*, DragDropCommonMove value)
390390

391391
//===========================================================================
392392
//
393-
// DragDropCommon::GhostTransparency property
393+
// DragDropCommon::GhostGUI property
394394
//
395395
//===========================================================================
396-
int get_GhostTransparency(this DragDropCommon*)
396+
GUI* get_GhostGUI(this DragDropCommon*)
397397
{
398-
return DDSet.GhostTransparency;
398+
return DDSet.GhostGUI;
399399
}
400400

401-
void set_GhostTransparency(this DragDropCommon*, int value)
401+
void set_GhostGUI(this DragDropCommon*, GUI* value)
402402
{
403-
DDSet.GhostTransparency = value;
403+
DDSet.GhostGUI = value;
404404
}
405405

406406
//===========================================================================
407407
//
408-
// DragDropCommon::GhostAlpha property
408+
// DragDropCommon::GhostTransparency property
409409
//
410410
//===========================================================================
411-
bool get_GhostAlpha(this DragDropCommon*)
411+
int get_GhostTransparency(this DragDropCommon*)
412412
{
413-
return DDSet.GhostAlpha;
413+
return DDSet.GhostTransparency;
414414
}
415415

416-
void set_GhostAlpha(this DragDropCommon*, bool value)
416+
void set_GhostTransparency(this DragDropCommon*, int value)
417417
{
418-
DDSet.GhostAlpha = value;
418+
DDSet.GhostTransparency = value;
419419
}
420420

421421
//===========================================================================
422422
//
423-
// DragDropCommon::GhostGUI property
423+
// DragDropCommon::GhostAlpha property
424424
//
425425
//===========================================================================
426-
GUI* get_GhostGUI(this DragDropCommon*)
426+
bool get_GhostAlpha(this DragDropCommon*)
427427
{
428-
return DDSet.GhostGUI;
428+
return DDSet.GhostAlpha;
429429
}
430430

431-
void set_GhostGUI(this DragDropCommon*, GUI* value)
431+
void set_GhostAlpha(this DragDropCommon*, bool value)
432432
{
433-
DDSet.GhostGUI = value;
433+
DDSet.GhostAlpha = value;
434434
}
435435

436436
//===========================================================================

scripts/ui/DragDrop/DragDropCommon.ash

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,28 @@ struct DragDropCommon
6666
// Functions and properties meant to configure the drag'n'drop behavior.
6767
//
6868
///////////////////////////////////////////////////////////////////////////
69-
69+
7070
/// Get/set whether particular drag'n'drop mode is enabled
7171
import static attribute bool ModeEnabled[];
7272
/// Disable drag'n'drop for all the modes
7373
import static void DisableAllModes();
74-
74+
7575
/// Get/set whether click on AGS object should be tested using pixel-perfect detection
7676
/// (alternatively only hit inside bounding rectangle is tested)
7777
import static attribute bool PixelPerfect;
7878
/// Get/set whether only Clickable AGS objects should be draggable
7979
import static attribute bool TestClickable;
80-
80+
8181
/// Get/set the way object's drag around is represented
8282
import static attribute DragDropCommonMove DragMove;
83-
/// Get/set transparency of a representation used when DragStyle is NOT eDragDropMoveSelf
84-
import static attribute int GhostTransparency;
85-
/// Get/set whether representation should keep sprite's alpha channel
86-
import static attribute bool GhostAlpha;
8783
/// Get/set the GUI used to represent dragged object
8884
import static attribute GUI* GhostGUI;
89-
90-
85+
/// Get/set whether representation should keep sprite's alpha channel
86+
import static attribute bool GhostAlpha;
87+
/// Get/set transparency of a representation used when DragStyle is NOT eDragDropMoveSelf
88+
import static attribute int GhostTransparency;
89+
90+
9191
///////////////////////////////////////////////////////////////////////////
9292
//
9393
// State control
@@ -96,7 +96,7 @@ struct DragDropCommon
9696
// and control its state.
9797
//
9898
///////////////////////////////////////////////////////////////////////////
99-
99+
100100
/// Gets current dragged character
101101
readonly import static attribute Character* _Character;
102102
/// Gets current dragged GUI
@@ -113,7 +113,7 @@ struct DragDropCommon
113113
readonly import static attribute int ObjectHeight;
114114
/// Gets current dragged overlay's graphic (only if drag style is NOT eDragDropMoveSelf)
115115
readonly import static attribute int UsedGhostGraphic;
116-
116+
117117
/// Start dragging a character under cursor
118118
import static bool TryHookCharacter();
119119
/// Start dragging a GUI under cursor

0 commit comments

Comments
 (0)