Ticket #2117: HVIFandSGI.patch

File HVIFandSGI.patch, 15.0 KB (added by yourpalal, 14 years ago)

modify HVIF and SGI translators to use the Layout API

  • src/add-ons/translators/sgi/SGIView.h

     
    4040
    4141class SGIView : public BView {
    4242public:
    43     SGIView(const BRect &frame, const char *name, uint32 resize,
    44         uint32 flags, TranslatorSettings *settings);
     43    SGIView(const char* name, uint32 flags, TranslatorSettings* settings);
    4544        // sets up the view
    4645       
    4746    ~SGIView();
    4847        // releases the SGITranslator settings
    4948
    5049    virtual void AllAttached();
    51     virtual void AttachedToWindow();
    52     virtual void MessageReceived(BMessage *message);
     50    virtual void MessageReceived(BMessage* message);
    5351
    54     virtual void Draw(BRect area);
    55         // draws information about the SGITranslator
    56     virtual void GetPreferredSize(float* width, float* height);
    57 
    5852    enum {
    5953        MSG_COMPRESSION_CHANGED = 'cmch',
    6054    };
     
    6256private:
    6357    BMenuField*             fCompressionMF;
    6458
    65     TranslatorSettings *fSettings;
     59    TranslatorSettings* fSettings;
    6660        // the actual settings for the translator,
    6761        // shared with the translator
    6862};
  • src/add-ons/translators/sgi/SGITranslator.cpp

     
    146146// Returns:
    147147// ---------------------------------------------------------------
    148148SGITranslator::SGITranslator()
    149     : BaseTranslator("SGI images", "SGI image translator",
     149    :
     150    BaseTranslator("SGI images", "SGI image translator",
    150151        SGI_TRANSLATOR_VERSION,
    151152        gInputFormats, sizeof(gInputFormats) / sizeof(translation_format),
    152153        gOutputFormats, sizeof(gOutputFormats) / sizeof(translation_format),
     
    732733BView *
    733734SGITranslator::NewConfigView(TranslatorSettings *settings)
    734735{
    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);
    737737}
  • src/add-ons/translators/sgi/SGIView.cpp

     
    3333#include <stdio.h>
    3434#include <string.h>
    3535
     36#include <GroupLayoutBuilder.h>
    3637#include <MenuBar.h>
    3738#include <MenuField.h>
    3839#include <MenuItem.h>
    3940#include <PopUpMenu.h>
     41#include <String.h>
     42#include <StringView.h>
     43#include <TextView.h>
    4044#include <Window.h>
    4145
    4246#include "SGIImage.h"
     
    7276//
    7377// Returns:
    7478// ---------------------------------------------------------------
    75 SGIView::SGIView(const BRect &frame, const char *name,
    76     uint32 resize, uint32 flags, TranslatorSettings *settings)
    77     :   BView(frame, name, resize, flags),
    78         fSettings(settings)
     79SGIView::SGIView(const char* name, uint32 flags, TranslatorSettings* settings)
     80    :
     81    BView(name, flags, new BGroupLayout(B_VERTICAL)),
     82    fSettings(settings)
    7983{
    80     SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    81     SetLowColor(ViewColor());
    82 
    8384    BPopUpMenu* menu = new BPopUpMenu("pick compression");
    8485
    8586    uint32 currentCompression = fSettings->SetGetInt32(SGI_SETTING_COMPRESSION);
     
    9697
    9798//  add_menu_item(menu, SGI_COMP_ARLE, "Agressive RLE", currentCompression);
    9899
    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);
    107101
    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);
    114103
    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);
    119107
    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);
    123116
    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    );
    125137
    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());
    127148}
    128149
     150
    129151// ---------------------------------------------------------------
    130152// Destructor
    131153//
     
    192214SGIView::AllAttached()
    193215{
    194216    fCompressionMF->Menu()->SetTargetForItems(this);
    195     fCompressionMF->ResizeToPreferred();
    196     fCompressionMF->SetDivider(fCompressionMF->StringWidth(fCompressionMF->Label()) + 3);
    197217}
    198218
    199 // ---------------------------------------------------------------
    200 // AttachedToWindow
    201 //
    202 // hack to make the window recognize our size
    203 //
    204 // Preconditions:
    205 //
    206 // Parameters: area,    not used
    207 //
    208 // Postconditions:
    209 //
    210 // Returns:
    211 // ---------------------------------------------------------------
    212 void
    213 SGIView::AttachedToWindow()
    214 {
    215     // Hack for DataTranslations which doesn't resize visible area to requested by view
    216     // which makes some parts of bigger than usual translationviews out of visible area
    217     // so if it was loaded to DataTranslations resize window if needed
    218     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 window
    233                 // also make sure view will be redrawed after resize
    234                 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 needed
    241                 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 // Draw
    253 //
    254 // Draws information about the SGITranslator to this view.
    255 //
    256 // Preconditions:
    257 //
    258 // Parameters: area,    not used
    259 //
    260 // Postconditions:
    261 //
    262 // Returns:
    263 // ---------------------------------------------------------------
    264 void
    265 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 // Draw
    311 //
    312 // calculated the preferred size of this view
    313 //
    314 // Preconditions:
    315 //
    316 // Parameters: width and height
    317 //
    318 // Postconditions:
    319 //
    320 // Returns: in width and height, the preferred size...
    321 // ---------------------------------------------------------------
    322 void
    323 SGIView::GetPreferredSize(float* width, float* height)
    324 {
    325     *width = fCompressionMF->Bounds().Width();
    326     // look at the two biggest strings
    327     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

     
    169169BView *
    170170HVIFTranslator::NewConfigView(TranslatorSettings *settings)
    171171{
    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);
    174173}
  • src/add-ons/translators/hvif/HVIFView.cpp

     
    99#include "HVIFView.h"
    1010#include "HVIFTranslator.h"
    1111
     12#include <GroupLayoutBuilder.h>
    1213#include <String.h>
    1314#include <StringView.h>
    1415
     
    1718#define HVIF_SETTING_RENDER_SIZE_CHANGED    'rsch'
    1819
    1920
    20 HVIFView::HVIFView(const BRect &frame, const char *name, uint32 resizeMode,
    21     uint32 flags, TranslatorSettings *settings)
    22     :   BView(frame, name, resizeMode, flags),
    23         fSettings(settings)
     21HVIFView::HVIFView(const char* name, uint32 flags, TranslatorSettings *settings)
     22    :
     23    BView(name, flags, new BGroupLayout(B_VERTICAL)),
     24    fSettings(settings)
    2425{
    25     SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
     26    BAlignment labelAlignment(B_ALIGN_LEFT, B_ALIGN_NO_VERTICAL);
    2627
    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",
    3329        "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);
    3732
    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",
    4135        int(B_TRANSLATION_MAJOR_VERSION(HVIF_TRANSLATOR_VERSION)),
    4236        int(B_TRANSLATION_MINOR_VERSION(HVIF_TRANSLATOR_VERSION)),
    4337        int(B_TRANSLATION_REVISION_VERSION(HVIF_TRANSLATOR_VERSION)),
    4438        __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);
    4841
    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",
    5443        B_UTF8_COPYRIGHT"2009 Haiku Inc.");
    55     stringView->ResizeToPreferred();
    56     AddChild(stringView);
     44    copyright->SetExplicitAlignment(labelAlignment);
    5745
    58     rect.OffsetBy(0, height + 5);
     46
    5947    int32 renderSize = fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE);
    6048    BString label = "Render size: ";
    6149    label << renderSize;
    62     fRenderSize = new BSlider(rect, "renderSize", label.String(), NULL, 1, 32);
    6350
    64     fRenderSize->ResizeToPreferred();
     51    fRenderSize = new BSlider("renderSize", label.String(),
     52        NULL, 1, 32, B_HORIZONTAL);
    6553    fRenderSize->SetValue(renderSize / 8);
    6654    fRenderSize->SetHashMarks(B_HASH_MARKS_BOTTOM);
    6755    fRenderSize->SetHashMarkCount(16);
    6856    fRenderSize->SetModificationMessage(
    6957        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));
    7174}
    7275
    7376
     77HVIFView::~HVIFView()
     78{
     79    fSettings->Release();
     80}
     81
     82
    7483void
    7584HVIFView::AttachedToWindow()
    7685{
  • src/add-ons/translators/hvif/HVIFView.h

     
    1515
    1616class HVIFView : public BView {
    1717public:
    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();
    2120
    22 virtual void                AttachedToWindow();
    23 virtual void                MessageReceived(BMessage *message);
     21    virtual void    AttachedToWindow();
     22    virtual void    MessageReceived(BMessage *message);
    2423
    2524private:
    26         BSlider *           fRenderSize;
    27         TranslatorSettings *fSettings;
     25    BSlider*            fRenderSize;
     26    TranslatorSettings* fSettings;
    2827};
    2928
    3029#endif  // HVIF_VIEW_H