Page 2 of 2

Re: Show a Gadget selected and ready to resize manually by user

Posted: Thu Mar 11, 2010 8:50 pm
by Demivec
Rook Zimbabwe wrote:Did y'all know that there is no ChildWindowFromPoint() in 4.4+ ???
Of course there is, it's API. :)

It just needs to be adjusted a little because it is supposed to pass a Point structure by value, not by reference (which was used in earlier versions). I'm not sure which of the recent PureBasic versions made the change but there is only one change needed to let it function in v4.41. Change line 7 from:

Code: Select all

hwin = ChildWindowFromPoint_(WindowID(0),WindowMouseX(0), WindowMouseY(0))
to:

Code: Select all

hwin = ChildWindowFromPoint_(WindowID(0),WindowMouseY(0) << 32 + WindowMouseX(0))

Re: Show a Gadget selected and ready to resize manually by user

Posted: Thu Mar 11, 2010 9:49 pm
by DoubleDutch
Rook: Here it is...

Code: Select all

hwin=ChildWindowFromPoint_(GadgetID(#DesignerWindowPage),CursorPosition\y<<32+CursorPosition\x)

Re: Show a Gadget selected and ready to resize manually by user

Posted: Thu Mar 11, 2010 9:52 pm
by DoubleDutch
Demivec: How come I beat you, but your post is ahead of mine? :shock:
(look at the date/time of the posts!!!)

Re: Show a Gadget selected and ready to resize manually by user

Posted: Thu Mar 11, 2010 10:15 pm
by c4s
DoubleDutch wrote:Demivec: How come I beat you, but your post is ahead of mine? :shock:
(look at the date/time of the posts!!!)
Looks like some winter/summer time stuff?!

For me it says:
Demivec - 8:50 pm
You - 9:49 pm

Re: Show a Gadget selected and ready to resize manually by user

Posted: Thu Mar 11, 2010 10:22 pm
by DoubleDutch
Ahh. For me your 8:50 and I'm 8:49 - but ur post wasn't there when I started to post and I didn't take 59 minutes! lol!

Re: Show a Gadget selected and ready to resize manually by user

Posted: Thu Mar 11, 2010 11:48 pm
by Demivec
DoubleDutch wrote:Ahh. For me your 8:50 and I'm 8:49 - but ur post wasn't there when I started to post and I didn't take 59 minutes! lol!
Maybe you had some peanut butter in your internet connection. :D

Rook posted the same comment in two different threads and RASHAD posted his response (and mine and yours) 10 minutes before I did, but in a different thread. It's the Twilight Zone all over again. :shock:

Re: Show a Gadget selected and ready to resize manually by user

Posted: Fri Mar 12, 2010 12:25 am
by Rook Zimbabwe
For your consideration... three dudes each with an answer... is it the right answer? Will it move the object without any other fuky stuff (which it isn't really)... theres the signpost up ahead... You are entering the PBZone!!! 8)

Do de doo do... do Deee do dooo... Dunh Nah NUNNNHHHH!!!

Re: Show a Gadget selected and ready to resize manually by u

Posted: Wed Jun 13, 2012 6:05 am
by IdeasVacuum
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! :mrgreen: