Advertisement
snake5

sgs-ui: basic menu example

Jun 8th, 2014
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sgs_ui_example_menu()
  2. {
  3.     MAIN_MENU = UI_CreateStatic( FRAME.root, 0, 0, 0, 0 );
  4.     MAIN_MENU.setAnchorMode( Anchor_All );
  5.     function MAIN_MENU.renderfunc()
  6.     {
  7.         SS_DrawColor2VRect( this.rx0, this.ry0, this.rx1, this.ry1, 0.5, 0.5, 0.5, 1, 0.2, 0.2, 0.2, 1 );
  8.     }
  9.    
  10.     // Title
  11.     mm_title = UI_CreateStatic( MAIN_MENU, 0, 0, 0, 0, "Menu Example", color(0) );
  12.     mm_title.setAnchorMode( Anchor_All );
  13.     mm_title.setFont( "fonts/gauge-oblique.ttf", 48 );
  14.     mm_title.setTextColor( color(0.3,0.7,0.9,1) );
  15.     mm_title.q1y = 0.5;
  16.    
  17.     // Menu
  18.     mm_menu = UI_CreateAutoLayout( MAIN_MENU, 0, 0, 0 );
  19.     mm_menu.setAnchorRect( 0.4, 0.5, 0.6, 1.0 );
  20.    
  21.     btn_start = UI_CreateButton( mm_menu, 0, 0, 0, 36, "Start" );
  22.     UI_CreateImage( btn_start, 0, 0, 36, 36, "icons/control_play.png" );
  23.    
  24.     btn_info = UI_CreateButton( mm_menu, 0, 0, 0, 36, "Info" );
  25.     UI_CreateImage( btn_info, 0, 0, 36, 36, "icons/information.png" );
  26.    
  27.     btn_options = UI_CreateButton( mm_menu, 0, 0, 0, 36, "Options" );
  28.     UI_CreateImage( btn_options, 0, 0, 36, 36, "icons/cog.png" );
  29.    
  30.     btn_quit = UI_CreateButton( mm_menu, 0, 0, 0, 36, "Quit" );
  31.     UI_CreateImage( btn_quit, 0, 0, 36, 36, "icons/stop.png" );
  32.     btn_quit.bindEvent( "click", function(){ global sys_exit = true; } );
  33.    
  34.     function MenuButton_Render()
  35.     {
  36.         if( this.rx0 == this.rx1 || this.ry0 == this.ry1 )
  37.             return;
  38.        
  39.         theme = this.frame.theme;
  40.         button_render_contents = theme.button_render_contents;
  41.        
  42.         alpha = if( this.clicked, 0.4, if( this.mouseOn, 0.2, 0.1 ) );
  43.         SS_DrawColorRect( this.rx0, this.ry0, this.rx1, this.ry1-1, 0, 0, 0, alpha );
  44.         SS_DrawColorRect( this.rx0, this.ry1-1, this.rx1, this.ry1, 0, 0, 0, alpha+0.1 );
  45.        
  46.         this!button_render_contents();
  47.     }
  48.     foreach( ctrl : mm_menu.children() )
  49.     {
  50.         ctrl.setAnchorMode( Anchor_Hor );
  51.         ctrl.setFont( "fonts/armata-regular.ttf", 16 );
  52.         ctrl.renderfunc = MenuButton_Render;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement