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 #include <stdio.h> 34 #include <string.h> 35 36 #include <Catalog.h> 37 #include <GroupLayoutBuilder.h> 38 #include <MenuBar.h> 39 #include <MenuField.h> 40 #include <MenuItem.h> 41 #include <PopUpMenu.h> 42 #include <String.h> 43 #include <StringView.h> 44 #include <TextView.h> 45 #include <Window.h> 46 47 #include "SGIImage.h" 48 #include "SGITranslator.h" 49 #include "SGIView.h" 50 51 const char* author = "Stephan Aßmus, <stippi@yellowbites.com>"; 52 53 #undef B_TRANSLATE_CONTEXT 54 #define B_TRANSLATE_CONTEXT "SGIView" 55 56 // add_menu_item 57 void 58 add_menu_item(BMenu* menu, 59 uint32 compression, 60 const char* label, 61 uint32 currentCompression) 62 { 63 BMessage* message = new BMessage(SGIView::MSG_COMPRESSION_CHANGED); 64 message->AddInt32("value", compression); 65 BMenuItem* item = new BMenuItem(label, message); 66 item->SetMarked(currentCompression == compression); 67 menu->AddItem(item); 68 } 69 70 // --------------------------------------------------------------- 71 // Constructor 72 // 73 // Sets up the view settings 74 // 75 // Preconditions: 76 // 77 // Parameters: 78 // 79 // Postconditions: 80 // 81 // Returns: 82 // --------------------------------------------------------------- 83 SGIView::SGIView(const char* name, uint32 flags, TranslatorSettings* settings) 84 : 85 BView(name, flags, new BGroupLayout(B_VERTICAL)), 86 fSettings(settings) 87 { 88 BPopUpMenu* menu = new BPopUpMenu("pick compression"); 89 90 uint32 currentCompression = 91 fSettings->SetGetInt32(SGI_SETTING_COMPRESSION); 92 // create the menu items with the various compression methods 93 add_menu_item(menu, SGI_COMP_NONE, B_TRANSLATE("None"), 94 currentCompression); 95 // menu->AddSeparatorItem(); 96 add_menu_item(menu, SGI_COMP_RLE, B_TRANSLATE("RLE"), currentCompression); 97 98 // DON'T turn this on, it's so slow that I didn't wait long enough 99 // the one time I tested this. So I don't know if the code even works. 100 // Supposedly, this would look for an already written scanline, and 101 // modify the scanline tables so that the current row is not written 102 // at all... 103 104 // add_menu_item(menu, SGI_COMP_ARLE, "Agressive RLE", currentCompression); 105 106 fCompressionMF = new BMenuField("compression", 107 B_TRANSLATE("Use compression:"), menu); 108 109 BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL); 110 111 BStringView* titleView = new BStringView("title", 112 B_TRANSLATE("SGI image translator")); 113 titleView->SetFont(be_bold_font); 114 titleView->SetExplicitAlignment(labelAlignment); 115 116 char detail[100]; 117 sprintf(detail, B_TRANSLATE("Version %d.%d.%d %s"), 118 static_cast<int>(B_TRANSLATION_MAJOR_VERSION(SGI_TRANSLATOR_VERSION)), 119 static_cast<int>(B_TRANSLATION_MINOR_VERSION(SGI_TRANSLATOR_VERSION)), 120 static_cast<int>(B_TRANSLATION_REVISION_VERSION( 121 SGI_TRANSLATOR_VERSION)), __DATE__); 122 BStringView* detailView = new BStringView("details", detail); 123 detailView->SetExplicitAlignment(labelAlignment); 124 125 BTextView* infoView = new BTextView("info"); 126 infoView->SetText(BString(B_TRANSLATE("written by:\n")) 127 .Append(author) 128 .Append(B_TRANSLATE("\n\nbased on GIMP SGI plugin v1.5:\n")) 129 .Append(kSGICopyright).String()); 130 infoView->SetExplicitAlignment(labelAlignment); 131 infoView->SetWordWrap(false); 132 infoView->MakeEditable(false); 133 infoView->MakeResizable(true); 134 infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 135 136 float padding = 5.0f; 137 AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) 138 .Add(titleView) 139 .Add(detailView) 140 .Add(fCompressionMF) 141 .Add(infoView) 142 .AddGlue() 143 .SetInsets(padding, padding, padding, padding) 144 ); 145 146 BFont font; 147 GetFont(&font); 148 SetExplicitPreferredSize( 149 BSize((font.Size() * 390) / 12, (font.Size() * 180) / 12)); 150 151 // TODO: remove this workaround for ticket #4217 152 infoView->SetExplicitPreferredSize( 153 BSize(infoView->LineWidth(4), infoView->TextHeight(0, 80))); 154 infoView->SetExplicitMaxSize(infoView->ExplicitPreferredSize()); 155 infoView->SetExplicitMinSize(infoView->ExplicitPreferredSize()); 156 } 157 158 159 // --------------------------------------------------------------- 160 // Destructor 161 // 162 // Does nothing 163 // 164 // Preconditions: 165 // 166 // Parameters: 167 // 168 // Postconditions: 169 // 170 // Returns: 171 // --------------------------------------------------------------- 172 SGIView::~SGIView() 173 { 174 fSettings->Release(); 175 } 176 177 // --------------------------------------------------------------- 178 // MessageReceived 179 // 180 // Handles state changes of the Compression menu field 181 // 182 // Preconditions: 183 // 184 // Parameters: area, not used 185 // 186 // Postconditions: 187 // 188 // Returns: 189 // --------------------------------------------------------------- 190 void 191 SGIView::MessageReceived(BMessage* message) 192 { 193 switch (message->what) { 194 case MSG_COMPRESSION_CHANGED: { 195 int32 value; 196 if (message->FindInt32("value", &value) >= B_OK) { 197 fSettings->SetGetInt32(SGI_SETTING_COMPRESSION, &value); 198 fSettings->SaveSettings(); 199 } 200 fCompressionMF->ResizeToPreferred(); 201 break; 202 } 203 default: 204 BView::MessageReceived(message); 205 } 206 } 207 208 // --------------------------------------------------------------- 209 // AllAttached 210 // 211 // sets the target for the controls controlling the configuration 212 // 213 // Preconditions: 214 // 215 // Parameters: area, not used 216 // 217 // Postconditions: 218 // 219 // Returns: 220 // --------------------------------------------------------------- 221 void 222 SGIView::AllAttached() 223 { 224 fCompressionMF->Menu()->SetTargetForItems(this); 225 } 226 227