tb_system.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // ================================================================================
  2. // == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
  3. // == See tb_core.h for more information. ==
  4. // ================================================================================
  5. #ifndef TB_SYSTEM_H
  6. #define TB_SYSTEM_H
  7. #include "tb_core.h"
  8. #include "tb_str.h"
  9. #ifdef TB_RUNTIME_DEBUG_INFO
  10. void TBDebugOut(const char *str);
  11. #define TBDebugPrint(str, ...) { tb::TBStr tmp; tmp.SetFormatted(str, __VA_ARGS__); TBDebugOut(tmp); }
  12. #else
  13. #define TBDebugOut(str) ((void)0)
  14. #define TBDebugPrint(str, ...) ((void)0)
  15. #endif
  16. namespace tb {
  17. // == Platform interface ===================================================
  18. /** TBSystem is porting interface for the underlaying OS. */
  19. class TBSystem
  20. {
  21. public:
  22. /** Get the system time in milliseconds since some undefined epoch. */
  23. static double GetTimeMS();
  24. /** Called when the need to call TBMessageHandler::ProcessMessages has changed due to changes in the
  25. message queue. fire_time is the new time is needs to be called.
  26. It may be 0 which means that ProcessMessages should be called asap (but NOT from this call!)
  27. It may also be TB_NOT_SOON which means that ProcessMessages doesn't need to be called. */
  28. static void RescheduleTimer(double fire_time);
  29. /** Get how many milliseconds it should take after a touch down event should generate a long click
  30. event. */
  31. static int GetLongClickDelayMS();
  32. /** Get how many pixels of dragging should start panning scrollable widgets. */
  33. static int GetPanThreshold();
  34. /** Get how many pixels a typical line is: The length that should be scrolled when turning a mouse
  35. wheel one notch. */
  36. static int GetPixelsPerLine();
  37. /** Get Dots Per Inch for the main screen. */
  38. static int GetDPI();
  39. };
  40. /** TBClipboard is a porting interface for the clipboard. */
  41. class TBClipboard
  42. {
  43. public:
  44. /** Empty the contents of the clipboard. */
  45. static void Empty();
  46. /** Return true if the clipboard currently contains text. */
  47. static bool HasText();
  48. /** Set the text of the clipboard in UTF-8 format. */
  49. static bool SetText(const char *text);
  50. /** Get the text from the clipboard in UTF-8 format.
  51. Returns true on success. */
  52. static bool GetText(TBStr &text);
  53. };
  54. typedef void (*TBFileExternalReaderFunction)(const char* filename, void** data, unsigned* length);
  55. /** TBFile is a porting interface for file access. */
  56. class TBFile
  57. {
  58. static TBFileExternalReaderFunction reader_function;
  59. public:
  60. enum TBFileMode { MODE_READ };
  61. static TBFile *Open(const char *filename, TBFileMode mode);
  62. static void SetReaderFunction(TBFileExternalReaderFunction function) { reader_function = function; }
  63. virtual ~TBFile() {}
  64. virtual long Size() = 0;
  65. virtual size_t Read(void *buf, size_t elemSize, size_t count) = 0;
  66. };
  67. }; // namespace tb
  68. #endif // TB_SYSTEM_H