It is currently Tue Oct 15, 2019 2:30 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: How to update window contents while resizing?
PostPosted: Sat Dec 08, 2018 12:33 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 5:38 am
Posts: 250
Location: Australia
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? :?:


Top
 Profile  
Reply with quote  
 Post subject: Re: How to update window contents while resizing?
PostPosted: Sat Dec 08, 2018 1:13 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10525
Location: Beyond the pale...
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)

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to update window contents while resizing?
PostPosted: Sat Dec 08, 2018 1:48 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 5:38 am
Posts: 250
Location: Australia
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


Top
 Profile  
Reply with quote  
 Post subject: Re: How to update window contents while resizing?
PostPosted: Sat Dec 08, 2018 2:00 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10525
Location: Beyond the pale...
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

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to update window contents while resizing?
PostPosted: Sat Dec 08, 2018 2:18 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 5:38 am
Posts: 250
Location: Australia
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to update window contents while resizing?
PostPosted: Sat Dec 08, 2018 2:31 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3416
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

_________________
Egypt my love


Last edited by RASHAD on Sat Dec 08, 2018 2:45 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: How to update window contents while resizing?
PostPosted: Sat Dec 08, 2018 2:35 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10525
Location: Beyond the pale...
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.

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to update window contents while resizing?
PostPosted: Sun Dec 09, 2018 12:35 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Nov 25, 2013 5:38 am
Posts: 250
Location: Australia
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?


Top
 Profile  
Reply with quote  
 Post subject: Re: How to update window contents while resizing?
PostPosted: Sun Dec 09, 2018 12:20 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10525
Location: Beyond the pale...
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.

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye