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