Multiple gadget ratio resizing problem

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

The below code takes care of a form with multiple gadgets. It uses code I've found here to resize with a callback by getting the resize of the gadgets to work with the size of the original form. As you can see, some of the gadgets only need to resize and not move, others need to resize and move.

The problem is using this method isn't correct for all gadgets. Some move out of their frames. Others don't maintain the original distance between the paralell gadget. I need the distance between a frame and it's child object to be the same. I also need the distance between 2 frames to remain the same.

I.e. If an object and it's frame start at the left of a window, that object must not move away from the left border but it can grow to the right and down but must maintain the distance inside the frame of the original dimensions. If another object and frame are next to it, this object can both move and grow.

Button objects can move but never grow.

Code: Select all

;-Init Constants

#TV_FIRST                               = $1100
#TVM_SETBKCOLOR                         = #TV_FIRST+29
#TVM_SETTEXTCOLOR                       = #TV_FIRST+30


#WindowIndex                            = 0
#GadgetIndex                            = 0
#ImageIndex                             = 0
#StatusBarIndex                         = 0
#MenuBarIndex                           = 0

;-Window Constants

#Window_FangChat                        = #WindowIndex:#WindowIndex=#WindowIndex+1

;Window_FangChat

#MenuBar_FangChat                       = #MenuBarIndex:#MenuBarIndex=#MenuBarIndex+1
#MenuBar_FangChat_ViewLog               = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_FangChat_ConnectLast           = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_FangChat_EditConnections       = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_FangChat_ChangeColour          = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_FangChat_DateStamp             = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_FangChat_HelpMe                = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#MenuBar_FangChat_AboutMe               = #GadgetIndex:#GadgetIndex=#GadgetIndex+1

#Gadget_FangChat_ChatFrame              = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_FangChat_ChatBox                = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_FangChat_TextEntryFrame         = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_FangChat_TextEntry              = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_FangChat_UserFrame              = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_FangChat_UserList               = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_FangChat_ControlFrame           = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_FangChat_SendText               = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_FangChat_SaveText               = #GadgetIndex:#GadgetIndex=#GadgetIndex+1
#Gadget_FangChat_Disconnect             = #GadgetIndex:#GadgetIndex=#GadgetIndex+1

#StatusBar_FangChat                     = #StatusBarIndex:#StatusBarIndex=#StatusBarIndex+1
#StatusBar_FangChat_Messages            = 0
#StatusBar_FangChat_Port                = 1
#StatusBar_FangChat_Online              = 2
#StatusBar_FangChat_Disconnect          = 3

Declare.l Window_FangChat()
Declare   MyWindowCallback(WindowID, Message, wParam, lParam)
Declare   BubbleTip(bWindow.l,bGadget.l,bText.s)

Global hWnd, OriginalWidth, OriginalHeight

