xref: /haiku/src/add-ons/translators/sgi/SGIView.cpp (revision 3ecb7fb4415b319b6aac606551d51efad21037df)
1 /*****************************************************************************/
2 // SGIView
3 // Adopted by Stephan Aßmus, <stippi@yellowbites.com>
4 // from TIFFView written by
5 // Picking the compression method added by Stephan Aßmus, <stippi@yellowbites.com>
6 //
7 // SGIView.cpp
8 //
9 // This BView based object displays information about the SGITranslator.
10 //
11 //
12 // Copyright (c) 2003 OpenBeOS Project
13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 /*****************************************************************************/
32 
33 
34 #include "SGIView.h"
35 
36 #include <stdio.h>
37 #include <string.h>
38 
39 #include <Catalog.h>
40 #include <LayoutBuilder.h>
41 #include <MenuBar.h>
42 #include <MenuField.h>
43 #include <MenuItem.h>
44 #include <PopUpMenu.h>
45 #include <String.h>
46 #include <StringView.h>
47 #include <TextView.h>
48 #include <Window.h>
49 
50 #include "SGIImage.h"
51 #include "SGITranslator.h"
52 
53 
54 const char* author = "Stephan Aßmus, <stippi@yellowbites.com>";
55 
56 #undef B_TRANSLATION_CONTEXT
57 #define B_TRANSLATION_CONTEXT "SGIView"
58 
59 
60 // add_menu_item
61 void
62 add_menu_item(BMenu* menu,
63 			  uint32 compression,
64 			  const char* label,
65 			  uint32 currentCompression)
66 {
67 	BMessage* message = new BMessage(SGIView::MSG_COMPRESSION_CHANGED);
68 	message->AddInt32("value", compression);
69 	BMenuItem* item = new BMenuItem(label, message);
70 	item->SetMarked(currentCompression == compression);
71 	menu->AddItem(item);
72 }
73 
74 
75 SGIView::SGIView(const char* name, uint32 flags, TranslatorSettings* settings)
76 	:
77 	BView(name, flags, new BGroupLayout(B_VERTICAL)),
78 	fSettings(settings)
79 {
80 	BPopUpMenu* menu = new BPopUpMenu("pick compression");
81 
82 	uint32 currentCompression =
83 		fSettings->SetGetInt32(SGI_SETTING_COMPRESSION);
84 	// create the menu items with the various compression methods
85 	add_menu_item(menu, SGI_COMP_NONE, B_TRANSLATE("None"),
86 		currentCompression);
87 	//menu->AddSeparatorItem();
88 	add_menu_item(menu, SGI_COMP_RLE, B_TRANSLATE("RLE"), currentCompression);
89 
90 	// DON'T turn this on, it's so slow that I didn't wait long enough
91 	// the one time I tested this. So I don't know if the code even works.
92 	// Supposedly, this would look for an already written scanline, and
93 	// modify the scanline tables so that the current row is not written
94 	// at all...
95 
96 	//add_menu_item(menu, SGI_COMP_ARLE, "Agressive RLE", currentCompression);
97 
98 	fCompressionMF = new BMenuField("compression",
99 		B_TRANSLATE("Use compression:"), menu);
100 
101 	BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL);
102 
103 	BStringView* titleView = new BStringView("title",
104 		B_TRANSLATE("SGI image translator"));
105 	titleView->SetFont(be_bold_font);
106 	titleView->SetExplicitAlignment(labelAlignment);
107 
108 	char detail[100];
109 	sprintf(detail, B_TRANSLATE("Version %d.%d.%d, %s"),
110 		static_cast<int>(B_TRANSLATION_MAJOR_VERSION(SGI_TRANSLATOR_VERSION)),
111 		static_cast<int>(B_TRANSLATION_MINOR_VERSION(SGI_TRANSLATOR_VERSION)),
112 		static_cast<int>(B_TRANSLATION_REVISION_VERSION(
113 			SGI_TRANSLATOR_VERSION)), __DATE__);
114 	BStringView* detailView = new BStringView("details", detail);
115 	detailView->SetExplicitAlignment(labelAlignment);
116 
117 	BTextView* infoView = new BTextView("info");
118 	infoView->SetText(BString(B_TRANSLATE("written by:\n"))
119 			.Append(author)
120 			.Append(B_TRANSLATE("\nbased on GIMP SGI plugin v1.5:\n"))
121 			.Append(kSGICopyright).String());
122 	infoView->SetExplicitAlignment(labelAlignment);
123 	infoView->SetWordWrap(false);
124 	infoView->MakeEditable(false);
125 	infoView->MakeResizable(true);
126 	infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
127 
128 	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
129 		.SetInsets(B_USE_DEFAULT_SPACING)
130 		.Add(titleView)
131 		.Add(detailView)
132 		.AddGlue()
133 		.AddGroup(B_HORIZONTAL)
134 			.Add(fCompressionMF)
135 			.AddGlue()
136 			.End()
137 		.AddGlue()
138 		.Add(infoView);
139 
140 	BFont font;
141 	GetFont(&font);
142 	SetExplicitPreferredSize(BSize((font.Size() * 390) / 12,
143 		(font.Size() * 180) / 12));
144 
145 	// TODO: remove this workaround for ticket #4217
146 	infoView->SetExplicitPreferredSize(
147 		BSize(infoView->LineWidth(3), infoView->TextHeight(0, 80)));
148 	infoView->SetExplicitMaxSize(infoView->ExplicitPreferredSize());
149 	infoView->SetExplicitMinSize(infoView->ExplicitPreferredSize());
150 }
151 
152 
153 SGIView::~SGIView()
154 {
155 	fSettings->Release();
156 }
157 
158 
159 void
160 SGIView::AllAttached()
161 {
162 	fCompressionMF->Menu()->SetTargetForItems(this);
163 }
164 
165 
166 void
167 SGIView::MessageReceived(BMessage* message)
168 {
169 	switch (message->what) {
170 		case MSG_COMPRESSION_CHANGED: {
171 			int32 value;
172 			if (message->FindInt32("value", &value) >= B_OK) {
173 				fSettings->SetGetInt32(SGI_SETTING_COMPRESSION, &value);
174 				fSettings->SaveSettings();
175 			}
176 			break;
177 		}
178 		default:
179 			BView::MessageReceived(message);
180 	}
181 }
182