Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   GuiCtrl Fader (https://forums.graalonline.com/forums/showthread.php?t=80229)

xXziroXx 06-25-2008 02:39 AM

GuiCtrl Fader
 
Uses alpha in order to fade it in and out depending on if you're hovering your mouse over the GuiCtrl or not.

Complete script, with a GuiWindowCtrl included as example on usage.

PHP Code:

//#CLIENTSIDE
function onCreated()
{
  new 
GuiWindowCtrl("ExampleGui") {
    
alpha this.baseAlpha .3;
    
    
thiso.catchevent(this"onMouseEnter""onMouseEnter");
    
thiso.catchevent(this"onMouseLeave""onMouseLeave");
  }
}

function 
onMouseEnter(objscheduleevent(.05"FadeGUI""setValue"obj1);
function 
onMouseLeave(objscheduleevent(.05"FadeGUI""setValue"objobj.baseAlpha);

function 
onFadeGUI(modeobjvalue)
{
  
// mode: 'setValue' or 'changeAlpha'
  // obj: GuiCtrl or name of GuiCtrl
  // value: Alpha to reach

  
temp.modifier .1// How much should the alpha change every 0.05 seconds?
  
  // Let's lets make sure that 'obj' really is a GuiCtrl, shall we?
  
if (obj.name == "obj") {
    
// If the GuiCtrl exists, we got it!
    
with ((@obj)) obj this;
    
    
// Can't change alpha on a TGraalVar!
    
if (obj.objecttype() == "TGraalVar") return;
  }
  
  
// Tadaa!
  
if (mode == "setValue") {
    
cancelEvents("changeAlpha");
    
obj.targetAlpha value;
    
scheduleevent(.05"FadeGUI""changeAlpha"obj);
  } else if (
mode == "changeAlpha") {
    if (
obj.alpha != obj.targetAlpha) {
      if (
obj.alpha obj.targetAlphaobj.alpha -= temp.modifier;
      else if (
obj.alpha obj.targetAlphaobj.alpha += temp.modifier;
      
scheduleevent(.05"FadeGUI""changeAlpha"obj);
    } else 
cancelEvents("changeAlpha");
  }


As always, please, use the forums reputation system to show if you like the script or not. Don't hesitate to leave your name saying who you are, I won't "strike back" if you give me negative rep! >_<

DrakilorP2P 06-25-2008 02:47 AM

I like it because it's simple.

cbk1994 06-25-2008 02:52 AM

I'm not a fan of your coding style, but it's personal preference I guess ;)

Nice script :)

xXziroXx 06-25-2008 02:53 AM

Quote:

Originally Posted by cbk1994 (Post 1399165)
I'm not a fan of your coding style, but it's personal preference I guess ;)

Heh, guess I deserved that one.. >_<

TheStan 06-25-2008 03:18 AM

Quote:

Originally Posted by DrakilorP2P (Post 1399159)
I like it because it's simple.

I've seen something like this done with a class joined to a gui control. For some reason I feel that that's a bit more organized/simpler/better. I can't find the right word to explain it, but something about that way strikes me better than the way Ziro did it.

Quote:

Originally Posted by xXziroXx (Post 1399168)
Heh, guess I deserved that one.. >_<

An excellent script nontheless tho buddy!


All times are GMT +2. The time now is 10:49 AM.

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