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 34 35 #include "TGAView.h" 36 #include "TGATranslator.h" 37 38 39 TGAView::TGAView(const BRect& frame, const char* name, uint32 resize, 40 uint32 flags, TranslatorSettings* settings) 41 : 42 BView(frame, name, resize, flags), 43 fSettings(settings) 44 { 45 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 46 SetLowColor(ViewColor()); 47 48 fpchkIgnoreAlpha = new BCheckBox(BRect(10, 45, 180, 62), 49 "Ignore TGA alpha channel", "Ignore TGA alpha channel", 50 new BMessage(CHANGE_IGNORE_ALPHA)); 51 int32 val = (fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA)) ? 1 : 0; 52 fpchkIgnoreAlpha->SetValue(val); 53 fpchkIgnoreAlpha->SetViewColor(ViewColor()); 54 AddChild(fpchkIgnoreAlpha); 55 fpchkIgnoreAlpha->ResizeToPreferred(); 56 57 fpchkRLE = new BCheckBox(BRect(10, 67, 180, 84), 58 "Save with RLE compression", "Save with RLE compression", 59 new BMessage(CHANGE_RLE)); 60 val = (fSettings->SetGetBool(TGA_SETTING_RLE)) ? 1 : 0; 61 fpchkRLE->SetValue(val); 62 fpchkRLE->SetViewColor(ViewColor()); 63 AddChild(fpchkRLE); 64 fpchkRLE->ResizeToPreferred(); 65 } 66 67 68 TGAView::~TGAView() 69 { 70 fSettings->Release(); 71 } 72 73 74 void 75 TGAView::AllAttached() 76 { 77 fpchkIgnoreAlpha->SetTarget(this); 78 fpchkRLE->SetTarget(this); 79 } 80 81 82 void 83 TGAView::MessageReceived(BMessage* message) 84 { 85 switch (message->what) { 86 case CHANGE_IGNORE_ALPHA: 87 { 88 bool ignoreAlpha = fpchkIgnoreAlpha->Value() == B_CONTROL_ON; 89 fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA, &ignoreAlpha); 90 fSettings->SaveSettings(); 91 } break; 92 93 case CHANGE_RLE: 94 { 95 bool saveWithRLE = fpchkRLE->Value() == B_CONTROL_ON; 96 fSettings->SetGetBool(TGA_SETTING_RLE, &saveWithRLE); 97 fSettings->SaveSettings(); 98 } break; 99 100 default: 101 BView::MessageReceived(message); 102 break; 103 } 104 } 105 106 107 void 108 TGAView::Draw(BRect area) 109 { 110 SetFont(be_bold_font); 111 font_height fh; 112 GetFontHeight(&fh); 113 float xbold, ybold; 114 xbold = fh.descent + 1; 115 ybold = fh.ascent + fh.descent * 2 + fh.leading; 116 117 DrawString("TGA image translator", BPoint(xbold, ybold)); 118 119 SetFont(be_plain_font); 120 font_height plainh; 121 GetFontHeight(&plainh); 122 float yplain; 123 yplain = plainh.ascent + plainh.descent * 2 + plainh.leading; 124 125 char detail[100]; 126 sprintf(detail, "Version %d.%d.%d %s", 127 static_cast<int>(B_TRANSLATION_MAJOR_VERSION(TGA_TRANSLATOR_VERSION)), 128 static_cast<int>(B_TRANSLATION_MINOR_VERSION(TGA_TRANSLATOR_VERSION)), 129 static_cast<int>(B_TRANSLATION_REVISION_VERSION(TGA_TRANSLATOR_VERSION)), 130 __DATE__); 131 DrawString(detail, BPoint(xbold, yplain + ybold)); 132 133 DrawString("Written by the Haiku Translation Kit team", 134 BPoint(xbold, yplain * 7 + ybold)); 135 } 136