george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 1 | /* 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 | |
| 23 | using namespace rfb::win32; |
| 24 | |
| 25 | PlayerOptions::PlayerOptions() { |
| 26 | writeDefaults(); |
| 27 | }; |
| 28 | |
| 29 | void PlayerOptions::readFromRegistry() { |
| 30 | try { |
george82 | 0981b34 | 2005-03-19 11:19:00 +0000 | [diff] [blame^] | 31 | PixelFormat *pPF = 0; |
| 32 | int pfSize = sizeof(PixelFormat); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 33 | RegKey regKey; |
| 34 | regKey.createKey(HKEY_CURRENT_USER, _T("Software\\TightVnc\\RfbPlayer")); |
| 35 | autoPlay = regKey.getBool(_T("AutoPlay"), DEFAULT_AUTOPLAY); |
george82 | 0981b34 | 2005-03-19 11:19:00 +0000 | [diff] [blame^] | 36 | 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)); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 39 | acceptBell = regKey.getBool(_T("AcceptBell"), DEFAULT_ACCEPT_BELL); |
| 40 | acceptCutText = regKey.getBool(_T("AcceptCutText"), DEFAULT_ACCEPT_CUT_TEXT); |
| 41 | autoStoreSettings = regKey.getBool(_T("AutoStoreSettings"), DEFAULT_STORE_SETTINGS); |
| 42 | autoPlay = regKey.getBool(_T("AutoPlay"), DEFAULT_AUTOPLAY); |
| 43 | loopPlayback = regKey.getBool(_T("LoopPlayback"), DEFAULT_LOOP_PLAYBACK); |
| 44 | askPixelFormat = regKey.getBool(_T("AskPixelFormat"), DEFAULT_ASK_PF); |
george82 | 0981b34 | 2005-03-19 11:19:00 +0000 | [diff] [blame^] | 45 | if (pPF) delete pPF; |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 46 | } catch (rdr::Exception e) { |
| 47 | MessageBox(0, e.str(), e.type(), MB_OK | MB_ICONERROR); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void PlayerOptions::writeToRegistry() { |
| 52 | try { |
| 53 | RegKey regKey; |
| 54 | regKey.createKey(HKEY_CURRENT_USER, _T("Software\\TightVnc\\RfbPlayer")); |
| 55 | regKey.setBool(_T("AutoPlay"), autoPlay); |
george82 | 0981b34 | 2005-03-19 11:19:00 +0000 | [diff] [blame^] | 56 | regKey.setInt(_T("PixelFormatIndex"), pixelFormatIndex); |
| 57 | regKey.setBinary(_T("PixelFormat"), &pixelFormat, sizeof(PixelFormat)); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 58 | regKey.setBool(_T("AcceptBell"), acceptBell); |
| 59 | regKey.setBool(_T("AcceptCutText"), acceptCutText); |
| 60 | regKey.setBool(_T("AutoStoreSettings"), autoStoreSettings); |
| 61 | regKey.setBool(_T("AutoPlay"), autoPlay); |
| 62 | regKey.setBool(_T("LoopPlayback"), loopPlayback); |
| 63 | regKey.setBool(_T("AskPixelFormat"), askPixelFormat); |
| 64 | } catch (rdr::Exception e) { |
| 65 | MessageBox(0, e.str(), e.type(), MB_OK | MB_ICONERROR); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void PlayerOptions::writeDefaults() { |
| 70 | initTime = DEFAULT_INIT_TIME; |
| 71 | playbackSpeed = DEFAULT_SPEED; |
george82 | 0981b34 | 2005-03-19 11:19:00 +0000 | [diff] [blame^] | 72 | pixelFormatIndex = PF_AUTO; |
| 73 | pixelFormat = PixelFormat(32,24,0,1,255,255,255,16,8,0); |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 74 | frameScale = DEFAULT_FRAME_SCALE; |
| 75 | autoPlay = DEFAULT_AUTOPLAY; |
| 76 | fullScreen = DEFAULT_FULL_SCREEN; |
| 77 | acceptBell = DEFAULT_ACCEPT_BELL; |
| 78 | acceptCutText = DEFAULT_ACCEPT_CUT_TEXT; |
| 79 | loopPlayback = DEFAULT_LOOP_PLAYBACK; |
| 80 | askPixelFormat = DEFAULT_ASK_PF; |
| 81 | autoStoreSettings = DEFAULT_STORE_SETTINGS; |
george82 | 7b1ebae | 2005-03-16 16:07:47 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void PlayerOptions::setPF(PixelFormat *newPF) { |
george82 | 0981b34 | 2005-03-19 11:19:00 +0000 | [diff] [blame^] | 85 | memcpy(&pixelFormat, newPF, sizeof(PixelFormat)); |
george82 | 7b1ebae | 2005-03-16 16:07:47 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | bool PlayerOptions::setPF(int rgb_order, int rm, int gm, int bm, bool big_endian) { |
| 89 | PixelFormat newPF; |
| 90 | |
| 91 | // Calculate the colour bits per pixel |
| 92 | int bpp = rm + gm + bm; |
| 93 | if (bpp < 0) { |
| 94 | return false; |
| 95 | } else if (bpp <= 8 ) { |
| 96 | newPF.bpp = 8; |
| 97 | } else if (bpp <= 16) { |
| 98 | newPF.bpp = 16; |
| 99 | } else if (bpp <= 32) { |
| 100 | newPF.bpp = 32; |
| 101 | } else { |
| 102 | return false; |
| 103 | } |
| 104 | newPF.depth = bpp; |
| 105 | |
| 106 | // Calculate the r, g and b bits shifts |
| 107 | switch (rgb_order) { |
| 108 | case RGB_ORDER: |
| 109 | newPF.redShift = gm + bm; |
| 110 | newPF.greenShift = bm; |
| 111 | newPF.blueShift = 0; |
| 112 | break; |
| 113 | case RBG_ORDER: |
| 114 | newPF.redShift = bm + gm; |
| 115 | newPF.blueShift = gm; |
| 116 | newPF.greenShift = 0; |
| 117 | break; |
| 118 | case GRB_ORDER: |
| 119 | newPF.greenShift = rm + bm; |
| 120 | newPF.redShift = bm; |
| 121 | newPF.blueShift = 0; |
| 122 | break; |
| 123 | case GBR_ORDER: |
| 124 | newPF.greenShift = bm + rm; |
| 125 | newPF.blueShift = rm; |
| 126 | newPF.redShift = 0; |
| 127 | break; |
| 128 | case BGR_ORDER: |
| 129 | newPF.blueShift = gm + rm; |
| 130 | newPF.greenShift = rm; |
| 131 | newPF.redShift = 0; |
| 132 | break; |
| 133 | case BRG_ORDER: |
| 134 | newPF.blueShift = rm + gm; |
| 135 | newPF.redShift = gm; |
| 136 | newPF.greenShift = 0; |
| 137 | break; |
| 138 | default: |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | newPF.trueColour = true; |
| 143 | newPF.bigEndian = big_endian; |
| 144 | newPF.redMax = (1 << rm) - 1; |
| 145 | newPF.greenMax = (1 << gm) - 1; |
| 146 | newPF.blueMax = (1 << bm) - 1; |
| 147 | setPF(&newPF); |
| 148 | return true; |
george82 | 5e7af74 | 2005-03-10 14:26:00 +0000 | [diff] [blame] | 149 | } |