I have been experimenting with this code using image gadgets. A lot of issues though. Firstly, can't seem to stop it from picking gadgets that should not be picked - such as a scroll area gadget upon which the image gadgets (created at run time) would reside. Also cannot have a 'background image gadget' because even though disabled, it gets picked-up. I use a background image to represent a sheet of paper.
The re-sizing/moving of the gadgets works well, but when sizing smaller, an artifact of the image is left on the Window (artifact can be 'erased' by moving a gadget over it), try this:
Code: Select all
UsePNGImageDecoder()
#SizerBtn = 1
Enumeration
#MainWin
#TestImage
EndEnumeration
Global igChildID.i = 0, igOldCallback.i = 0, igSizerBtn.i = 0, igMoveIt.i = 0
Global igWinColour.i = 14794425
;...Load cursor to use for sizing
Global curMove = LoadCursor_(0, #IDC_SIZEALL)
;...Make our igSizerBtn transparent
Global hTransBrush = GetStockObject_(#HOLLOW_BRUSH)
Procedure FindChild()
;--------------------
hwin = ChildWindowFromPoint_(WindowID(#MainWin),WindowMouseY(#MainWin) << 32 + WindowMouseX(#MainWin))
If hwin <> igSizerBtn
igChildID = GetDlgCtrlID_(hwin)
If igChildID = 0
topWin = GetTopWindow_(hwin)
igChildID = GetDlgCtrlID_(topWin)
EndIf
If igChildID > 1
HideGadget(#SizerBtn, 0)
InvalidateRect_(igSizerBtn, 0, 1)
MoveWindow_(GadgetID(#SizerBtn), GadgetX(igChildID)-2, GadgetY(igChildID)-2, GadgetWidth(igChildID)+4, GadgetHeight(igChildID)+4, 1)
InvalidateRect_(GadgetID(igChildID), 0, 1)
ElseIf igChildID = 1
igMoveIt = #False
ResizeGadget(#SizerBtn, 0, 0, 5, 5)
HideGadget(#SizerBtn, 1)
EndIf
EndIf
If igMoveIt = #True
ReleaseCapture_()
SendMessage_(igSizerBtn, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
EndIf
ProcedureReturn igChildID
EndProcedure
Procedure WinCallback(hwnd, msg, wParam, lParam)
;-----------------------------------------------
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_CTLCOLORBTN
If lParam = igSizerBtn
SetTextColor_(wParam,$000000)
SetBkMode_(wParam, #TRANSPARENT)
If StartDrawing(WindowOutput(0))
DrawingMode(4)
Box(GadgetX(#SizerBtn),GadgetY(#SizerBtn),GadgetWidth(#SizerBtn),GadgetHeight(#SizerBtn), RGB(255, 0, 0))
Box(GadgetX(#SizerBtn)+1,GadgetY(#SizerBtn)+1,GadgetWidth(#SizerBtn)-2,GadgetHeight(#SizerBtn)-2, RGB(255, 0, 0))
Box(GadgetX(#SizerBtn)+2,GadgetY(#SizerBtn)+2,GadgetWidth(#SizerBtn)-4,GadgetHeight(#SizerBtn)-4, RGB(255, 0, 0))
StopDrawing()
EndIf
result = hTransBrush
EndIf
EndSelect
ProcedureReturn result
EndProcedure
Procedure SizerCallback(hwnd, msg, wParam, lParam)
;-------------------------------------------------
Shared prevX, prevY
result = CallWindowProc_(igOldCallback, hwnd, msg, wParam, lParam)
Select msg
Case #WM_LBUTTONDOWN : igMoveIt = #True
Case #WM_LBUTTONUP : igMoveIt = #False : ReleaseCapture_()
Case #WM_EXITSIZEMOVE : igMoveIt = #False
Case #WM_SIZING
ResizeGadget(igChildID, GadgetX(#SizerBtn)+2, GadgetY(#SizerBtn)+2, GadgetWidth(#SizerBtn)-4, GadgetHeight(#SizerBtn)-4)
Case #WM_MOVING
InvalidateRect_(igSizerBtn, 0, 1)
ResizeGadget(igChildID, GadgetX(#SizerBtn)+2, GadgetY(#SizerBtn)+2, GadgetWidth(#SizerBtn)-4, GadgetHeight(#SizerBtn)-4)
ResizeImage(#TestImage,GadgetWidth(igChildID), GadgetHeight(igChildID),#PB_Image_Smooth)
SetGadgetState(igChildID,ImageID(#TestImage))
Case #WM_GETMINMAXINFO
*mmi.MINMAXINFO = lParam
*mmi\ptMinTrackSize\x = 5
*mmi\ptMinTrackSize\y = 5
EndSelect
hWnd = WindowID(#MainWin)
UpdateWindow_(hWnd)
ProcedureReturn result
EndProcedure
Procedure MainWin()
;------------------
If OpenWindow(#MainWin, 0, 0, 855, 680, "Sizing-Positioning", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
curDef = GetClassLong_(WindowID(#MainWin), #GCL_HCURSOR)
SetWindowColor(#MainWin, igWinColour)
SetWindowCallback(@WinCallback())
;...The igSizerBtn is the one that we are able to grip
;...All other gadgets move and resize as the igSizerBtn does
igSizerBtn = ButtonGadget(#SizerBtn, 0, 0, 1, 1,"",#WS_SIZEBOX)
SetWindowLongPtr_(igSizerBtn, #GWL_STYLE, GetWindowLongPtr_(igSizerBtn, #GWL_STYLE)|#WS_CHILD|#WS_VISIBLE|#BS_OWNERDRAW)
SetWindowLongPtr_(igSizerBtn, #GWL_EXSTYLE, GetWindowLongPtr_(igSizerBtn, #GWL_EXSTYLE)|#WS_EX_TRANSPARENT)
SetClassLong_(GadgetID(#SizerBtn), #GCL_HCURSOR, curMove)
igOldCallback = SetWindowLongPtr_(igSizerBtn, #GWL_WNDPROC, @SizerCallback())
sTempFile.s = "C:\Temp.png"
LoadImage(#TestImage, sTempFile)
ImageGadget(4, 20, 20, 200, 200, Image003)
SetGadgetState(4,ImageID(#TestImage))
EndIf
EndProcedure
MainWin()
Repeat
event = WaitWindowEvent()
Select event
Case #WM_NCMOUSEMOVE : FindChild()
Case #WM_MOUSEMOVE : FindChild()
EndSelect
Until event = #PB_Event_CloseWindow
End
I think there must be a better way? At run time, the User will add images to the page, resizing those images to suit. Sounds simple.....
Edit: Yep, I think the Canvas Gadget is probably the way to go. Time for more experiments!