Add text entry to go to frame in the status bar (issue #6).

+ Added a button to create new frames in the status bar.
This commit is contained in:
David Capello 2012-01-09 21:18:32 -03:00
parent b97fb14e0a
commit 917f724861
6 changed files with 108 additions and 9 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

View File

@ -83,6 +83,8 @@
<part id="sunken_focused" x="0" y="48" w1="4" w2="4" w3="4" h1="4" h2="4" h3="4" /> <part id="sunken_focused" x="0" y="48" w1="4" w2="4" w3="4" h1="4" h2="4" h3="4" />
<part id="sunken2_normal" x="0" y="64" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" /> <part id="sunken2_normal" x="0" y="64" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="sunken2_focused" x="0" y="80" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" /> <part id="sunken2_focused" x="0" y="80" w1="5" w2="6" w3="5" h1="5" h2="6" h3="5" />
<part id="sunken_mini_normal" x="16" y="64" w1="4" w2="4" w3="4" h1="4" h2="4" h3="4" />
<part id="sunken_mini_focused" x="16" y="80" w1="4" w2="4" w3="4" h1="4" h2="4" h3="4" />
<part id="window" x="0" y="0" w1="3" w2="7" w3="3" h1="15" h2="4" h3="5" /> <part id="window" x="0" y="0" w1="3" w2="7" w3="3" h1="15" h2="4" h3="5" />
<part id="menu" x="0" y="96" w1="3" w2="10" w3="3" h1="3" h2="9" h3="4" /> <part id="menu" x="0" y="96" w1="3" w2="10" w3="3" h1="3" h2="9" h3="4" />
<part id="window_close_button_normal" x="16" y= "0" w="9" h="11" /> <part id="window_close_button_normal" x="16" y= "0" w="9" h="11" />

View File

@ -120,6 +120,24 @@ enum {
PART_SUNKEN2_FOCUSED_SW, PART_SUNKEN2_FOCUSED_SW,
PART_SUNKEN2_FOCUSED_W, PART_SUNKEN2_FOCUSED_W,
PART_SUNKEN_MINI_NORMAL_NW,
PART_SUNKEN_MINI_NORMAL_N,
PART_SUNKEN_MINI_NORMAL_NE,
PART_SUNKEN_MINI_NORMAL_E,
PART_SUNKEN_MINI_NORMAL_SE,
PART_SUNKEN_MINI_NORMAL_S,
PART_SUNKEN_MINI_NORMAL_SW,
PART_SUNKEN_MINI_NORMAL_W,
PART_SUNKEN_MINI_FOCUSED_NW,
PART_SUNKEN_MINI_FOCUSED_N,
PART_SUNKEN_MINI_FOCUSED_NE,
PART_SUNKEN_MINI_FOCUSED_E,
PART_SUNKEN_MINI_FOCUSED_SE,
PART_SUNKEN_MINI_FOCUSED_S,
PART_SUNKEN_MINI_FOCUSED_SW,
PART_SUNKEN_MINI_FOCUSED_W,
PART_WINDOW_NW, PART_WINDOW_NW,
PART_WINDOW_N, PART_WINDOW_N,
PART_WINDOW_NE, PART_WINDOW_NE,

View File

@ -113,6 +113,8 @@ SkinTheme::SkinTheme()
sheet_mapping["sunken_focused"] = PART_SUNKEN_FOCUSED_NW; sheet_mapping["sunken_focused"] = PART_SUNKEN_FOCUSED_NW;
sheet_mapping["sunken2_normal"] = PART_SUNKEN2_NORMAL_NW; sheet_mapping["sunken2_normal"] = PART_SUNKEN2_NORMAL_NW;
sheet_mapping["sunken2_focused"] = PART_SUNKEN2_FOCUSED_NW; sheet_mapping["sunken2_focused"] = PART_SUNKEN2_FOCUSED_NW;
sheet_mapping["sunken_mini_normal"] = PART_SUNKEN_MINI_NORMAL_NW;
sheet_mapping["sunken_mini_focused"] = PART_SUNKEN_MINI_FOCUSED_NW;
sheet_mapping["window"] = PART_WINDOW_NW; sheet_mapping["window"] = PART_WINDOW_NW;
sheet_mapping["menu"] = PART_MENU_NW; sheet_mapping["menu"] = PART_MENU_NW;
sheet_mapping["window_close_button_normal"] = PART_WINDOW_CLOSE_BUTTON_NORMAL; sheet_mapping["window_close_button_normal"] = PART_WINDOW_CLOSE_BUTTON_NORMAL;
@ -892,10 +894,16 @@ void SkinTheme::paintEntry(PaintEvent& ev)
bg = COLOR_BACKGROUND; bg = COLOR_BACKGROUND;
bool isMiniLook = false;
SharedPtr<SkinProperty> skinPropery = widget->getProperty(SkinProperty::SkinPropertyName);
if (skinPropery != NULL)
isMiniLook = (skinPropery->getLook() == MiniLook);
draw_bounds_nw(ji_screen, draw_bounds_nw(ji_screen,
x1, y1, x2, y2, x1, y1, x2, y2,
widget->hasFocus() ? PART_SUNKEN_FOCUSED_NW: (widget->hasFocus() ?
PART_SUNKEN_NORMAL_NW, bg); (isMiniLook ? PART_SUNKEN_MINI_FOCUSED_NW: PART_SUNKEN_FOCUSED_NW):
(isMiniLook ? PART_SUNKEN_MINI_NORMAL_NW : PART_SUNKEN_NORMAL_NW)), bg);
/* draw the text */ /* draw the text */
x = widget->rc->x1 + widget->border_width.l; x = widget->rc->x1 + widget->border_width.l;

View File

@ -71,6 +71,42 @@ static int statusbar_type()
return type; return type;
} }
// This widget is used to show the current frame.
class GotoFrameEntry : public Entry {
public:
GotoFrameEntry() : Entry(4, "") {
}
bool onProcessMessage(Message* msg) OVERRIDE {
switch (msg->type) {
// When the mouse enter in this entry, it got the focus and the
// text is automatically selected.
case JM_MOUSEENTER:
requestFocus();
selectText(0, -1);
break;
case JM_KEYPRESSED:
if (msg->key.scancode == KEY_ENTER ||
msg->key.scancode == KEY_ENTER_PAD) {
Command* cmd = CommandsModule::instance()->getCommandByName(CommandId::GotoFrame);
Params params;
int frame = strtol(this->getText(), NULL, 10);
if (frame > 0) {
params.set("frame", this->getText());
UIContext::instance()->executeCommand(cmd, &params);
}
// Select the text again
selectText(0, -1);
return true; // Key used.
}
break;
}
return Entry::onProcessMessage(msg);
}
};
StatusBar::StatusBar() StatusBar::StatusBar()
: Widget(statusbar_type()) : Widget(statusbar_type())
, m_color(Color::fromMask()) , m_color(Color::fromMask())
@ -106,9 +142,15 @@ StatusBar::StatusBar()
Box* box1 = new Box(JI_HORIZONTAL); Box* box1 = new Box(JI_HORIZONTAL);
Box* box2 = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS); Box* box2 = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS);
Box* box3 = new Box(JI_HORIZONTAL); Box* box3 = new Box(JI_HORIZONTAL);
Box* box4 = new Box(JI_HORIZONTAL);
m_slider = new Slider(0, 255, 255); m_slider = new Slider(0, 255, 255);
m_currentFrame = new GotoFrameEntry();
m_newFrame = new Button("+");
m_newFrame->Click.connect(Bind<void>(&StatusBar::newFrame, this));
setup_mini_look(m_slider); setup_mini_look(m_slider);
setup_mini_look(m_currentFrame);
setup_mini_look(m_newFrame);
ICON_NEW(m_b_first, PART_ANI_FIRST, ACTION_FIRST); ICON_NEW(m_b_first, PART_ANI_FIRST, ACTION_FIRST);
ICON_NEW(m_b_prev, PART_ANI_PREVIOUS, ACTION_PREV); ICON_NEW(m_b_prev, PART_ANI_PREVIOUS, ACTION_PREV);
@ -124,6 +166,9 @@ StatusBar::StatusBar()
jwidget_noborders(box3); jwidget_noborders(box3);
jwidget_expansive(box3, true); jwidget_expansive(box3, true);
box4->addChild(m_currentFrame);
box4->addChild(m_newFrame);
box2->addChild(m_b_first); box2->addChild(m_b_first);
box2->addChild(m_b_prev); box2->addChild(m_b_prev);
box2->addChild(m_b_play); box2->addChild(m_b_play);
@ -131,6 +176,7 @@ StatusBar::StatusBar()
box2->addChild(m_b_last); box2->addChild(m_b_last);
box1->addChild(box3); box1->addChild(box3);
box1->addChild(box4);
box1->addChild(box2); box1->addChild(box2);
box1->addChild(m_slider); box1->addChild(m_slider);
@ -219,6 +265,9 @@ void StatusBar::clearText()
bool StatusBar::setStatusText(int msecs, const char *format, ...) bool StatusBar::setStatusText(int msecs, const char *format, ...)
{ {
// TODO this call should be in a listener of the "current frame" property changes.
updateCurrentFrame();
if ((ji_clock > m_timeout) || (msecs > 0)) { if ((ji_clock > m_timeout) || (msecs > 0)) {
char buf[256]; // TODO warning buffer overflow char buf[256]; // TODO warning buffer overflow
va_list ap; va_list ap;
@ -606,10 +655,13 @@ bool StatusBar::onProcessMessage(Message* msg)
} }
case JM_MOUSEENTER: { case JM_MOUSEENTER: {
bool state = (UIContext::instance()->getActiveDocument() != NULL); const Document* document = UIContext::instance()->getActiveDocument();
bool state = (document != NULL);
if (!hasChild(m_movePixelsBox)) { if (!hasChild(m_movePixelsBox)) {
if (state && !hasChild(m_commandsBox)) { if (state && !hasChild(m_commandsBox)) {
updateCurrentFrame();
m_b_first->setEnabled(state); m_b_first->setEnabled(state);
m_b_prev->setEnabled(state); m_b_prev->setEnabled(state);
m_b_play->setEnabled(state); m_b_play->setEnabled(state);
@ -830,3 +882,17 @@ void StatusBar::updateFromLayer()
m_slider->setEnabled(false); m_slider->setEnabled(false);
} }
} }
void StatusBar::updateCurrentFrame()
{
const Document* document = UIContext::instance()->getActiveDocument();
if (document)
m_currentFrame->setTextf("%d", document->getSprite()->getCurrentFrame()+1);
}
void StatusBar::newFrame()
{
Command* cmd = CommandsModule::instance()->getCommandByName(CommandId::NewFrame);
UIContext::instance()->executeCommand(cmd);
updateCurrentFrame();
}

View File

@ -32,6 +32,7 @@
class Box; class Box;
class Button; class Button;
class ColorButton; class ColorButton;
class Entry;
class Frame; class Frame;
class Slider; class Slider;
class StatusBar; class StatusBar;
@ -99,6 +100,8 @@ private:
void onCurrentToolChange(); void onCurrentToolChange();
void onTransparentColorChange(); void onTransparentColorChange();
void updateFromLayer(); void updateFromLayer();
void updateCurrentFrame();
void newFrame();
enum State { SHOW_TEXT, SHOW_COLOR, SHOW_TOOL }; enum State { SHOW_TEXT, SHOW_COLOR, SHOW_TOOL };
@ -120,6 +123,8 @@ private:
// Box of main commands // Box of main commands
Widget* m_commandsBox; Widget* m_commandsBox;
Slider* m_slider; // Opacity slider Slider* m_slider; // Opacity slider
Entry* m_currentFrame; // Current frame and go to frame entry
Button* m_newFrame; // Button to create a new frame
Button* m_b_first; // Go to first frame Button* m_b_first; // Go to first frame
Button* m_b_prev; // Go to previous frame Button* m_b_prev; // Go to previous frame
Button* m_b_play; // Play animation Button* m_b_play; // Play animation