xref: /haiku/src/add-ons/translators/tga/TGAView.cpp (revision 9ecf9d1c1d4888d341a6eac72112c72d1ae3a4cb)
1 /*****************************************************************************/
2 // TGAView
3 // Written by Michael Wilber, OBOS Translation Kit Team
4 //
5 // TGAView.cpp
6 //
7 // This BView based object displays information about the TGATranslator.
8 //
9 //
10 // Copyright (c) 2002 OpenBeOS Project
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining a
13 // copy of this software and associated documentation files (the "Software"),
14 // to deal in the Software without restriction, including without limitation
15 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 // and/or sell copies of the Software, and to permit persons to whom the
17 // Software is furnished to do so, subject to the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be included
20 // in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 // DEALINGS IN THE SOFTWARE.
29 /*****************************************************************************/
30 
31 #include <stdio.h>
32 #include <string.h>
33 #include "TGAView.h"
34 #include "TGATranslator.h"
35 
36 // ---------------------------------------------------------------
37 // Constructor
38 //
39 // Sets up the view settings
40 //
41 // Preconditions:
42 //
43 // Parameters:
44 //
45 // Postconditions:
46 //
47 // Returns:
48 // ---------------------------------------------------------------
49 TGAView::TGAView(const BRect &frame, const char *name,
50 	uint32 resize, uint32 flags, TranslatorSettings *settings)
51 	:	BView(frame, name, resize, flags)
52 {
53 	fSettings = settings;
54 
55 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
56 
57 	BMessage *pmsg;
58 	int32 val;
59 
60 	pmsg = new BMessage(CHANGE_IGNORE_ALPHA);
61 	fpchkIgnoreAlpha = new BCheckBox(BRect(10, 45, 180, 62),
62 		"Ignore TGA alpha channel",
63 		"Ignore TGA alpha channel", pmsg);
64 	val = (fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA)) ? 1 : 0;
65 	fpchkIgnoreAlpha->SetValue(val);
66 	fpchkIgnoreAlpha->SetViewColor(ViewColor());
67 	AddChild(fpchkIgnoreAlpha);
68 
69 	pmsg = new BMessage(CHANGE_RLE);
70 	fpchkRLE = new BCheckBox(BRect(10, 67, 180, 84),
71 		"Save with RLE Compression",
72 		"Save with RLE Compression", pmsg);
73 	val = (fSettings->SetGetBool(TGA_SETTING_RLE)) ? 1 : 0;
74 	fpchkRLE->SetValue(val);
75 	fpchkRLE->SetViewColor(ViewColor());
76 	AddChild(fpchkRLE);
77 }
78 
79 // ---------------------------------------------------------------
80 // Destructor
81 //
82 // Releases the translator settings
83 //
84 // Preconditions:
85 //
86 // Parameters:
87 //
88 // Postconditions:
89 //
90 // Returns:
91 // ---------------------------------------------------------------
92 TGAView::~TGAView()
93 {
94 	fSettings->Release();
95 }
96 
97 // ---------------------------------------------------------------
98 // AllAttached
99 //
100 //
101 //
102 // Preconditions:
103 //
104 // Parameters:
105 //
106 // Postconditions:
107 //
108 // Returns:
109 // ---------------------------------------------------------------
110 void
111 TGAView::AllAttached()
112 {
113 	BMessenger msgr(this);
114 	fpchkIgnoreAlpha->SetTarget(msgr);
115 	fpchkRLE->SetTarget(msgr);
116 }
117 
118 // ---------------------------------------------------------------
119 // MessageReceived
120 //
121 // Handles state changes of the RLE setting checkbox
122 //
123 // Preconditions:
124 //
125 // Parameters: message	the actual BMessage that was received
126 //
127 // Postconditions:
128 //
129 // Returns:
130 // ---------------------------------------------------------------
131 void
132 TGAView::MessageReceived(BMessage *message)
133 {
134 	bool bnewval;
135 	switch (message->what) {
136 		case CHANGE_IGNORE_ALPHA:
137 			if (fpchkIgnoreAlpha->Value())
138 				bnewval = true;
139 			else
140 				bnewval = false;
141 			fSettings->SetGetBool(TGA_SETTING_IGNORE_ALPHA, &bnewval);
142 			fSettings->SaveSettings();
143 			break;
144 
145 		case CHANGE_RLE:
146 			if (fpchkRLE->Value())
147 				bnewval = true;
148 			else
149 				bnewval = false;
150 			fSettings->SetGetBool(TGA_SETTING_RLE, &bnewval);
151 			fSettings->SaveSettings();
152 			break;
153 
154 		default:
155 			BView::MessageReceived(message);
156 			break;
157 	}
158 }
159 
160 // ---------------------------------------------------------------
161 // Draw
162 //
163 // Draws information about the TGATranslator to this view.
164 //
165 // Preconditions:
166 //
167 // Parameters: area,	not used
168 //
169 // Postconditions:
170 //
171 // Returns:
172 // ---------------------------------------------------------------
173 void
174 TGAView::Draw(BRect area)
175 {
176 	SetFont(be_bold_font);
177 	font_height fh;
178 	GetFontHeight(&fh);
179 	float xbold, ybold;
180 	xbold = fh.descent + 1;
181 	ybold = fh.ascent + fh.descent * 2 + fh.leading;
182 
183 	char title[] = "TGA Image Translator";
184 	DrawString(title, BPoint(xbold, ybold));
185 
186 	SetFont(be_plain_font);
187 	font_height plainh;
188 	GetFontHeight(&plainh);
189 	float yplain;
190 	yplain = plainh.ascent + plainh.descent * 2 + plainh.leading;
191 
192 	char detail[100];
193 	sprintf(detail, "Version %d.%d.%d %s",
194 		static_cast<int>(B_TRANSLATION_MAJOR_VERSION(TGA_TRANSLATOR_VERSION)),
195 		static_cast<int>(B_TRANSLATION_MINOR_VERSION(TGA_TRANSLATOR_VERSION)),
196 		static_cast<int>(B_TRANSLATION_REVISION_VERSION(TGA_TRANSLATOR_VERSION)),
197 		__DATE__);
198 	DrawString(detail, BPoint(xbold, yplain + ybold));
199 /*	char copyright[] = "© 2002 Haiku Project";
200 	DrawString(copyright, BPoint(xbold, yplain * 2 + ybold));
201 */
202 	char writtenby[] = "Written by the Haiku Translation Kit Team";
203 	DrawString(writtenby, BPoint(xbold, yplain * 7 + ybold));
204 }
205