xref: /haiku/src/add-ons/translators/sgi/SGIView.cpp (revision 2710b4f5d4251c5cf88c82b0114ea99b0ef46d22)
19949213aSStephan Aßmus /*****************************************************************************/
29949213aSStephan Aßmus // SGIView
39949213aSStephan Aßmus // Adopted by Stephan Aßmus, <stippi@yellowbites.com>
49949213aSStephan Aßmus // from TIFFView written by
59949213aSStephan Aßmus // Picking the compression method added by Stephan Aßmus, <stippi@yellowbites.com>
69949213aSStephan Aßmus //
79949213aSStephan Aßmus // SGIView.cpp
89949213aSStephan Aßmus //
99949213aSStephan Aßmus // This BView based object displays information about the SGITranslator.
109949213aSStephan Aßmus //
119949213aSStephan Aßmus //
12*2ca13760SColdfirex // Copyright (c) 2003 Haiku Project
139949213aSStephan Aßmus //
149949213aSStephan Aßmus // Permission is hereby granted, free of charge, to any person obtaining a
159949213aSStephan Aßmus // copy of this software and associated documentation files (the "Software"),
169949213aSStephan Aßmus // to deal in the Software without restriction, including without limitation
179949213aSStephan Aßmus // the rights to use, copy, modify, merge, publish, distribute, sublicense,
189949213aSStephan Aßmus // and/or sell copies of the Software, and to permit persons to whom the
199949213aSStephan Aßmus // Software is furnished to do so, subject to the following conditions:
209949213aSStephan Aßmus //
219949213aSStephan Aßmus // The above copyright notice and this permission notice shall be included
229949213aSStephan Aßmus // in all copies or substantial portions of the Software.
239949213aSStephan Aßmus //
249949213aSStephan Aßmus // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
259949213aSStephan Aßmus // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
269949213aSStephan Aßmus // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
279949213aSStephan Aßmus // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
289949213aSStephan Aßmus // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
299949213aSStephan Aßmus // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
309949213aSStephan Aßmus // DEALINGS IN THE SOFTWARE.
319949213aSStephan Aßmus /*****************************************************************************/
329949213aSStephan Aßmus 
3344efd205SJohn Scipione 
3444efd205SJohn Scipione #include "SGIView.h"
3544efd205SJohn Scipione 
369949213aSStephan Aßmus #include <stdio.h>
379949213aSStephan Aßmus #include <string.h>
389949213aSStephan Aßmus 
3970d59669SSiarzhuk Zharski #include <Catalog.h>
407d48219bSHannah Boneß #include <LayoutBuilder.h>
419949213aSStephan Aßmus #include <MenuBar.h>
429949213aSStephan Aßmus #include <MenuField.h>
439949213aSStephan Aßmus #include <MenuItem.h>
449949213aSStephan Aßmus #include <PopUpMenu.h>
45c497ec37SStephan Aßmus #include <String.h>
46c497ec37SStephan Aßmus #include <StringView.h>
479949213aSStephan Aßmus #include <Window.h>
489949213aSStephan Aßmus 
499949213aSStephan Aßmus #include "SGIImage.h"
509949213aSStephan Aßmus #include "SGITranslator.h"
5144efd205SJohn Scipione 
529949213aSStephan Aßmus 
539949213aSStephan Aßmus const char* author = "Stephan Aßmus, <stippi@yellowbites.com>";
549949213aSStephan Aßmus 
55546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
56546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "SGIView"
5770d59669SSiarzhuk Zharski 
5844efd205SJohn Scipione 
599949213aSStephan Aßmus // add_menu_item
609949213aSStephan Aßmus void
add_menu_item(BMenu * menu,uint32 compression,const char * label,uint32 currentCompression)619949213aSStephan Aßmus add_menu_item(BMenu* menu,
629949213aSStephan Aßmus 			  uint32 compression,
639949213aSStephan Aßmus 			  const char* label,
649949213aSStephan Aßmus 			  uint32 currentCompression)
659949213aSStephan Aßmus {
669949213aSStephan Aßmus 	BMessage* message = new BMessage(SGIView::MSG_COMPRESSION_CHANGED);
679949213aSStephan Aßmus 	message->AddInt32("value", compression);
689949213aSStephan Aßmus 	BMenuItem* item = new BMenuItem(label, message);
699949213aSStephan Aßmus 	item->SetMarked(currentCompression == compression);
709949213aSStephan Aßmus 	menu->AddItem(item);
719949213aSStephan Aßmus }
729949213aSStephan Aßmus 
7344efd205SJohn Scipione 
SGIView(const char * name,uint32 flags,TranslatorSettings * settings)74c497ec37SStephan Aßmus SGIView::SGIView(const char* name, uint32 flags, TranslatorSettings* settings)
75c497ec37SStephan Aßmus 	:
76c497ec37SStephan Aßmus 	BView(name, flags, new BGroupLayout(B_VERTICAL)),
779949213aSStephan Aßmus 	fSettings(settings)
789949213aSStephan Aßmus {
799949213aSStephan Aßmus 	BPopUpMenu* menu = new BPopUpMenu("pick compression");
809949213aSStephan Aßmus 
8170d59669SSiarzhuk Zharski 	uint32 currentCompression =
8270d59669SSiarzhuk Zharski 		fSettings->SetGetInt32(SGI_SETTING_COMPRESSION);
839949213aSStephan Aßmus 	// create the menu items with the various compression methods
8470d59669SSiarzhuk Zharski 	add_menu_item(menu, SGI_COMP_NONE, B_TRANSLATE("None"),
8570d59669SSiarzhuk Zharski 		currentCompression);
869949213aSStephan Aßmus 	//menu->AddSeparatorItem();
8770d59669SSiarzhuk Zharski 	add_menu_item(menu, SGI_COMP_RLE, B_TRANSLATE("RLE"), currentCompression);
889949213aSStephan Aßmus 
899949213aSStephan Aßmus 	// DON'T turn this on, it's so slow that I didn't wait long enough
909949213aSStephan Aßmus 	// the one time I tested this. So I don't know if the code even works.
919949213aSStephan Aßmus 	// Supposedly, this would look for an already written scanline, and
929949213aSStephan Aßmus 	// modify the scanline tables so that the current row is not written
939949213aSStephan Aßmus 	// at all...
949949213aSStephan Aßmus 
959949213aSStephan Aßmus 	//add_menu_item(menu, SGI_COMP_ARLE, "Agressive RLE", currentCompression);
969949213aSStephan Aßmus 
9770d59669SSiarzhuk Zharski 	fCompressionMF = new BMenuField("compression",
9870d59669SSiarzhuk Zharski 		B_TRANSLATE("Use compression:"), menu);
999949213aSStephan Aßmus 
100c497ec37SStephan Aßmus 	BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL);
1019949213aSStephan Aßmus 
10270d59669SSiarzhuk Zharski 	BStringView* titleView = new BStringView("title",
10370d59669SSiarzhuk Zharski 		B_TRANSLATE("SGI image translator"));
104c497ec37SStephan Aßmus 	titleView->SetFont(be_bold_font);
105c497ec37SStephan Aßmus 	titleView->SetExplicitAlignment(labelAlignment);
1069949213aSStephan Aßmus 
107c497ec37SStephan Aßmus 	char detail[100];
108037bc75eSJanus 	sprintf(detail, B_TRANSLATE("Version %d.%d.%d, %s"),
109c497ec37SStephan Aßmus 		static_cast<int>(B_TRANSLATION_MAJOR_VERSION(SGI_TRANSLATOR_VERSION)),
110c497ec37SStephan Aßmus 		static_cast<int>(B_TRANSLATION_MINOR_VERSION(SGI_TRANSLATOR_VERSION)),
11170d59669SSiarzhuk Zharski 		static_cast<int>(B_TRANSLATION_REVISION_VERSION(
11270d59669SSiarzhuk Zharski 			SGI_TRANSLATOR_VERSION)), __DATE__);
113c497ec37SStephan Aßmus 	BStringView* detailView = new BStringView("details", detail);
114c497ec37SStephan Aßmus 	detailView->SetExplicitAlignment(labelAlignment);
1159949213aSStephan Aßmus 
116800e6fe4SKacper Kasper 	BStringView* infoView = new BStringView("info",
117800e6fe4SKacper Kasper 		BString(B_TRANSLATE("written by:\n"))
118c497ec37SStephan Aßmus 			.Append(author)
1197bfb4a1eSJanus 			.Append(B_TRANSLATE("\nbased on GIMP SGI plugin v1.5:\n"))
120c497ec37SStephan Aßmus 			.Append(kSGICopyright).String());
1219949213aSStephan Aßmus 
122037bc75eSJanus 	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
123037bc75eSJanus 		.SetInsets(B_USE_DEFAULT_SPACING)
124c497ec37SStephan Aßmus 		.Add(titleView)
125c497ec37SStephan Aßmus 		.Add(detailView)
126037bc75eSJanus 		.AddGlue()
127e339efbfSJohn Scipione 		.AddGroup(B_HORIZONTAL)
128c497ec37SStephan Aßmus 			.Add(fCompressionMF)
129e339efbfSJohn Scipione 			.AddGlue()
130e339efbfSJohn Scipione 			.End()
131037bc75eSJanus 		.AddGlue()
132037bc75eSJanus 		.Add(infoView);
1339949213aSStephan Aßmus }
1349949213aSStephan Aßmus 
135c497ec37SStephan Aßmus 
~SGIView()1369949213aSStephan Aßmus SGIView::~SGIView()
1379949213aSStephan Aßmus {
1389949213aSStephan Aßmus 	fSettings->Release();
1399949213aSStephan Aßmus }
1409949213aSStephan Aßmus 
14144efd205SJohn Scipione 
14244efd205SJohn Scipione void
AllAttached()14344efd205SJohn Scipione SGIView::AllAttached()
14444efd205SJohn Scipione {
14544efd205SJohn Scipione 	fCompressionMF->Menu()->SetTargetForItems(this);
14644efd205SJohn Scipione }
14744efd205SJohn Scipione 
14844efd205SJohn Scipione 
1499949213aSStephan Aßmus void
MessageReceived(BMessage * message)1509949213aSStephan Aßmus SGIView::MessageReceived(BMessage* message)
1519949213aSStephan Aßmus {
1529949213aSStephan Aßmus 	switch (message->what) {
1539949213aSStephan Aßmus 		case MSG_COMPRESSION_CHANGED: {
1549949213aSStephan Aßmus 			int32 value;
1559949213aSStephan Aßmus 			if (message->FindInt32("value", &value) >= B_OK) {
1569949213aSStephan Aßmus 				fSettings->SetGetInt32(SGI_SETTING_COMPRESSION, &value);
1579949213aSStephan Aßmus 				fSettings->SaveSettings();
1589949213aSStephan Aßmus 			}
1599949213aSStephan Aßmus 			break;
1609949213aSStephan Aßmus 		}
1619949213aSStephan Aßmus 		default:
1629949213aSStephan Aßmus 			BView::MessageReceived(message);
1639949213aSStephan Aßmus 	}
1649949213aSStephan Aßmus }
165