Mirage Source
Optimizing drag function - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: General (https://mirage-engine.uk/forums/forumdisplay.php?fid=17)
+---- Thread: Optimizing drag function (/showthread.php?tid=1590)



Optimizing drag function - Stomach Pulser - 02-03-2008

Well, I am adding a custom top bar to my game (the bar at the top of everything with a minimize, maximize, and exit button). I am coding it myself and made this code to drag it. It occurs when you click on the label that is over the dragable part of the bar.

x2 and y2 are integers to store the original location of the cursor (when the user clicks on the bar).

Code:
Private Sub lblDragBar_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    x2 = X
    y2 = Y
End Sub

Private Sub lblDragBar_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Select Case Button
        Case 1
            If x2 > X Then frmMirage.Left = frmMirage.Left + (X - x2)
            If x2 < X Then frmMirage.Left = frmMirage.Left - (x2 - X)
            If y2 > Y Then frmMirage.top = frmMirage.top + (Y - y2)
            If y2 < Y Then frmMirage.top = frmMirage.top - (y2 - Y)
    End Select
End Sub

Is there any way to optimize this?


Re: Optimizing drag function - Anthony - 03-03-2008

This is a good place for my question I have been wondering forever haha.

Do With statements actually optimize anything?


Re: Optimizing drag function - Dr. Spoon - 03-03-2008

simply yes
in stead of evaluating/reading the part multiple times
it reads With once and reuses what it read the first time


Re: Optimizing drag function - Stomach Pulser - 03-03-2008

So this:
[code]Public Sub ItemEditorInit()
'****************************************************************
'* WHEN WHO WHAT
'* ---- --- ----
'* 07/12/2005 Shannara Added gfx constant.
'****************************************************************

frmItemEditor.picItems.Picture = LoadPicture(App.Path & GFX_PATH & "items" & GFX_EXT)

frmItemEditor.txtName.Text = Trim(Item(EditorIndex).Name)
frmItemEditor.scrlPic.Value = Item(EditorIndex).Pic
frmItemEditor.cmbType.ListIndex = Item(EditorIndex).Type

If (frmItemEditor.cmbType.ListIndex >= ITEM_TYPE_WEAPON) And (frmItemEditor.cmbType.ListIndex = ITEM_TYPE_POTIONADDHP) And (frmItemEditor.cmbType.ListIndex


Re: Optimizing drag function - Dr. Spoon - 03-03-2008

basically yes..


Re: Optimizing drag function - Kousaten - 07-03-2008

Interesting. Any clue as to how much improvement we're looking at if one was to optimize all of the initializations with 'With'?