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 Haiku 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 <Window.h> 48 49#include "SGIImage.h" 50#include "SGITranslator.h" 51 52 53const char* author = "Stephan A��mus, <stippi@yellowbites.com>"; 54 55#undef B_TRANSLATION_CONTEXT 56#define B_TRANSLATION_CONTEXT "SGIView" 57 58 59// add_menu_item 60void 61add_menu_item(BMenu* menu, 62 uint32 compression, 63 const char* label, 64 uint32 currentCompression) 65{ 66 BMessage* message = new BMessage(SGIView::MSG_COMPRESSION_CHANGED); 67 message->AddInt32("value", compression); 68 BMenuItem* item = new BMenuItem(label, message); 69 item->SetMarked(currentCompression == compression); 70 menu->AddItem(item); 71} 72 73 74SGIView::SGIView(const char* name, uint32 flags, TranslatorSettings* settings) 75 : 76 BView(name, flags, new BGroupLayout(B_VERTICAL)), 77 fSettings(settings) 78{ 79 BPopUpMenu* menu = new BPopUpMenu("pick compression"); 80 81 uint32 currentCompression = 82 fSettings->SetGetInt32(SGI_SETTING_COMPRESSION); 83 // create the menu items with the various compression methods 84 add_menu_item(menu, SGI_COMP_NONE, B_TRANSLATE("None"), 85 currentCompression); 86 //menu->AddSeparatorItem(); 87 add_menu_item(menu, SGI_COMP_RLE, B_TRANSLATE("RLE"), currentCompression); 88 89 // DON'T turn this on, it's so slow that I didn't wait long enough 90 // the one time I tested this. So I don't know if the code even works. 91 // Supposedly, this would look for an already written scanline, and 92 // modify the scanline tables so that the current row is not written 93 // at all... 94 95 //add_menu_item(menu, SGI_COMP_ARLE, "Agressive RLE", currentCompression); 96 97 fCompressionMF = new BMenuField("compression", 98 B_TRANSLATE("Use compression:"), menu); 99 100 BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL); 101 102 BStringView* titleView = new BStringView("title", 103 B_TRANSLATE("SGI image translator")); 104 titleView->SetFont(be_bold_font); 105 titleView->SetExplicitAlignment(labelAlignment); 106 107 char detail[100]; 108 sprintf(detail, B_TRANSLATE("Version %d.%d.%d, %s"), 109 static_cast<int>(B_TRANSLATION_MAJOR_VERSION(SGI_TRANSLATOR_VERSION)), 110 static_cast<int>(B_TRANSLATION_MINOR_VERSION(SGI_TRANSLATOR_VERSION)), 111 static_cast<int>(B_TRANSLATION_REVISION_VERSION( 112 SGI_TRANSLATOR_VERSION)), __DATE__); 113 BStringView* detailView = new BStringView("details", detail); 114 detailView->SetExplicitAlignment(labelAlignment); 115 116 BStringView* infoView = new BStringView("info", 117 BString(B_TRANSLATE("written by:\n")) 118 .Append(author) 119 .Append(B_TRANSLATE("\nbased on GIMP SGI plugin v1.5:\n")) 120 .Append(kSGICopyright).String()); 121 122 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 123 .SetInsets(B_USE_DEFAULT_SPACING) 124 .Add(titleView) 125 .Add(detailView) 126 .AddGlue() 127 .AddGroup(B_HORIZONTAL) 128 .Add(fCompressionMF) 129 .AddGlue() 130 .End() 131 .AddGlue() 132 .Add(infoView); 133} 134 135 136SGIView::~SGIView() 137{ 138 fSettings->Release(); 139} 140 141 142void 143SGIView::AllAttached() 144{ 145 fCompressionMF->Menu()->SetTargetForItems(this); 146} 147 148 149void 150SGIView::MessageReceived(BMessage* message) 151{ 152 switch (message->what) { 153 case MSG_COMPRESSION_CHANGED: { 154 int32 value; 155 if (message->FindInt32("value", &value) >= B_OK) { 156 fSettings->SetGetInt32(SGI_SETTING_COMPRESSION, &value); 157 fSettings->SaveSettings(); 158 } 159 break; 160 } 161 default: 162 BView::MessageReceived(message); 163 } 164} 165