You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Viewport.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
  3. *
  4. * This is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This software is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this software; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  17. * USA.
  18. */
  19. #ifndef __VIEWPORT_H__
  20. #define __VIEWPORT_H__
  21. #include <map>
  22. #include <FL/Fl.H>
  23. #include <FL/Fl_Widget.H>
  24. #include <FL/Fl_Menu_Button.H>
  25. #include <FL/Fl_RGB_Image.H>
  26. #include <rfb/Rect.h>
  27. #include <rfb/Region.h>
  28. #include <rfb/Timer.h>
  29. #include <rfb/PixelBuffer.h>
  30. #include <rfb/PixelTransformer.h>
  31. #if defined(WIN32)
  32. #include "Win32PixelBuffer.h"
  33. #elif defined(__APPLE__)
  34. #include "OSXPixelBuffer.h"
  35. #else
  36. #include "X11PixelBuffer.h"
  37. #endif
  38. // We also have a generic version of the above, using pure FLTK:
  39. //
  40. // #include "PlatformPixelBuffer.h"
  41. //
  42. class CConn;
  43. class Viewport : public Fl_Widget {
  44. public:
  45. Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
  46. ~Viewport();
  47. // PixelFormat of incoming write operations
  48. void setServerPF(const rfb::PixelFormat& pf);
  49. // Most efficient format (from Viewport's point of view)
  50. const rfb::PixelFormat &getPreferredPF();
  51. // Flush updates to screen
  52. void updateWindow();
  53. // Methods forwarded from CConn
  54. void setName(const char *name);
  55. void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
  56. void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
  57. if (pixelTrans) {
  58. rfb::Pixel pix2;
  59. if (colourMapChange)
  60. commitColourMap();
  61. pixelTrans->translatePixels(&pix, &pix2, 1);
  62. pix = pix2;
  63. }
  64. frameBuffer->fillRect(r, pix);
  65. damageRect(r);
  66. }
  67. void imageRect(const rfb::Rect& r, void* pixels) {
  68. if (pixelTrans) {
  69. if (colourMapChange)
  70. commitColourMap();
  71. pixelTrans->translateRect(pixels, r.width(),
  72. rfb::Rect(0, 0, r.width(), r.height()),
  73. frameBuffer->data, frameBuffer->getStride(),
  74. r.tl);
  75. } else {
  76. frameBuffer->imageRect(r, pixels);
  77. }
  78. damageRect(r);
  79. }
  80. void copyRect(const rfb::Rect& r, int srcX, int srcY) {
  81. frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
  82. damageRect(r);
  83. }
  84. rdr::U8* getPixelsRW(const rfb::Rect& r, int* stride) {
  85. return frameBuffer->getPixelsRW(r, stride);
  86. }
  87. void damageRect(const rfb::Rect& r) {
  88. damage.assign_union(rfb::Region(r));
  89. if (!Fl::has_timeout(handleUpdateTimeout, this))
  90. Fl::add_timeout(0.500, handleUpdateTimeout, this);
  91. };
  92. void setCursor(int width, int height, const rfb::Point& hotspot,
  93. void* data, void* mask);
  94. // Fl_Widget callback methods
  95. void draw();
  96. void resize(int x, int y, int w, int h);
  97. int handle(int event);
  98. private:
  99. static void handleUpdateTimeout(void *data);
  100. void commitColourMap();
  101. static void handleClipboardChange(int source, void *data);
  102. void handlePointerEvent(const rfb::Point& pos, int buttonMask);
  103. static void handlePointerTimeout(void *data);
  104. rdr::U32 translateKeyEvent(int keyCode, int origKeyCode, const char *keyText);
  105. void handleKeyEvent(int keyCode, int origKeyCode, const char *keyText, bool down);
  106. void initContextMenu();
  107. void popupContextMenu();
  108. void setMenuKey();
  109. static void handleOptions(void *data);
  110. private:
  111. CConn* cc;
  112. PlatformPixelBuffer* frameBuffer;
  113. rfb::PixelTransformer *pixelTrans;
  114. rfb::SimpleColourMap colourMap;
  115. bool colourMapChange;
  116. rfb::Region damage;
  117. rfb::Point lastPointerPos;
  118. int lastButtonMask;
  119. typedef std::map<int, rdr::U32> DownMap;
  120. DownMap downKeySym;
  121. int menuKeyCode;
  122. Fl_Menu_Button *contextMenu;
  123. bool menuCtrlKey;
  124. bool menuAltKey;
  125. Fl_RGB_Image *cursor;
  126. rfb::Point cursorHotspot;
  127. };
  128. #endif