コード例 #1
0
void
ToolSelectionWindow::ChangeTool(int32 tool)
{
    if (fSelectionWindow && fSelectionWindow->Lock()) {
        ToolMap::const_iterator it = gToolMap.find(tool);
        if (it != gToolMap.end())
            it->second->SetValue(B_CONTROL_ON);
        fSelectionWindow->Unlock();
    }
}
コード例 #2
0
ToolSelectionWindow::ToolSelectionWindow(BRect frame)
    : BWindow(frame, StringServer::ReturnString(TOOLS_STRING),
              B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_NOT_H_RESIZABLE |
              B_NOT_ZOOMABLE | B_WILL_ACCEPT_FIRST_CLICK | B_AVOID_FRONT)
{
    int32 pictureSize = LARGE_TOOL_ICON_SIZE + 4.0;

    window_feel feel = B_NORMAL_WINDOW_FEEL;
    if (SettingsServer* server = SettingsServer::Instance()) {
        server->SetValue(SettingsServer::Application, skSelectToolWindowVisible,
                         true);

        BMessage settings;
        server->GetApplicationSettings(&settings);
        settings.FindInt32(skSelectToolWindowFeel, (int32*)&feel);
    }

    fMatrixView = new MatrixView(pictureSize, pictureSize, kExtraEdge);

    _AddTool(ToolManager::Instance().ReturnTool(FREE_LINE_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(STRAIGHT_LINE_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(RECTANGLE_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(ELLIPSE_TOOL));

    // Here we could add a separator to the tool window.

    _AddTool(ToolManager::Instance().ReturnTool(BRUSH_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(HAIRY_BRUSH_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(AIR_BRUSH_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(BLUR_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(FILL_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(TEXT_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(TRANSPARENCY_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(ERASER_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(SELECTOR_TOOL));
    _AddTool(ToolManager::Instance().ReturnTool(COLOR_SELECTOR_TOOL));

    ToolMap::iterator it = gToolMap.find(ToolManager::Instance().ReturnActiveToolType());
    if (it != gToolMap.end())
        it->second->SetValue(B_CONTROL_ON);

    AddChild(fMatrixView);
    fMatrixView->ResizeTo(Bounds().Width(), Bounds().Height());

    SetFeel(feel);
    if (feel == B_NORMAL_WINDOW_FEEL)
        SetLook(B_TITLED_WINDOW_LOOK);
    else
        SetLook(B_FLOATING_WINDOW_LOOK);

    float minDimension = 2 * kExtraEdge + pictureSize;
    float maxDimension = 1 + kExtraEdge + fMatrixView->CountChildren() *
                         (pictureSize + kExtraEdge);
    SetSizeLimits(minDimension, maxDimension, minDimension, maxDimension);

    if (Lock()) {
        AddCommonFilter(new BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE,
                                           B_MOUSE_DOWN, window_activation_filter));
        AddCommonFilter(new BMessageFilter(B_KEY_DOWN, AppKeyFilterFunction));
        Unlock();
    }

    Show();

    // NOTE: this is broken/ not implemented in Haiku, so the tools window
    //		 will not show up horizontal as it should be, enable if implemented
    //SetWindowAlignment(B_PIXEL_ALIGNMENT, 0, 0, picture_size + kExtraEdge,
    //	kExtraEdge + 1, 0, 0, picture_size + kExtraEdge, kExtraEdge + 1);

    // remove this if SetWindowAlignment is implemented
    ResizeBy(0.0, maxDimension - pictureSize);

    fSelectionWindow = this;
    FloaterManager::AddFloater(this);
}