Implemented issue 260: Scroll-bars for sprite editor

This commit is contained in:
David Capello 2014-01-26 13:28:11 -03:00
parent c2e50acb0b
commit eee1719109
17 changed files with 129 additions and 37 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -213,6 +213,8 @@
<part id="colorbar_border_hotfg" x="32" y="224" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="scrollbar_bg" x="64" y="144" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="scrollbar_thumb" x="64" y="160" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="mini_scrollbar_bg" x="64" y="176" w1="3" w2="2" w3="3" h1="3" h2="2" h3="3" />
<part id="mini_scrollbar_thumb" x="64" y="192" w1="3" w2="2" w3="3" h1="3" h2="2" h3="3" />
<part id="tooltip" x="112" y="64" w1="5" w2="6" w3="5" h1="5" h2="5" h3="6" />
<part id="tooltip_arrow" x="128" y="64" w1="5" w2="6" w3="5" h1="5" h2="5" h3="6" />
<part id="ani_first" x="144" y="192" w="8" h="8" />
@ -312,6 +314,22 @@
<stylesheet>
<!-- scrollbar -->
<style id="scrollbar">
<background color="scrollbar_bg_face" part="scrollbar_bg" />
</style>
<style id="scrollbar_thumb">
<background color="scrollbar_thumb_face" part="scrollbar_thumb" />
</style>
<!-- mini_scrollbar -->
<style id="mini_scrollbar">
<background part="mini_scrollbar_bg" />
</style>
<style id="mini_scrollbar_thumb">
<background part="mini_scrollbar_thumb" />
</style>
<!-- timeline -->
<style id="timeline">
<background color="timeline_normal" part="timeline_normal" />

View File

@ -11,6 +11,7 @@
<separator text="Editor:" horizontal="true" />
<check text="Smooth auto-scroll" id="smooth" />
<check text="Show timeline automatically" id="autotimeline" tooltip="Show the timeline automatically&#10;when a new frame or layer is added." />
<check text="Show scroll-bars in sprite editor" id="show_scrollbars" tooltip="Show scroll-bars in all sprite editors." />
<check text="2 Click Movement" id="move_click2" disabled="true" />
<check text="2 Click Drawing" id="draw_click2" disabled="true" />
<grid columns="2">

View File

@ -70,6 +70,7 @@ void OptionsCommand::onExecute(Context* context)
base::UniquePtr<Window> window(app::load_widget<Window>("options.xml", "options"));
Widget* check_smooth = app::find_widget<Widget>(window, "smooth");
Widget* check_autotimeline = app::find_widget<Widget>(window, "autotimeline");
Widget* show_scrollbars = app::find_widget<Widget>(window, "show_scrollbars");
Widget* move_click2 = app::find_widget<Widget>(window, "move_click2");
Widget* draw_click2 = app::find_widget<Widget>(window, "draw_click2");
Widget* cursor_color_box = app::find_widget<Widget>(window, "cursor_color_box");
@ -90,7 +91,8 @@ void OptionsCommand::onExecute(Context* context)
cursor_color_box->addChild(cursor_color);
// Get global settings for documents
IDocumentSettings* docSettings = context->getSettings()->getDocumentSettings(NULL);
ISettings* settings = context->settings();
IDocumentSettings* docSettings = settings->getDocumentSettings(NULL);
// Grid color
ColorButton* grid_color = new ColorButton(docSettings->getGridColor(), IMAGE_RGB);
@ -115,6 +117,9 @@ void OptionsCommand::onExecute(Context* context)
if (get_config_bool("Options", "AutoShowTimeline", true))
check_autotimeline->setSelected(true);
if (settings->getShowSpriteEditorScrollbars())
show_scrollbars->setSelected(true);
// Checked background size
m_checked_bg->addItem("16x16");
m_checked_bg->addItem("8x8");
@ -158,6 +163,8 @@ void OptionsCommand::onExecute(Context* context)
set_config_bool("Options", "MoveClick2", move_click2->isSelected());
set_config_bool("Options", "DrawClick2", draw_click2->isSelected());
settings->setShowSpriteEditorScrollbars(show_scrollbars->isSelected());
RenderEngine::setCheckedBgType((RenderEngine::CheckedBgType)m_checked_bg->getSelectedItemIndex());
RenderEngine::setCheckedBgZoom(m_checked_bg_zoom->isSelected());
RenderEngine::setCheckedBgColor1(m_checked_bg_color1->getColor());

View File

