1 /*****************************************************************************/ 2 // TGAView 3 // Written by Michael Wilber, OBOS 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 OpenBeOS 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 #include <SpaceLayoutItem.h> 35 36 #include <stdio.h> 37 #include <string.h> 38 39 #include "TGAView.h" 40 #include "TGATranslator.h" 41 42 #undef B_TRANSLATION_CONTEXT 43 #define B_TRANSLATION_CONTEXT "TGAView" 44 45 46 TGAView::TGAView(const char *name, uint32 flags, TranslatorSettings *settings) 47 : 48 BView(name, flags), 49 fSettings(settings) 50 { 51 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 52 SetLowColor(ViewColor()); 53 54 fTitle = new BStringView("title", B_TRANSLATE("TGA image translator")); 55 fTitle->SetFont(be_bold_font); 56 57 char detail[100]; 58 sprintf(detail, B_TRANSLATE("Version %d.%d.%d %s"), 59 static_cast<int>(B_TRANSLATION_MAJOR_VERSION(TGA_TRANSLATOR_VERSION)), 60 static_cast<int>(B_TRANSLATION_MINOR_VERSION(TGA_TRANSLATOR_VERSION)), 61 static_cast<int>(B_TRANSLATION_REVISION_VERSION( 62 TGA_TRANSLATOR_VERSION)), __DATE__); 63 fDetail = new BStringView("detail", detail); 64 fWrittenBy = new BStringView("writtenby", 65 B_TRANSLATE("Written by the Haiku Translation Kit Team")); 66 67 fpchkIgnoreAlpha = new BCheckBox(B_TRANSLATE("Ignore TGA alpha channel"), 68 new BMessage(CHANGE_IGNORE_ALPHA)); 69 int32 val = (fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA)) ? 1 : 0; 70 fpchkIgnoreAlpha->SetValue(val); 71 fpchkIgnoreAlpha->SetViewColor(ViewColor()); 72 73 fpchkRLE = new BCheckBox(B_TRANSLATE("Save with RLE Compression"), 74 new BMessage(CHANGE_RLE)); 75 val = (fSettings->SetGetBool(TGA_SETTING_RLE)) ? 1 : 0; 76 fpchkRLE->SetValue(val); 77 fpchkRLE->SetViewColor(ViewColor()); 78 79 // Build the layout 80 BLayoutBuilder::Group<>(this, B_VERTICAL, 7) 81 .SetInsets(5) 82 .Add(fTitle) 83 .Add(fDetail) 84 .AddGlue() 85 .Add(fpchkIgnoreAlpha) 86 .Add(fpchkRLE) 87 .AddGlue() 88 .Add(fWrittenBy) 89 .AddGlue(); 90 91 BFont font; 92 GetFont(&font); 93 SetExplicitPreferredSize(BSize((font.Size() * 333)/12, 94 (font.Size() * 200)/12)); 95 } 96 97 98 TGAView::~TGAView() 99 { 100 fSettings->Release(); 101 } 102 103 104 void 105 TGAView::AllAttached() 106 { 107 fpchkIgnoreAlpha->SetTarget(this); 108 fpchkRLE->SetTarget(this); 109 } 110 111 112 void 113 TGAView::MessageReceived(BMessage* message) 114 { 115 switch (message->what) { 116 case CHANGE_IGNORE_ALPHA: 117 { 118 bool ignoreAlpha = fpchkIgnoreAlpha->Value() == B_CONTROL_ON; 119 fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA, &ignoreAlpha); 120 fSettings->SaveSettings(); 121 } break; 122 123 case CHANGE_RLE: 124 { 125 bool saveWithRLE = fpchkRLE->Value() == B_CONTROL_ON; 126 fSettings->SetGetBool(TGA_SETTING_RLE, &saveWithRLE); 127 fSettings->SaveSettings(); 128 } break; 129 130 default: 131 BView::MessageReceived(message); 132 break; 133 } 134 } 135 136