modes.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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;
  46. modes : PPTCMode;
  47. index : Integer;
  48. Begin
  49. console := Nil;
  50. Try
  51. Try
  52. { create console }
  53. console := TPTCConsole.Create;
  54. { get list of console modes }
  55. modes := console.modes;
  56. { check for empty list }
  57. If Not modes[0].valid Then
  58. { the console mode list was empty }
  59. Writeln('[console mode list is not available]')
  60. Else
  61. Begin
  62. { print mode list header }
  63. Writeln('[console modes]');
  64. { mode index }
  65. index := 0;
  66. { iterate through all modes }
  67. While modes[index].valid Do
  68. Begin
  69. { print mode }
  70. print(modes[index]);
  71. { next mode }
  72. Inc(index);
  73. End;
  74. End;
  75. Finally
  76. console.Free;
  77. End;
  78. Except
  79. On error : TPTCError Do
  80. { report error }
  81. error.report;
  82. End;
  83. End.