xref: /haiku/src/add-ons/translators/tga/TGAView.cpp (revision 445d4fd926c569e7b9ae28017da86280aaecbae2)
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 
89 
90 TGAView::~TGAView()
91 {
92 	fSettings->Release();
93 }
94 
95 
96 void
97 TGAView::AllAttached()
98 {
99 	fpchkIgnoreAlpha->SetTarget(this);
100 	fpchkRLE->SetTarget(this);
101 }
102 
103 
104 void
105 TGAView::MessageReceived(BMessage* message)
106 {
107 	switch (message->what) {
108 		case CHANGE_IGNORE_ALPHA:
109 		{
110 			bool ignoreAlpha = fpchkIgnoreAlpha->Value() == B_CONTROL_ON;
111 			fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA, &ignoreAlpha);
112 			fSettings->SaveSettings();
113 		}	break;
114 
115 		case CHANGE_RLE:
116 		{
117 			bool saveWithRLE = fpchkRLE->Value() == B_CONTROL_ON;
118 			fSettings->SetGetBool(TGA_SETTING_RLE, &saveWithRLE);
119 			fSettings->SaveSettings();
120 		}	break;
121 
122 		default:
123 			BView::MessageReceived(message);
124 			break;
125 	}
126 }
127 
128