summaryrefslogtreecommitdiff
path: root/plugins/Watrack/waticons.pas
blob: 94b511767e4047f0309e67be94175bbdbdee1183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
unit WATIcons;
interface

uses wat_api;

const // to not load icobuttons module
  AST_NORMAL  = 0;
  AST_HOVERED = 1;
  AST_PRESSED = 2;

// main Enable/Disable icons
const // name in icolib
  IcoBtnEnable :PAnsiChar='WATrack_Enabled';
  IcoBtnDisable:PAnsiChar='WATrack_Disabled';

function RegisterIcons:boolean;

// frame button icons
function RegisterButtonIcons:boolean;
function GetIcon(action:integer;stat:integer=AST_NORMAL):cardinal;
function DoAction(action:integer):integer;
function GetIconDescr(action:integer):pAnsiChar;
{
const
  AST_NORMAL  = 0;
  AST_HOVERED = 1;
  AST_PRESSED = 2;
}
implementation

uses m_api,windows;

{$include waticons.inc}

const
  ICOCtrlName = 'watrack_buttons.dll';

const
  IconsLoaded:bool = false;

function DoAction(action:integer):integer;
begin
  result:=CallService(MS_WAT_PRESSBUTTON,action,0);
end;

function RegisterIcons:boolean;
var
  sid:TSKINICONDESC;
  buf:array [0..511] of AnsiChar;
  hIconDLL:THANDLE;
begin
  result:=true;
  sid.szDefaultFile.a:='icons\'+ICOCtrlName;
  CallService(MS_UTILS_PATHTOABSOLUTE,wparam(sid.szDefaultFile),lparam(@buf));

  hIconDLL:=LoadLibraryA(buf);
  if hIconDLL=0 then // not found
  begin
    sid.szDefaultFile.a:='plugins\'+ICOCtrlName;
    CallService(MS_UTILS_PATHTOABSOLUTE,wparam(sid.szDefaultFile),lparam(@buf));
    hIconDLL:=LoadLibraryA(buf);
  end;

  if hIconDLL=0 then
    hIconDLL:=hInstance;

  FillChar(sid,SizeOf(TSKINICONDESC),0);
  sid.cbSize:=SizeOf(TSKINICONDESC);
  sid.cx:=16;
  sid.cy:=16;
  sid.szSection.a:='WATrack';

  sid.hDefaultIcon   :=LoadImage(hIconDLL,
      MAKEINTRESOURCE(IDI_PLUGIN_ENABLE),IMAGE_ICON,16,16,0);
  sid.pszName        :=IcoBtnEnable;
  sid.szDescription.a:='Plugin Enabled';
  Skin_AddIcon(@sid);
  DestroyIcon(sid.hDefaultIcon);

  sid.hDefaultIcon   :=LoadImage(hIconDLL,
      MAKEINTRESOURCE(IDI_PLUGIN_DISABLE),IMAGE_ICON,16,16,0);
  sid.pszName        :=IcoBtnDisable;
  sid.szDescription.a:='Plugin Disabled';
  Skin_AddIcon(@sid);
  DestroyIcon(sid.hDefaultIcon);

  if hIconDLL<>hInstance then
    FreeLibrary(hIconDLL);
end;

type
  PAWKIconButton = ^TAWKIconButton;
  TAWKIconButton = record
    descr:PAnsiChar;
    name :PAnsiChar;
    id   :int_ptr;
  end;
