1 /*****************************************************************************/ 2 // TGAView 3 // Written by Michael Wilber, OBOS Translation Kit Team 4 // 5 // TGAView.cpp 6 // 7 // This BView based object displays information about the TGATranslator. 8 // 9 // 10 // Copyright (c) 2002 OpenBeOS Project 11 // 12 // Permission is hereby granted, free of charge, to any person obtaining a 13 // copy of this software and associated documentation files (the "Software"), 14 // to deal in the Software without restriction, including without limitation 15 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 // and/or sell copies of the Software, and to permit persons to whom the 17 // Software is furnished to do so, subject to the following conditions: 18 // 19 // The above copyright notice and this permission notice shall be included 20 // in all copies or substantial portions of the Software. 21 // 22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 // DEALINGS IN THE SOFTWARE. 29 /*****************************************************************************/ 30 31 #include <stdio.h> 32 #include <string.h> 33 #include "TGAView.h" 34 #include "TGATranslator.h" 35 36 // --------------------------------------------------------------- 37 // Constructor 38 // 39 // Sets up the view settings 40 // 41 // Preconditions: 42 // 43 // Parameters: 44 // 45 // Postconditions: 46 // 47 // Returns: 48 // --------------------------------------------------------------- 49 TGAView::TGAView(const BRect &frame, const char *name, 50 uint32 resize, uint32 flags, TranslatorSettings *settings) 51 : BView(frame, name, resize, flags) 52 { 53 fSettings = settings; 54 55 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 56 SetLowColor(ViewColor()); 57 58 BMessage *pmsg; 59 int32 val; 60 61 pmsg = new BMessage(CHANGE_IGNORE_ALPHA); 62 fpchkIgnoreAlpha = new BCheckBox(BRect(10, 45, 180, 62), 63 "Ignore TGA alpha channel", 64 "Ignore TGA alpha channel", pmsg); 65 val = (fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA)) ? 1 : 0; 66 fpchkIgnoreAlpha->SetValue(val); 67 fpchkIgnoreAlpha->SetViewColor(ViewColor()); 68 AddChild(fpchkIgnoreAlpha); 69 70 pmsg = new BMessage(CHANGE_RLE); 71 fpchkRLE = new BCheckBox(BRect(10, 67, 180, 84), 72 "Save with RLE Compression", 73 "Save with RLE Compression", pmsg); 74 val = (fSettings->SetGetBool(TGA_SETTING_RLE)) ? 1 : 0; 75 fpchkRLE->SetValue(val); 76 fpchkRLE->SetViewColor(ViewColor()); 77 AddChild(fpchkRLE); 78 } 79 80 // --------------------------------------------------------------- 81 // Destructor 82 // 83 // Releases the translator settings 84 // 85 // Preconditions: 86 // 87 // Parameters: 88 // 89 // Postconditions: 90 // 91 // Returns: 92 // --------------------------------------------------------------- 93 TGAView::~TGAView() 94 { 95 fSettings->Release(); 96 } 97 98 // --------------------------------------------------------------- 99 // AllAttached 100 // 101 // 102 // 103 // Preconditions: 104 // 105 // Parameters: 106 // 107 // Postconditions: 108 // 109 // Returns: 110 // --------------------------------------------------------------- 111 void 112 TGAView::AllAttached() 113 { 114 BMessenger msgr(this); 115 fpchkIgnoreAlpha->SetTarget(msgr); 116 fpchkRLE->SetTarget(msgr); 117 } 118 119 // --------------------------------------------------------------- 120 // MessageReceived 121 // 122 // Handles state changes of the RLE setting checkbox 123 // 124 // Preconditions: 125 // 126 // Parameters: message the actual BMessage that was received 127 // 128 // Postconditions: 129 // 130 // Returns: 131 // --------------------------------------------------------------- 132 void 133 TGAView::MessageReceived(BMessage *message) 134 { 135 bool bnewval; 136 switch (message->what) { 137 case CHANGE_IGNORE_ALPHA: 138 if (fpchkIgnoreAlpha->Value()) 139 bnewval = true; 140 else 141 bnewval = false; 142 fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA, &bnewval); 143 fSettings->SaveSettings(); 144 break; 145 146 case CHANGE_RLE: 147 if (fpchkRLE->Value()) 148 bnewval = true; 149 else 150 bnewval = false; 151 fSettings->SetGetBool(TGA_SETTING_RLE, &bnewval); 152 fSettings->SaveSettings(); 153 break; 154 155 default: 156 BView::MessageReceived(message); 157 break; 158 } 159 } 160 161 // --------------------------------------------------------------- 162 // Draw 163 // 164 // Draws information about the TGATranslator to this view. 165 // 166 // Preconditions: 167 // 168 // Parameters: area, not used 169 // 170 // Postconditions: 171 // 172 // Returns: 173 // --------------------------------------------------------------- 174 void 175 TGAView::Draw(BRect area) 176 { 177 SetFont(be_bold_font); 178 font_height fh; 179 GetFontHeight(&fh); 180 float xbold, ybold; 181 xbold = fh.descent + 1; 182 ybold = fh.ascent + fh.descent * 2 + fh.leading; 183 184 char title[] = "TGA Image Translator"; 185 DrawString(title, BPoint(xbold, ybold)); 186 187 SetFont(be_plain_font); 188 font_height plainh; 189 GetFontHeight(&plainh); 190 float yplain; 191 yplain = plainh.ascent + plainh.descent * 2 + plainh.leading; 192 193 char detail[100]; 194 sprintf(detail, "Version %d.%d.%d %s", 195 static_cast<int>(B_TRANSLATION_MAJOR_VERSION(TGA_TRANSLATOR_VERSION)), 196 static_cast<int>(B_TRANSLATION_MINOR_VERSION(TGA_TRANSLATOR_VERSION)), 197 static_cast<int>(B_TRANSLATION_REVISION_VERSION(TGA_TRANSLATOR_VERSION)), 198 __DATE__); 199 DrawString(detail, BPoint(xbold, yplain + ybold)); 200 /* char copyright[] = "© 2002 Haiku Project"; 201 DrawString(copyright, BPoint(xbold, yplain * 2 + ybold)); 202 */ 203 char writtenby[] = "Written by the Haiku Translation Kit Team"; 204 DrawString(writtenby, BPoint(xbold, yplain * 7 + ybold)); 205 } 206