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