const
  CtrlIcoLib:array [WAT_CTRL_FIRST..WAT_CTRL_LAST,AST_NORMAL..AST_PRESSED] of
    TAWKIconButton = (
    ((descr:'Prev'               ;name:'WATrack_Prev'   ; id:IDI_PREV_NORMAL),
     (descr:'Prev Hovered'       ;name:'WATrack_PrevH'  ; id:IDI_PREV_HOVERED),
     (descr:'Prev Pushed'        ;name:'WATrack_PrevP'  ; id:IDI_PREV_PRESSED)),

    ((descr:'Play'               ;name:'WATrack_Play'   ; id:IDI_PLAY_NORMAL),
     (descr:'Play Hovered'       ;name:'WATrack_PlayH'  ; id:IDI_PLAY_HOVERED),
     (descr:'Play Pushed'        ;name:'WATrack_PlayP'  ; id:IDI_PLAY_PRESSED)),

    ((descr:'Pause'              ;name:'WATrack_Pause'  ; id:IDI_PAUSE_NORMAL),
     (descr:'Pause Hovered'      ;name:'WATrack_PauseH' ; id:IDI_PAUSE_HOVERED),
     (descr:'Pause Pushed'       ;name:'WATrack_PauseP' ; id:IDI_PAUSE_PRESSED)),

    ((descr:'Stop'               ;name:'WATrack_Stop'   ; id:IDI_STOP_NORMAL),
     (descr:'Stop Hovered'       ;name:'WATrack_StopH'  ; id:IDI_STOP_HOVERED),
     (descr:'Stop Pushed'        ;name:'WATrack_StopP'  ; id:IDI_STOP_PRESSED)),

    ((descr:'Next'               ;name:'WATrack_Next'   ; id:IDI_NEXT_NORMAL),
     (descr:'Next Hovered'       ;name:'WATrack_NextH'  ; id:IDI_NEXT_HOVERED),
     (descr:'Next Pushed'        ;name:'WATrack_NextP'  ; id:IDI_NEXT_PRESSED)),

    ((descr:'Volume Down'        ;name:'WATrack_VolDn'  ; id:IDI_VOLDN_NORMAL),
     (descr:'Volume Down Hovered';name:'WATrack_VolDnH' ; id:IDI_VOLDN_HOVERED),
     (descr:'Volume Down Pushed' ;name:'WATrack_VolDnP' ; id:IDI_VOLDN_PRESSED)),

    ((descr:'Volume Up'          ;name:'WATrack_VolUp'  ; id:IDI_VOLUP_NORMAL),
     (descr:'Volume Up Hovered'  ;name:'WATrack_VolUpH' ; id:IDI_VOLUP_HOVERED),
     (descr:'Volume Up Pushed'   ;name:'WATrack_VolUpP' ; id:IDI_VOLUP_PRESSED)),

    ((descr:'Slider'             ;name:'WATrack_Slider' ; id:IDI_SLIDER_NORMAL),
     (descr:'Slider Hovered'     ;name:'WATrack_SliderH'; id:IDI_SLIDER_HOVERED),
     (descr:'Slider Pushed'      ;name:'WATrack_SliderP'; id:IDI_SLIDER_PRESSED))
    );

function RegisterButtonIcons:boolean;
var
  sid:TSKINICONDESC;
  buf:array [0..511] of AnsiChar;
  hIconDLL:THANDLE;
  i,j:integer;
  path:pAnsiChar;
begin
  if not IconsLoaded then
  begin
    path:='icons\'+ICOCtrlName;
    CallService(MS_UTILS_PATHTOABSOLUTE,wparam(path),lparam(@buf));

    hIconDLL:=LoadLibraryA(buf);
    if hIconDLL=0 then // not found
    begin
      sid.szDefaultFile.a:='plugins\'+ICOCtrlName;
      CallService(MS_UTILS_PATHTOABSOLUTE,wparam(path),lparam(@buf));
      hIconDLL:=LoadLibraryA(buf);
    end;

    if hIconDLL<>0 then
    begin
      FreeLibrary(hIconDLL);
      FillChar(sid,SizeOf(sid),0);
      sid.flags:=0;
      sid.cbSize:=SizeOf(TSKINICONDESC);
      sid.cx:=16;
      sid.cy:=16;

      sid.szSection.a    :='WATrack/Frame Controls';
      sid.szDefaultFile.a:=path;
      i:=WAT_CTRL_FIRST;
      repeat
        j:=AST_NORMAL;
        repeat
          // increment from 1 by order, so - just decrease number (for iconpack import)
          sid.iDefaultIndex  :=CtrlIcoLib[i][j].id-1;
          sid.pszName        :=CtrlIcoLib[i][j].name;
          sid.szDescription.a:=CtrlIcoLib[i][j].descr;

          Skin_AddIcon(@sid);
          Inc(j);
        until j>AST_PRESSED;
        Inc(i);
      until i>WAT_CTRL_LAST;
      IconsLoaded:=true;
    end;
  end;

  result:=IconsLoaded;
end;

function GetIcon(action:integer;stat:integer):cardinal;
begin
  result:=CallService(MS_SKIN2_GETICON,0,
      lparam(CtrlIcoLib[action][stat].name));
end;

function GetIconDescr(action:integer):pAnsiChar;
begin
  result:=CtrlIcoLib[action][AST_NORMAL].descr;
end;

end.