@ -51,12 +51,13 @@ namespace app {
virtual ~ISettings() { }
// General settings
virtual bool getShowSpriteEditorScrollbars() = 0;
virtual app::Color getFgColor() = 0;
virtual app::Color getBgColor() = 0;
virtual tools::Tool* getCurrentTool() = 0;
virtual app::ColorSwatches* getColorSwatches() = 0;
virtual void setShowSpriteEditorScrollbars(bool state) = 0;
virtual void setFgColor(const app::Color& color) = 0;
virtual void setBgColor(const app::Color& color) = 0;
virtual void setCurrentTool(tools::Tool* tool) = 0;

View File

@ -69,6 +69,7 @@ namespace app {
public:
virtual ~GlobalSettingsObserver() {}
virtual void onSetShowSpriteEditorScrollbars(bool state) {}
virtual void onSetFgColor(app::Color newColor) {}
virtual void onSetBgColor(app::Color newColor) {}
virtual void onSetCurrentTool(tools::Tool* newTool) {}

View File

@ -177,6 +177,7 @@ UISettingsImpl::UISettingsImpl()
, m_globalDocumentSettings(new UIDocumentSettingsImpl)
, m_colorSwatches(NULL)
, m_selectionSettings(new UISelectionSettingsImpl)
, m_showSpriteEditorScrollbars(get_config_bool("Options", "ShowScrollbars", true))
{
m_colorSwatches = new app::ColorSwatches("Default");
for (size_t i=0; i<16; ++i)
@ -206,6 +207,11 @@ UISettingsImpl::~UISettingsImpl()
//////////////////////////////////////////////////////////////////////
// General settings
bool UISettingsImpl::getShowSpriteEditorScrollbars()
{
return m_showSpriteEditorScrollbars;
}
app::Color UISettingsImpl::getFgColor()
{
return ColorBar::instance()->getFgColor();
@ -229,6 +235,13 @@ app::ColorSwatches* UISettingsImpl::getColorSwatches()
return m_colorSwatches;
}
void UISettingsImpl::setShowSpriteEditorScrollbars(bool state)
{
m_showSpriteEditorScrollbars = state;
notifyObservers<bool>(&GlobalSettingsObserver::onSetShowSpriteEditorScrollbars, state);
}
void UISettingsImpl::setFgColor(const app::Color& color)
{
ColorBar::instance()->setFgColor(color);

View File

@ -39,12 +39,13 @@ namespace app {
~UISettingsImpl();
// ISettings implementation
bool getShowSpriteEditorScrollbars() OVERRIDE;
app::Color getFgColor() OVERRIDE;
app::Color getBgColor() OVERRIDE;
tools::Tool* getCurrentTool() OVERRIDE;
app::ColorSwatches* getColorSwatches() OVERRIDE;
void setShowSpriteEditorScrollbars(bool state) OVERRIDE;
void setFgColor(const app::Color& color) OVERRIDE;
void setBgColor(const app::Color& color) OVERRIDE;
void setCurrentTool(tools::Tool* tool) OVERRIDE;
@ -71,6 +72,7 @@ namespace app {
app::ColorSwatches* m_colorSwatches;
std::vector<app::ColorSwatches*> m_colorSwatchesStore;
ISelectionSettings* m_selectionSettings;
bool m_showSpriteEditorScrollbars;
};
} // namespace app

View File

@ -137,7 +137,6 @@ DocumentView::DocumentView(Document* document, Type type)
m_view->attachToView(m_editor);
m_view->setExpansive(true);
m_view->hideScrollBars();
m_editor->setDocumentView(this);
m_document->addObserver(this);

View File

@ -22,9 +22,12 @@
#include "app/ui/editor/editor_view.h"
#include "app/ui/editor/editor.h"
#include "app/modules/editors.h"
#include "app/modules/gui.h"
#include "app/settings/settings.h"
#include "app/ui/editor/editor.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui_context.h"
#include "ui/message.h"
#include "ui/resize_event.h"
@ -46,7 +49,14 @@ EditorView::EditorView(EditorView::Type type)
int b = theme->get_part(PART_EDITOR_SELECTED_S)->h;
jwidget_set_border(this, l, t, r, b);
hideScrollBars();
setupScrollbars();
UIContext::instance()->settings()->addObserver(this);
}
EditorView::~EditorView()
{
UIContext::instance()->settings()->removeObserver(this);
}
bool EditorView::onProcessMessage(Message* msg)
@ -94,4 +104,26 @@ void EditorView::onResize(ResizeEvent& ev)
updateView();
}
void EditorView::onSetShowSpriteEditorScrollbars(bool state)
{
setupScrollbars();
}
void EditorView::setupScrollbars()
{
if (m_type == AlwaysSelected ||
!UIContext::instance()->settings()->getShowSpriteEditorScrollbars())
hideScrollBars();
else {
// TODO hardcoded scroll bar width should be get from skin.xml file
getHorizontalBar()->setBarWidth(6*jguiscale());
getVerticalBar()->setBarWidth(6*jguiscale());
setup_mini_look(getHorizontalBar());
setup_mini_look(getVerticalBar());
showScrollBars();
}
}
} // namespace app

View File

@ -20,20 +20,28 @@
#define APP_UI_EDITOR_VIEW_H_INCLUDED
#include "ui/view.h"
#include "app/settings/settings_observers.h"
namespace app {
class EditorView : public ui::View {
class EditorView : public ui::View,
public GlobalSettingsObserver {
public:
enum Type { CurrentEditorMode, AlwaysSelected };
EditorView(Type type);
~EditorView();
protected:
bool onProcessMessage(ui::Message* msg) OVERRIDE;
void onResize(ui::ResizeEvent& ev) OVERRIDE;
// GlobalSettingsObserver impl
void onSetShowSpriteEditorScrollbars(bool state) OVERRIDE;
private:
void setupScrollbars();
Type m_type;
};

View File

@ -123,8 +123,6 @@ namespace app {
SKIN_PART_NESW(PART_COLORBAR_BORDER_FG),
SKIN_PART_NESW(PART_COLORBAR_BORDER_BG),
SKIN_PART_NESW(PART_COLORBAR_BORDER_HOTFG),
SKIN_PART_NESW(PART_SCROLLBAR_BG),
SKIN_PART_NESW(PART_SCROLLBAR_THUMB),
SKIN_PART_NESW(PART_TOOLTIP),
SKIN_PART_NESW(PART_TOOLTIP_ARROW),

View File

@ -221,8 +221,6 @@ SkinTheme::SkinTheme()
sheet_mapping["colorbar_border_fg"] = PART_COLORBAR_BORDER_FG_NW;
sheet_mapping["colorbar_border_bg"] = PART_COLORBAR_BORDER_BG_NW;
sheet_mapping["colorbar_border_hotfg"] = PART_COLORBAR_BORDER_HOTFG_NW;
sheet_mapping["scrollbar_bg"] = PART_SCROLLBAR_BG_NW;
sheet_mapping["scrollbar_thumb"] = PART_SCROLLBAR_THUMB_NW;
sheet_mapping["tooltip"] = PART_TOOLTIP_NW;
sheet_mapping["tooltip_arrow"] = PART_TOOLTIP_ARROW_NW;
sheet_mapping["ani_first"] = PART_ANI_FIRST;
@ -1721,8 +1719,7 @@ void SkinTheme::paintView(PaintEvent& ev)
Graphics* g = ev.getGraphics();
View* widget = static_cast<View*>(ev.getSource());
// Outside borders
jdraw_rectfill(widget->getBounds(), BGCOLOR);
g->fillRect(BGCOLOR, widget->getClientBounds());
draw_bounds_nw(g, widget->getClientBounds(),
widget->hasFocus() ? PART_SUNKEN_FOCUSED_NW:
@ -1736,13 +1733,19 @@ void SkinTheme::paintViewScrollbar(PaintEvent& ev)
Graphics* g = ev.getGraphics();
int pos, len;
bool isMiniLook = false;
SkinPropertyPtr skinPropery = widget->getProperty(SkinProperty::Name);
if (skinPropery != NULL)
isMiniLook = (skinPropery->getLook() == MiniLook);
skin::Style* bgStyle = get_style(isMiniLook ? "mini_scrollbar": "scrollbar");
skin::Style* thumbStyle = get_style(isMiniLook ? "mini_scrollbar_thumb": "scrollbar_thumb");
widget->getScrollBarThemeInfo(&pos, &len);
gfx::Rect rc = widget->getClientBounds();
draw_bounds_nw(g, rc,
PART_SCROLLBAR_BG_NW,
getColor(ThemeColor::ScrollBarBgFace));
bgStyle->paint(g, rc, NULL, Style::State());
// Horizontal bar
if (widget->getAlign() & JI_HORIZONTAL) {
@ -1755,9 +1758,7 @@ void SkinTheme::paintViewScrollbar(PaintEvent& ev)
rc.h = len;
}
draw_bounds_nw(g, rc,
PART_SCROLLBAR_THUMB_NW,
getColor(ThemeColor::ScrollBarThumbFace));
thumbStyle->paint(g, rc, NULL, Style::State());
}
void SkinTheme::paintViewViewport(PaintEvent& ev)

View File

@ -27,6 +27,7 @@ ScrollBar::ScrollBar(int align)
: Widget(kViewScrollbarWidget)
, m_pos(0)
, m_size(0)
, m_barWidth(getTheme()->scrollbar_size)
{
setAlign(align);
initTheme();
@ -34,8 +35,7 @@ ScrollBar::ScrollBar(int align)
void ScrollBar::setPos(int pos)
{
if (m_pos != pos)
{
if (m_pos != pos) {
m_pos = pos;
invalidate();
}
@ -43,8 +43,7 @@ void ScrollBar::setPos(int pos)
void ScrollBar::setSize(int size)
{
if (m_size != size)
{
if (m_size != size) {
m_size = size;
invalidate();
}

View File

@ -12,11 +12,13 @@
namespace ui {
class ScrollBar : public Widget
{
class ScrollBar : public Widget {
public:
ScrollBar(int align);
int getBarWidth() const { return m_barWidth; }
void setBarWidth(int barWidth) { m_barWidth = barWidth; }
int getPos() const { return m_pos; }
void setPos(int pos);
@ -34,6 +36,7 @@ namespace ui {
private:
void getScrollBarInfo(int* _pos, int* _len, int* _bar_size, int* _viewport_size);
int m_barWidth;
int m_pos;
int m_size;

View File

@ -18,7 +18,8 @@
#include "ui/view.h"
#include "ui/widget.h"
#define BAR_SIZE getTheme()->scrollbar_size
#define HBAR_SIZE (m_scrollbar_h.getBarWidth())
#define VBAR_SIZE (m_scrollbar_v.getBarWidth())
namespace ui {
@ -70,7 +71,12 @@ void View::makeVisibleAllScrollableArea()
void View::hideScrollBars()
{
m_hasBars = false;
updateView();
}
void View::showScrollBars()
{
m_hasBars = true;
updateView();
}
@ -86,7 +92,7 @@ void View::setScrollableSize(const Size& sz)
((sz.w > (m_viewport.getBounds().w \
- m_viewport.border_width.l \
- m_viewport.border_width.r)) && \
(BAR_SIZE < pos.w) && (BAR_SIZE < pos.h))
(VBAR_SIZE < pos.w) && (HBAR_SIZE < pos.h))
m_scrollbar_h.setSize(sz.w);
m_scrollbar_v.setSize(sz.h);
@ -99,45 +105,45 @@ void View::setScrollableSize(const Size& sz)
if (m_hasBars) {
if (CHECK(w, h, l, t, r, b)) {
pos.h -= BAR_SIZE;
pos.h -= HBAR_SIZE;
addChild(&m_scrollbar_h);
if (CHECK(h, w, t, l, b, r)) {
pos.w -= BAR_SIZE;
pos.w -= VBAR_SIZE;
if (CHECK(w, h, l, t, r, b))
addChild(&m_scrollbar_v);
else {
pos.w += BAR_SIZE;
pos.h += BAR_SIZE;
pos.w += VBAR_SIZE;
pos.h += HBAR_SIZE;
removeChild(&m_scrollbar_h);
}
}
}
else if (CHECK(h, w, t, l, b, r)) {
pos.w -= BAR_SIZE;
pos.w -= VBAR_SIZE;
addChild(&m_scrollbar_v);
if (CHECK(w, h, l, t, r, b)) {
pos.h -= BAR_SIZE;
pos.h -= HBAR_SIZE;
if (CHECK(h, w, t, l, b, r))
addChild(&m_scrollbar_h);
else {
pos.w += BAR_SIZE;
pos.h += BAR_SIZE;
pos.w += VBAR_SIZE;
pos.h += HBAR_SIZE;
removeChild(&m_scrollbar_v);
}
}
}
if (hasChild(&m_scrollbar_h)) {
m_scrollbar_h.setBounds(gfx::Rect(pos.x, pos.y2(), pos.w, BAR_SIZE));
m_scrollbar_h.setBounds(gfx::Rect(pos.x, pos.y2(), pos.w, HBAR_SIZE));
m_scrollbar_h.setVisible(true);
}
else
m_scrollbar_h.setVisible(false);
if (hasChild(&m_scrollbar_v)) {
m_scrollbar_v.setBounds(gfx::Rect(pos.x2(), pos.y, BAR_SIZE, pos.h));
m_scrollbar_v.setBounds(gfx::Rect(pos.x2(), pos.y, VBAR_SIZE, pos.h));
m_scrollbar_v.setVisible(true);
}
else

View File

@ -22,9 +22,12 @@ public:
View();
bool hasScrollBars();
ScrollBar* getHorizontalBar() { return &m_scrollbar_h; }
ScrollBar* getVerticalBar() { return &m_scrollbar_v; }
void attachToView(Widget* viewableWidget);
void hideScrollBars();
void showScrollBars();
void makeVisibleAllScrollableArea();
// Returns the maximum viewable size requested by the attached