Procedure MyWindowCallback(WindowID, Message, wParam, lParam) 

  Result = #PB_ProcessPureBasicEvents 
    Select message
      Case #WM_SIZE ; Form's size has changed.
        RatioW.f = WindowWidth()  / OriginalWidth   ; Get horizontal difference.
        RatioH.f = WindowHeight() / OriginalHeight  ; Get vertical difference.
        ResizeGadget(#Gadget_FangChat_ChatFrame,       5         ,   0         , 305 * RatioW, 225 * RatioH)
        ResizeGadget(#Gadget_FangChat_ChatBox,        10         ,  10         , 295 * RatioW, 210 * RatioH)
        ResizeGadget(#Gadget_FangChat_TextEntryFrame,  5         , 225 * RatioH, 305 * RatioW,  35         )
        ResizeGadget(#Gadget_FangChat_TextEntry,      10         , 235 * RatioH, 295 * RatioW,  20         )
        ResizeGadget(#Gadget_FangChat_UserFrame,     315 * RatioW,   0 * RatioH, 180 * RatioW, 225 * RatioH)
        ResizeGadget(#Gadget_FangChat_UserList,      320 * RatioW,  10 * RatioH, 170 * RatioW, 210 * RatioH)
        ResizeGadget(#Gadget_FangChat_ControlFrame,  315 * RatioW, 225 * RatioH, 180 * RatioW,  35         )
        ResizeGadget(#Gadget_FangChat_SendText,      320 * RatioW, 235 * RatioH,  50         ,  20         )
        ResizeGadget(#Gadget_FangChat_SaveText,      370 * RatioW, 235 * RatioH,  50         ,  20         )
        ResizeGadget(#Gadget_FangChat_Disconnect,    420 * RatioW, 235 * RatioH,  70         ,  20         )
        UpdateStatusBar(#StatusBar_FangChat)
    EndSelect
  ProcedureReturn Result 

EndProcedure 

Procedure.l Window_FangChat()

  If OpenWindow(#Window_FangChat,26,12,500,307,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_Invisible,"FangChat")
  OriginalWidth  = WindowWidth()  ; Original non-client width.
  OriginalHeight = WindowHeight() ; Original non-client height.
    CreateMenu(#MenuBar_FangChat,WindowID(#Window_FangChat))
      MenuTitle("File")
      MenuItem(#MenuBar_FangChat_ViewLog,"View Log File")
      MenuTitle("Connections")
      MenuItem(#MenuBar_FangChat_ConnectLast,"Connect To Last")
      MenuItem(#MenuBar_FangChat_EditConnections,"Edit Connections")
      MenuTitle("Setup")
      MenuItem(#MenuBar_FangChat_ChangeColour,"Change Form Colour")
      MenuItem(#MenuBar_FangChat_DateStamp,"Date/Time Stamp")
      MenuTitle("Help")
      MenuItem(#MenuBar_FangChat_HelpMe,"Help")
      MenuItem(#MenuBar_FangChat_AboutMe,"About")
    If CreateGadgetList(WindowID())
      Frame3DGadget(#Gadget_FangChat_ChatFrame,5,0,305,225,"")
      StringGadget(#Gadget_FangChat_ChatBox,10,10,295,210,"")
      Frame3DGadget(#Gadget_FangChat_TextEntryFrame,5,225,305,35,"")
      StringGadget(#Gadget_FangChat_TextEntry,10,235,295,20,"")
      Frame3DGadget(#Gadget_FangChat_UserFrame,315,0,180,225,"")
      ListIconGadget(#Gadget_FangChat_UserList,320,10,170,210,"ListIcon14",166)
      ChangeListIconGadgetDisplay(#Gadget_FangChat_UserList, 0) 
      Frame3DGadget(#Gadget_FangChat_ControlFrame,315,225,180,35,"")
      ButtonGadget(#Gadget_FangChat_SendText,320,235,50,20,"Send")
      ButtonGadget(#Gadget_FangChat_SaveText,370,235,50,20,"Save")
      ButtonGadget(#Gadget_FangChat_Disconnect,420,235,70,20,"Disconnect")
      CreateStatusBar(#StatusBar_FangChat,WindowID(#Window_FangChat))
        AddStatusBarField(252)
        AddStatusBarField(50)
        AddStatusBarField(100)
        AddStatusBarField(100)
      HideWindow(#Window_FangChat,0)
      ProcedureReturn WindowID()
    EndIf
  EndIf
  
EndProcedure

Procedure BubbleTip(bWindow.l,bGadget.l,bText.s)

  ToolTipControl=CreateWindowEx_(0,"ToolTips_Class32","",$D0000000|$40,0,0,0,0,WindowID(bWindow),0,GetModuleHandle_(0),0)
  SendMessage_(ToolTipControl,1044,0,0)
  SendMessage_(ToolTipControl,1043,$DFFFFF,0)
  SendMessage_(ToolTipControl,1048,0,180)
  Button.TOOLINFO\cbSize=SizeOf(TOOLINFO)
  Button\uFlags=$11
  Button\hWnd=GadgetID(bGadget)
  Button\uId=GadgetID(bGadget)
  Button\lpszText=@bText
  SendMessage_(ToolTipControl,$0404,0,Button)
  
EndProcedure

If Window_FangChat()

  SetWindowCallback(@MyWindowCallback())

  Repeat
    EventID = WaitWindowEvent()
  Until EventID = #PB_Event_CloseWindow And EventWindowID() = #Window_FangChat
  CloseWindow(#Window_FangChat)

EndIf

End
;

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Jose.

Ok, had a quick look at the code, I think you need to build in some logic to cope with the restrictions that you mentioned.

You need to establish the minimum sizes and cope with those, then always adjust evrything to fit within the space available.

You also must not allow the window to get sized below the minimum size limit.

Hope that helps, I'll look at the code closer in time.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Me build in logic?? I'm amazed I know how to walk some days. Yes, I gathered I had to do that but am struggling with the math (ROFL)

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Jose.

OK, I'm not talking about Math.
I mean, as example, you know the buttons can not be less then 170 wide plus the space between them (I see in code), plus the size of 3dFrame, so this is a minimum width limit for that side of window, the user must NOT be able to resize below this, so basic logic code is

IF width < mybtnWidth then... you get the picture.

From what I've done in other languages, there is no magic formula for doing this without the knowing the limits and using some IF logic to work out what and where.
I thinks...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

ROFL. I shall exercise the grey matter shortly, everyone else is going to sleep except me :(

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

Take a look at the code below, it should work pretty ok.

Something that looks weird though is the #Gadget_FangChat_TextEntry gadget there's some visual glitches when resizing, maybe it's because the border of the frame gadget is to close to the text gadget?

Here you go:

Code: Select all

Procedure MyWindowCallback(WindowID, Message, wParam, lParam) 
  Result = #PB_ProcessPureBasicEvents 
  Select message
    Case #WM_GETMINMAXINFO
      ; Restrict the minimum size to 500x(307+MenuHeight()), borders included
      Result = 0
      *ptr.MINMAXINFO = lParam
      *ptr\ptMinTrackSize\x = 500
      *ptr\ptMinTrackSize\y = 307+MenuHeight()
    Case #WM_SIZE ; Form's size has changed.
      winwidth.l = WindowWidth() : winheight.l = WindowHeight()
      RatioW.f = winwidth / OriginalWidth   ; Get horizontal difference.
      RatioH.f = winheight / OriginalHeight  ; Get vertical difference.
      width.l = 295 * RatioW
      height.l = winheight-82
      ResizeGadget(#Gadget_FangChat_ChatFrame,      -1, -1, width+10, height)
      ResizeGadget(#Gadget_FangChat_ChatBox,        -1, -1, width   , height-15)
      ResizeGadget(#Gadget_FangChat_TextEntryFrame, -1, height, width + 10, 35)
      ResizeGadget(#Gadget_FangChat_TextEntry,      -1, height+10, width, 20)
      ResizeGadget(#Gadget_FangChat_UserFrame,      width+20, -1, winwidth-width-25, height)
      ResizeGadget(#Gadget_FangChat_UserList,       width+25, -1, winwidth-width-35, height-15)
      ResizeGadget(#Gadget_FangChat_ControlFrame,   width+20, height, winwidth-width-25, 35)
      xpos.l = width+25
      RatioW = (winwidth-width-35)/170
      ResizeGadget(#Gadget_FangChat_SendText,       xpos, height+10, 50*RatioW, 20)
      xpos + (50*RatioW)
      ResizeGadget(#Gadget_FangChat_SaveText,       xpos, height+10, 50*RatioW, 20)
      xpos + (50*RatioW)
      ResizeGadget(#Gadget_FangChat_Disconnect,     xpos, height+10, 70*RatioW, 20)
      UpdateStatusBar(#StatusBar_FangChat)
  EndSelect
  ProcedureReturn Result 
EndProcedure 
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Jose.

@Pupil, good stuff.
The problem with display of textgadget only happen once.

@All
One little question, if you make window wider, the status bar fields do not change, does one have to work this out by percentage?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

I've noticed something strange. With ResizeGadget(#Gadget_FangChat_TextEntry... if you resize horizontally, the gadget gets screwed up right royally but returns to normal back to its' original size (most times).

If you resize horizontally and vertically (drag corner), it's always okay. That's so strange.

I decided to drag the window horizontally very slowly and it appears that it recycles slowly through the frame so it must be out an order of several digits. Going to have to play with that and see why

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Jose.

@Fangbeast,
If you set focus to the textgadget it fixes sometimes, weird...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.
Originally posted by Jose

@All
One little question, if you make window wider, the status bar fields do not change, does one have to work this out by percentage?
If you want the status bar field to resize also you have to free it and then recreate it each time you resize, as there is no resize command for the status bar field, however this method looks really ugly if you do it while you drag the borders of the window..

Maybe something to post in the request thread of this forum - resize command for status bar field..
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Hum, what about UpdateStatusBar()?

"Resize the specified StatusBar to the parent window dimension. This command is tipically called after a
#PB_Event_SizeWindow."


Timo




-------------------------------
http://freak.coolfreepages.com/
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.

> Hum, what about UpdateStatusBar()?

That command doesn't resize the individual fields, i just locates the bar at the bottom of the window.. You can see the result if you run Fangbeast's program at the top of this thread, there he has a UpdateStatusBar() in the callback routine..
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.
Originally posted by Jose

@Fangbeast,
If you set focus to the textgadget it fixes sometimes, weird...
Hmm, Okay, I'll try that :):) (Must hunt up breakast first)

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

@Jose, it made little or no difference.

@Pupil, Somone told me; possibly you?; that the borders might be too close to the object and that's causing the problem. It's strange that this only happens to the one gadget because the borders are close on all of them.

Just to experiment, when I dragged the window off screen and back again, the object had been repainted perfectly. Maybe I need to force a repaint after a redraw or just redesign the form with bigger borders :):)

We are Dyslexic of Borg, prepare to have your ass laminated!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Finally found this in the forum. Seems to update everything neatly after a redraw and one of the positive sides is that it reduces the visible flickering during a redraw.

RedrawWindow_(WindowID(), 0, 0, #RDW_INVALIDATE)


We are Dyslexic of Borg, prepare to have your ass laminated!
Post Reply