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 <GroupLayout.h> 33 #include <GroupLayoutBuilder.h> 34 #include <SpaceLayoutItem.h> 35 36 #include <stdio.h> 37 #include <string.h> 38 39 40 #include "TGAView.h" 41 #include "TGATranslator.h" 42 43 44 TGAView::TGAView(const char *name, uint32 flags, TranslatorSettings *settings) 45 : 46 BView(name, flags), 47 fSettings(settings) 48 { 49 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 50 SetLowColor(ViewColor()); 51 52 fTitle = new BStringView("title", "TGA Image Translator"); 53 fTitle->SetFont(be_bold_font); 54 55 char detail[100]; 56 sprintf(detail, "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(TGA_TRANSLATOR_VERSION)), 60 __DATE__); 61 fDetail = new BStringView("detail", detail); 62 fWrittenBy = new BStringView("writtenby", 63 "Written by the Haiku Translation Kit Team"); 64 65 fpchkIgnoreAlpha = new BCheckBox("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("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 SetLayout(new BGroupLayout(B_HORIZONTAL)); 79 80 AddChild(BGroupLayoutBuilder(B_VERTICAL, 7) 81 .Add(fTitle) 82 .Add(fDetail) 83 .AddGlue() 84 .Add(fpchkIgnoreAlpha) 85 .Add(fpchkRLE) 86 .AddGlue() 87 .Add(fWrittenBy) 88 .AddGlue() 89 .SetInsets(5, 5, 5, 5) 90 ); 91 92 BFont font; 93 GetFont(&font); 94 SetExplicitPreferredSize(BSize((font.Size() * 333)/12, (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