blob: c4bbfaafc1fb803cb1da2505fde49ef298358eb1 [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);
george8234be1fa2005-03-20 09:50:09 +000036 autoDetectPF = regKey.getBool(_T("AutoDetectPixelFormat"), DEFAULT_AUTOPF);
george828c37e422005-03-20 11:38:12 +000037 bigEndianFlag = regKey.getBool(_T("BigEndianFlag"), DEFAULT_BIG_ENDIAN);
george8234be1fa2005-03-20 09:50:09 +000038 pixelFormatIndex = regKey.getInt(_T("PixelFormatIndex"), DEFAULT_PF_INDEX);
george820981b342005-03-19 11:19:00 +000039 regKey.getBinary(_T("PixelFormat"), (void**)&pPF, &pfSize,
40 &PixelFormat(32,24,0,1,255,255,255,16,8,0), sizeof(PixelFormat));
george82bf212f52005-03-19 11:27:29 +000041 setPF(pPF);
george825e7af742005-03-10 14:26:00 +000042 acceptBell = regKey.getBool(_T("AcceptBell"), DEFAULT_ACCEPT_BELL);
43 acceptCutText = regKey.getBool(_T("AcceptCutText"), DEFAULT_ACCEPT_CUT_TEXT);
44 autoStoreSettings = regKey.getBool(_T("AutoStoreSettings"), DEFAULT_STORE_SETTINGS);
45 autoPlay = regKey.getBool(_T("AutoPlay"), DEFAULT_AUTOPLAY);
46 loopPlayback = regKey.getBool(_T("LoopPlayback"), DEFAULT_LOOP_PLAYBACK);
47 askPixelFormat = regKey.getBool(_T("AskPixelFormat"), DEFAULT_ASK_PF);
george820981b342005-03-19 11:19:00 +000048 if (pPF) delete pPF;
george825e7af742005-03-10 14:26:00 +000049 } catch (rdr::Exception e) {
50 MessageBox(0, e.str(), e.type(), MB_OK | MB_ICONERROR);
51 }
52}
53
54void PlayerOptions::writeToRegistry() {
55 try {
56 RegKey regKey;
57 regKey.createKey(HKEY_CURRENT_USER, _T("Software\\TightVnc\\RfbPlayer"));
58 regKey.setBool(_T("AutoPlay"), autoPlay);
george8234be1fa2005-03-20 09:50:09 +000059 regKey.setBool(_T("AutoDetectPixelFormat"), autoDetectPF);
george828c37e422005-03-20 11:38:12 +000060 regKey.setBool(_T("BigEndianFlag"), bigEndianFlag);
george820981b342005-03-19 11:19:00 +000061 regKey.setInt(_T("PixelFormatIndex"), pixelFormatIndex);
62 regKey.setBinary(_T("PixelFormat"), &pixelFormat, sizeof(PixelFormat));
george825e7af742005-03-10 14:26:00 +000063 regKey.setBool(_T("AcceptBell"), acceptBell);
64 regKey.setBool(_T("AcceptCutText"), acceptCutText);
65 regKey.setBool(_T("AutoStoreSettings"), autoStoreSettings);
66 regKey.setBool(_T("AutoPlay"), autoPlay);
67 regKey.setBool(_T("LoopPlayback"), loopPlayback);
68 regKey.setBool(_T("AskPixelFormat"), askPixelFormat);
69 } catch (rdr::Exception e) {
70 MessageBox(0, e.str(), e.type(), MB_OK | MB_ICONERROR);
71 }
72}
73
74void PlayerOptions::writeDefaults() {
75 initTime = DEFAULT_INIT_TIME;
76 playbackSpeed = DEFAULT_SPEED;
george8234be1fa2005-03-20 09:50:09 +000077 autoDetectPF = DEFAULT_AUTOPF;
george828c37e422005-03-20 11:38:12 +000078 bigEndianFlag = DEFAULT_BIG_ENDIAN;
george8234be1fa2005-03-20 09:50:09 +000079 pixelFormatIndex = DEFAULT_PF_INDEX;
george820981b342005-03-19 11:19:00 +000080 pixelFormat = PixelFormat(32,24,0,1,255,255,255,16,8,0);
george825e7af742005-03-10 14:26:00 +000081 frameScale = DEFAULT_FRAME_SCALE;
82 autoPlay = DEFAULT_AUTOPLAY;
83 fullScreen = DEFAULT_FULL_SCREEN;
84 acceptBell = DEFAULT_ACCEPT_BELL;
85 acceptCutText = DEFAULT_ACCEPT_CUT_TEXT;
86 loopPlayback = DEFAULT_LOOP_PLAYBACK;
87 askPixelFormat = DEFAULT_ASK_PF;
88 autoStoreSettings = DEFAULT_STORE_SETTINGS;
george827b1ebae2005-03-16 16:07:47 +000089}
90
91void PlayerOptions::setPF(PixelFormat *newPF) {
george820981b342005-03-19 11:19:00 +000092 memcpy(&pixelFormat, newPF, sizeof(PixelFormat));
george827b1ebae2005-03-16 16:07:47 +000093}
94
95bool PlayerOptions::setPF(int rgb_order, int rm, int gm, int bm, bool big_endian) {
96 PixelFormat newPF;
97
98 // Calculate the colour bits per pixel
99 int bpp = rm + gm + bm;
100 if (bpp < 0) {
101 return false;
102 } else if (bpp <= 8 ) {
103 newPF.bpp = 8;
104 } else if (bpp <= 16) {
105 newPF.bpp = 16;
106 } else if (bpp <= 32) {
107 newPF.bpp = 32;
108 } else {
109 return false;
110 }
111 newPF.depth = bpp;
112
113 // Calculate the r, g and b bits shifts
114 switch (rgb_order) {
115 case RGB_ORDER:
116 newPF.redShift = gm + bm;
117 newPF.greenShift = bm;
118 newPF.blueShift = 0;
119 break;
120 case RBG_ORDER:
121 newPF.redShift = bm + gm;
122 newPF.blueShift = gm;
123 newPF.greenShift = 0;
124 break;
125 case GRB_ORDER:
126 newPF.greenShift = rm + bm;
127 newPF.redShift = bm;
128 newPF.blueShift = 0;
129 break;
130 case GBR_ORDER:
131 newPF.greenShift = bm + rm;
132 newPF.blueShift = rm;
133 newPF.redShift = 0;
134 break;
135 case BGR_ORDER:
136 newPF.blueShift = gm + rm;
137 newPF.greenShift = rm;
138 newPF.redShift = 0;
139 break;
140 case BRG_ORDER:
141 newPF.blueShift = rm + gm;
142 newPF.redShift = gm;
143 newPF.greenShift = 0;
144 break;
145 default:
146 return false;
147 }
148
149 newPF.trueColour = true;
150 newPF.bigEndian = big_endian;
151 newPF.redMax = (1 << rm) - 1;
152 newPF.greenMax = (1 << gm) - 1;
153 newPF.blueMax = (1 << bm) - 1;
154 setPF(&newPF);
155 return true;
george825e7af742005-03-10 14:26:00 +0000156}