var
  MiniMode:boolean;

//每十分钟刷一次背景，以保证背景能自动更换
procedure OntmrTimer;
begin
  BeginUpdate;
  imgbg.FileName:=WidgetPath+'images\bg.png';
  EndUpdate;
end;

function RefreshWeatherIcon:string;
var
  aType,s,sicon:string;
begin
  aType:=GetWeatherInfo(0,'Type');
  case aType of
    'Sunny','SunnyHot':
       begin s:='sun'; sicon:='f0'; end;
    'CloudyLightPartly','CloudyPartly','Night_CloudyMostly','Night_CloudyPartly','Night_LightPartlyCloudy','Night_Clear','Windy': 
       begin s:='CloudyLightPartly'; sicon:='f1'; end;
	  'Cloudy','CloudyMostly':
	     begin s:='cloudy'; sicon:='f1'; end;
    
    'Rain','RainLight','RainHeavy','ShowerLight','Shower','ShowerHeavy','LighteningLight','Lightening','Thunderstorms','Night_Rain','Night_Thunderstorms','RainIcyLight','RainnIcy','RainIcyHeavy','SnowRainMix':
       begin s:='rain'; sicon:='f2'; end;

    'SnowLight','Snow','Snowflakes','SnowHeavy','SnowWindy','Frigid','Night_Snow':
      begin s:='snow'; sicon:='f2'; end;
    'Hail','Dust','Fog','Haze','Smoke': begin s:='dust'; sicon:='f1'; end;
    'NA': begin s:=''; sicon:=''; end;
  else
    s:='';
  end;
  imgw0.FileName:=WidgetPath+'images\'+s+'.png'
  imgIcon.FileName:=WidgetPath+'images\'+sicon+'.png'
end;

//更新皮肤中的天气显示信息
procedure WeatherChange;
var
  s,sIcon:string;
  h,m:integer;
begin
  Beginupdate;
  lblTmp.caption:=format('%s~%s°',[GetWeatherInfo(0,'tmplow'),GetWeatherInfo(0,'tmphigh')]);
  lblDesc0.caption:=GetWeatherInfo(0,'desc');
  lblcity.caption:=GetWeatherInfo(0,'City');
  imgw0.Hint:='--- 今日天气 ---'#13#10+GetWeatherDayDesc(0);
  DecodeTime(now,h,m,m,m);
  //imgbg.FileName:=WidgetPath+'images\'+GetbgName+'.png';
  RefreshWeatherIcon;
  EndUpdate;
end;

procedure SetMiniMode(value:boolean);
begin
  if docking and not value then
    exit;
  MiniMode:=value;
  BeginUpdate;
  WeatherChange;
  if value then
  begin
    Widget.Width:=136;
    Widget.Height:=72;
    imgbg.Width:=130;
    imgbg.height:=60;
    imgIcon.left:=35;
    imgIcon.width:=90;
    imgIcon.height:=51;

    imgRefresh.Top:=52;
    imgRefresh.left:=110;
    lbltmp.left:=5;
    lbltmp.top:=15;
    lbltmp.FontStyle.font.size:=14;
    lblCity.left:=5;
    lblCity.top:=32;
    lblCity.FontStyle.font.size:=10;
    lblDesc0.left:=5;
    lblDesc0.top:=48;
    lblDesc0.FontStyle.font.size:=8;
  end
  else
  begin
    Widget.Width:=250;
    Widget.Height:=116;
    imgbg.Width:=218;
    imgbg.height:=104;
    imgIcon.left:=70;
    imgIcon.width:=175;
    imgIcon.height:=99;

    imgRefresh.Top:=95;
    imgRefresh.left:=195;
    lbltmp.left:=15;
    lbltmp.top:=25;
    lbltmp.FontStyle.font.size:=16;
    lblCity.left:=15;
    lblCity.top:=50;
    lblCity.FontStyle.font.size:=11;
    lblDesc0.left:=15;
    lblDesc0.top:=80;
    lblDesc0.FontStyle.font.size:=9;
  end;
  imgw0.left:=imgIcon.left;
  imgw0.width:=imgIcon.width;
  imgw0.height:=imgIcon.height;
  EndUpdate;
end;

//--- Widget移入边栏事件，当Widget被移到边栏上时会触发此事件 ---
procedure OnWidgetDock;
begin
  SetMiniMode(true);
end;

//--- Widget移出边栏事件，当Widget被移出边栏时会触发此事件 ---
procedure OnWidgetUnDock;
begin
  SetMiniMode(false);
end;

//--- Widget初始化事件，当打开Widget时会触发此事件 ---
procedure OnWidgetInit;
begin
  MiniMode:=GetSettingInt('MiniMode',0)=1;
  BeginUpdate;
  WeatherChange;
  SetMiniMode(MiniMode);
  EndUpdate;
end;

//--- Widget关闭事件，当关闭Widget时会触发此事件 ---
procedure OnWidgetClose;
begin

end;

//--- 天气刷新事件，当天气成功刷新后会触发此事件 ---
procedure OnRefreshWidgetWeatherInfo;
begin
  WeatherChange;
end;

//--- Widget事件，当打开鼠标移到Widget区域内时触发此事件 ---
procedure OnWidgetMouseEnter;
begin
  BeginUpdate;
  imgbg.Opacity:=255;
  EndUpdate;
end;

//--- Widget事件，当打开鼠标移出Widget区域时触发此事件 ---
procedure OnWidgetMouseLeave;
begin
  BeginUpdate;
  imgbg.Opacity:=191;
  EndUpdate;
end;

