modes.pp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. {
  2. Ported to FPC by Nikolay Nikolov ([email protected])
  3. }
  4. {
  5. Modes example for OpenPTC 1.0 C++ implementation
  6. Copyright (c) Glenn Fiedler ([email protected])
  7. This source code is in the public domain
  8. }
  9. program ModesExample;
  10. {$MODE objfpc}
  11. uses
  12. ptc;
  13. procedure print(format: IPTCFormat);
  14. begin
  15. { check format type }
  16. if format.direct then
  17. { check alpha }
  18. if format.a = 0 then
  19. { direct color format without alpha }
  20. Write('Format(', format.bits:2, ',$', HexStr(format.r, 8), ',$', HexStr(format.g, 8), ',$', HexStr(format.b, 8), ')')
  21. else
  22. { direct color format with alpha }
  23. Write('Format(', format.bits:2, ',$', HexStr(format.r, 8), ',$', HexStr(format.g, 8), ',$', HexStr(format.b, 8), ',$', HexStr(format.a, 8), ')')
  24. else
  25. { indexed color format }
  26. Write('Format(', format.bits:2, ')');
  27. end;
  28. procedure print(mode: IPTCMode);
  29. begin
  30. { print mode width and height }
  31. Write(' ', mode.width:4, ' x ', mode.height);
  32. if mode.height < 1000 then
  33. Write(' ');
  34. if mode.height < 100 then
  35. Write(' ');
  36. if mode.height < 10 then
  37. Write(' ');
  38. Write(' x ');
  39. { print mode format }
  40. print(mode.format);
  41. { newline }
  42. Writeln;
  43. end;
  44. var
  45. console: IPTCConsole;
  46. modes: TPTCModeList;
  47. index: Integer;
  48. begin
  49. try
  50. { create console }
  51. console := TPTCConsoleFactory.CreateNew;
  52. { get list of console modes }
  53. modes := console.modes;
  54. { check for empty list }
  55. if Length(modes) = 0 then
  56. { the console mode list was empty }
  57. Writeln('[console mode list is not available]')
  58. else
  59. begin
  60. { print mode list header }
  61. Writeln('[console modes]');
  62. { iterate through all modes }
  63. for index := Low(modes) to High(modes) do
  64. begin
  65. { print mode }
  66. print(modes[index]);
  67. end;
  68. end;
  69. except
  70. on error: TPTCError do
  71. { report error }
  72. error.report;
  73. end;
  74. end.