G-spot - rule based window / gadget / 2D element resizing

Share your advanced PureBasic knowledge/code with the community.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

G-spot - rule based window / gadget / 2D element resizing

Post by blueznl »

(Edit: I think this belongs in 'announcements'...)

This is a work in progress. It's a set of routines to add more intelligent resizing to GUI's. After creating multiple objects, you can add rules that will move and / or resize them, depending on size and position of other GUI elements.

The code is a bit long, but I was trying to figure out a most universal system, which could also be used for other purposes, such as 2D CAD applications, and mixtures of and interactions between gadgets and windows.

In application it would look like this:

Code: Select all

ButtonGadget(#g_button1,190,190,20,20,"1")
ButtonGadget(#g_button2,360,360,40,40,"2")
gs_addrule(#gs_gadget,#g_button2,#gs_below,#gs_gadget,#g_button1,0,0)
The third line above would make sure button 2 would always be located directly below button 1.

The impact on your existing code and gadgets would be close to nill. All it would take is add rules for those gadgets you want to control, and add a call to gs_apply() in your event handler when a window is resized or moved.

The code detects if gadgets or windows exist. You can build an extensive ruleset for hundreds of gadgets, and the ruleset stays applicable, even when some parts of your program (ie. the windows and the gadgets they contain) are inactive ie. not open (yet). I did not want to walk through a linked list or array so I (ab)used :-) a hash table, but I may change that in the future for speed purposes.

Some rules in an example:

Code: Select all

gs_init()
;
Enumeration
  #w_main_nr
  #w_slave_nr
  #g_button1
  #g_button2
  #g_button3
EndEnumeration
;
Global event.i
;
OpenWindow(#w_main_nr,10,10,400,400,"gspot",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget)
OpenWindow(#w_slave_nr,10,10,220,220,"slave",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget)
;
UseGadgetList(WindowID(#w_main_nr))
ButtonGadget(#g_button1,190,190,20,20,"1")
ButtonGadget(#g_button2,360,360,40,40,"2")
gs_addrule(#gs_gadget,#g_button2,#gs_below,#gs_gadget,#g_button1,10,20)
gs_addrule(#gs_gadget,#g_button2,#gs_rightof,#gs_gadget,#g_button1,10,20)
gs_addrule(#gs_gadget,#g_button2,#gs_spandown,#gs_window,#w_main_nr,10,20)
gs_addrule(#gs_gadget,#g_button2,#gs_spanright,#gs_window,#w_main_nr,10,20)
gs_addrule(#gs_window,#w_slave_nr,#gs_aligntop,#gs_window,#w_main_nr)
gs_addrule(#gs_window,#w_slave_nr,#gs_rightof,#gs_window,#w_main_nr,10)
gs_addrule(#gs_window,#w_slave_nr,#gs_setsize,#gs_window,#w_main_nr)
;
Repeat
  event = WaitWindowEvent()
  Select event
  Case #PB_Event_SizeWindow, #PB_Event_MoveWindow
    ResizeGadget(#g_button1,WindowWidth(#w_main_nr)/2,WindowHeight(#w_main_nr)/2,#PB_Ignore,#PB_Ignore)
    gs_apply()
  EndSelect
Until event = #PB_Event_CloseWindow
;
gs_end()
Full code in the next post.
Last edited by blueznl on Sun Apr 04, 2010 12:54 am, edited 4 times in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Gspot - rule based window / gadget placement and resizin

Post by blueznl »

(Edit) I've made so many changes that I've removed the code from here and will post a link to the source in the future. Thinkgs are coming along quite nicely though :-)

Code: Select all

... code removed ... It'll be doing an Arnold... it'll be back! ...
Last edited by blueznl on Wed Mar 24, 2010 4:43 pm, edited 2 times in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 575
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Re: G-spot - rule based window / gadget placement and resizing

Post by bembulak »

Works pretty well on Linux Mint 8 Gloria!
Thanks a lot!

P.S.: I really feel the need of Layout/Resizing Lib. ;)
cheers,

bembulak
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: G-spot - rule based window / gadget placement and resizing

Post by blueznl »

Well, now you have one :-)

I'm still working on it, more to come. The core should stay multi platform, some future parts may become windows only, but I'll try to avoid that.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: G-spot - rule based window / gadget placement and resizing

Post by c4s »

Looks really good!
But at the moment it seems hard for me to create a logical window design that works with it. ;)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: G-spot - rule based window / gadget placement and resizi

Post by blueznl »

I think it would be better if a moderator would move this thread to 'announcements'... Here's a sneak peek anyway at the current codebase:

http://www.youtube.com/watch?v=kpDzIs2AcGY

(Hmm. Turns out YouTube might be of some use after all :-))
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: G-spot - rule based window / gadget / 2D element resizin

Post by blueznl »

And another update. The following three examples use the same codebase...

http://www.youtube.com/watch?v=ao0vdbbe3Y8

If you're wondering what you are looking at... :-) In the first part of the video there's a simple requester with resizing / relocating gadgets.

The second part shows loads of rules all interacting with each other, and two additional windows (part of g-spot) showing values of all oobjects / gadgets involved, plus a graphical representation.

The third part doesn't do anything ruleswise (except resizing the image and image gadget) but it uses the simple graphic elements from part two to make a very basic 'line viewer' where you can zoom in, out etc.

Darn, I notice the lines are too thin in the last part, here's another try.

http://www.youtube.com/watch?v=glYAzggU-60

The code for the third example ie. second move is approx. 130 lines long. The include file is now 2500 lines long, but there are loads of comments in there :-) Here's some slices taken from the code to show the concept.

Code: Select all

...
ImageGadget(#g_main_nr,0,ToolBarHeight(1),10,10,0)
CreateImage(#i_main_nr,10,10)
gs_rule(0,#gs_setsize,#gs_gadget,#g_main_nr,#gs_window,#w_main_nr)
gs_rule(0,#gs_setsize,#gs_image,#i_main_nr,#gs_gadget,#g_main_nr)
;
; add some 2d objects ie elements to look at
;
gs_linexy(0,100,100,100,200,RGB($FF,0,0))
gs_circle(0,200,150,50,RGB($FF,0,0),#PB_2DDrawing_Outlined)
gs_linexy(0,200,150,300,250,RGB(0,0,$FF))
gs_linexy(0,50,250,300,250,RGB(0,0,$FF))
;
; turn on autoscale, and define the viewpane (ie. what's used for sizing the output)
; all output goes onto the iamge #i_main_nr, so we'll use that
; and lets make sure we will set the viewport so that all elements are shown
;
gs_setviewpane(0,0,#gs_image,#i_main_nr)
gs_zoomall()
gs_autoscale = #True
...

...
  Case #PB_Event_MoveWindow, #PB_Event_SizeWindow, #PB_Event_MaximizeWindow, #PB_Event_RestoreWindow
    ;
    ; any window change should generate a call to gs_apply(), if gs_apply() detects a change
    ; that caused one of the defined rules to change an object, it will return a #true which can
    ; be used to trigger the redraw of all elements further down
    ;
    If gs_apply()
      refresh = #True
    EndIf
...

...

...
  If refresh = #True
    If IsWindow(gs_internalsviewer_windownr)
      gs_internalsviewer("")
    EndIf
    refresh = #False
    StartDrawing(ImageOutput(#i_main_nr))
      Box(0,0,ImageWidth(#i_main_nr),ImageHeight(#i_main_nr),0)
      gs_drawallelements()
    StopDrawing()
    SetGadgetState(#g_main_nr,ImageID(#i_main_nr))
  EndIf
...
I still think this belongs in 'announcements', but okay...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: G-spot - rule based window / gadget / 2D element resizin

Post by c4s »

Looks even better - can't wait for the code. :)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: G-spot - rule based window / gadget / 2D element resizin

Post by blueznl »

I've upped the source for g_spot including some examples.

It's part of 'Sweetspot', which you can download here: http://www.xs4all.nl/~bluez/purebasic/sweetspot.zip

More about Sweetspot here: http://www.xs4all.nl/~bluez/purebasic/purebasic 29.htm#sweetspot

There's little known about Sweetspot yet. It's all a secret :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: G-spot - rule based window / gadget / 2D element resizin

Post by c4s »

Your G-Spot thing seems to be very powerful because it has a huge set of functions and constants.

Your website says:
Download sweetspot.zip and look for the folder g_spot in there. In it you will find the include file, and a few examples.
However I can't find any example. Can you post a simple one which shows some basic stuff?
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: G-spot - rule based window / gadget / 2D element resizin

Post by blueznl »

Will do, please remind me in about ten days or so, as I'm currently on a holliday... in Japan :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: G-spot - rule based window / gadget / 2D element resizin

Post by c4s »

blueznl wrote:Will do, please remind me in about ten days or so, as I'm currently on a holliday... in Japan :-)
*Bump*
So what about a demo?! ;)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: G-spot - rule based window / gadget / 2D element resizin

Post by blueznl »

Yeah, suffered from RLI lately, but I've just included a few sample programs in the upload.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: G-spot - rule based window / gadget / 2D element resizin

Post by blueznl »

Minor update... I've been doing a little more work on the g_spot library, and it can now be used as a minor 2D drawing library, handling some primitives (circles, lines, dots, boxes) on multiple planes, zoom in / out, different kinds of panning, enz.

Little teaser vid here:

http://www.youtube.com/watch?v=YuCEoEl9OeY

Going to upload the latest version tonight.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: G-spot - rule based window / gadget / 2D element resizin

Post by blueznl »

Ooops. Forgot to upload it. But hey, now it's there.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Post Reply