Ticket #2117: HVIFandSGI.patch
File HVIFandSGI.patch, 15.0 KB (added by , 14 years ago) |
---|
-
src/add-ons/translators/sgi/SGIView.h
40 40 41 41 class SGIView : public BView { 42 42 public: 43 SGIView(const BRect &frame, const char *name, uint32 resize, 44 uint32 flags, TranslatorSettings *settings); 43 SGIView(const char* name, uint32 flags, TranslatorSettings* settings); 45 44 // sets up the view 46 45 47 46 ~SGIView(); 48 47 // releases the SGITranslator settings 49 48 50 49 virtual void AllAttached(); 51 virtual void AttachedToWindow(); 52 virtual void MessageReceived(BMessage *message); 50 virtual void MessageReceived(BMessage* message); 53 51 54 virtual void Draw(BRect area);55 // draws information about the SGITranslator56 virtual void GetPreferredSize(float* width, float* height);57 58 52 enum { 59 53 MSG_COMPRESSION_CHANGED = 'cmch', 60 54 }; … … 62 56 private: 63 57 BMenuField* fCompressionMF; 64 58 65 TranslatorSettings *fSettings;59 TranslatorSettings* fSettings; 66 60 // the actual settings for the translator, 67 61 // shared with the translator 68 62 }; -
src/add-ons/translators/sgi/SGITranslator.cpp
146 146 // Returns: 147 147 // --------------------------------------------------------------- 148 148 SGITranslator::SGITranslator() 149 : BaseTranslator("SGI images", "SGI image translator", 149 : 150 BaseTranslator("SGI images", "SGI image translator", 150 151 SGI_TRANSLATOR_VERSION, 151 152 gInputFormats, sizeof(gInputFormats) / sizeof(translation_format), 152 153 gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format), … … 732 733 BView * 733 734 SGITranslator::NewConfigView(TranslatorSettings *settings) 734 735 { 735 return new SGIView(BRect(0, 0, 225, 175), "SGITranslator Settings", 736 B_FOLLOW_ALL, B_WILL_DRAW, settings); 736 return new SGIView("SGITranslator Settings", B_WILL_DRAW, settings); 737 737 } -
src/add-ons/translators/sgi/SGIView.cpp
33 33 #include <stdio.h> 34 34 #include <string.h> 35 35 36 #include <GroupLayoutBuilder.h> 36 37 #include <MenuBar.h> 37 38 #include <MenuField.h> 38 39 #include <MenuItem.h> 39 40 #include <PopUpMenu.h> 41 #include <String.h> 42 #include <StringView.h> 43 #include <TextView.h> 40 44 #include <Window.h> 41 45 42 46 #include "SGIImage.h" … … 72 76 // 73 77 // Returns: 74 78 // --------------------------------------------------------------- 75 SGIView::SGIView(const BRect &frame, const char *name,76 uint32 resize, uint32 flags, TranslatorSettings *settings)77 : BView(frame, name, resize, flags),78 79 SGIView::SGIView(const char* name, uint32 flags, TranslatorSettings* settings) 80 : 81 BView(name, flags, new BGroupLayout(B_VERTICAL)), 82 fSettings(settings) 79 83 { 80 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));81 SetLowColor(ViewColor());82 83 84 BPopUpMenu* menu = new BPopUpMenu("pick compression"); 84 85 85 86 uint32 currentCompression = fSettings->SetGetInt32(SGI_SETTING_COMPRESSION); … … 96 97 97 98 // add_menu_item(menu, SGI_COMP_ARLE, "Agressive RLE", currentCompression); 98 99 99 BRect menuFrame = Bounds(); 100 menuFrame.bottom = menuFrame.top + menu->Bounds().Height(); 101 fCompressionMF = new BMenuField(menuFrame, "compression", 102 "Use compression:", menu, true/*, 103 B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP*/); 104 if (fCompressionMF->MenuBar()) 105 fCompressionMF->MenuBar()->ResizeToPreferred(); 106 fCompressionMF->ResizeToPreferred(); 100 fCompressionMF = new BMenuField("compression", "Use compression:", menu); 107 101 108 // figure out where the text ends 109 font_height fh; 110 be_bold_font->GetHeight(&fh); 111 float xbold, ybold; 112 xbold = fh.descent + 1; 113 ybold = fh.ascent + fh.descent * 2 + fh.leading; 102 BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL); 114 103 115 font_height plainh; 116 be_plain_font->GetHeight(&plainh); 117 float yplain; 118 yplain = plainh.ascent + plainh.descent * 2 + plainh.leading; 104 BStringView* titleView = new BStringView("title", "SGI image translator"); 105 titleView->SetFont(be_bold_font); 106 titleView->SetExplicitAlignment(labelAlignment); 119 107 120 // position the menu field below all the text we draw in Draw() 121 BPoint textOffset(0.0, yplain * 2 + ybold); 122 fCompressionMF->MoveTo(textOffset); 108 char detail[100]; 109 sprintf(detail, "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(SGI_TRANSLATOR_VERSION)), 113 __DATE__); 114 BStringView* detailView = new BStringView("details", detail); 115 detailView->SetExplicitAlignment(labelAlignment); 123 116 124 AddChild(fCompressionMF); 117 BTextView* infoView = new BTextView("info"); 118 infoView->SetText(BString("written by:\n") 119 .Append(author) 120 .Append("\n\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 float padding = 5.0f; 129 AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) 130 .Add(titleView) 131 .Add(detailView) 132 .Add(fCompressionMF) 133 .Add(infoView) 134 .AddGlue() 135 .SetInsets(padding, padding, padding, padding) 136 ); 125 137 126 ResizeToPreferred(); 138 BFont font; 139 GetFont(&font); 140 SetExplicitPreferredSize( 141 BSize((font.Size() * 390) / 12, (font.Size() * 180) / 12)); 142 143 // TODO: remove this workaround for ticket #4217 144 infoView->SetExplicitPreferredSize( 145 BSize(infoView->LineWidth(4), infoView->TextHeight(0, 80))); 146 infoView->SetExplicitMaxSize(infoView->ExplicitPreferredSize()); 147 infoView->SetExplicitMinSize(infoView->ExplicitPreferredSize()); 127 148 } 128 149 150 129 151 // --------------------------------------------------------------- 130 152 // Destructor 131 153 // … … 192 214 SGIView::AllAttached() 193 215 { 194 216 fCompressionMF->Menu()->SetTargetForItems(this); 195 fCompressionMF->ResizeToPreferred();196 fCompressionMF->SetDivider(fCompressionMF->StringWidth(fCompressionMF->Label()) + 3);197 217 } 198 218 199 // ---------------------------------------------------------------200 // AttachedToWindow201 //202 // hack to make the window recognize our size203 //204 // Preconditions:205 //206 // Parameters: area, not used207 //208 // Postconditions:209 //210 // Returns:211 // ---------------------------------------------------------------212 void213 SGIView::AttachedToWindow()214 {215 // Hack for DataTranslations which doesn't resize visible area to requested by view216 // which makes some parts of bigger than usual translationviews out of visible area217 // so if it was loaded to DataTranslations resize window if needed218 BWindow *window = Window();219 if (!strcmp(window->Name(), "DataTranslations")) {220 BView *view = Parent();221 if (view) {222 BRect frame = view->Frame();223 float x, y;224 GetPreferredSize(&x, &y);225 if (frame.Width() < x || (frame.Height() - 48) < y) {226 x -= frame.Width();227 y -= frame.Height() - 48;228 if (x < 0) x = 0;229 if (y < 0) y = 0;230 231 // DataTranslations has main view called "Background"232 // change it's resizing mode so it will always resize with window233 // also make sure view will be redrawed after resize234 view = window->FindView("Background");235 if (view) {236 view->SetResizingMode(B_FOLLOW_ALL);237 view->SetFlags(B_FULL_UPDATE_ON_RESIZE);238 }239 240 // The same with "Info..." button, except redrawing, which isn't needed241 view = window->FindView("Info" B_UTF8_ELLIPSIS);242 if (view)243 view->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);244 245 window->ResizeBy( x, y);246 }247 }248 }249 }250 251 // ---------------------------------------------------------------252 // Draw253 //254 // Draws information about the SGITranslator to this view.255 //256 // Preconditions:257 //258 // Parameters: area, not used259 //260 // Postconditions:261 //262 // Returns:263 // ---------------------------------------------------------------264 void265 SGIView::Draw(BRect area)266 {267 SetFont(be_bold_font);268 font_height fh;269 GetFontHeight(&fh);270 float xbold, ybold;271 xbold = fh.descent + 1;272 ybold = fh.ascent + fh.descent * 2 + fh.leading;273 274 const char* text = "SGI image translator";275 DrawString(text, BPoint(xbold, ybold));276 277 SetFont(be_plain_font);278 font_height plainh;279 GetFontHeight(&plainh);280 float yplain;281 yplain = plainh.ascent + plainh.descent * 2 + plainh.leading;282 283 char detail[100];284 sprintf(detail, "Version %d.%d.%d %s",285 static_cast<int>(B_TRANSLATION_MAJOR_VERSION(SGI_TRANSLATOR_VERSION)),286 static_cast<int>(B_TRANSLATION_MINOR_VERSION(SGI_TRANSLATOR_VERSION)),287 static_cast<int>(B_TRANSLATION_REVISION_VERSION(SGI_TRANSLATOR_VERSION)),288 __DATE__);289 DrawString(detail, BPoint(xbold, yplain + ybold));290 291 BPoint offset = fCompressionMF->Frame().LeftBottom();292 offset.x += xbold;293 offset.y += 2 * ybold;294 295 text = "written by:";296 DrawString(text, offset);297 offset.y += ybold;298 299 DrawString(author, offset);300 offset.y += 2 * ybold;301 302 text = "based on GIMP SGI plugin v1.5:";303 DrawString(text, offset);304 offset.y += ybold;305 306 DrawString(kSGICopyright, offset);307 }308 309 // ---------------------------------------------------------------310 // Draw311 //312 // calculated the preferred size of this view313 //314 // Preconditions:315 //316 // Parameters: width and height317 //318 // Postconditions:319 //320 // Returns: in width and height, the preferred size...321 // ---------------------------------------------------------------322 void323 SGIView::GetPreferredSize(float* width, float* height)324 {325 *width = fCompressionMF->Bounds().Width();326 // look at the two biggest strings327 float width1 = StringWidth(kSGICopyright) + 15.0;328 if (*width < width1)329 *width = width1;330 float width2 = be_plain_font->StringWidth(author) + 15.0;331 if (*width < width2)332 *width = width2;333 334 font_height fh;335 be_bold_font->GetHeight(&fh);336 float ybold = fh.ascent + fh.descent * 2 + fh.leading;337 338 *height = fCompressionMF->Bounds().bottom + 7 * ybold;339 } -
src/add-ons/translators/hvif/HVIFTranslator.cpp
169 169 BView * 170 170 HVIFTranslator::NewConfigView(TranslatorSettings *settings) 171 171 { 172 return new HVIFView(BRect(0, 0, 250, 150), "HVIFTranslator Settings", 173 B_FOLLOW_ALL, B_WILL_DRAW, settings); 172 return new HVIFView("HVIFTranslator Settings", B_WILL_DRAW, settings); 174 173 } -
src/add-ons/translators/hvif/HVIFView.cpp
9 9 #include "HVIFView.h" 10 10 #include "HVIFTranslator.h" 11 11 12 #include <GroupLayoutBuilder.h> 12 13 #include <String.h> 13 14 #include <StringView.h> 14 15 … … 17 18 #define HVIF_SETTING_RENDER_SIZE_CHANGED 'rsch' 18 19 19 20 20 HVIFView::HVIFView(const BRect &frame, const char *name, uint32 resizeMode,21 uint32 flags, TranslatorSettings *settings)22 : BView(frame, name, resizeMode, flags),23 21 HVIFView::HVIFView(const char* name, uint32 flags, TranslatorSettings *settings) 22 : 23 BView(name, flags, new BGroupLayout(B_VERTICAL)), 24 fSettings(settings) 24 25 { 25 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));26 BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL); 26 27 27 font_height fontHeight; 28 be_bold_font->GetHeight(&fontHeight); 29 float height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; 30 31 BRect rect(10, 10, 200, 10 + height); 32 BStringView *stringView = new BStringView(rect, "title", 28 BStringView* title= new BStringView("title", 33 29 "Native Haiku icon format translator"); 34 stringView->SetFont(be_bold_font); 35 stringView->ResizeToPreferred(); 36 AddChild(stringView); 30 title->SetFont(be_bold_font); 31 title->SetExplicitAlignment(labelAlignment); 37 32 38 rect.OffsetBy(0, height + 10); 39 char version[256]; 40 snprintf(version, sizeof(version), "Version %d.%d.%d, %s", 33 char versionString[256]; 34 snprintf(versionString, sizeof(versionString), "Version %d.%d.%d, %s", 41 35 int(B_TRANSLATION_MAJOR_VERSION(HVIF_TRANSLATOR_VERSION)), 42 36 int(B_TRANSLATION_MINOR_VERSION(HVIF_TRANSLATOR_VERSION)), 43 37 int(B_TRANSLATION_REVISION_VERSION(HVIF_TRANSLATOR_VERSION)), 44 38 __DATE__); 45 stringView = new BStringView(rect, "version", version); 46 stringView->ResizeToPreferred(); 47 AddChild(stringView); 39 BStringView* version = new BStringView("version", versionString); 40 version->SetExplicitAlignment(labelAlignment); 48 41 49 GetFontHeight(&fontHeight); 50 height = fontHeight.descent + fontHeight.ascent + fontHeight.leading; 51 52 rect.OffsetBy(0, height + 5); 53 stringView = new BStringView(rect, "copyright", 42 BStringView* copyright = new BStringView("copyright", 54 43 B_UTF8_COPYRIGHT"2009 Haiku Inc."); 55 stringView->ResizeToPreferred(); 56 AddChild(stringView); 44 copyright->SetExplicitAlignment(labelAlignment); 57 45 58 rect.OffsetBy(0, height + 5); 46 59 47 int32 renderSize = fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE); 60 48 BString label = "Render size: "; 61 49 label << renderSize; 62 fRenderSize = new BSlider(rect, "renderSize", label.String(), NULL, 1, 32);63 50 64 fRenderSize->ResizeToPreferred(); 51 fRenderSize = new BSlider("renderSize", label.String(), 52 NULL, 1, 32, B_HORIZONTAL); 65 53 fRenderSize->SetValue(renderSize / 8); 66 54 fRenderSize->SetHashMarks(B_HASH_MARKS_BOTTOM); 67 55 fRenderSize->SetHashMarkCount(16); 68 56 fRenderSize->SetModificationMessage( 69 57 new BMessage(HVIF_SETTING_RENDER_SIZE_CHANGED)); 70 AddChild(fRenderSize); 58 fRenderSize->SetExplicitAlignment(labelAlignment); 59 60 float padding = 5.0f; 61 AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) 62 .Add(title) 63 .Add(version) 64 .Add(copyright) 65 .Add(fRenderSize) 66 .AddGlue() 67 .SetInsets(padding, padding, padding, padding) 68 ); 69 70 BFont font; 71 GetFont(&font); 72 SetExplicitPreferredSize( 73 BSize((font.Size() * 270) / 12, (font.Size() * 100) / 12)); 71 74 } 72 75 73 76 77 HVIFView::~HVIFView() 78 { 79 fSettings->Release(); 80 } 81 82 74 83 void 75 84 HVIFView::AttachedToWindow() 76 85 { -
src/add-ons/translators/hvif/HVIFView.h
15 15 16 16 class HVIFView : public BView { 17 17 public: 18 HVIFView(const BRect &frame, const char *name, 19 uint32 resizeMode, uint32 flags, 20 TranslatorSettings *settings); 18 HVIFView(const char *name, uint32 flags, TranslatorSettings *settings); 19 ~HVIFView(); 21 20 22 virtual voidAttachedToWindow();23 virtual voidMessageReceived(BMessage *message);21 virtual void AttachedToWindow(); 22 virtual void MessageReceived(BMessage *message); 24 23 25 24 private: 26 BSlider* fRenderSize;27 TranslatorSettings *fSettings;25 BSlider* fRenderSize; 26 TranslatorSettings* fSettings; 28 27 }; 29 28 30 29 #endif // HVIF_VIEW_H