Show a Gadget selected and ready to resize manually by user

Just starting out? Need help? Post your questions and find answers here.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Show a Gadget selected and ready to resize manually by user

Post by QuimV »

:D Hi,

In Visual Designer, when we insert a gadget in a Window, it appears selected and with 8 small squares around, in order to permit the user manually resize the Gadget.

My question is: How Could I do that by code?. I mean with an Gadget inserted, show it selected and with its 8 small squares, ready to permit the user manually resize the Gadget.

Thanks In advanced.
QuimV
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

This may not be exactly what you are looking for but I figured I'd throw it out there just the same. It's very old code and not fully tested with all PB gadgets, so you may need to optimize it here and there. It's not fully commented but it may give you a push in the right direction. :)

Code: Select all

;...Load cursor to use for sizing
curMove = LoadCursor_(0, #IDC_SIZEALL)
;...Make our sizerbutton transparent
Global hTransBrush = GetStockObject_(#HOLLOW_BRUSH)
Global idChild, oldCallback, sizerButton, moveit
Procedure findChild()
  hwin = ChildWindowFromPoint_(WindowID(0),WindowMouseX(0), WindowMouseY(0))
  If hwin <> sizerButton
    idChild = GetDlgCtrlID_(hwin)
    If idChild = 0 
      topWin = GetTopWindow_(hwin)
      idChild = GetDlgCtrlID_(topWin)
    EndIf
    If idChild > 1
      HideGadget(1, 0)
      InvalidateRect_(sizerButton, 0, 1)
      MoveWindow_(GadgetID(1), GadgetX(idChild)-2, GadgetY(idChild)-2, GadgetWidth(idChild)+4, GadgetHeight(idChild)+4, 1)
      InvalidateRect_(GadgetID(idChild), 0, 1)
    ElseIf idChild = 1
      moveit = #False
      ResizeGadget(1, 0, 0, 5, 5)
      HideGadget(1, 1)
    EndIf
  EndIf
  If moveit = #True
    ReleaseCapture_()
    SendMessage_(sizerButton, #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
  EndIf
  ProcedureReturn idChild
EndProcedure

Procedure WinCallback(hwnd, msg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_CTLCOLORBTN 
      If lParam = sizerButton
        SetTextColor_(wParam,$000000) 
        SetBkMode_(wParam, #TRANSPARENT) 
        If StartDrawing(WindowOutput(0)) 
          DrawingMode(4) 
          Box(GadgetX(1),GadgetY(1),GadgetWidth(1),GadgetHeight(1), RGB(255, 0, 0)) 
          Box(GadgetX(1)+1,GadgetY(1)+1,GadgetWidth(1)-2,GadgetHeight(1)-2, RGB(255, 0, 0)) 
          StopDrawing() 
        EndIf 
        result=hTransBrush 
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure

Procedure sizerCallback(hwnd, msg, wParam, lParam)
  Shared prevX, prevY
  result = CallWindowProc_(oldCallback, hwnd, msg, wParam, lParam)
  Select msg
    Case #WM_LBUTTONDOWN
      moveit = #True
    Case #WM_LBUTTONUP
      moveit = #False
      ReleaseCapture_()
    Case #WM_EXITSIZEMOVE
      moveit = #False
    Case #WM_SIZING
      ResizeGadget(idChild, GadgetX(1)+2, GadgetY(1)+2, GadgetWidth(1)-4, GadgetHeight(1)-4)
    Case #WM_MOVING
      InvalidateRect_(sizerButton, 0, 1)
      ResizeGadget(idChild, GadgetX(1)+2, GadgetY(1)+2, GadgetWidth(1)-4, GadgetHeight(1)-4)
    Case #WM_GETMINMAXINFO   
      *mmi.MINMAXINFO = lParam 
      *mmi\ptMinTrackSize\x = 5 
      *mmi\ptMinTrackSize\y = 5 
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 0, 0, 700, 500, "Manula Gadget Sizing / Positioning", #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
  curDef = GetClassLong_(WindowID(0), #GCL_HCURSOR)
  SetWindowCallback(@WinCallback())
  ;...The sizerbutton is the one that we are able to grip
  ;...All other gadgets move and resize as the sizerbutton does
  sizerButton = ButtonGadget(1, 0, 0, 1, 1,"",#WS_SIZEBOX)
  SetWindowLong_(sizerButton, #GWL_STYLE, GetWindowLong_(sizerButton, #GWL_STYLE)|#WS_CHILD|#WS_VISIBLE|#BS_OWNERDRAW)
  SetWindowLong_(sizerButton, #GWL_EXSTYLE, GetWindowLong_(sizerButton, #GWL_EXSTYLE)|#WS_EX_TRANSPARENT)
  SetClassLong_(GadgetID(1), #GCL_HCURSOR, curMove)
  oldCallback = SetWindowLong_(sizerButton, #GWL_WNDPROC, @sizerCallback()) 
  ExplorerTreeGadget(2, 10, 10, 200, 100, "c:\")
  ButtonGadget(3, 10, 120, 100, 40, "Button")
  ExplorerListGadget(4, 300, 10, 200, 100, "c:/")
  Frame3DGadget(5, 300, 120, 200, 100, "Hello World")
  Repeat
    event = WaitWindowEvent()
    Select event
      Case #WM_NCMOUSEMOVE 
        findChild()
      Case #WM_MOUSEMOVE
        findChild()
    EndSelect
  Until event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Post by QuimV »

Thank You Sparkie,
It's perfect and a great start point for me.
Thanks again.
QuimV
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Nice one sparks. Pretty cool.
I may look like a mule, but I'm not a complete ass.
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

Another example demonstrating how to move gadgets inside a window of a running program you can find in a German forum post from Danilo, modified for PB4 by teachco:
http://www.purebasic.fr/german/viewtopi ... 3&start=15

DarkDragon even demonstrates for a button gadget how to change from drag mode to resize mode and change the button size during runtime (PB 3.9x):
http://www.purebasic.fr/german/viewtopi ... 3&start=13
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

@QuimV: You are very welcome :)

@srod: Thank you :)

I came up with that code a couple of years ago whilst attempting to create my own visual designer. I scrapped the project after I realized that I rarely, if ever, use a visual designer.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

Is there a possibilty to move and resize a gadget manually by user with the new lib Drag'n'Drop to do that multiplateform?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Resize - no.

Move - possibly, but not without quite a bit of work. First, you'd either have to use a private drag/drop format or create your own clipboard format. Secondly, you'd undoubtedly require a visual representation of the gadget being dragged and so you'd need to declare a drag callback function.

It would be more effort than the myriad of other methods available.

Bericko's designer is crossplatform and done without the new drag/drop lib.

**EDIT : second thoughts, it probably wouldn't be that much work! :) Yes, a private drag format combined with a drag callback... Wouldn't be my first choice though!
I may look like a mule, but I'm not a complete ass.
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

Sorry, but i don't understand all your english... :o

What are " the myriad of other methods available" for moving and resizing gadgets with multiplateform code ?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Yes I added the cross-platform remark after realising that you were seeking a cross-platform method - sorry!

Bericko's visual designer, whilst crossplatform, must still use some api (e.g. the change of cursor) but is undoubtedly using some conditional compilation. Still, I imagine he makes good use of Purebasic's 2d-drawing commands wherever possible.

I think that any crossplatform designer will still use some platform dependant code, you'll just have to use conditional compilation in order to sift out code for other platforms etc. In terms of specifics I can only comment on Windows as I don't do Linux I'm afraid!
I may look like a mule, but I'm not a complete ass.
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

Very thank you for your comment...

I find a ggod source for moving and sizing gadgets under Windows... but not for Linux...

@Bericko but others too : If you hear that, which trick do you use for moving and sizing gadgets under Linux ?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

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

Post by DoubleDutch »

Has anyone messed with code like this, but also with a background grid and/or snap?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

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

Post by srod »

Yes.

:)
I may look like a mule, but I'm not a complete ass.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

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

Post by DoubleDutch »

lol, any example - just to get me started. ;)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

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

Post by Rook Zimbabwe »

Did y'all know that there is no ChildWindowFromPoint() in 4.4+ ???
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Post Reply