PureBasic Forum
http://forums.purebasic.com/english/

How to update window contents while resizing?
http://forums.purebasic.com/english/viewtopic.php?f=13&t=71891
Page 1 of 1

Author:  coco2 [ Sat Dec 08, 2018 12:33 pm ]
Post subject:  How to update window contents while resizing?

I know CreateDialog() will do it, but that's not quite what I want. I want to resize and change the contents of a canvas while resizing the window, cross platform. Any way it can be done? :?:

Author:  srod [ Sat Dec 08, 2018 1:13 pm ]
Post subject:  Re: How to update window contents while resizing?

Use BindEvent() on your main window to get live resize events and in your event handler resize the canvas using ResizeGadget() etc. You can either repaint the canvas after resizing or bind a gadget event of type #PB_EventType_Resize to the canvas and repaint in this event handler (PB 5.62 onwards).

Code:
BindEvent(#PB_Event_SizeWindow, @winSize(), #Window)

Author:  coco2 [ Sat Dec 08, 2018 1:48 pm ]
Post subject:  Re: How to update window contents while resizing?

Thanks srod that seems to be what I need, but now I have a problem, how do I get the parameters into the bound event?

Code:
Procedure ResizeAppWindow()
  Debug "Resizing window, width: " + WindowWidth(0) + " height: " + WindowHeight(0)
EndProcedure

Define Quit.i

Quit = 0

OpenWindow(0, 0, 0, 640, 480, "Resize Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
BindEvent(#PB_Event_SizeWindow, @ResizeAppWindow(), 0)

Repeat
  Select WaitWindowEvent()
    Case  #PB_Event_CloseWindow
      Quit = 1
  EndSelect
Until Quit

Author:  srod [ Sat Dec 08, 2018 2:00 pm ]
Post subject:  Re: How to update window contents while resizing?

Which parameters? I think you've asked this before with live scrolling events? You can pass any info you want in the same ways as before; e.g. a combination of SetGadgetData()/GetGadgetData() and pointers etc. Easy enough.

viewtopic.php?f=13&t=70069

Author:  coco2 [ Sat Dec 08, 2018 2:18 pm ]
Post subject:  Re: How to update window contents while resizing?

Since it's resizing the window it'll probably need just about all the variables. I have them set up in a hierarchy with a pointer to the whole lot. I'm not sure if that's recommended way of doing it, but someone said it was fine to do it that way. I see what you are saying, I can just pick a gadget and set a pointer as the data. Thanks I'll have a play around with it.

Author:  RASHAD [ Sat Dec 08, 2018 2:31 pm ]
Post subject:  Re: How to update window contents while resizing?

Hi srod
Hi coco2
Maybe that is what you want
Code:
Procedure sizeCB()
  ww = WindowWidth(0)-20 : hh = WindowHeight(0)-20
  ResizeGadget(0,10,10,ww,hh)
  StartDrawing(CanvasOutput(0))
    DrawImage(ImageID(10),0, 0, OutputWidth(),OutputHeight())
  StopDrawing()
EndProcedure
 
  If OpenWindow(0, 0, 0, 420, 420, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered |#PB_Window_SizeGadget)
 
    CanvasGadget(0, 10, 10, 400, 400, #PB_Canvas_Container)
    ButtonGadget(1, 10, 10, 80, 30, "Clean up")
    CloseGadgetList()
    BindEvent(#PB_Event_SizeWindow,@sizeCB())
    Repeat
      Event = WaitWindowEvent()
   
      If Event = #PB_Event_Gadget
        Select EventGadget()
          Case 0
            If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
              If StartDrawing(CanvasOutput(0))
                x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
                y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
                Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
                GrabDrawingImage(10,0,0,OutputWidth(),OutputHeight())
                StopDrawing()
              EndIf
            EndIf
         
          Case 1
            If IsImage(10)
              SaveImage(10,GetHomeDirectory()+"CanvasTest.bmp")
            EndIf
            If StartDrawing(CanvasOutput(0))
              Box(0, 0, OutputWidth(),OutputHeight(), $FFFFFF)
              GrabDrawingImage(10,0,0,OutputWidth(),OutputHeight())
              StopDrawing()
            EndIf
        EndSelect
      EndIf
   
    Until Event = #PB_Event_CloseWindow
  EndIf

Author:  srod [ Sat Dec 08, 2018 2:35 pm ]
Post subject:  Re: How to update window contents while resizing?

Well, how you wrap up and arrange your program's internal data is down to the way you have designed your program's data structures etc. It is always the first thing I consider when designing any program, but I don't want to get into a lecture on data structures - or anything else for that matter! :)

When you have your data structures sorted out then everything else normally slots into place. In your case, if your window resizing routine needs access to all child gadgets and their sizes and so on then, well, this would normally be very straight forward. Any sensible app will be structured so that it can easily identify which gadgets belong to which window and so on. If this is not the case then rethink the way you organise your gadgets! :)

Incidentally, you can use EventWindow() in your window event proc to determine which window the underyling event pertains to in the case that one such procedure is servicing multiple windows etc. From here, once you have the relevant window#, consult your relevant data structures before proceeding.

Author:  coco2 [ Sun Dec 09, 2018 12:35 am ]
Post subject:  Re: How to update window contents while resizing?

Thanks for the code rashad, I'll have a look.

srod some procedures like the event handler need to access almost all the variables in the application so I pass a pointer to the entire set of variables. It is basically an extension of the main loop so it needs all the variables. As the procedures go deeper I pass only the parameters needed to complete that function. Is this how you do it?

Author:  srod [ Sun Dec 09, 2018 12:20 pm ]
Post subject:  Re: How to update window contents while resizing?

Well, I usually wrap things up in basic classes via interfaces and associated 'class' template structures so I am only passing around those 'objects' which are required for any given situation. Just my personal preference as it allows me to keep on top of things no matter how complex things get. :) This way I minimize the number of separate non-temporary variables I have floating about needing to keep track of. If you are passing a single pointer to your variable set about then it sounds like you are doing something similar.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/