blob: de85adde3234a87e8cdf1b17c63686af1dc6399c [file] [log] [blame]
Pierre Ossman5156d5e2011-03-09 09:42:34 +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 __DESKTOPWINDOW_H__
21#define __DESKTOPWINDOW_H__
22
23#include <FL/Fl.H>
24#include <FL/Fl_Window.H>
25
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
32class CConn;
33
34class DesktopWindow : public Fl_Window {
35public:
36
37 DesktopWindow(int w, int h, const char *name,
38 const rfb::PixelFormat& serverPF, CConn* cc_);
39 ~DesktopWindow();
40
41 // PixelFormat of incoming write operations
42 void setServerPF(const rfb::PixelFormat& pf);
43 // Most efficient format (from DesktopWindow's point of view)
44 const rfb::PixelFormat &getPreferredPF();
45
46 // setCursor() sets the shape of the local cursor
47 void setCursor(int width, int height, const rfb::Point& hotspot,
48 void* data, void* mask);
49
50 // Flush updates to screen
51 void updateWindow();
52
53 // Methods forwarded from CConn
54 void setName(const char *name);
55
56 void setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs);
57
58 void fillRect(const rfb::Rect& r, rfb::Pixel pix) {
59 if (pixelTrans) {
60 rfb::Pixel pix2;
61 pixelTrans->translatePixels(&pix, &pix2, 1);
62 pix = pix2;
63 }
64
65 frameBuffer->fillRect(r, pix);
66 damageRect(r);
67 }
68 void imageRect(const rfb::Rect& r, void* pixels) {
69 if (pixelTrans)
70 pixelTrans->translateRect(pixels, r.width(),
71 rfb::Rect(0, 0, r.width(), r.height()),
72 frameBuffer->data, frameBuffer->getStride(),
73 r.tl);
74 else
75 frameBuffer->imageRect(r, pixels);
76 damageRect(r);
77 }
78 void copyRect(const rfb::Rect& r, int srcX, int srcY) {
79 frameBuffer->copyRect(r, rfb::Point(r.tl.x-srcX, r.tl.y-srcY));
80 damageRect(r);
81 }
82
83 // Fl_Window callback methods
84 void draw();
85
86private:
87
88 void damageRect(const rfb::Rect& r) {
89 damage.assign_union(rfb::Region(r));
90 if (!Fl::has_timeout(handleUpdateTimeout, this))
91 Fl::add_timeout(0.100, handleUpdateTimeout, this);
92 };
93
94 static void handleUpdateTimeout(void *data);
95 static void handleColourMap(void *data);
96
97 static void handleClose(Fl_Widget *wnd, void *data);
98
99private:
100 CConn* cc;
101
102 rfb::ManagedPixelBuffer* frameBuffer;
103
104 rfb::PixelTransformer *pixelTrans;
105 rfb::SimpleColourMap colourMap;
106
107 rfb::Region damage;
108};
109
110#endif