/*--------------------------------------------------------------------
 System functions.

 This scripts handles various system functions, like toggling of some
 configuration options (crossfading for example), and temporary output
 in the song ticker (volume, seek, clicks on the player buttons).
--------------------------------------------------------------------*/

#include "../../../lib/std.mi"

Function setTempText(String txt);
Function emptyTempText();

Global Text Songticker;
Global Slider Volbar;
Global Timer Songtickertimer;

Class GuiObject HintObject;

Global HintObject Play, Stop, Previous, Next, Pause, Open, plmode, Minimize, Close;

System.onScriptUnloading() {
  delete Songtickertimer;
}

System.onScriptLoaded() {

  // Timers won't start until .start(); is called
  Songtickertimer = new Timer;
  Songtickertimer.setDelay(1000);
  
  Layout mainshade = getContainer("main").getLayout("shade");
   
  // Get songticker, Volbar & Seeker
  Songticker = mainshade.getObject("Songticker");
  Volbar = mainshade.getObject("Volume");
  
  // Get Various buttons
  Play = mainshade.getObject("Play");
  Pause = mainshade.getObject("Pause");
  Stop = mainshade.getObject("Stop");
  Next = mainshade.getObject("Next");
  Previous = mainshade.getObject("Previous");
  Open = mainshade.getObject("Eject");
  Minimize = mainshade.getObject("Minimize");
  plmode = mainshade.getObject("plmode");
  Close = mainshade.getObject("Close");

}

Songtickertimer.onTimer() {
  Songticker.setText("");
  stop();
}

Volbar.onSetPosition(int p) {
  Float f;
  f = p;
  f = f / 255 * 100;
  setTempText("Volume: " + System.integerToString(f) + "%");
}

Volbar.onSetFinalPosition(int p) {
  Songticker.setText("");
}

HintObject.onLeftButtonDown(int x, int y) {
  if (HintObject == Play) setTempText("Play");
  else if (HintObject == Stop) setTempText("Stop");
  else if (HintObject == Pause) setTempText("Pause");
  else if (HintObject == Next) setTempText("Next");
  else if (HintObject == Previous) setTempText("Previous");
  else if (HintObject == Open) setTempText("Open");
  else if (HintObject == Minimize) setTempText("Minimize");
  else if (HintObject == plmode) setTempText("Normal Mode");
  else if (HintObject == Close) setTempText("Exit.... but Why ???");

}

HintObject.onLeftButtonUp(int x, int y) {
  emptyTempText();
}

setTempText(String txt) {
  Songtickertimer.stop();
  Songticker.setText(txt);
  Songtickertimer.start();
}

emptyTempText() {
  Songticker.setText("");
  Songtickertimer.stop();
}

Songticker.onNotify(String s1, String s2, int i1, int i2) {
  setTempText(s1);
}
