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: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341:
|
unit MyMenus;
interface uses GLXDraws,GLXImageList,GLXFont,SysUtils,dialogs,Graphics,Controls,Classes,Windows, Messages;
type TMyMenuItem = record Enabled:Boolean; x,x1, y,y1:Integer; German_Caption,German_Hint:String; Englisch_Caption,Englisch_Hint:String; end;
TMMenus = record Items:array of TMyMenuitem; Caption:String; end;
TMenuIndex = record MenuIndex, MainMenuIndex:Integer; end;
type TMyMenus = class
Private FEnterPressed: TNotifyEvent; HintX, HintY:Integer; xCaption, yCaption:Integer; MenuIndex, MainMenuIndex, SelMenuIndex:Integer; Menus:array of TMMenus; GLXImageList:TGLXImageList; GLXFont: TGLXFont; GLXDraw:TGLXDraw; MenuDir, MenuFile:String; Englisch:Boolean; Autor_Name, Erstellungs_Datum,EMail,HP :String; procedure MenuSaveFile(aFileName:String); procedure MenuLoadFile(aFileName:String); procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
protected procedure DoEnterPressed();
Public constructor create(pMenuFile:String; GLXDraw1:TGLXDraw);
procedure DrawMenu; procedure MouseMove(PosX,PosY:Integer); procedure KeyInput(Key:word); procedure SetMainMenuIndex(MIndex:Integer); function GetIndex:TMenuIndex;
property OnEnterPressed: TNotifyEvent read FEnterPressed write FEnterPressed; end;
implementation
uses Tools;
procedure TMyMenu.WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN; begin if Message.Key == VK_ENTER then DoEnterPressed; end;
procedure TMyMenus.DoEnterPressed(); begin if assigned(FEnterPressed) then FEnterPressed(Self); end;
procedure TMyMenus.MenuLoadFile(aFileName:String); var x,i:Integer; begin Englisch:=StrToBool( ReadIni(aFileName,'Einstellungen','Englisch','0' )); HintX:=StrToInt( GetToken( ReadIni(aFileName,'Einstellungen','HintPos','0'),':',1)); HintY:=StrToInt( GetToken( ReadIni(aFileName,'Einstellungen','HintPos','0'),':',2)); xCaption:=StrToInt( GetToken( ReadIni(aFileName,'Einstellungen','CaptionPos','0'),':',1)); yCaption:=StrToInt( GetToken( ReadIni(aFileName,'Einstellungen','CaptionPos','0'),':',2)); Autor_Name:=ReadIni(aFileName,'Autor_Infos','Autor_Name','KA'); Erstellungs_Datum:=ReadIni(aFileName,'Autor_Infos','Erstellungs_Datum','KA'); EMail:=ReadIni(aFileName,'Autor_Infos','EMail','KA'); HP:=ReadIni(aFileName,'Autor_Infos','HP','KA'); SetLength(Menus,StrToInt( ReadIni(aFileName,'Einstellungen','Menue_Count','0' ))+1);
for x:=0 to High(Menus) do begin Menus[x].Caption:=ReadIni(aFileName,IntToStr(x),'MenuCaption',''); SetLength(Menus[x].items,StrToInt( ReadIni(aFileName,IntToStr(x),'Items_Count',''))+1); for i:=0 to High( Menus[x].items ) do begin Menus[x].Items[i].German_Caption:=ReadIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'German_Caption',''); Menus[x].Items[i].German_Hint:=ReadIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'German_Hint','');
Menus[x].Items[i].Englisch_Caption:=ReadIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'Englisch_Caption',''); Menus[x].Items[i].Englisch_Hint:=ReadIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'Englisch_Hint',''); Menus[x].Items[i].x:= StrToInt(GetToken( ReadIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'Pos',''),':',1)); Menus[x].Items[i].y:= StrToInt(GetToken( ReadIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'Pos',''),':',2));
Menus[x].Items[i].x1:= StrToInt(GetToken( ReadIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'EndPos',''),':',1)); Menus[x].Items[i].y1:= StrToInt(GetToken( ReadIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'EndPos',''),':',2)); Menus[x].Items[i].Enabled:= StrToBool( ReadIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'Enabled',''));
end; end; end;
procedure TMyMenus.MenuSaveFile(aFileName:String); var x,i:Integer; begin WriteIni(aFileName,'Einstellungen','Englisch', BoolToStr(Englisch) ); WriteIni(aFileName,'Einstellungen','HintPos', IntToStr(HintX) + ':' + IntToStr(HintY) ); WriteIni(aFileName,'Einstellungen','CaptionPos', IntToStr(xCaption) + ':' + IntToStr(yCaption) );
WriteIni(aFileName,'Einstellungen','Menue_Count', IntToStr(High(Menus) ));
WriteIni(aFileName,'Autor_Infos','Autor_Name', Autor_Name ); WriteIni(aFileName,'Autor_Infos','Erstellungs_Datum', Erstellungs_Datum ); WriteIni(aFileName,'Autor_Infos','HP', HP ); WriteIni(aFileName,'Autor_Infos','EMail', EMail );
for x:=0 to HIGH(MENUS) do begin WriteIni(aFileName,IntToStr(x),'MenuCaption', Menus[x].Caption ); WriteIni(aFileName,IntToStr(x),'Items_Count', IntToStr( High(Menus[x].items) )); for i:=0 to High(Menus[x].Items) do begin WriteIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'German_Caption', Menus[x].items[i].German_Caption ); WriteIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'Englisch_Caption', Menus[x].items[i].Englisch_Caption ); WriteIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'German_Hint', Menus[x].items[i].German_Hint ); WriteIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'Englisch_Hint', Menus[x].items[i].Englisch_Hint ); WriteIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'Pos', IntToStr( Menus[x].items[i].x) + ':' + IntToStr( Menus[x].items[i].y)); WriteIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'EndPos', IntToStr( Menus[x].items[i].x1) + ':' + IntToStr( Menus[x].items[i].y1)); WriteIni(aFileName,IntToStr(x),'MenuItem' + IntToStr(i) + 'Enabled', BoolToStr(Menus[x].Items[i].Enabled) ); end; end; end;
constructor TMyMenus.create(pMenuFile:String; GLXDraw1:TGLXDraw); begin GLXDraw:=GLXDraw1;
GLXImageList:=TGLXImageList.Create(GLXImageList); GLXImageList.GLXDraw:=GLXDraw;
GLXFont:=TGLXFont.Create(GLXFont); GLXFont.GLXDraw:=GLXDraw;
MenuDir:=GetExeDir + 'menus\' + ExtractFileDir(pMenuFile) + '\'; MenuFile:=MenuDir + pMenuFile + 'menus.txt';
if FileExists(MenuDir + 'menus.grf') then GLXImageList.Items.LoadFromFile(MenuDir + 'menus.grf') else begin ShowMessage('menus.grf wurde nicht im verzeichnis: ' +#10#13 + '"' + MenuDir + '"' + #10#13+'gefunden'); Exit; end;
Englisch:=False; with GLXFont.Items.Add do begin FontType:=ftSystem; Font.Color:=clRed; Font.Size:=20; BuildFont; end;
with GLXFont.Items.Add do begin FontType:=ftSystem; Font.Color:=clBlue; Font.Size:=20; Font.Style:=[fsUnderline]; BuildFont; end;
with GLXFont.Items.Add do begin FontType:=ftSystem; Font.Color:=clLime; Font.Size:=40; Font.Style:=[fsBold]; BuildFont;
end;
with GLXFont.Items.Add do begin FontType:=ftSystem; Font.Color:=clGray; Font.Size:=20; BuildFont; end;
MenuLoadFile( GetExeDir + 'menu.txt' ); end;
function TMyMenus.GetIndex:TMenuIndex; begin result.MenuIndex:=SelMenuIndex; result.MainMenuIndex:=MainMenuIndex; end;
procedure TMyMenus.SetMainMenuIndex(MIndex:Integer); begin MainMenuIndex:=MIndex; end;
procedure TMyMenus.KeyInput(Key:word); function GetEnabledIndexDec:Integer; var i:Integer; begin for i:= SelMenuIndex-1 downto 0 do begin
if Menus[MainMenuIndex].Items[i].Enabled = True then begin result:=i; break; end;
end; end;
function GetEnabledIndexInc:Integer; var i:Integer; begin for i:=SelMenuIndex+1 to High(Menus[MainMenuIndex].items) do begin
if Menus[MainMenuIndex].Items[i].Enabled = True then begin result:=i; break; end;
end; end;
begin if Key = VK_UP then begin if SelMenuIndex <= 0 then SelMenuIndex:=High( Menus[MainMenuIndex].items )+1; SelMenuIndex:=GetEnabledIndexDec+1; dec(SelMenuIndex); end;
if Key = VK_DOWN then begin if SelMenuIndex >= High( Menus[MainMenuIndex].items ) then SelMenuIndex:=-1; SelMenuIndex:=GetEnabledIndexInc-1; inc(SelMenuIndex); end;
if Key = VK_RETURN then begin DoEnterPressed; SelMenuindex:=0; end; end;
procedure TMyMenus.MouseMove(PosX,PosY:Integer); var i:Integer; begin GLXDraw.Cursor:=crDefault; for i:=0 to High( Menus[MainMenuIndex].Items ) do begin with Menus[MainMenuIndex].Items[i] do begin if (PosX > x) and (PosX < X1) and (PosY > Y) and (PosY < Y1) and (Enabled = True) then begin SelMenuIndex:=i; GLXDraw.Cursor:=crHandPoint; end; end; end; end;
procedure TMyMenus.DrawMenu; var i:Integer; begin GLXImageList.Items[3].Draw(0,0,0); GLXFont.Items[2].Font.Color:=clLime; GLXFont.Items[2].TextOut(xCaption,yCaption,Menus[MainMenuIndex].caption);
for i:=0 to High( Menus[MainMenuIndex].Items ) do begin if i <> SelMenuIndex then begin with Menus[MainMenuIndex].Items[i] do begin GLXFont.Items[0].Font.Color:=clRed; if Englisch = False then GLXFont.Items[0].TextOut(x,y,German_caption) else GLXFont.Items[0].TextOut(x,y,Englisch_caption) end; end else begin with Menus[MainMenuIndex].Items[SelMenuIndex] do begin GLXFont.Items[0].Font.Color:=clLime;
with Menus[MainMenuIndex] do begin if Englisch = False then GLXFont.Items[0].TextOut(HintX,HintY,German_Hint) else GLXFont.Items[0].TextOut(HintX,HintY,Englisch_Hint); end;
GLXFont.Items[1].Font.Color:=clBlue; if Englisch = False then GLXFont.Items[1].TextOut(x,y,German_caption) else GLXFont.Items[1].TextOut(x,y,Englisch_caption) end; end;
with Menus[MainMenuIndex].Items[i] do begin if Enabled = False then begin GLXFont.Items[3].Font.Color:=clGray; if Englisch = False then GLXFont.Items[3].TextOut(x,y,German_caption) else GLXFont.Items[3].TextOut(x,y,Englisch_Caption); end; end;
end; end;
end. |