mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-30 22:21:12 +00:00
Add GotoFrame command (like issue #6, but it does not use the status bar).
+ Replaced ScopedPtr defined in gui.h with UniquePtr. + Fix problem in keycombo_get_string() converting keyboard shortcuts with "Alt" modifier.
This commit is contained in:
parent
f91063bcef
commit
b97fb14e0a
@ -58,6 +58,7 @@
|
||||
<key command="GotoPreviousFrame" shortcut="Left" />
|
||||
<key command="GotoNextFrame" shortcut="Right" />
|
||||
<key command="GotoLastFrame" shortcut="End" />
|
||||
<key command="GotoFrame" shortcut="Alt+G" />
|
||||
<key command="PlayAnimation" shortcut="Enter" />
|
||||
<!-- Select -->
|
||||
<key command="MaskAll" shortcut="Ctrl+A" />
|
||||
@ -303,6 +304,8 @@
|
||||
<item command="GotoPreviousFrame" text="&Previous Frame" />
|
||||
<item command="GotoNextFrame" text="&Next Frame" />
|
||||
<item command="GotoLastFrame" text="&Last Frame" />
|
||||
<separator />
|
||||
<item command="GotoFrame" text="&Go to Frame" />
|
||||
</menu>
|
||||
<item command="PlayAnimation" text="&Play Animation" />
|
||||
<separator />
|
||||
|
18
data/widgets/goto_frame.xml
Normal file
18
data/widgets/goto_frame.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<!-- ASEPRITE -->
|
||||
<!-- Copyright (C) 2001-2012 by David Capello -->
|
||||
<jinete>
|
||||
<window text="Go to Frame" name="goto_frame">
|
||||
<grid columns="3">
|
||||
<label text="Frame number:" />
|
||||
<entry expansive="true" maxsize="4" name="frame" magnetic="true" />
|
||||
<box cell_align="horizontal" />
|
||||
|
||||
<separator horizontal="true" cell_hspan="3" />
|
||||
|
||||
<box horizontal="true" homogeneous="true" cell_hspan="3" cell_align="right">
|
||||
<button text="&OK" closewindow="true" name="ok" magnetic="true" minwidth="60" />
|
||||
<button text="&Cancel" closewindow="true" />
|
||||
</box>
|
||||
</grid>
|
||||
</window>
|
||||
</jinete>
|
@ -41,6 +41,13 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
// Constructor with static_cast.
|
||||
template<typename CompatibleT>
|
||||
explicit UniquePtr(CompatibleT* ptr)
|
||||
: m_ptr(static_cast<pointer>(ptr))
|
||||
{
|
||||
}
|
||||
|
||||
// Constructor with customized deleter.
|
||||
UniquePtr(pointer ptr, deleter_type deleter)
|
||||
: m_ptr(ptr)
|
||||
|
@ -19,11 +19,15 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "commands/command.h"
|
||||
#include "modules/gui.h"
|
||||
#include "commands/params.h"
|
||||
#include "document_wrappers.h"
|
||||
#include "gui/frame.h"
|
||||
#include "modules/editors.h"
|
||||
#include "modules/gui.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "widgets/editor/editor.h"
|
||||
#include "document_wrappers.h"
|
||||
|
||||
#include <allegro/unicode.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// goto_first_frame
|
||||
@ -183,6 +187,75 @@ void GotoLastFrameCommand::onExecute(Context* context)
|
||||
current_editor->updateStatusBar();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// goto_frame
|
||||
|
||||
class GotoFrameCommand : public Command
|
||||
|
||||
{
|
||||
public:
|
||||
GotoFrameCommand();
|
||||
Command* clone() { return new GotoFrameCommand(*this); }
|
||||
|
||||
protected:
|
||||
void onLoadParams(Params* params) OVERRIDE;
|
||||
bool onEnabled(Context* context);
|
||||
void onExecute(Context* context);
|
||||
|
||||
private:
|
||||
// The frame to go. 0 is "show the UI dialog", another value is the
|
||||
// frame (1 is the first name for the user).
|
||||
int m_frame;
|
||||
};
|
||||
|
||||
GotoFrameCommand::GotoFrameCommand()
|
||||
: Command("GotoFrame",
|
||||
"Goto Frame",
|
||||
CmdRecordableFlag)
|
||||
, m_frame(0)
|
||||
{
|
||||
}
|
||||
|
||||
void GotoFrameCommand::onLoadParams(Params* params)
|
||||
{
|
||||
std::string frame = params->get("frame");
|
||||
if (!frame.empty()) m_frame = ustrtol(frame.c_str(), NULL, 10);
|
||||
else m_frame = 0;
|
||||
}
|
||||
|
||||
bool GotoFrameCommand::onEnabled(Context* context)
|
||||
{
|
||||
return context->checkFlags(ContextFlags::ActiveDocumentIsReadable);
|
||||
}
|
||||
|
||||
void GotoFrameCommand::onExecute(Context* context)
|
||||
{
|
||||
if (m_frame == 0 && context->isUiAvailable()) {
|
||||
Widget* frame, *ok;
|
||||
FramePtr window(load_widget("goto_frame.xml", "goto_frame"));
|
||||
get_widgets(window,
|
||||
"frame", &frame,
|
||||
"ok", &ok, NULL);
|
||||
|
||||
frame->setTextf("%d", context->getActiveDocument()->getSprite()->getCurrentFrame()+1);
|
||||
|
||||
window->open_window_fg();
|
||||
if (window->get_killer() != ok)
|
||||
return;
|
||||
|
||||
m_frame = strtol(frame->getText(), NULL, 10);
|
||||
}
|
||||
|
||||
ActiveDocumentWriter document(context);
|
||||
Sprite* sprite = document->getSprite();
|
||||
int newFrame = MID(0, m_frame-1, sprite->getTotalFrames()-1);
|
||||
|
||||
sprite->setCurrentFrame(newFrame);
|
||||
|
||||
update_screen_for_document(document);
|
||||
current_editor->updateStatusBar();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// CommandFactory
|
||||
|
||||
@ -205,3 +278,8 @@ Command* CommandFactory::createGotoLastFrameCommand()
|
||||
{
|
||||
return new GotoLastFrameCommand;
|
||||
}
|
||||
|
||||
Command* CommandFactory::createGotoFrameCommand()
|
||||
{
|
||||
return new GotoFrameCommand;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ FOR_EACH_COMMAND(FlattenLayers)
|
||||
FOR_EACH_COMMAND(Flip)
|
||||
FOR_EACH_COMMAND(FrameProperties)
|
||||
FOR_EACH_COMMAND(GotoFirstFrame)
|
||||
FOR_EACH_COMMAND(GotoFrame)
|
||||
FOR_EACH_COMMAND(GotoLastFrame)
|
||||
FOR_EACH_COMMAND(GotoNextFrame)
|
||||
FOR_EACH_COMMAND(GotoNextLayer)
|
||||
|
@ -366,6 +366,9 @@ static void keycombo_get_string(KeyCombo *key, char *buf)
|
||||
if (key->shifts & KB_CTRL_FLAG)
|
||||
ustrcat(buf, "Ctrl+");
|
||||
|
||||
if (key->shifts & KB_ALT_FLAG)
|
||||
ustrcat(buf, "Alt+");
|
||||
|
||||
if (key->shifts & KB_SHIFT_FLAG)
|
||||
ustrcat(buf, "Shift+");
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include "base/exception.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "gui/base.h"
|
||||
#include "gui/accel.h"
|
||||
#include "skin/skin_property.h"
|
||||
@ -133,62 +134,7 @@ void* get_monitor_data(Monitor* monitor);
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Smart Widget* pointer
|
||||
|
||||
template<typename T>
|
||||
class ScopedPtr
|
||||
{
|
||||
T* m_ptr;
|
||||
|
||||
// TODO make this class copyable and count references (so this is
|
||||
// really "smart" pointer)...
|
||||
ScopedPtr(const ScopedPtr&);
|
||||
ScopedPtr& operator=(const ScopedPtr&);
|
||||
|
||||
public:
|
||||
ScopedPtr() {
|
||||
m_ptr = NULL;
|
||||
}
|
||||
|
||||
explicit ScopedPtr(T* widget) {
|
||||
m_ptr = widget;
|
||||
}
|
||||
|
||||
template<typename T2>
|
||||
explicit ScopedPtr(T2* widget) {
|
||||
m_ptr = static_cast<T*>(widget);
|
||||
}
|
||||
|
||||
~ScopedPtr() {
|
||||
delete m_ptr;
|
||||
}
|
||||
|
||||
ScopedPtr& operator=(T* widget) {
|
||||
if (m_ptr)
|
||||
delete m_ptr;
|
||||
|
||||
m_ptr = widget;
|
||||
return *this;
|
||||
}
|
||||
|
||||
operator T*() {
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
T* get() {
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
const T* get() const {
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
T* operator->() {
|
||||
ASSERT(m_ptr != NULL);
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef ScopedPtr<Widget> WidgetPtr;
|
||||
typedef ScopedPtr<Frame> FramePtr;
|
||||
typedef UniquePtr<Widget> WidgetPtr;
|
||||
typedef UniquePtr<Frame> FramePtr;
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user