blob: 04c578474c746d69b93a569703d3bf31df965b91 [file] [log] [blame]
george825e7af742005-03-10 14:26:00 +00001/* Copyright (C) 2004 TightVNC Team. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- PlayerOptions class
20
21#include <rfbplayer/PlayerOptions.h>
22
23using namespace rfb::win32;
24
25PlayerOptions::PlayerOptions() {
26 writeDefaults();
27};
28
29void PlayerOptions::readFromRegistry() {
30 try {
george820981b342005-03-19 11:19:00 +000031 PixelFormat *pPF = 0;
32 int pfSize = sizeof(PixelFormat);
george825e7af742005-03-10 14:26:00 +000033 RegKey regKey;
34 regKey.createKey(HKEY_CURRENT_USER, _T("Software\\TightVnc\\RfbPlayer"));
35 autoPlay = regKey.getBool(_T("AutoPlay"), DEFAULT_AUTOPLAY);
george820981b342005-03-19 11:19:00 +000036 pixelFormatIndex = regKey.getInt(_T("PixelFormatIndex"), DEFAULT_PF);
37 regKey.getBinary(_T("PixelFormat"), (void**)&pPF, &pfSize,
38 &PixelFormat(32,24,0,1,255,255,255,16,8,0), sizeof(PixelFormat));
george82bf212f52005-03-19 11:27:29 +000039 setPF(pPF);
george825e7af742005-03-10 14:26:00 +000040 acceptBell = regKey.getBool(_T("AcceptBell"), DEFAULT_ACCEPT_BELL);
41 acceptCutText = regKey.getBool(_T("AcceptCutText"), DEFAULT_ACCEPT_CUT_TEXT);
42 autoStoreSettings = regKey.getBool(_T("AutoStoreSettings"), DEFAULT_STORE_SETTINGS);
43 autoPlay = regKey.getBool(_T("AutoPlay"), DEFAULT_AUTOPLAY);
44 loopPlayback = regKey.getBool(_T("LoopPlayback"), DEFAULT_LOOP_PLAYBACK);
45 askPixelFormat = regKey.getBool(_T("AskPixelFormat"), DEFAULT_ASK_PF);
george820981b342005-03-19 11:19:00 +000046 if (pPF) delete pPF;
george825e7af742005-03-10 14:26:00 +000047 } catch (rdr::Exception e) {
48 MessageBox(0, e.str(), e.type(), MB_OK | MB_ICONERROR);
49 }
50}
51
52void PlayerOptions::writeToRegistry() {
53 try {
54 RegKey regKey;
55 regKey.createKey(HKEY_CURRENT_USER, _T("Software\\TightVnc\\RfbPlayer"));
56 regKey.setBool(_T("AutoPlay"), autoPlay);
george820981b342005-03-19 11:19:00 +000057 regKey.setInt(_T("PixelFormatIndex"), pixelFormatIndex);
58 regKey.setBinary(_T("PixelFormat"), &pixelFormat, sizeof(PixelFormat));
george825e7af742005-03-10 14:26:00 +000059 regKey.setBool(_T("AcceptBell"), acceptBell);
60 regKey.setBool(_T("AcceptCutText"), acceptCutText);
61 regKey.setBool(_T("AutoStoreSettings"), autoStoreSettings);
62 regKey.setBool(_T("AutoPlay"), autoPlay);
63 regKey.setBool(_T("LoopPlayback"), loopPlayback);
64 regKey.setBool(_T("AskPixelFormat"), askPixelFormat);
65 } catch (rdr::Exception e) {
66 MessageBox(0, e.str(), e.type(), MB_OK | MB_ICONERROR);
67 }
68}
69
70void PlayerOptions::writeDefaults() {
71 initTime = DEFAULT_INIT_TIME;
72 playbackSpeed = DEFAULT_SPEED;
george820981b342005-03-19 11:19:00 +000073 pixelFormatIndex = PF_AUTO;
74 pixelFormat = PixelFormat(32,24,0,1,255,255,255,16,8,0);
george825e7af742005-03-10 14:26:00 +000075 frameScale = DEFAULT_FRAME_SCALE;
76 autoPlay = DEFAULT_AUTOPLAY;
77 fullScreen = DEFAULT_FULL_SCREEN;
78 acceptBell = DEFAULT_ACCEPT_BELL;
79 acceptCutText = DEFAULT_ACCEPT_CUT_TEXT;
80 loopPlayback = DEFAULT_LOOP_PLAYBACK;
81 askPixelFormat = DEFAULT_ASK_PF;
82 autoStoreSettings = DEFAULT_STORE_SETTINGS;
george827b1ebae2005-03-16 16:07:47 +000083}
84
85void PlayerOptions::setPF(PixelFormat *newPF) {
george820981b342005-03-19 11:19:00 +000086 memcpy(&pixelFormat, newPF, sizeof(PixelFormat));
george827b1ebae2005-03-16 16:07:47 +000087}
88
89bool PlayerOptions::setPF(int rgb_order, int rm, int gm, int bm, bool big_endian) {
90 PixelFormat newPF;
91
92 // Calculate the colour bits per pixel
93 int bpp = rm + gm + bm;
94 if (bpp < 0) {
95 return false;
96 } else if (bpp <= 8 ) {
97 newPF.bpp = 8;
98 } else if (bpp <= 16) {
99 newPF.bpp = 16;
100 } else if (bpp <= 32) {
101 newPF.bpp = 32;
102 } else {
103 return false;
104 }
105 newPF.depth = bpp;
106
107 // Calculate the r, g and b bits shifts
108 switch (rgb_order) {
109 case RGB_ORDER:
110 newPF.redShift = gm + bm;
111 newPF.greenShift = bm;
112 newPF.blueShift = 0;
113 break;
114 case RBG_ORDER:
115 newPF.redShift = bm + gm;
116 newPF.blueShift = gm;
117 newPF.greenShift = 0;
118 break;
119 case GRB_ORDER:
120 newPF.greenShift = rm + bm;
121 newPF.redShift = bm;
122 newPF.blueShift = 0;
123 break;
124 case GBR_ORDER:
125 newPF.greenShift = bm + rm;
126 newPF.blueShift = rm;
127 newPF.redShift = 0;
128 break;
129 case BGR_ORDER:
130 newPF.blueShift = gm + rm;
131 newPF.greenShift = rm;
132 newPF.redShift = 0;
133 break;
134 case BRG_ORDER:
135 newPF.blueShift = rm + gm;
136 newPF.redShift = gm;
137 newPF.greenShift = 0;
138 break;
139 default:
140 return false;
141 }
142
143 newPF.trueColour = true;
144 newPF.bigEndian = big_endian;
145 newPF.redMax = (1 << rm) - 1;
146 newPF.greenMax = (1 << gm) - 1;
147 newPF.blueMax = (1 << bm) - 1;
148 setPF(&newPF);
149 return true;
george825e7af742005-03-10 14:26:00 +0000150}