Nice job. Anyway I see that somehow you prevent the mouse coordinates to be recorded when outside the app.
I mean when the mouse is found to be outside the application window you will freeze the things in a way that I didn't try to track down in the code (maybe you use the clipping option , I don't know), but I can see what occuring when using DRAG is that the mouse jumps outside rather than reaching the border just before this event.
In my opinion you should not let this happen because you can never follow the mouse pointer in a smooth way. So if one is very fast the mouse will jump in the outerspace of the app before it crosses the border, which makes it feel a little iggly. I know anyway that it can be avoided. I will try to look in deep at what you do exactly later when I have time. Maybe however you can see what I mean already, and may have this fixed.
Just for the record, I see that I ran into a similar issue when I tried the same exercise a while before. I was sending the object at (-1, -1) then, which is even worst. I don't know why I didn't get it fixed at the time by the way :)
Code: Select all
'UDT designer - graphical interface
'Draggable button with drop zones
'drop zone can be rectangle/ellipse
'landing zones can be muliple if overlaping
#include "fbgfx.bi"
#define _DEBUG
#macro _P(id)
? #id, id :
#endMacro
const as double _pi => 4*atn(1)
const as double _2pi => 8*atn(1)
#define _MIN(a, b) iif((a)<(b), (a), (b))
#define _MAX(a, b) iif((a)>(b), (a), (b))
#macro _COMPLEMENTCOLOR(value, depth)
value + iif(value<(2^(depth - 1)), +(2^(depth - 1)), -2^(depth - 1))
#endMacro
#macro _DYNARRAYINCREASE(array)
redim preserve array(uBound(array) + 1)
#endMacro
#macro _DYNARRAYDECREASE(array)
if uBound(array)>0 then
redim preserve array(uBound(array) - 1)
else
erase array
end if
#endMacro
#macro _DYNARRAYINCREASEBYRANGE(array, range)
redim preserve array(uBound(array) + range)
#endMacro
#macro _ARRAYLASTITEM(array)
array(uBound(array))
#endMacro
#macro _ARRAYRANGE(array)
(uBound(array) - lBound(array) + 1)
#endMacro
#macro _IMGCREATE(imgvariablename, imgW, imgH, bckgColor, imgColorDepth)
imgvariablename = imageCreate(imgW, imgH, bckgColor, imgColorDepth)
#endMacro
#macro _IMGRESET(imgvariablename, bckgColor, imgColorDepth)
scope
dim as integer imgW, imgH
imageInfo imgvariablename, imgW, imgH
imageDestroy(imgvariablename)
imgvariablename = imageCreate(imgW, imgH, bckgColor, imgColorDepth)
end scope
#endMacro
#macro _IMGDESTROY(imgvariablename)
imageDestroy(imgvariablename)
imgvariablename = 0
#endMacro
type BIINTVALUE
as integer _bivi
as integer _bivj
end type
type POSITIONXY
as integer _x
as integer _y
end type
declare operator -(byval as POSITIONXY, byval as POSITIONXY) as POSITIONXY
declare operator <>(byval as POSITIONXY, byval as POSITIONXY) as boolean
operator -(byval LeftOperand as POSITIONXY, byval RightOperand as POSITIONXY) as POSITIONXY
dim as POSITIONXY operationResult
operationResult._x = LeftOperand._x - RightOperand._x
operationResult._y = LeftOperand._y - RightOperand._y
'---->
return operationResult
end operator
operator <>(byval LeftOperand as POSITIONXY, byval RightOperand as POSITIONXY) as boolean
if LeftOperand._x<>RightOperand._x orElse _
LeftOperand._y<>RightOperand._y then
'---->
return TRUE
else
'---->
return FALSE
end if
end operator
type WIDHEI
#define _refreshErrorType typeOf(Err())
declare operator Cast() as integer
declare property Wid() as integer
declare property Wid(byval as integer)
declare property Hei() as integer
declare property Hei(byval as integer)
declare property Max() as integer
declare property RatioForEllipse() as single
declare function Xf(byval as integer) as integer
declare function Yf(byval as integer) as integer
declare function Refresh(byval as integer=-1, _
byval as integer=-1) _
as _refreshErrorType
as integer _wid
as integer _hei
as integer _maxOfWH
as single _ratioForEllipse
#undef _refreshErrorType
end type
operator WIDHEI.Cast() as integer
'---->
return THIS._wid
end operator
property WIDHEI.Wid() as integer
'---->
return THIS._wid
end property
property WIDHEI.Wid(byval SetValue as integer)
THIS.Refresh(SetValue)
end property
property WIDHEI.Hei() as integer
'---->
return THIS._hei
end property
property WIDHEI.Hei(byval SetValue as integer)
THIS.Refresh( , SetValue)
end property
property WIDHEI.Max() as integer
'---->
return THIS._maxOfWH
end property
property WIDHEI.RatioForEllipse() as single
'---->
return THIS._ratioForEllipse
end property
function WIDHEI.Xf(byval Xi as integer) as integer
'---->
return Xi + THIS._wid - 1
end function
function WIDHEI.Yf(byval Yi as integer) as integer
'---->
return Yi + THIS._hei - 1
end function
#define _refreshErrorType typeOf(Err())
function WIDHEI.Refresh(byval W as integer=-1, _
byval H as integer=-1) _
as _refreshErrorType
dim as _refreshErrorType returnValue
'
if W<1 then
returnValue += 1
else
THIS._wid = W
end if
if H<1 then
returnValue += 1
else
THIS._hei = H
end if
'
THIS._maxOfWH = _MAX(THIS._wid, THIS._hei)
THIS._ratioForEllipse = THIS._hei/THIS._wid
'
'---->
return returnValue
end function
#undef _refreshErrorType
type DROPZONE
enum _DROPZONESHAPE
_fullRectangle
_maximumEllipse
end enum
declare constructor()
declare property Xi() as integer
declare property Yi() as integer
declare property Xf() as integer
declare property Yf() as integer
declare function IsInDropzoneShape overload(byval as integer, _
byval as integer) _
as boolean
declare function IsInDropzoneShape(byval as POSITIONXY) as boolean
declare sub DrawDropZone(byval as integer=-1)
as _DROPZONESHAPE _dzShape
as POSITIONXY _topLeftCorner
as WIDHEI _widHei
as string _keyId
end type
type DZ as DROPZONE
constructor DROPZONE()
dim as integer scrW, scrH
screenInfo scrW, scrH
'
with THIS
._dzShape => DZ._DROPZONESHAPE._fullRectangle
._topLeftCorner._x => scrW\4
._topLeftCorner._y => scrH\3
._widHei.Wid => scrW\2
._widHei.Hei => scrH\2
._keyId => "ID"& str(int(rnd*9e+12))
end with
end constructor
property DZ.Xi() as integer
'---->
return THIS._topLeftCorner._x
end property
property DZ.Yi() as integer
'---->
return THIS._topLeftCorner._y
end property
property DZ.Xf() as integer
'---->
return THIS._widHei.Xf(THIS._topLeftCorner._x)
end property
property DZ.Yf() as integer
'---->
return THIS._widHei.Yf(THIS._topLeftCorner._y)
end property
function DZ.IsInDropzoneShape(byval PosX as integer, _
byval PosY as integer) _
as boolean
select case THIS._dzShape
case DZ._DROPZONESHAPE._fullRectangle
if PosX>=THIS.Xi andAlso _
PosX<=THIS.Xf andAlso _
PosY>=THIS.Yi andAlso _
PosY<=THIS.Yf then
'---->
return TRUE
else
'---->
return FALSE
end if
case else
'DZ._DROPZONESHAPE._maximumEllipse
if PosX>=THIS.Xi andAlso _
PosX<=THIS.Xf andAlso _
PosY>=THIS.Yi andAlso _
PosY<=THIS.Yf then
dim as single xCenter => (THIS.Xi + THIS.Xf)\2
dim as single yCenter => (THIS.Yi + THIS.Yf)\2
dim as single rX => THIS._widhei._wid\2
dim as single rY => THIS._widhei._hei\2
if (((PosX - xCenter)/rX)^2 + ((PosY - yCenter)/rY)^2)<1 then
'---->
return TRUE
else
'---->
return FALSE
end if
else
'---->
return FALSE
end if
end select
end function
function DZ.IsInDropzoneShape(byval PosXY as POSITIONXY) as boolean
select case THIS._dzShape
case DZ._DROPZONESHAPE._fullRectangle
if PosXY._x>=THIS.Xi andAlso _
PosXY._x<=THIS.Xf andAlso _
PosXY._y>=THIS.Yi andAlso _
PosXY._y<=THIS.Yf then
'---->
return TRUE
else
'---->
return FALSE
end if
case else
'DZ._DROPZONESHAPE._maximumEllipse
if PosXY._x>=THIS.Xi andAlso _
PosXY._x<=THIS.Xf andAlso _
PosXY._y>=THIS.Yi andAlso _
PosXY._y<=THIS.Yf then
dim as single xCenter => (THIS.Xi + THIS.Xf)\2
dim as single yCenter => (THIS.Yi + THIS.Yf)\2
dim as single rX => THIS._widhei._wid\2
dim as single rY => THIS._widhei._hei\2
if (((PosXY._x - xCenter)/rX)^2 + ((PosXY._y - yCenter)/rY)^2)<1 then
'---->
return TRUE
else
'---->
return FALSE
end if
else
'---->
return FALSE
end if
end select
end function
sub DZ.DrawDropZone(byval DrawingFlag as integer=-1)
static as integer counter
static as boolean isFlipped
'
'get background color
dim as integer bkgColor
screenControl fb.GET_COLOR, , bkgColor
'get screen color depth
dim as integer scrDepth
screenInfo , , scrDepth
'
line (THIS.Xi, THIS.Yi)-(THIS.Xf, THIS.Yf), _
_COMPLEMENTCOLOR(bkgColor, scrDepth), _
b, _
iif(isFlipped, &b1111000011111111, &b0000111111110000)
select case THIS._dzShape
case DZ._DROPZONESHAPE._fullRectangle
line (THIS.Xi + 1, THIS.Yi + 1)-(THIS.Xf - 1, THIS.Yf - 1), _
_COMPLEMENTCOLOR(bkgColor, scrDepth), _
b, _
iif(isFlipped, &b1111000011111111, &b0000111111110000)
if DrawingFlag<>-1 then
line (THIS.Xi + 4, THIS.Yi + 4)-(THIS.Xf - 4, THIS.Yf - 4), _
_COMPLEMENTCOLOR(bkgColor, scrDepth), _
bf, _
iif(isFlipped, &b1111000011111111, &b0000111111110000)
end if
case else
'DZ._DROPZONESHAPE._maximumEllipse
circle ((THIS.Xi + THIS.Xf)\2, (THIS.Yi + THIS.Yf)\2), _
THIS._widhei.Max\2, _
5 , _
(_pi/180)*(counter + 10), _
(_pi/180)*(counter + 20), _
THIS._widhei.RatioForEllipse
circle ((THIS.Xi + THIS.Xf)\2, (THIS.Yi + THIS.Yf)\2), _
THIS._widhei.Max\2, _
13 , _
(_pi/180)*(counter + 30), _
(_pi/180)*(counter + 40), _
THIS._widhei.RatioForEllipse
if DrawingFlag<>-1 then
circle ((THIS.Xi + THIS.Xf)\2, (THIS.Yi + THIS.Yf)\2), _
THIS._widhei.Max\2 - 4, _
5 , _
, _
, _
THIS._widhei.RatioForEllipse, _
f
end if
end select
'
counter += 1
if counter>310 then counter = 0
if (counter mod 12)=0 then isFlipped = not isFlipped
end sub
type DRAGDROPBUTTON
enum _DGDPBTNSHAPE
_naked
_squared
_rounded
end enum
declare constructor()
declare property FontWidth() as integer
declare property FontHeight() as integer
declare property Xi() as integer
declare property Yi() as integer
declare property Xf() as integer
declare property Yf() as integer
declare property RoundedShapeRadius() as BIINTVALUE
declare property DropZoneCount() as integer
declare sub AddDropZoneToArrayOfPtr(byval as DROPZONE ptr)
declare sub AddDropZoneArrayOfPtrToArrayOfPtr(() as DROPZONE ptr)
declare sub RemoveAllDropZoneFromArrayOfPtr() ''todo
declare sub RemoveDropZoneFromArrayOfPtrAtIndexAtIndex(byval as integer) ''todo
declare sub RemoveDropZoneFromArrayOfPtrAtIndexByKeyId(byval as string) ''todo
declare sub TestScreen()
declare sub ResetLandableZone()
declare sub AddDropZoneAsLandableZoneAtIndex(byval as integer)
declare function IsInButtonShape(byval as integer, _
byval as integer) _
as boolean
declare sub TestMouse()
declare sub ShowAllDropZone()
declare sub ShowAllLandableZone()
declare sub ShowDropZoneAtIndex(byval as integer) ''todo
declare sub ShowDropZoneAtKeyId(byval as string) ''todo
declare sub DrawDgdpbtn()
as _DGDPBTNSHAPE _btnShape
as integer _roundedShapeRadius
as string _btnTxt
as POSITIONXY _topLeftCorner
as WIDHEI _widHei
'
as integer _dpZoneCount
as DROPZONE ptr _dpZoneArrayPtr(any)
as DROPZONE ptr _landableDropZone(any)
as fb.IMAGE ptr _dgdpbtnImage
as ulong _idleColour
as ulong _mouseOverColour
as ulong _mouseClickColour
as ulong _mouseDragColour
as ulong _mouseDroppableColour
as ulong _mouseDroppedColour
as boolean _hasMouseOver
as boolean _hasMouseClick
as POSITIONXY _offsetAtClick
as boolean _hasDragStarted
as boolean _isMouseOverDropZone
as boolean _isMouseDropped
'
as integer _scrW
as integer _scrH
as integer _scrDepth
as integer _colWidth
as integer _rowWidth
static as integer constructionCount
static as integer arrayOfDragDropButtonPtrCount
static as DRAGDROPBUTTON ptr arrayOfDragDropButtonPtr(any)
end type
type DGDPBTN as DRAGDROPBUTTON
dim as integer DGDPBTN.constructionCount
dim as integer DGDPBTN.arrayOfDragDropButtonPtrCount
dim as DGDPBTN ptr DGDPBTN.arrayOfDragDropButtonPtr(any)
constructor DRAGDROPBUTTON()
DGDPBTN.constructionCount += 1
_DYNARRAYINCREASE(DGDPBTN.arrayOfDragDropButtonPtr)
_ARRAYLASTITEM(DGDPBTN.arrayOfDragDropButtonPtr) => @THIS
'
THIS.TestScreen()
'
with THIS
._btnShape => DGDPBTN._DGDPBTNSHAPE._naked
._btnTxt => "OK"
._topLeftCorner => type<POSITIONXY>(THIS._scrW/2, THIS._scrH/2)
._widHei.Wid => _MAX(18, .FontWidth*len(._btnTxt))
._widHei.Hei => .FontHeight + 4
'
.AddDropZoneToArrayOfPtr(0)
_IMGCREATE(._dgdpbtnImage, ._widHei._wid, ._widHei._hei, 13, 8)
'
._idleColour => &h007
._mouseOverColour => &h00F
._mouseClickColour => &h00A
._mouseDragColour => &h00B
._mouseDroppableColour => &h00E
._mouseDroppedColour => &h000
._hasMouseOver => FALSE
._hasMouseClick => FALSE
._offsetAtClick => type<POSITIONXY>(-1, -1)
._hasDragStarted => FALSE
._isMouseOverDropZone => FALSE
._isMouseDropped => FALSE
end with
end constructor
property DGDPBTN.FontWidth() as integer
'---->
return 8
end property
property DGDPBTN.FontHeight() as integer
'---->
return 8
end property
property DGDPBTN.Xi() as integer
'---->
return THIS._topLeftCorner._x
end property
property DGDPBTN.Yi() as integer
'---->
return THIS._topLeftCorner._y
end property
property DGDPBTN.Xf() as integer
'---->
return THIS._widHei.Xf(THIS._topLeftCorner._x)
end property
property DGDPBTN.Yf() as integer
'---->
return THIS._widHei.Yf(THIS._topLeftCorner._y)
end property
property DGDPBTN.RoundedShapeRadius() as BIINTVALUE
dim as BIINTVALUE returnValue
returnValue._bivi = THIS._widHei._wid\6
returnValue._bivj = THIS._widHei._hei\2
'---->
return returnValue
end property
property DGDPBTN.DropZoneCount() as integer
'---->
return THIS._dpZoneCount
end property
sub DGDPBTN.AddDropZoneToArrayOfPtr(byval DZitem as DROPZONE ptr)
if DZitem=0 then exit sub
'
#define _ALIAS THIS._dpZoneArrayPtr
'
_DYNARRAYINCREASE(_ALIAS)
_ARRAYLASTITEM(_ALIAS) => DZitem
'
#ifdef _ALIAS
#undef _ALIAS
#endif
end sub
sub DGDPBTN.AddDropZoneArrayOfPtrToArrayOfPtr(DZArrayOfPtr() as DROPZONE ptr)
if uBound(DZArrayOfPtr)<0 then exit sub
'
#define _ALIAS THIS._dpZoneArrayPtr
'
dim as integer initialLastIndex = uBound(_ALIAS)
for index as integer = 0 to uBound(DZArrayOfPtr)
if DZArrayOfPtr(index)<>0 then
_DYNARRAYINCREASE(_ALIAS)
_ARRAYLASTITEM(_ALIAS) => DZArrayOfPtr(index)
end if
next index
'
#ifdef _ALIAS
#undef _ALIAS
#endif
end sub
sub DGDPBTN.TestScreen()
screenInfo THIS._scrW, _
THIS._scrH, _
THIS._scrDepth
dim as ulong scrWidth => width()
THIS._colWidth => loWord(scrWidth)
THIS._rowWidth => hiWord(scrWidth)
end sub
sub DGDPBTN.ResetLandableZone()
erase(THIS._landableDropZone)
end sub
sub DGDPBTN.AddDropZoneAsLandableZoneAtIndex(byval Index as integer)
_DYNARRAYINCREASE(THIS._landableDropZone)
_ARRAYLASTITEM(THIS._landableDropZone) = THIS._dpZoneArrayPtr(index)
end sub
function DGDPBTN.IsInButtonShape(byval GmX as integer, _
byval GmY as integer) _
as boolean
select case THIS._btnShape
case DGDPBTN._DGDPBTNSHAPE._naked
if GmX>=THIS.Xi andAlso _
GmX<=THIS.Xf andAlso _
GmY>=THIS.Yi andAlso _
GmY<=THIS.Yf then
'---->
return TRUE
else
'---->
return FALSE
end if
case DGDPBTN._DGDPBTNSHAPE._squared
if GmX>=THIS.Xi - 8 andAlso _
GmX<=THIS.Xf + 8 andAlso _
GmY>=THIS.Yi - 8 andAlso _
GmY<=THIS.Yf + 8 then
'---->
return TRUE
else
'---->
return FALSE
end if
case else
'DGDPBTN._DGDPBTNSHAPE._rounded
if GmX>=THIS.Xi - THIS._widHei._wid/2 andAlso _
GmX<=THIS.Xf + THIS._widHei._wid/2 andAlso _
GmY>=THIS.Yi - THIS._widHei._hei/2 andAlso _
GmY<=THIS.Yf + THIS._widHei._hei/2 then
if ( GmX>=THIS.Xi andAlso _
GmX<=THIS.Xf andAlso _
GmY>=THIS.Yi - THIS._widHei._hei/2 andAlso _
GmY<=THIS.Yf + THIS._widHei._wid/2 ) then
'---->
return TRUE
else
dim as integer rx => THIS.RoundedShapeRadius._bivi
dim as integer ry => THIS.RoundedShapeRadius._bivj
dim as single yrMinLeft => THIS.Yi - sqr(rx^2 - ( GmX - THIS.Xi)^2)*ry/rx
dim as single yrMaxLeft => THIS.Yf + sqr(rx^2 - ( GmX - THIS.Xi)^2)*ry/rx
dim as single yrMinRight => THIS.Yi - sqr(rx^2 - ( GmX - THIS.Xf)^2)*ry/rx
dim as single yrMaxRight => THIS.Yf + sqr(rx^2 - ( GmX - THIS.Xf)^2)*ry/rx
if ( GmX>=THIS.Xi - THIS._widHei._wid/2 andAlso _
GmX<=THIS.Xi andAlso _
GmY>=yrMinLeft andAlso _
GmY<=yrMaxLeft ) orElse _
( GmX>=THIS.Xf andAlso _
GmX<=THIS.Xf + THIS._widHei._wid/2 andAlso _
GmY>=yrMinRight andAlso _
GmY<=yrMaxRight ) then
'---->
return TRUE
else
'---->
return FALSE
end if
end if
else
'---->
return FALSE
end if
end select
end function
sub DGDPBTN.TestMouse()
static as boolean hasMovedAtLeastOnce
dim as integer gmX, gmY, gmWheel, gmBtn
getMouse gmX, gmY, gmWheel, gmBtn
'
#ifdef _DEBUG
_P(hasMovedAtLeastOnce)
_P(THIS._hasMouseClick)
_P(THIS._hasDragStarted)
_P(THIS._hasMouseOver)
_P(THIS._isMouseOverDropZone)
_P(THIS._isMouseDropped)
#endif
select case THIS._hasMouseClick
case TRUE
if THIS._isMouseDropped then THIS._isMouseDropped = FALSE
THIS._hasDragStarted = TRUE
'
if not _
( gmX=(THIS._topLeftCorner._x + THIS._offsetAtClick._x) andAlso _
gmY=(THIS._topLeftCorner._y + THIS._offsetAtClick._y) ) then
'moving -> update position
if not hasMovedAtLeastOnce then hasMovedAtLeastOnce = TRUE
THIS._topLeftCorner._x = gmX - THIS._offsetAtClick._x
THIS._topLeftCorner._y = gmY - THIS._offsetAtClick._y
else
'not moving
if not hasMovedAtLeastOnce then
THIS._hasDragStarted = FALSE
else
THIS._hasDragStarted = TRUE
end if
'
if THIS.IsInButtonShape(gmX, gmY) then
if not gmBtn>0 then
'reset mouseClick state
if hasMovedAtLeastOnce then hasMovedAtLeastOnce = FALSE
THIS._hasMouseClick = FALSE
THIS._offsetAtClick._x = -1
THIS._offsetAtClick._y = -1
end if
else
'reset mouseOver state
THIS._hasMouseOver = FALSE
end if
end if
case else
'THIS._hasMouseClick==FALSE
if THIS._hasDragStarted then
THIS._hasDragStarted = FALSE
end if
'
if THIS.IsInButtonShape(gmX, gmY) then
if not THIS._hasMouseOver then THIS._hasMouseOver = TRUE
'
if gmBtn>0 then
THIS._hasMouseClick = TRUE
THIS._offsetAtClick._x = gmX - THIS._topLeftCorner._x
THIS._offsetAtClick._y = gmY - THIS._topLeftCorner._y
end if
else
if THIS._hasMouseOver then THIS._hasMouseOver = FALSE
end if
end select
'
if THIS._hasDragStarted then
'test if dropped if dropability previously granted
select case THIS._isMouseOverDropZone
case TRUE
'is dropable
if THIS.IsInButtonShape(gmX, gmY) then
if not gmBtn>0 then
'is dropped
if not THIS._isMouseDropped then THIS._isMouseDropped = TRUE
'reset mouseClick state
THIS._hasMouseClick = FALSE
THIS._offsetAtClick._x = -1
THIS._offsetAtClick._y = -1
end if
else
'reset mouseOver state
THIS._hasMouseOver = FALSE
end if
case else
'is not dropable
if THIS.IsInButtonShape(gmX, gmY) then
if not gmBtn>0 then
'is not dropped
if THIS._isMouseDropped then THIS._isMouseDropped = FALSE
'reset mouseClick state
THIS._hasMouseClick = FALSE
THIS._offsetAtClick._x = -1
THIS._offsetAtClick._y = -1
end if
else
'reset mouseOver state
THIS._hasMouseOver = FALSE
end if
end select
'test for dropability if not dropped already
if not THIS._isMouseDropped then
ResetLandableZone()
for index as integer = 0 to uBound(THIS._dpZoneArrayPtr)
'
_P(index)
_P(THIS._dpZoneArrayPtr(index)->IsInDropzoneShape(gmX, gmY))
'
if THIS._dpZoneArrayPtr(index)->IsInDropzoneShape(gmX, gmY) then
if not THIS._isMouseOverDropZone then THIS._isMouseOverDropZone = TRUE
THIS.AddDropZoneAsLandableZoneAtIndex(index)
else
if THIS._isMouseOverDropZone then THIS._isMouseOverDropZone = FALSE
end if
next index
if _ARRAYRANGE(THIS._landableDropZone)>0 then
if not THIS._isMouseOverDropZone then THIS._isMouseOverDropZone = TRUE
end if
end if
'
end if
end sub
sub DGDPBTN.ShowAllDropZone()
#define _ALIAS THIS._dpZoneArrayPtr
'
'get background color
dim as integer bkgColor
screenControl fb.GET_COLOR, , bkgColor
'get screen color depth
dim as integer scrDepth
screenInfo , , scrDepth
'
for index as integer = 0 to uBound(THIS._dpZoneArrayPtr)
line (_ALIAS(index)->Xi + 2, _ALIAS(index)->Yi + 2)- _
(_ALIAS(index)->Xf - 2, _ALIAS(index)->Yf - 2), _
_COMPLEMENTCOLOR(bkgColor, scrDepth\2), _
b
next index
'
#ifdef _ALIAS
#undef _ALIAS
#endif
end sub
sub DGDPBTN.ShowAllLandableZone()
for index as integer = 0 to uBound(THIS._landableDropZone)
THIS._landableDropZone(index)->DrawDropZone(0)
next index
end sub
sub DGDPBTN.DrawDgdpbtn()
THIS.TestMouse()
'
dim as ulong btnColour
if THIS._isMouseOverDropZone then
btnColour = THIS._mouseDroppableColour
elseIf THIS._hasDragStarted then
btnColour = THIS._mouseDragColour
elseIf THIS._hasMouseClick then
btnColour = THIS._mouseClickColour
elseIf THIS._hasMouseOver then
btnColour = THIS._mouseOverColour
else
btnColour = THIS._idleColour
end if
'
if THIS._isMouseOverDropZone then THIS.ShowAllLandableZone()
'
select case THIS._btnShape
case DGDPBTN._DGDPBTNSHAPE._naked
line (THIS.Xi, THIS.Yi)-(THIS.Xf, THIS.Yf), _COMPLEMENTCOLOR(btnColour, 4), bf
case DGDPBTN._DGDPBTNSHAPE._squared
line (THIS.Xi - 8, THIS.Yi - 8)- _
(THIS.Xf + 8, THIS.Yf + 8), _
_COMPLEMENTCOLOR(btnColour, 4), _
bf
case else
dim as integer rx => THIS.RoundedShapeRadius._bivi
dim as integer ry => THIS.RoundedShapeRadius._bivj
dim as integer rr => _MAX(THIS.RoundedShapeRadius._bivi, THIS.RoundedShapeRadius._bivj)
line (THIS.Xi - 1, THIS.Yi - 1)-(THIS.Xf + 1, THIS.Yf + 1), btnColour, bf
'
line (THIS.Xi - rx, THIS.Yi)-(THIS.Xi, THIS.Yf), btnColour, bf
line (THIS.Xi, THIS.Yf + ry)-(THIS.Xf, THIS.Yf), btnColour, bf
line (THIS.Xf + rx, THIS.Yf)-(THIS.Xf, THIS.Yi), btnColour, bf
line (THIS.Xf, THIS.Yi - ry)-(THIS.Xi, THIS.Yi), btnColour, bf
'
dim as integer inc => rr
while inc>=0
inc -= 1
circle (THIS.Xi, THIS.Yi), _
inc, _
btnColour, _
_pi/2, _
_pi, _
THIS.RoundedShapeRadius._bivj/THIS.RoundedShapeRadius._bivi
circle (THIS.Xi, THIS.Yf), _
inc, _
btnColour, _
_pi, _
3*_pi/2, _
THIS.RoundedShapeRadius._bivj/THIS.RoundedShapeRadius._bivi
circle (THIS.Xf, THIS.Yf), _
inc, _
btnColour, _
3*_pi/2, _
_2pi, _
THIS.RoundedShapeRadius._bivj/THIS.RoundedShapeRadius._bivi
circle (THIS.Xf, THIS.Yi), _
inc, _
btnColour, _
0, _
_pi/2, _
THIS.RoundedShapeRadius._bivj/THIS.RoundedShapeRadius._bivi
wend
end select
'
draw string (THIS.Xi, THIS.Yi), _
THIS._btnTxt, _
_COMPLEMENTCOLOR(btnColour, 4)
end sub
'````````````````````````````````````````````````````````````````
'````````````````````````````````````````````````````````````````
screen 18, 8
color 0, 8
dim as DRAGDROPBUTTON ddb1
ddb1._btnShape = DGDPBTN._DGDPBTNSHAPE._naked
dim as DRAGDROPBUTTON ddb2
ddb2._topLeftCorner._y = 300
ddb2._btnShape = DGDPBTN._DGDPBTNSHAPE._squared
dim as DRAGDROPBUTTON ddb3
ddb3._topLeftCorner._y = 400
ddb3._btnShape = DGDPBTN._DGDPBTNSHAPE._rounded
dim as DROPZONE dz1
/'
dz1._topLeftCorner._x = 10
dz1._topLeftCorner._y = 200
dz1._widHei.Wid = 80
dz1._widHei.Hei = 50
'/
dim as DROPZONE dz2
dz2._dzShape = DZ._DROPZONESHAPE._maximumEllipse
/'
dz2._topLeftCorner._x = 320
dz2._topLeftCorner._y = 200
dz2._widHei.Wid = 80
dz2._widHei.Hei = 150
'/
scope
redim as DZ ptr arrayOfDZptr(1)
arrayOfDZptr(0) = @dz1
arrayOfDZptr(1) = @dz2
ddb1.AddDropZoneArrayOfPtrToArrayOfPtr(arrayOfDZptr())
end scope
do
screenLock
cls
dz1.DrawDropZone()
dz2.DrawDropZone()
ddb1.DrawDgdpbtn()
'ddb2.DrawDgdpbtn()
'ddb3.DrawDgdpbtn()
screenUnlock
'
sleep 25
loop until inkey()=chr(27)
'````````````````````````````````````````````````````````````````
'````````````````````````````````````````````````````````````````
getKey()
'(eof)