mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-01 18:00:26 +00:00
Add Timeline visibility button to Toolbar, extracted button draw logic to separate member function
This commit is contained in:
parent
27ec013f8b
commit
4f73b14f8f
@ -2120,6 +2120,8 @@ jumble = Jumble Tool
|
||||
shortcut = Shortcut: {0}
|
||||
preview_hide = Hide Preview
|
||||
preview_show = Show Preview
|
||||
timeline_hide = Hide Timeline
|
||||
timeline_show = Show Timeline
|
||||
|
||||
[undo_history]
|
||||
title = Undo History
|
||||
|
@ -156,6 +156,14 @@ bool ToolBar::onProcessMessage(Message* msg)
|
||||
bool state = preview->isPreviewEnabled();
|
||||
preview->setPreviewEnabled(!state);
|
||||
}
|
||||
|
||||
toolrc = getToolGroupBounds(TimelineVisibilityIndex);
|
||||
if (mousePos.y >= toolrc.y &&
|
||||
mousePos.y < toolrc.y + toolrc.h) {
|
||||
// Toggle timeline visibility
|
||||
bool state = App::instance()->mainWindow()->getTimelineVisibility();
|
||||
App::instance()->mainWindow()->setTimelineVisibility(!state);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -193,6 +201,12 @@ bool ToolBar::onProcessMessage(Message* msg)
|
||||
new_hot_index = PreviewVisibilityIndex;
|
||||
}
|
||||
|
||||
toolrc = getToolGroupBounds(TimelineVisibilityIndex);
|
||||
if (mousePos.y >= toolrc.y &&
|
||||
mousePos.y < toolrc.y + toolrc.h) {
|
||||
new_hot_index = TimelineVisibilityIndex;
|
||||
}
|
||||
|
||||
// hot button changed
|
||||
if (new_hot_tool != m_hotTool ||
|
||||
new_hot_index != m_hotIndex) {
|
||||
@ -299,13 +313,14 @@ void ToolBar::onPaint(ui::PaintEvent& ev)
|
||||
ToolGroupList::iterator it = toolbox->begin_group();
|
||||
int groups = toolbox->getGroupsCount();
|
||||
Rect toolrc;
|
||||
SkinPartPtr nw;
|
||||
os::Surface* icon;
|
||||
|
||||
g->fillRect(theme->colors.tabActiveFace(), bounds);
|
||||
|
||||
for (int c=0; c<groups; ++c, ++it) {
|
||||
ToolGroup* tool_group = *it;
|
||||
Tool* tool = m_selectedInGroup[tool_group];
|
||||
SkinPartPtr nw;
|
||||
|
||||
if (activeTool == tool || m_hotIndex == c) {
|
||||
nw = theme->parts.toolbuttonHot();
|
||||
@ -315,36 +330,28 @@ void ToolBar::onPaint(ui::PaintEvent& ev)
|
||||
theme->parts.toolbuttonLast();
|
||||
}
|
||||
|
||||
toolrc = getToolGroupBounds(c);
|
||||
toolrc.offset(-origin());
|
||||
theme->drawRect(g, toolrc, nw.get());
|
||||
|
||||
// Draw the tool icon
|
||||
os::Surface* icon = theme->getToolIcon(tool->getId().c_str());
|
||||
if (icon) {
|
||||
g->drawRgbaSurface(icon,
|
||||
CALC_FOR_CENTER(toolrc.x, toolrc.w, icon->width()),
|
||||
CALC_FOR_CENTER(toolrc.y, toolrc.h, icon->height()));
|
||||
}
|
||||
icon = theme->getToolIcon(tool->getId().c_str());
|
||||
drawToolIcon(g, c, nw, icon);
|
||||
}
|
||||
|
||||
// Draw button to show/hide preview
|
||||
toolrc = getToolGroupBounds(PreviewVisibilityIndex);
|
||||
toolrc.offset(-origin());
|
||||
bool isHot = (m_hotIndex == PreviewVisibilityIndex ||
|
||||
App::instance()->mainWindow()->getPreviewEditor()->isPreviewEnabled());
|
||||
theme->drawRect(
|
||||
g,
|
||||
toolrc,
|
||||
(isHot ? theme->parts.toolbuttonHot().get():
|
||||
theme->parts.toolbuttonLast().get()));
|
||||
nw = isHot ? theme->parts.toolbuttonHot():
|
||||
theme->parts.toolbuttonLast();
|
||||
icon = theme->getToolIcon("minieditor");
|
||||
|
||||
os::Surface* icon = theme->getToolIcon("minieditor");
|
||||
if (icon) {
|
||||
g->drawRgbaSurface(icon,
|
||||
CALC_FOR_CENTER(toolrc.x, toolrc.w, icon->width()),
|
||||
CALC_FOR_CENTER(toolrc.y, toolrc.h, icon->height()));
|
||||
}
|
||||
drawToolIcon(g, PreviewVisibilityIndex, nw, icon);
|
||||
|
||||
// Draw button to show/hide timeline
|
||||
isHot = (m_hotIndex == TimelineVisibilityIndex ||
|
||||
App::instance()->mainWindow()->getTimelineVisibility());
|
||||
nw = isHot ? theme->parts.toolbuttonHot():
|
||||
theme->parts.toolbuttonLast();
|
||||
icon = theme->getToolIcon("minieditor");
|
||||
|
||||
drawToolIcon(g, TimelineVisibilityIndex, nw, icon);
|
||||
}
|
||||
|
||||
void ToolBar::onVisible(bool visible)
|
||||
@ -457,6 +464,11 @@ Rect ToolBar::getToolGroupBounds(int group_index)
|
||||
rc.h = iconsize.h+2*guiscale();
|
||||
break;
|
||||
|
||||
case TimelineVisibilityIndex:
|
||||
rc.y += rc.h - iconsize.h - iconsize.h - 2*guiscale();
|
||||
rc.h = iconsize.h+2*guiscale();
|
||||
break;
|
||||
|
||||
default:
|
||||
rc.y += group_index*(iconsize.h-1*guiscale());
|
||||
rc.h = group_index < groups-1 ? iconsize.h+1*guiscale():
|
||||
@ -517,6 +529,12 @@ void ToolBar::openTipWindow(int group_index, Tool* tool)
|
||||
else
|
||||
tooltip = Strings::tools_preview_show();
|
||||
}
|
||||
else if (group_index == TimelineVisibilityIndex) {
|
||||
if (App::instance()->mainWindow()->getTimelineVisibility())
|
||||
tooltip = Strings::tools_timeline_hide();
|
||||
else
|
||||
tooltip = Strings::tools_timeline_show();
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
@ -586,6 +604,20 @@ void ToolBar::onClosePopup()
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void ToolBar::drawToolIcon(Graphics* g, int group_index, SkinPartPtr skin, os::Surface* icon) {
|
||||
auto theme = SkinTheme::get(this);
|
||||
Rect toolrc = getToolGroupBounds(group_index);
|
||||
toolrc.offset(-origin());
|
||||
|
||||
theme->drawRect(g, toolrc, skin.get());
|
||||
|
||||
if (icon) {
|
||||
g->drawRgbaSurface(icon,
|
||||
CALC_FOR_CENTER(toolrc.x, toolrc.w, icon->width()),
|
||||
CALC_FOR_CENTER(toolrc.y, toolrc.h, icon->height()));
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// ToolStrip
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "app/tools/active_tool_observer.h"
|
||||
#include "app/ui/skin/skin_part.h"
|
||||
#include "gfx/point.h"
|
||||
#include "obs/connection.h"
|
||||
#include "ui/timer.h"
|
||||
@ -37,6 +38,7 @@ namespace app {
|
||||
|
||||
static const int NoneIndex = -1;
|
||||
static const int PreviewVisibilityIndex = -2;
|
||||
static const int TimelineVisibilityIndex = -3;
|
||||
|
||||
ToolBar();
|
||||
~ToolBar();
|
||||
@ -62,6 +64,7 @@ namespace app {
|
||||
gfx::Point getToolPositionInGroup(int group_index, tools::Tool* tool);
|
||||
void openTipWindow(int group_index, tools::Tool* tool);
|
||||
void onClosePopup();
|
||||
void drawToolIcon(ui::Graphics* g, int group_index, skin::SkinPartPtr skin, os::Surface* icon);
|
||||
|
||||
// ActiveToolObserver impl
|
||||
void onActiveToolChange(tools::Tool* tool) override;
|
||||
|
Loading…
Reference in New Issue
Block a user