1 /*****************************************************************************/ 2 // TGAView 3 // Written by Michael Wilber, Haiku Translation Kit Team 4 // Use of Layout API added by Maxime Simon, maxime.simon@gmail.com, 2009. 5 // 6 // TGAView.cpp 7 // 8 // This BView based object displays information about the TGATranslator. 9 // 10 // 11 // Copyright (c) 2002 Haiku Project 12 // 13 // Permission is hereby granted, free of charge, to any person obtaining a 14 // copy of this software and associated documentation files (the "Software"), 15 // to deal in the Software without restriction, including without limitation 16 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 17 // and/or sell copies of the Software, and to permit persons to whom the 18 // Software is furnished to do so, subject to the following conditions: 19 // 20 // The above copyright notice and this permission notice shall be included 21 // in all copies or substantial portions of the Software. 22 // 23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 // DEALINGS IN THE SOFTWARE. 30 /*****************************************************************************/ 31 32 #include <Catalog.h> 33 #include <LayoutBuilder.h> 34 35 #include <stdio.h> 36 #include <string.h> 37 38 #include "TGAView.h" 39 #include "TGATranslator.h" 40 41 #undef B_TRANSLATION_CONTEXT 42 #define B_TRANSLATION_CONTEXT "TGAView" 43 44 45 TGAView::TGAView(const char *name, uint32 flags, TranslatorSettings *settings) 46 : 47 BView(name, flags), 48 fSettings(settings) 49 { 50 SetViewUIColor(B_PANEL_BACKGROUND_COLOR); 51 52 fTitle = new BStringView("title", B_TRANSLATE("TGA image translator")); 53 fTitle->SetFont(be_bold_font); 54 55 char detail[100]; 56 sprintf(detail, B_TRANSLATE("Version %d.%d.%d, %s"), 57 static_cast<int>(B_TRANSLATION_MAJOR_VERSION(TGA_TRANSLATOR_VERSION)), 58 static_cast<int>(B_TRANSLATION_MINOR_VERSION(TGA_TRANSLATOR_VERSION)), 59 static_cast<int>(B_TRANSLATION_REVISION_VERSION( 60 TGA_TRANSLATOR_VERSION)), __DATE__); 61 fDetail = new BStringView("detail", detail); 62 fWrittenBy = new BStringView("writtenby", 63 B_TRANSLATE("Written by the Haiku Translation Kit Team")); 64 65 fpchkIgnoreAlpha = new BCheckBox(B_TRANSLATE("Ignore TGA alpha channel"), 66 new BMessage(CHANGE_IGNORE_ALPHA)); 67 int32 val = (fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA)) ? 1 : 0; 68 fpchkIgnoreAlpha->SetValue(val); 69 fpchkIgnoreAlpha->SetViewColor(ViewColor()); 70 71 fpchkRLE = new BCheckBox(B_TRANSLATE("Save with RLE compression"), 72 new BMessage(CHANGE_RLE)); 73 val = (fSettings->SetGetBool(TGA_SETTING_RLE)) ? 1 : 0; 74 fpchkRLE->SetValue(val); 75 fpchkRLE->SetViewColor(ViewColor()); 76 77 // Build the layout 78 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 79 .SetInsets(B_USE_DEFAULT_SPACING) 80 .Add(fTitle) 81 .Add(fDetail) 82 .AddGlue() 83 .Add(fpchkIgnoreAlpha) 84 .Add(fpchkRLE) 85 .AddGlue() 86 .Add(fWrittenBy); 87 88 BFont font; 89 GetFont(&font); 90 SetExplicitPreferredSize(BSize((font.Size() * 333)/12, 91 (font.Size() * 200)/12)); 92 } 93 94 95 TGAView::~TGAView() 96 { 97 fSettings->Release(); 98 } 99 100 101 void 102 TGAView::AllAttached() 103 { 104 fpchkIgnoreAlpha->SetTarget(this); 105 fpchkRLE->SetTarget(this); 106 } 107 108 109 void 110 TGAView::MessageReceived(BMessage* message) 111 { 112 switch (message->what) { 113 case CHANGE_IGNORE_ALPHA: 114 { 115 bool ignoreAlpha = fpchkIgnoreAlpha->Value() == B_CONTROL_ON; 116 fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA, &ignoreAlpha); 117 fSettings->SaveSettings(); 118 } break; 119 120 case CHANGE_RLE: 121 { 122 bool saveWithRLE = fpchkRLE->Value() == B_CONTROL_ON; 123 fSettings->SetGetBool(TGA_SETTING_RLE, &saveWithRLE); 124 fSettings->SaveSettings(); 125 } break; 126 127 default: 128 BView::MessageReceived(message); 129 break; 130 } 131 } 132 133