I went with the first thing that came to my mind...
Code: Select all
;...Red horizontal lines for gadgets 0 and 1 (top and bottom lines)
CreateImage(0, 300, 1)
StartDrawing(ImageOutput(0))
Box(0, 0, 300, 1, #Red)
StopDrawing()
;...Red vertical lines for gadgets 2 and 3 (left and right lines)
CreateImage(1, 1, 300)
StartDrawing(ImageOutput(1))
Box(0, 0, 1, 300, #Red)
StopDrawing()
;...Our main image
CreateImage(2, 300, 300)
StartDrawing(ImageOutput(2))
Circle(150, 150, 150, #Yellow)
StopDrawing()
;...Load cursors
cursorNS = LoadCursor_(0, #IDC_SIZENS)
cursorWE = LoadCursor_(0, #IDC_SIZEWE)
If OpenWindow(0, 0, 0, 300, 300, "Guide Lines", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
;...Make sure none of the 'line' gadgets have an ID of 0
;...as this will not work properly
ImageGadget(1, 0, 10, 300, 1, ImageID(0)) ;...top line
ImageGadget(2, 0, 290, 300, 1, ImageID(0)) ;...bottom line
ImageGadget(3, 10, 0, 1, 300, ImageID(1)) ;...left line
ImageGadget(4, 290, 0, 1, 300, ImageID(1)) ;...right line
ImageGadget(5, 0, 0, 300, 300, ImageID(2)) ;...main image
;...Clip sibling gadgets for proper redraw while moving lines
For i = 1 To 5
SetWindowLong_(GadgetID(i), #GWL_STYLE, GetWindowLong_(GadgetID(i), #GWL_STYLE) | #WS_CLIPSIBLINGS)
Next i
Repeat
event = WaitWindowEvent()
Select event
Case #WM_LBUTTONUP
gadId = 0
Case #WM_MOUSEMOVE
;...If mouse is moving and left button is down
If GetAsyncKeyState_(#VK_LBUTTON) And gadId > 0
Select gadId
Case 1, 2
SetCursor_(cursorNS)
;...Prevent lines from moving outside main image
If WindowMouseY(0) > GadgetY(5) - 1 And WindowMouseY(0) < (GadgetY(5) + GadgetHeight(5))
ResizeGadget(gadId, #PB_Ignore, WindowMouseY(0), #PB_Ignore, #PB_Ignore)
EndIf
Case 3, 4
SetCursor_(cursorWE)
;...Prevent lines from moving outside main image
If WindowMouseX(0) > GadgetX(5) - 1 And WindowMouseX(0) < (GadgetX(5) + GadgetWidth(5))
ResizeGadget(gadId, WindowMouseX(0), #PB_Ignore, #PB_Ignore, #PB_Ignore)
EndIf
EndSelect
Else
;...If mouse is moving but left button is not down
;...set the cursor when it's over a red line
gadId = GetDlgCtrlID_(ChildWindowFromPoint_(WindowID(0), WindowMouseX(0), WindowMouseY(0)))
Select gadId
Case 1, 2
SetCursor_(cursorNS)
Case 3, 4
SetCursor_(cursorWE)
EndSelect
EndIf
Case #PB_Event_Gadget
;...If one of our lines is clicked, set the gadID and the cursor
If EventGadget() > 0 And EventGadget() < 5
gadId = EventGadget()
Select gadId
Case 1, 2
SetCursor_(cursorNS)
Case 3, 4
SetCursor_(cursorWE)
EndSelect
EndIf
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
End