modes.pp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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(const format: TPTCFormat);
  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(const mode: TPTCMode);
  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: TPTCConsole = nil;
  46. modes: PPTCMode;
  47. index: Integer;
  48. begin
  49. try
  50. try
  51. { create console }
  52. console := TPTCConsole.Create;
  53. { get list of console modes }
  54. modes := console.modes;
  55. { check for empty list }
  56. if not modes[0].valid then
  57. { the console mode list was empty }
  58. Writeln('[console mode list is not available]')
  59. else
  60. begin
  61. { print mode list header }
  62. Writeln('[console modes]');
  63. { mode index }
  64. index := 0;
  65. { iterate through all modes }
  66. while modes[index].valid do
  67. begin
  68. { print mode }
  69. print(modes[index]);
  70. { next mode }
  71. Inc(index);
  72. end;
  73. end;
  74. finally
  75. console.Free;
  76. end;
  77. except
  78. on error: TPTCError do
  79. { report error }
  80. error.report;
  81. end;
  82. end.