blob: d8a584ae2912df979ef64f446219cd9bde1d9730 [file] [log] [blame]
Pierre Ossmand50b3d12011-04-15 07:46:56 +00001/* 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
20#ifndef __VIEWPORT_H__
21#define __VIEWPORT_H__
22
23#include <map>
24
25#include <FL/Fl.H>
26#include <FL/Fl_Widget.H>
27
28#include <rfb/Rect.h>
29#include <rfb/Region.h>
30#include <rfb/Timer.h>
31#include <rfb/PixelBuffer.h>
32#include <rfb/PixelTransformer.h>
33
34class CConn;
35
36class Viewport : public Fl_Widget {
37public:
38
39 Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_);
40 ~Viewport();
41
42 // PixelFormat of incoming write operations
43 void setServerPF(const rfb::PixelFormat& pf);
44 // Most efficient format (from Viewport's point of view)
45 const rfb::PixelFormat &getPreferredPF();
46
47 // Flush updates to screen
48 void updateWindow();
49
50 // Methods forwarded from CConn
51 void setName(const char *name);
52
53 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
54
55 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
56 if (pixelTrans) {
57 rfb::Pixel pix2;
58 pixelTrans->translatePixels(&pix, &pix2, 1);
59 pix = pix2;
60 }
61
62 frameBuffer->fillRect(r, pix);
63 damageRect(r);
64 }
65 void imageRect(const rfb::Rect& r, void* pixels) {
66 if (pixelTrans)
67 pixelTrans->translateRect(pixels, r.width(),
68 rfb::Rect(0, 0, r.width(), r.height()),
69 frameBuffer->data, frameBuffer->getStride(),
70 r.tl);
71 else
72 frameBuffer->imageRect(r, pixels);
73 damageRect(r);
74 }
75 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
76 frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
77 damageRect(r);
78 }
79
80 // Fl_Widget callback methods
81 void draw();
82 int handle(int event);
83
84private:
85
86 void damageRect(const rfb::Rect& r) {
87 damage.assign_union(rfb::Region(r));
88 if (!Fl::has_timeout(handleUpdateTimeout, this))
89 Fl::add_timeout(0.100, handleUpdateTimeout, this);
90 };
91
92 static void handleUpdateTimeout(void *data);
93 static void handleColourMap(void *data);
94
95 void handlePointerEvent(const rfb::Point& pos, int buttonMask);
96 static void handlePointerTimeout(void *data);
97
98 rdr::U32 translateKeyEvent(int keyCode, const char *keyText);
99 void handleKeyEvent(int keyCode, const char *keyText, bool down);
100
101private:
102 CConn* cc;
103
104 rfb::ManagedPixelBuffer* frameBuffer;
105
106 rfb::PixelTransformer *pixelTrans;
107 rfb::SimpleColourMap colourMap;
108
109 rfb::Region damage;
110
111 rfb::Point lastPointerPos;
112 int lastButtonMask;
113
114 typedef std::map<int, rdr::U32> DownMap;
115 DownMap downKeySym;
116};
117
118#endif