#include <lib/std.mi>

#define ROTATION_LAYER_VAR MyVar
#include <lib/rotationlayer.m>

Global Group thisGroup;
Global Layer seekLayer;
Global Map seekMap;
Global Timer m_timer;

System.onScriptLoaded() {
  thisGroup = getScriptGroup();
  seekMap = new map;
  seekMap.loadMap("shade.map");
  seekLayer = thisGroup.getObject("POS full");

  m_timer = new timer;
  m_timer.setDelay(200);
  m_timer.start();

  _MyVarInit(thisGroup, "knobs");
}

System.onVolumeChanged(int newvol) {
  _MyVarRotateDegree(newvol*(360/255));
}

System.onSeek(int newpos) {
  if (newpos <= 0) return;
  int len = getPlayItemLength();
  if(len <= 0) return;
  int devby = len/255;
  if(devby <= 0) return;
  seekLayer.setRegionFromMap(seekMap,newpos/devby,1);
}

m_timer.onTimer() {
  System.onSeek(getPosition());
}