Ticket #2837: 2837.diff

File 2837.diff, 5.4 KB (added by maxime.simon, 15 years ago)

Playground now uses a BColorControl instead of multiple BTextControls.

  • src/tests/servers/app/playground/ObjectWindow.cpp

     
    99#include <Box.h>
    1010#include <Button.h>
    1111#include <CheckBox.h>
     12#include <ColorControl.h>
    1213#include <ListItem.h>
    1314#include <ListView.h>
    1415#include <Menu.h>
     
    285286    item->SetMarked(true);
    286287    popupMenu->AddItem(item);
    287288
    288     b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
     289    b.OffsetBy(0, radioButton->Bounds().Height() + 10.0);
    289290    fDrawingModeMF = new BMenuField(b, "drawing mode field", "Mode",
    290291                                    popupMenu);
    291292
    292293    controlGroup->AddChild(fDrawingModeMF);
    293294
    294295    fDrawingModeMF->SetDivider(fDrawingModeMF->StringWidth(fDrawingModeMF->Label()) + 10.0);
    295 
    296     // red text control
    297     b.OffsetBy(0, fDrawingModeMF->Bounds().Height() + 5.0);
    298     fRedTC = new BTextControl(b, "red text control", "Red", "",
    299                               new BMessage(MSG_SET_COLOR));
    300     controlGroup->AddChild(fRedTC);
    301 
    302     // green text control
    303     b.OffsetBy(0, fRedTC->Bounds().Height() + 5.0);
    304     fGreenTC = new BTextControl(b, "green text control", "Green", "",
    305                                 new BMessage(MSG_SET_COLOR));
    306     controlGroup->AddChild(fGreenTC);
    307 
    308     // blue text control
    309     b.OffsetBy(0, fGreenTC->Bounds().Height() + 5.0);
    310     fBlueTC = new BTextControl(b, "blue text control", "Blue", "",
    311                                new BMessage(MSG_SET_COLOR));
    312     controlGroup->AddChild(fBlueTC);
    313 
     296   
     297    // color control
     298    b.OffsetBy(0, fDrawingModeMF->Bounds().Height() + 10.0);
     299    fColorControl = new BColorControl(b.LeftTop(), B_CELLS_16x16, 8, "color control",
     300                                        new BMessage(MSG_SET_COLOR));
     301    controlGroup->AddChild(fColorControl);
     302   
    314303    // alpha text control
    315     b.OffsetBy(0, fBlueTC->Bounds().Height() + 5.0);
     304    b.OffsetBy(0, fColorControl-> Bounds().Height() + 5.0);
    316305    fAlphaTC = new BTextControl(b, "alpha text control", "Alpha", "",
    317306                                new BMessage(MSG_SET_COLOR));
    318307    controlGroup->AddChild(fAlphaTC);
    319308
    320309    // divide text controls the same
    321     float mWidth = fDrawingModeMF->StringWidth(fDrawingModeMF->Label());
    322     float rWidth = fRedTC->StringWidth(fRedTC->Label());
    323     float gWidth = fGreenTC->StringWidth(fGreenTC->Label());
    324     float bWidth = fBlueTC->StringWidth(fBlueTC->Label());
    325     float aWidth = fAlphaTC->StringWidth(fAlphaTC->Label());
    326 
    327     float width = max_c(mWidth, max_c(rWidth, max_c(gWidth, max_c(bWidth, aWidth)))) + 10.0;
     310    float mWidth = fDrawingModeMF->StringWidth(fDrawingModeMF->Label());
     311    float aWidth = fAlphaTC->StringWidth(fAlphaTC->Label());
     312   
     313    float width = max_c(mWidth, aWidth) + 20.0;
    328314    fDrawingModeMF->SetDivider(width);
    329     fRedTC->SetDivider(width);
    330     fGreenTC->SetDivider(width);
    331     fBlueTC->SetDivider(width);
    332315    fAlphaTC->SetDivider(width);
    333316
    334317    // fill check box
     
    355338    b.InsetBy(9.0, 7.0);
    356339    b.left = b.left + b.Width() / 2.0 + 6.0;
    357340    b.right -= B_V_SCROLL_BAR_WIDTH;
    358 b.bottom = fDrawingModeMF->Frame().top - 5.0;
     341    b.bottom = fDrawingModeMF->Frame().top - 10.0;
    359342
    360343    fObjectLV = new ObjectListView(b, "object list", B_SINGLE_SELECTION_LIST);
    361344    fObjectLV->SetSelectionMessage(new BMessage(MSG_OBJECT_SELECTED));
     
    366349                                 B_FANCY_BORDER);
    367350    controlGroup->AddChild(scrollView);
    368351
    369     // add a dummy tab view
    370     b.top = b.bottom + 10.0;
    371     b.right += B_V_SCROLL_BAR_WIDTH;
    372     b.bottom = controlGroup->Bounds().bottom - 7.0;
    373     BTabView* tabView = new BTabView(b, "tab view", B_WIDTH_FROM_WIDEST,
    374                                      B_FOLLOW_ALL, B_FULL_UPDATE_ON_RESIZE |
    375                                      B_WILL_DRAW | B_NAVIGABLE_JUMP |
    376                                      B_FRAME_EVENTS | B_NAVIGABLE);
    377    
    378     BView* tabChild = new TestView(BRect(0, 0, 40, 40), "T", B_FOLLOW_ALL, 0);
    379     tabView->AddTab(tabChild);
    380     tabChild = new TestView(BRect(0, 0, 40, 40), "T", B_FOLLOW_ALL, 0);
    381     tabView->AddTab(tabChild);
    382     tabChild = new BTextControl(BRect(0, 0, 80, 40), "T", "Test", "Text", NULL);
    383     tabView->AddTab(tabChild);
    384     controlGroup->AddChild(tabView);
    385 
    386352    // enforce some size limits
    387353    float minWidth = controlGroup->Frame().Width() + 30.0;
    388354    float minHeight = fPenSizeS->Frame().bottom +
     
    520486    rgb_color c = fObjectView->StateColor();
    521487    char string[32];
    522488
    523     sprintf(string, "%d", c.red);
    524     fRedTC->SetText(string);
    525 
    526     sprintf(string, "%d", c.green);
    527     fGreenTC->SetText(string);
    528 
    529     sprintf(string, "%d", c.blue);
    530     fBlueTC->SetText(string);
    531 
    532489    sprintf(string, "%d", c.alpha);
    533490    fAlphaTC->SetText(string);
     491
     492    fColorControl->SetValue(c);
    534493}
    535494
    536495// _GetColor
     
    538497ObjectWindow::_GetColor() const
    539498{
    540499    rgb_color c;
    541     c.red   = max_c(0, min_c(255, atoi(fRedTC->Text())));
    542     c.green = max_c(0, min_c(255, atoi(fGreenTC->Text())));
    543     c.blue  = max_c(0, min_c(255, atoi(fBlueTC->Text())));
    544     c.alpha = max_c(0, min_c(255, atoi(fAlphaTC->Text())));
    545 
     500   
     501    c = fColorControl->ValueAsColor();
     502    c.alpha = max_c(0, min_c(255, atoi(fAlphaTC->Text())));
     503   
    546504    return c;
    547505}
    548506
  • src/tests/servers/app/playground/ObjectWindow.h

     
    77
    88class BButton;
    99class BCheckBox;
     10class BColorControl;
    1011class BListView;
    1112class BMenuField;
    1213class BTextControl;
     
    3738
    3839    BMenuField*         fDrawingModeMF;
    3940
    40     BTextControl*       fRedTC;
    41     BTextControl*       fGreenTC;
    42     BTextControl*       fBlueTC;
     41    BColorControl*      fColorControl;
    4342    BTextControl*       fAlphaTC;
    4443
    4544    BCheckBox*          fFillCB;