GUI controller

Share your advanced knowledge/code with the community.
User avatar
eddy
Posts: 124
Joined: Thu Mar 27, 2014 8:34 am

GUI controller

Post by eddy »

Code: Select all

; ******************************
; utility functions
; ******************************

Procedure UsePlugin(Plugin.s, Path.s, *FunctionUsingPlugin, EnforceDefine=#False)
  !cfg={ enforceDefine: v_enforcedefine, paths: {} };
  !cfg.paths[v_plugin]=v_path;
  !requirejs.config(cfg);
  
  !require([v_plugin], function(plug) { 
  !   p_functionusingplugin(plug);  
  !});
EndProcedure

; *************************
; Create custom GUI bound to data
; *************************

Import ""
  CreateGUIPanel() As "var datGuiItem, datGuiPanel, datGuiParent=datGuiPanel=new dat.GUI"
  OpenGUIFolder(FolderName.s) As "datGuiParent=datGuiPanel.addFolder"
  CloseGUIFolder() As "datGuiParent=datGuiPanel;//"
  GUIItem(Object, Property.s) As "datGuiItem=datGuiParent.add"
  GUIColorItem(Object, Property.s) As "datGuiItem=datGuiParent.addColor"
  SetGUIItemMin(Min.f) As "datGuiItem=datGuiItem.min" 
  SetGUIItemMax(Max.f) As "datGuiItem=datGuiItem.max" 
  SetGUIItemStep(Value.f) As "datGuiItem=datGuiItem.step" 
  SetGUIItemName(Name.s) As "datGuiItem.name" 
EndImport

Structure ROBOT
  Name.s
  Speed.f
  PosX.i
  PosY.i
  Color.i
  IsActive.b
EndStructure


Procedure CreateYourGui()   
  Protected MyRobot.ROBOT
  MyRobot\Name="T800"
  MyRobot\PosX=33
  MyRobot\Speed=0.5
  MyRobot\Color=$FF0000    
  MyRobot\IsActive=1
  !v_myrobot._isactive=!!v_myrobot._isactive;
  
  Debug MyRobot\IsActive
  
  CreateGUIPanel();
  GUIItem(MyRobot, "_name")
  OpenGUIFolder("position of robot")
  GUIItem(MyRobot, "_posx"):  SetGUIItemStep(5)
  GUIItem(MyRobot, "_posy"):  SetGUIItemStep(5)
  CloseGUIFolder() 
  GUIItem(MyRobot, "_speed"):  SetGUIItemMin(0.0):  SetGUIItemMax(10.0): SetGUIItemName("speed of robot")
  GUIColorItem(MyRobot, "_color")         
  GUIItem(MyRobot, "_isactive")   
EndProcedure

;original URL (converted by rawgit): https://raw.githubusercontent.com/jaxry/dat.gui/master/build/dat.gui.js
UsePlugin("dat.gui","//rawgit.com/jaxry/dat.gui/master/build/dat.gui",@CreateYourGui())
Last edited by eddy on Mon Apr 20, 2015 10:29 pm, edited 2 times in total.
User avatar
eddy
Posts: 124
Joined: Thu Mar 27, 2014 8:34 am

Re: GUI controller

Post by eddy »

Updated
- fixed plugin loading
Hi-Toro
Posts: 6
Joined: Mon May 19, 2014 1:09 pm

Re: GUI controller

Post by Hi-Toro »

Nice... some good example stuff you've been posting! Thanks.
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: GUI controller

Post by Fred »

Nice and clever code
Post Reply