Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   CuteGS2 GUI Builder (https://forums.graalonline.com/forums/showthread.php?t=134263993)

fowlplay4 07-24-2011 01:06 AM

CuteGS2 GUI Builder
 
1 Attachment(s)
My latest (fun) side-project that consumed my scripting time these last couple days.

The main purpose of this was to create what I believe is "cuter" (and more flexible) GUI code.

Pretty much every function returns the object, or the object it created. Objects that are created are also joined to gui_builder which allows them access to the same functions. Which in practice allows me to write more "verbose" code. I.e:

PHP Code:

// assuming an object with the ID "Other" exists
createButton("New").  // Create Button with "New" as it's ID
  
position().         // Position it (Actually sets it position to 0,0 but below fixes the position)
    
below("Other").   // Below the "Other" object
    
offset(016).    // Offset it's position by 0 X and 16 Y
  
built();            // Button is now Built 

When you're done creating and manipulating an gui_builder object you call the built() function to leave the class, and it returns the parent of the object which allows you to traverse your creation in the same function call.

You can use catch/bind to catch events like onAction to your own functions. I.e: bind("onAction", "onButtonClicked").

I've also added dimensions(width, height) which allows you to change the clientwidth and clientheight of the object. This is much better explained with code however.

Example:

PHP Code:

function onCreated() {
  
this.join("gui_builder");
}

//#CLIENTSIDE
function onCreated() {
  
// Create Window
  // Calling it Test"Window" is kind of redundant since the builder automatically
  // places _Window at the end of it's ID.
  
createWindow("TestWindow").
    
features().
      
canclose().
    
dimensions(30010 32 13).
    
text("Test Window").
    
center();
  
  
// Add Buttons  
  
for (temp.button: {"Hello""Test""Winning"}) {
    
getWindow("TestWindow").
      
createButton(temp.button).
        
text(temp.button).
        
position(22).
        
sizing("width""").
        
dimensions(300 432).
        
below(temp.last2).
        
bind("onAction""onButtonClicked").
        
built();
    
temp.last temp.button;  
  }  
  
  
// Adding More Controls
  
getWindow("TestWindow").
    
// Add Text
    
createText("TestText").
      
profileMods().
        
profileMod("fontsize"20).
        
profileMod("fontstyle""b").
      
text("This is nifty!").
      
position().
        
below("Winning"2).     
        
center("x").
        
offset(-40).
      
built().
    
// Add Text Edit
    
createTextEdit("TestTextEdit").
      
copy("Winning""dimensions").
      
position().
        
below("TestText"2).
        
copy("Winning""x").
      
built();
      
  
// Add Checkboxes
  
for (temp.checkbox: {"A""B""C""D""E"}) {
    
getWindow("TestWindow").
      
createCheckBox(temp.checkbox).
        
dimensions(6016).
        
text(temp.checkbox).
        
position().
          
below("TestTextEdit"2).
          
offset(166).
          
rightOf(temp.last_check).
        
built();
    
temp.last_check temp.checkbox;
  }
  
  
// Add Radio Buttons
  
for (temp.radio: {"1""2""3""4""5"}) {
    
getWindow("TestWindow").
      
createRadioButton(temp.radio).
        
dimensions(6016).
        
text(temp.radio).
        
position().
          
below("A").
          
offset(016).
          
rightOf(temp.last_radio).
        
built();
    
temp.last_radio temp.radio;
  }
  
  
// TextList
  
getWindow("TestWindow").
    
createScroll("TestScroll").
      
copy("Winning""dimensions").
      
height(100).
      
position().
        
below("1"4).
        
offset(-160).
      
createTextList("List").
        
addRows({"Hello"player.account"OMG!""WTF?"}).
        
built().
      
built().
    
createScroll("TestMLScroll").
      
copy("TestScroll""dimensions").
      
position().
        
below("TestScroll"2).
      
createMLText("Description").
        
copy("TestScroll""dimensions").
        
adjust("width", -4).
        
text("What a nifty way to create GUIs fp4! Test 123 Hello World super star!!!").
        
built().
      
built();
  
  
// Window Finished
  
getWindow("TestWindow").built();


Output:

http://i.imgur.com/TBd3W.jpg

http://i.imgur.com/IOhLJ.jpg

Functions:

PHP Code:

// See Script for Documentation
// GUI Creation Functions
createWindow(window_id)
createBitmapBorder(border_id)
createButton(button_id)
createCheckBox(checkBox_id)
createControl(control_id)
createMLText(mltext_id)
createMLTextEdit(mltextedit_id)
createPopUpMenu(popUpMenu_id)
createPopUpEdit(popUpEdit_id)
createProgress(progress_id)
createRadioButton(radioButton_id)
createScroll(scroll_id)
createSlider(slider_id)
createText(text_id)
createTextEdit(textEdit_id)
createTextList(textlist_id)

// GUI Accessors
getWindow(window_id)
getBorder(border_id)
getButton(button_id)
getCheckBox(checkbox_id)
getControl(control_id)
getMLText(mltext_id)
getMLTextEdit(mltextedit_id)
getPopUpMenu(popupmenu_id)
getPopUpEdit(popupedit_id)
getProgress(progress_id)
getRadioButton(radiobutton_id)
getScroll(scroll_id)
getSlider(slider_id)
getText(text_id)
getTextEdit(textedit_id)
getTextList(textlist_id)

// Debugging
debug(msg)

// GUI Object Positioning
above(objspace)
below(objspace)
leftOf(objspace)
rightOf(objspace)
position(txty)
center(center_pos)

// GUI Object Modifiers
adjust(av)
addRows(rows)
bind(ab)
built()
canResize()
canClose()
canMinimize()
canMaximize()
catch(
ab)
clear()
copy(cv)
dimensions(wh)
features(v)
height(v)
offset(txty)
profile(p)
profileMod(av)
profileMods(av)
set(av)
setValues(av)
setValue(av)
sizing(horizvert)
text(v)
width(v


MattKan 07-24-2011 01:14 AM

<3

fatcat123 07-24-2011 02:14 AM

Nice:redface:

Twinny 07-26-2011 01:04 PM

I dunno...quite honestly i think the 'CuteGS2' code is more ugly that the original. Seems it just adds an unnecessary wrapper?

WhiteDragon 07-26-2011 02:44 PM

Didn't see this earlier, very nice. I very much like this because it lets me avoid that weird object creation syntax.

xAndrewx 07-26-2011 09:44 PM

Quote:

Originally Posted by Twinny (Post 1660366)
I dunno...quite honestly i think the 'CuteGS2' code is more ugly that the original. Seems it just adds an unnecessary wrapper?

It's interesting, but I agree...

fowlplay4 07-26-2011 10:01 PM

Quote:

Originally Posted by Twinny (Post 1660366)
I dunno...quite honestly i think the 'CuteGS2' code is more ugly that the original. Seems it just adds an unnecessary wrapper?

To each their own, I just really like to chain function calls together.

Pretty sure my code should/would work like this too:

PHP Code:

with (createWindow("Test")) {
  
with (createButton("A")) {
    
// stuff...
    
built();
  }
  
built();




All times are GMT +2. The time now is 05:15 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.