mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-18 07:21:09 +00:00
Show the clipboard image size as default size in NewFileCommand.
This commit is contained in:
parent
c359e8585e
commit
0a88e797f4
@ -35,6 +35,7 @@
|
||||
#include "raster/palette.h"
|
||||
#include "raster/sprite.h"
|
||||
#include "ui_context.h"
|
||||
#include "util/clipboard.h"
|
||||
#include "widgets/color_bar.h"
|
||||
|
||||
#include <allegro/config.h>
|
||||
@ -98,6 +99,14 @@ void NewFileCommand::onExecute(Context* context)
|
||||
bg = get_config_int("NewSprite", "Background", 4); // Default = Background color
|
||||
ncolors = get_config_int("NewSprite", "Colors", 256);
|
||||
|
||||
// If the clipboard contains an image, we can show the size of the
|
||||
// clipboard as default image size.
|
||||
gfx::Size clipboardSize;
|
||||
if (clipboard::get_image_size(clipboardSize)) {
|
||||
w = clipboardSize.w;
|
||||
h = clipboardSize.h;
|
||||
}
|
||||
|
||||
width->setTextf("%d", MAX(1, w));
|
||||
height->setTextf("%d", MAX(1, h));
|
||||
colors->setTextf("%d", MID(2, ncolors, 256));
|
||||
|
@ -198,3 +198,20 @@ void clipboard::paste()
|
||||
if (src_image != clipboard_image)
|
||||
image_free(src_image);
|
||||
}
|
||||
|
||||
bool clipboard::get_image_size(gfx::Size& size)
|
||||
{
|
||||
#ifdef ALLEGRO_WINDOWS
|
||||
// Get the image from the clipboard.
|
||||
return get_win32_clipboard_bitmap_size(size);
|
||||
#else
|
||||
if (clipboard_image != NULL) {
|
||||
size.w = clipboard_image->w;
|
||||
size.h = clipboard_image->h;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#ifndef UTIL_CLIPBOARD_H_INCLUDED
|
||||
#define UTIL_CLIPBOARD_H_INCLUDED
|
||||
|
||||
#include "gfx/size.h"
|
||||
#include "gui/base.h"
|
||||
|
||||
class Image;
|
||||
@ -34,6 +35,11 @@ namespace clipboard {
|
||||
void copy_image(Image* image, Palette* palette);
|
||||
void paste();
|
||||
|
||||
// Returns true and fills the specified "size"" with the image's
|
||||
// size in the clipboard, or return false in case that the clipboard
|
||||
// doesn't contain an image at all.
|
||||
bool get_image_size(gfx::Size& size);
|
||||
|
||||
} // namespace clipboard
|
||||
|
||||
#endif
|
||||
|
@ -325,3 +325,20 @@ static void get_win32_clipboard_bitmap(Image*& image, Palette*& palette)
|
||||
|
||||
CloseClipboard();
|
||||
}
|
||||
|
||||
static bool get_win32_clipboard_bitmap_size(gfx::Size& size)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
if (win32_clipboard_contains_bitmap() &&
|
||||
OpenClipboard(win_get_window())) {
|
||||
BITMAPINFO* bi = (BITMAPINFO*)GetClipboardData(CF_DIB);
|
||||
if (bi) {
|
||||
size.w = bi->bmiHeader.biWidth;
|
||||
size.h = ABS(bi->bmiHeader.biHeight);
|
||||
result = true;
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user