mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 12:44:53 +00:00
Convert the mouse cursor into an ui::Overlay (now it support alpha channel).
- Added Cursor class and CursorType enum.
This commit is contained in:
parent
d7862744b4
commit
c6fe95231d
@ -156,7 +156,7 @@ int App::run()
|
||||
PRINTF("GUI mode\n");
|
||||
|
||||
// Setup the GUI screen
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
ui::Manager::getDefault()->invalidate();
|
||||
|
||||
// Create the main window and show it.
|
||||
|
@ -104,7 +104,7 @@ void PreviewCommand::onExecute(Context* context)
|
||||
int old_mouse_x = jmouse_x(0);
|
||||
int old_mouse_y = jmouse_y(0);
|
||||
|
||||
jmouse_set_cursor(JI_CURSOR_NULL);
|
||||
jmouse_set_cursor(kNoCursor);
|
||||
jmouse_set_position(JI_SCREEN_W/2, JI_SCREEN_H/2);
|
||||
|
||||
int pos_x = - scroll.x + vp.x + editor->getOffsetX();
|
||||
@ -240,7 +240,7 @@ void PreviewCommand::onExecute(Context* context)
|
||||
clear_keybuf();
|
||||
|
||||
jmouse_set_position(old_mouse_x, old_mouse_y);
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
|
||||
ui::Manager::getDefault()->invalidate();
|
||||
}
|
||||
|
@ -210,12 +210,12 @@ bool ColorCurveEditor::onProcessMessage(Message* msg)
|
||||
// Change scroll
|
||||
if (msg->any.shifts & KB_SHIFT_FLAG) {
|
||||
m_status = STATUS_SCROLLING;
|
||||
jmouse_set_cursor(JI_CURSOR_SCROLL);
|
||||
jmouse_set_cursor(kScrollCursor);
|
||||
}
|
||||
/* scaling */
|
||||
/* else if (msg->shifts & KB_CTRL_FLAG) { */
|
||||
/* m_status = STATUS_SCALING; */
|
||||
/* jmouse_set_cursor(JI_CURSOR_SCROLL); */
|
||||
/* jmouse_set_cursor(kScrollCursor); */
|
||||
/* } */
|
||||
// Show manual-entry dialog
|
||||
else if (msg->mouse.right) {
|
||||
@ -243,7 +243,7 @@ bool ColorCurveEditor::onProcessMessage(Message* msg)
|
||||
&m_editY);
|
||||
|
||||
m_status = STATUS_MOVING_POINT;
|
||||
jmouse_set_cursor(JI_CURSOR_HAND);
|
||||
jmouse_set_cursor(kHandCursor);
|
||||
}
|
||||
|
||||
captureMouse();
|
||||
@ -300,15 +300,15 @@ bool ColorCurveEditor::onProcessMessage(Message* msg)
|
||||
switch (m_status) {
|
||||
|
||||
case STATUS_SCROLLING:
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
break;
|
||||
|
||||
/* case STATUS_SCALING: */
|
||||
/* jmouse_set_cursor(JI_CURSOR_NORMAL); */
|
||||
/* jmouse_set_cursor(kArrowCursor); */
|
||||
/* break; */
|
||||
|
||||
case STATUS_MOVING_POINT:
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
CurveEditorChange();
|
||||
|
||||
m_editPoint = NULL;
|
||||
|
@ -815,19 +815,19 @@ void AnimationEditor::setCursor(int x, int y)
|
||||
|
||||
// Is the mouse in the separator.
|
||||
if (mx > m_separator_x-2 && mx < m_separator_x+2) {
|
||||
jmouse_set_cursor(JI_CURSOR_SIZE_L);
|
||||
jmouse_set_cursor(kSizeLCursor);
|
||||
}
|
||||
// Scrolling.
|
||||
else if (m_state == STATE_SCROLLING ||
|
||||
m_space_pressed) {
|
||||
jmouse_set_cursor(JI_CURSOR_SCROLL);
|
||||
jmouse_set_cursor(kScrollCursor);
|
||||
}
|
||||
// Moving a frame.
|
||||
else if (m_state == STATE_MOVING_FRAME &&
|
||||
m_clk_part == A_PART_HEADER_FRAME &&
|
||||
m_hot_part == A_PART_HEADER_FRAME &&
|
||||
m_clk_frame != m_hot_frame) {
|
||||
jmouse_set_cursor(JI_CURSOR_MOVE);
|
||||
jmouse_set_cursor(kMoveCursor);
|
||||
}
|
||||
// Moving a layer.
|
||||
else if (m_state == STATE_MOVING_LAYER &&
|
||||
@ -835,9 +835,9 @@ void AnimationEditor::setCursor(int x, int y)
|
||||
m_hot_part == A_PART_LAYER &&
|
||||
m_clk_layer != m_hot_layer) {
|
||||
if (m_layers[m_clk_layer]->is_background())
|
||||
jmouse_set_cursor(JI_CURSOR_FORBIDDEN);
|
||||
jmouse_set_cursor(kForbiddenCursor);
|
||||
else
|
||||
jmouse_set_cursor(JI_CURSOR_MOVE);
|
||||
jmouse_set_cursor(kMoveCursor);
|
||||
}
|
||||
// Moving a cel.
|
||||
else if (m_state == STATE_MOVING_CEL &&
|
||||
@ -845,11 +845,11 @@ void AnimationEditor::setCursor(int x, int y)
|
||||
m_hot_part == A_PART_CEL &&
|
||||
(m_clk_frame != m_hot_frame ||
|
||||
m_clk_layer != m_hot_layer)) {
|
||||
jmouse_set_cursor(JI_CURSOR_MOVE);
|
||||
jmouse_set_cursor(kMoveCursor);
|
||||
}
|
||||
// Normal state.
|
||||
else {
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,6 +133,7 @@ protected:
|
||||
void saveLayout(Widget* widget, const std::string& str) OVERRIDE;
|
||||
};
|
||||
|
||||
static she::Display* main_display = NULL;
|
||||
static CustomizedGuiManager* manager = NULL;
|
||||
static Theme* ase_theme = NULL;
|
||||
|
||||
@ -165,16 +166,16 @@ int init_module_gui()
|
||||
// Set the graphics mode...
|
||||
load_gui_config(w, h, maximized);
|
||||
|
||||
she::Display* display = NULL;
|
||||
try {
|
||||
display = she::Instance()->createDisplay(w, h, screen_scaling);
|
||||
main_display = she::Instance()->createDisplay(w, h, screen_scaling);
|
||||
}
|
||||
catch (const she::DisplayCreationException&) {
|
||||
for (c=min_possible_dsk_res; try_resolutions[c].width; ++c) {
|
||||
try {
|
||||
display = she::Instance()->createDisplay(try_resolutions[c].width,
|
||||
try_resolutions[c].height,
|
||||
try_resolutions[c].scale);
|
||||
main_display =
|
||||
she::Instance()->createDisplay(try_resolutions[c].width,
|
||||
try_resolutions[c].height,
|
||||
try_resolutions[c].scale);
|
||||
|
||||
screen_scaling = try_resolutions[c].scale;
|
||||
break;
|
||||
@ -185,20 +186,20 @@ int init_module_gui()
|
||||
}
|
||||
}
|
||||
|
||||
if (!display) {
|
||||
if (!main_display) {
|
||||
allegro_message("Unable to create a user-interface display.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create the default-manager
|
||||
manager = new CustomizedGuiManager();
|
||||
manager->setDisplay(display);
|
||||
manager->setDisplay(main_display);
|
||||
|
||||
// Setup the GUI theme for all widgets
|
||||
CurrentTheme::set(ase_theme = new SkinTheme());
|
||||
|
||||
if (maximized)
|
||||
display->maximize();
|
||||
main_display->maximize();
|
||||
|
||||
// Configure ji_screen
|
||||
gui_setup_screen(true);
|
||||
@ -232,6 +233,8 @@ void exit_module_gui()
|
||||
|
||||
remove_keyboard();
|
||||
remove_mouse();
|
||||
|
||||
main_display->dispose();
|
||||
}
|
||||
|
||||
static void load_gui_config(int& w, int& h, bool& maximized)
|
||||
@ -305,7 +308,7 @@ void gui_feedback()
|
||||
Manager* manager = Manager::getDefault();
|
||||
OverlayManager* overlays = OverlayManager::instance();
|
||||
|
||||
jmouse_draw_cursor();
|
||||
ui::UpdateCursorOverlay();
|
||||
|
||||
// Draw overlays.
|
||||
overlays->captureOverlappedAreas();
|
||||
@ -328,8 +331,8 @@ void gui_setup_screen(bool reload_font)
|
||||
bool regen = false;
|
||||
bool reinit = false;
|
||||
|
||||
Manager::getDefault()->getDisplay()->setScale(screen_scaling);
|
||||
ui::SetDisplay(Manager::getDefault()->getDisplay());
|
||||
main_display->setScale(screen_scaling);
|
||||
ui::SetDisplay(main_display);
|
||||
|
||||
// Update guiscale factor
|
||||
int old_guiscale = jguiscale();
|
||||
|
@ -50,20 +50,22 @@ namespace she {
|
||||
class Alleg4Surface : public Surface
|
||||
, public LockedSurface {
|
||||
public:
|
||||
Alleg4Surface(BITMAP* bmp)
|
||||
enum DestroyFlag { NoDestroy, AutoDestroy };
|
||||
|
||||
Alleg4Surface(BITMAP* bmp, DestroyFlag destroy)
|
||||
: m_bmp(bmp)
|
||||
, m_destroy(false)
|
||||
, m_destroy(destroy)
|
||||
{
|
||||
}
|
||||
|
||||
Alleg4Surface(int width, int height)
|
||||
: m_bmp(create_bitmap(width, height))
|
||||
, m_destroy(true)
|
||||
, m_destroy(AutoDestroy)
|
||||
{
|
||||
}
|
||||
|
||||
~Alleg4Surface() {
|
||||
if (m_destroy)
|
||||
if (m_destroy == AutoDestroy)
|
||||
destroy_bitmap(m_bmp);
|
||||
}
|
||||
|
||||
@ -119,7 +121,7 @@ public:
|
||||
|
||||
private:
|
||||
BITMAP* m_bmp;
|
||||
bool m_destroy;
|
||||
DestroyFlag m_destroy;
|
||||
};
|
||||
|
||||
class Alleg4Display : public Display {
|
||||
@ -288,6 +290,11 @@ public:
|
||||
return new Alleg4Surface(width, height);
|
||||
}
|
||||
|
||||
Surface* createSurfaceFromNativeHandle(void* nativeHandle) {
|
||||
return new Alleg4Surface(reinterpret_cast<BITMAP*>(nativeHandle),
|
||||
Alleg4Surface::AutoDestroy);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static System* g_instance;
|
||||
|
@ -28,6 +28,7 @@ namespace she {
|
||||
virtual Capabilities capabilities() const = 0;
|
||||
virtual Display* createDisplay(int width, int height, int scale) = 0;
|
||||
virtual Surface* createSurface(int width, int height) = 0;
|
||||
virtual Surface* createSurfaceFromNativeHandle(void* nativeHandle) = 0;
|
||||
};
|
||||
|
||||
System* CreateSystem();
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "skin/skin_property.h"
|
||||
#include "skin/skin_slider_property.h"
|
||||
#include "skin/skin_theme.h"
|
||||
#include "she/system.h"
|
||||
#include "ui/gui.h"
|
||||
#include "ui/intern.h"
|
||||
#include "xml_exception.h"
|
||||
@ -78,7 +79,7 @@ protected:
|
||||
switch (msg->type) {
|
||||
|
||||
case JM_SETCURSOR:
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
return true;
|
||||
|
||||
case JM_DRAW:
|
||||
@ -107,38 +108,35 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
static struct
|
||||
{
|
||||
const char* id;
|
||||
int focusx, focusy;
|
||||
} cursors_info[JI_CURSORS] = {
|
||||
{ "null", 0, 0 }, // JI_CURSOR_NULL
|
||||
{ "normal", 0, 0 }, // JI_CURSOR_NORMAL
|
||||
{ "normal_add", 0, 0 }, // JI_CURSOR_NORMAL_ADD
|
||||
{ "forbidden", 0, 0 }, // JI_CURSOR_FORBIDDEN
|
||||
{ "hand", 0, 0 }, // JI_CURSOR_HAND
|
||||
{ "scroll", 0, 0 }, // JI_CURSOR_SCROLL
|
||||
{ "move", 0, 0 }, // JI_CURSOR_MOVE
|
||||
{ "size_tl", 0, 0 }, // JI_CURSOR_SIZE_TL
|
||||
{ "size_t", 0, 0 }, // JI_CURSOR_SIZE_T
|
||||
{ "size_tr", 0, 0 }, // JI_CURSOR_SIZE_TR
|
||||
{ "size_l", 0, 0 }, // JI_CURSOR_SIZE_L
|
||||
{ "size_r", 0, 0 }, // JI_CURSOR_SIZE_R
|
||||
{ "size_bl", 0, 0 }, // JI_CURSOR_SIZE_BL
|
||||
{ "size_b", 0, 0 }, // JI_CURSOR_SIZE_B
|
||||
{ "size_br", 0, 0 }, // JI_CURSOR_SIZE_BR
|
||||
{ "rotate_tl", 0, 0 }, // JI_CURSOR_ROTATE_TL
|
||||
{ "rotate_t", 0, 0 }, // JI_CURSOR_ROTATE_T
|
||||
{ "rotate_tr", 0, 0 }, // JI_CURSOR_ROTATE_TR
|
||||
{ "rotate_l", 0, 0 }, // JI_CURSOR_ROTATE_L
|
||||
{ "rotate_r", 0, 0 }, // JI_CURSOR_ROTATE_R
|
||||
{ "rotate_bl", 0, 0 }, // JI_CURSOR_ROTATE_BL
|
||||
{ "rotate_b", 0, 0 }, // JI_CURSOR_ROTATE_B
|
||||
{ "rotate_br", 0, 0 }, // JI_CURSOR_ROTATE_BR
|
||||
{ "eyedropper", 0, 0 }, // JI_CURSOR_EYEDROPPER
|
||||
static const char* cursor_names[kCursorTypes] = {
|
||||
"null", // kNoCursor
|
||||
"normal", // kArrowCursor
|
||||
"normal_add", // kArrowPlusCursor
|
||||
"forbidden", // kForbiddenCursor
|
||||
"hand", // kHandCursor
|
||||
"scroll", // kScrollCursor
|
||||
"move", // kMoveCursor
|
||||
"size_tl", // kSizeTLCursor
|
||||
"size_t", // kSizeTCursor
|
||||
"size_tr", // kSizeTRCursor
|
||||
"size_l", // kSizeLCursor
|
||||
"size_r", // kSizeRCursor
|
||||
"size_bl", // kSizeBLCursor
|
||||
"size_b", // kSizeBCursor
|
||||
"size_br", // kSizeBRCursor
|
||||
"rotate_tl", // kRotateTLCursor
|
||||
"rotate_t", // kRotateTCursor
|
||||
"rotate_tr", // kRotateTRCursor
|
||||
"rotate_l", // kRotateLCursor
|
||||
"rotate_r", // kRotateRCursor
|
||||
"rotate_bl", // kRotateBLCursor
|
||||
"rotate_b", // kRotateBCursor
|
||||
"rotate_br", // kRotateBRCursor
|
||||
"eyedropper" // kEyedropperCursor
|
||||
};
|
||||
|
||||
SkinTheme::SkinTheme()
|
||||
: m_cursors(ui::kCursorTypes, NULL)
|
||||
{
|
||||
this->name = "Skin Theme";
|
||||
m_selected_skin = get_config_string("Skin", "Selected", "default");
|
||||
@ -146,8 +144,6 @@ SkinTheme::SkinTheme()
|
||||
|
||||
// Initialize all graphics in NULL (these bitmaps are loaded from the skin)
|
||||
m_sheet_bmp = NULL;
|
||||
for (int c=0; c<JI_CURSORS; ++c)
|
||||
m_cursors[c] = NULL;
|
||||
for (int c=0; c<PARTS; ++c)
|
||||
m_part[c] = NULL;
|
||||
|
||||
@ -281,9 +277,9 @@ SkinTheme::SkinTheme()
|
||||
|
||||
SkinTheme::~SkinTheme()
|
||||
{
|
||||
for (int c=0; c<JI_CURSORS; ++c)
|
||||
if (m_cursors[c])
|
||||
destroy_bitmap(m_cursors[c]);
|
||||
// Delete all cursors.
|
||||
for (size_t c=0; c<m_cursors.size(); ++c)
|
||||
delete m_cursors[c];
|
||||
|
||||
for (int c=0; c<PARTS; ++c)
|
||||
destroy_bitmap(m_part[c]);
|
||||
@ -383,18 +379,23 @@ void SkinTheme::onRegenerate()
|
||||
int focusy = strtol(xmlCursor->Attribute("focusy"), NULL, 10);
|
||||
int c;
|
||||
|
||||
for (c=0; c<JI_CURSORS; ++c) {
|
||||
if (id != cursors_info[c].id)
|
||||
for (c=0; c<kCursorTypes; ++c) {
|
||||
if (id != cursor_names[c])
|
||||
continue;
|
||||
|
||||
cursors_info[c].focusx = focusx;
|
||||
cursors_info[c].focusy = focusy;
|
||||
delete m_cursors[c];
|
||||
m_cursors[c] = NULL;
|
||||
|
||||
m_cursors[c] = cropPartFromSheet(m_cursors[c], x, y, w, h, true);
|
||||
BITMAP* bmp = cropPartFromSheet(NULL, x, y, w, h);
|
||||
she::Surface* surface =
|
||||
she::Instance()->createSurfaceFromNativeHandle(reinterpret_cast<void*>(bmp));
|
||||
|
||||
m_cursors[c] = new Cursor(surface, gfx::Point(focusx*jguiscale(),
|
||||
focusy*jguiscale()));
|
||||
break;
|
||||
}
|
||||
|
||||
if (c == JI_CURSORS) {
|
||||
if (c == kCursorTypes) {
|
||||
throw base::Exception("Unknown cursor specified in '%s':\n"
|
||||
"<cursor id='%s' ... />\n", xml_filename.c_str(), id.c_str());
|
||||
}
|
||||
@ -475,9 +476,9 @@ void SkinTheme::onRegenerate()
|
||||
}
|
||||
}
|
||||
|
||||
BITMAP* SkinTheme::cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h, bool cursor)
|
||||
BITMAP* SkinTheme::cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h)
|
||||
{
|
||||
int colordepth = (cursor ? bitmap_color_depth(screen): 32);
|
||||
int colordepth = 32;
|
||||
|
||||
if (bmp &&
|
||||
(bmp->w != w ||
|
||||
@ -490,32 +491,17 @@ BITMAP* SkinTheme::cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h, bo
|
||||
if (!bmp)
|
||||
bmp = create_bitmap_ex(colordepth, w, h);
|
||||
|
||||
if (cursor) {
|
||||
clear_to_color(bmp, bitmap_mask_color(bmp));
|
||||
|
||||
set_alpha_blender();
|
||||
draw_trans_sprite(bmp, m_sheet_bmp, -x, -y);
|
||||
set_trans_blender(0, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
blit(m_sheet_bmp, bmp, x, y, 0, 0, w, h);
|
||||
}
|
||||
|
||||
blit(m_sheet_bmp, bmp, x, y, 0, 0, w, h);
|
||||
return ji_apply_guiscale(bmp);
|
||||
}
|
||||
|
||||
BITMAP* SkinTheme::set_cursor(int type, int* focus_x, int* focus_y)
|
||||
Cursor* SkinTheme::getCursor(CursorType type)
|
||||
{
|
||||
if (type == JI_CURSOR_NULL) {
|
||||
*focus_x = 0;
|
||||
*focus_y = 0;
|
||||
if (type == kNoCursor) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
ASSERT(type >= 0 && type < JI_CURSORS);
|
||||
|
||||
*focus_x = cursors_info[type].focusx*jguiscale();
|
||||
*focus_y = cursors_info[type].focusy*jguiscale();
|
||||
ASSERT(type >= kFirstCursorType && type <= kLastCursorType);
|
||||
return m_cursors[type];
|
||||
}
|
||||
}
|
||||
|
@ -19,16 +19,16 @@
|
||||
#ifndef SKIN_THEME_H_INCLUDED
|
||||
#define SKIN_THEME_H_INCLUDED
|
||||
|
||||
#include <allegro/color.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "gfx/rect.h"
|
||||
#include "skin/skin_parts.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/system.h"
|
||||
#include "ui/theme.h"
|
||||
|
||||
#include "skin/skin_parts.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <allegro/color.h>
|
||||
|
||||
namespace ui {
|
||||
class Graphics;
|
||||
@ -41,9 +41,9 @@ class SkinTheme : public ui::Theme
|
||||
{
|
||||
std::string m_selected_skin;
|
||||
BITMAP* m_sheet_bmp;
|
||||
BITMAP* m_cursors[ui::JI_CURSORS];
|
||||
BITMAP* m_part[PARTS];
|
||||
std::map<std::string, BITMAP*> m_toolicon;
|
||||
std::vector<ui::Cursor*> m_cursors;
|
||||
FONT* m_minifont;
|
||||
|
||||
public:
|
||||
@ -57,7 +57,7 @@ public:
|
||||
void reload_skin();
|
||||
void reload_fonts();
|
||||
|
||||
BITMAP* set_cursor(int type, int* focus_x, int* focus_y);
|
||||
ui::Cursor* getCursor(ui::CursorType type);
|
||||
void init_widget(ui::Widget* widget);
|
||||
ui::JRegion get_window_mask(ui::Widget* widget);
|
||||
void map_decorative_widget(ui::Widget* widget);
|
||||
@ -169,7 +169,7 @@ private:
|
||||
void draw_bounds_template(ui::Graphics* g, const gfx::Rect& rc,
|
||||
int nw, int n, int ne, int e, int se, int s, int sw, int w);
|
||||
|
||||
BITMAP* cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h, bool cursor = false);
|
||||
BITMAP* cropPartFromSheet(BITMAP* bmp, int x, int y, int w, int h);
|
||||
int get_bg_color(ui::Widget* widget);
|
||||
void draw_textstring(const char *t, int fg_color, int bg_color,
|
||||
bool fill_bg, ui::Widget* widget, const ui::JRect rect,
|
||||
|
@ -9,6 +9,7 @@ add_library(ui-lib
|
||||
clipboard.cpp
|
||||
combobox.cpp
|
||||
component.cpp
|
||||
cursor.cpp
|
||||
custom_label.cpp
|
||||
draw.cpp
|
||||
entry.cpp
|
||||
|
27
src/ui/cursor.cpp
Normal file
27
src/ui/cursor.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// ASEPRITE gui library
|
||||
// Copyright (C) 2001-2012 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ui/cursor.h"
|
||||
|
||||
#include "she/surface.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
Cursor::Cursor(she::Surface* surface, const gfx::Point& focus)
|
||||
: m_surface(surface)
|
||||
, m_focus(focus)
|
||||
{
|
||||
ASSERT(m_surface != NULL);
|
||||
}
|
||||
|
||||
Cursor::~Cursor()
|
||||
{
|
||||
m_surface->dispose();
|
||||
}
|
||||
|
||||
} // namespace ui
|
32
src/ui/cursor.h
Normal file
32
src/ui/cursor.h
Normal file
@ -0,0 +1,32 @@
|
||||
// ASEPRITE gui library
|
||||
// Copyright (C) 2001-2012 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef UI_CURSOR_H_INCLUDED
|
||||
#define UI_CURSOR_H_INCLUDED
|
||||
|
||||
#include "gfx/point.h"
|
||||
|
||||
namespace she { class Surface; }
|
||||
|
||||
namespace ui {
|
||||
|
||||
class Cursor {
|
||||
public:
|
||||
// The surface is disposed in ~Cursor.
|
||||
Cursor(she::Surface* surface, const gfx::Point& focus);
|
||||
~Cursor();
|
||||
|
||||
she::Surface* getSurface() { return m_surface; }
|
||||
const gfx::Point& getFocus() const { return m_focus; }
|
||||
|
||||
private:
|
||||
she::Surface* m_surface;
|
||||
gfx::Point m_focus;
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
44
src/ui/cursor_type.h
Normal file
44
src/ui/cursor_type.h
Normal file
@ -0,0 +1,44 @@
|
||||
// ASEPRITE gui library
|
||||
// Copyright (C) 2001-2012 David Capello
|
||||
//
|
||||
// This source file is ditributed under a BSD-like license, please
|
||||
// read LICENSE.txt for more information.
|
||||
|
||||
#ifndef UI_CURSOR_TYPE_H_INCLUDED
|
||||
#define UI_CURSOR_TYPE_H_INCLUDED
|
||||
|
||||
namespace ui {
|
||||
|
||||
enum CursorType {
|
||||
kFirstCursorType = 0,
|
||||
kNoCursor = 0,
|
||||
kArrowCursor,
|
||||
kArrowPlusCursor,
|
||||
kForbiddenCursor,
|
||||
kHandCursor,
|
||||
kScrollCursor,
|
||||
kMoveCursor,
|
||||
kSizeTLCursor,
|
||||
kSizeTCursor,
|
||||
kSizeTRCursor,
|
||||
kSizeLCursor,
|
||||
kSizeRCursor,
|
||||
kSizeBLCursor,
|
||||
kSizeBCursor,
|
||||
kSizeBRCursor,
|
||||
kRotateTLCursor,
|
||||
kRotateTCursor,
|
||||
kRotateTRCursor,
|
||||
kRotateLCursor,
|
||||
kRotateRCursor,
|
||||
kRotateBLCursor,
|
||||
kRotateBCursor,
|
||||
kRotateBRCursor,
|
||||
kEyedropperCursor,
|
||||
kLastCursorType = kEyedropperCursor,
|
||||
kCursorTypes
|
||||
};
|
||||
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
@ -15,6 +15,8 @@
|
||||
#include "ui/clipboard.h"
|
||||
#include "ui/combobox.h"
|
||||
#include "ui/component.h"
|
||||
#include "ui/cursor.h"
|
||||
#include "ui/cursor_type.h"
|
||||
#include "ui/custom_label.h"
|
||||
#include "ui/draw.h"
|
||||
#include "ui/entry.h"
|
||||
|
@ -39,7 +39,7 @@ bool LinkLabel::onProcessMessage(Message* msg)
|
||||
case JM_SETCURSOR:
|
||||
// TODO theme stuff
|
||||
if (isEnabled()) {
|
||||
jmouse_set_cursor(JI_CURSOR_HAND);
|
||||
jmouse_set_cursor(kHandCursor);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
@ -154,7 +154,7 @@ Manager::~Manager()
|
||||
// Finish the main manager.
|
||||
if (m_defaultManager == this) {
|
||||
// No more cursor
|
||||
jmouse_set_cursor(JI_CURSOR_NULL);
|
||||
jmouse_set_cursor(kNoCursor);
|
||||
|
||||
// Destroy timers
|
||||
Timer::checkNoTimers();
|
||||
@ -199,7 +199,7 @@ bool Manager::generateMessages()
|
||||
first_time_poll = false;
|
||||
|
||||
Manager::getDefault()->invalidate();
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
}
|
||||
|
||||
// First check: there are windows to manage?
|
||||
@ -1192,7 +1192,7 @@ void Manager::generateSetCursorMessage()
|
||||
enqueueMessage(msg);
|
||||
}
|
||||
else
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -25,23 +25,39 @@ Overlay::Overlay(she::Surface* overlaySurface, const gfx::Point& pos, ZOrder zor
|
||||
|
||||
Overlay::~Overlay()
|
||||
{
|
||||
Manager* manager = Manager::getDefault();
|
||||
if (manager)
|
||||
manager->invalidateRect(gfx::Rect(m_pos.x, m_pos.y,
|
||||
m_surface->width(),
|
||||
m_surface->height()));
|
||||
m_surface->dispose();
|
||||
if (m_surface) {
|
||||
Manager* manager = Manager::getDefault();
|
||||
if (manager)
|
||||
manager->invalidateRect(gfx::Rect(m_pos.x, m_pos.y,
|
||||
m_surface->width(),
|
||||
m_surface->height()));
|
||||
m_surface->dispose();
|
||||
}
|
||||
|
||||
if (m_overlap)
|
||||
m_overlap->dispose();
|
||||
}
|
||||
|
||||
she::Surface* Overlay::setSurface(she::Surface* newSurface)
|
||||
{
|
||||
she::Surface* oldSurface = m_surface;
|
||||
m_surface = newSurface;
|
||||
return oldSurface;
|
||||
}
|
||||
|
||||
gfx::Rect Overlay::getBounds() const
|
||||
{
|
||||
return gfx::Rect(m_pos.x, m_pos.y, m_surface->width(), m_surface->height());
|
||||
if (m_surface)
|
||||
return gfx::Rect(m_pos.x, m_pos.y, m_surface->width(), m_surface->height());
|
||||
else
|
||||
return gfx::Rect(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
void Overlay::drawOverlay(she::LockedSurface* screen)
|
||||
{
|
||||
if (!m_surface)
|
||||
return;
|
||||
|
||||
she::ScopedSurfaceLock lockedSurface(m_surface);
|
||||
screen->drawAlphaSurface(lockedSurface, m_pos.x, m_pos.y);
|
||||
}
|
||||
@ -53,6 +69,9 @@ void Overlay::moveOverlay(const gfx::Point& newPos)
|
||||
|
||||
void Overlay::captureOverlappedArea(she::LockedSurface* screen)
|
||||
{
|
||||
if (!m_surface)
|
||||
return;
|
||||
|
||||
if (!m_overlap)
|
||||
m_overlap = she::Instance()->createSurface(m_surface->width(), m_surface->height());
|
||||
|
||||
@ -63,6 +82,9 @@ void Overlay::captureOverlappedArea(she::LockedSurface* screen)
|
||||
|
||||
void Overlay::restoreOverlappedArea(she::LockedSurface* screen)
|
||||
{
|
||||
if (!m_surface)
|
||||
return;
|
||||
|
||||
if (!m_overlap)
|
||||
return;
|
||||
|
||||
|
@ -22,9 +22,14 @@ namespace ui {
|
||||
public:
|
||||
typedef int ZOrder;
|
||||
|
||||
static const ZOrder NormalZOrder = 0;
|
||||
static const ZOrder MouseZOrder = 5000;
|
||||
|
||||
Overlay(she::Surface* overlaySurface, const gfx::Point& pos, ZOrder zorder = 0);
|
||||
~Overlay();
|
||||
|
||||
she::Surface* setSurface(she::Surface* newSurface);
|
||||
|
||||
gfx::Rect getBounds() const;
|
||||
|
||||
void captureOverlappedArea(she::LockedSurface* screen);
|
||||
|
@ -253,12 +253,12 @@ void Slider::setupSliderCursor()
|
||||
{
|
||||
if (hasCapture()) {
|
||||
if (slider_press_left)
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
else
|
||||
jmouse_set_cursor(JI_CURSOR_SIZE_L);
|
||||
jmouse_set_cursor(kSizeLCursor);
|
||||
}
|
||||
else
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
@ -164,9 +164,9 @@ bool Splitter::onProcessMessage(Message* msg)
|
||||
|
||||
if (change_cursor) {
|
||||
if (this->getAlign() & JI_HORIZONTAL)
|
||||
jmouse_set_cursor(JI_CURSOR_SIZE_L);
|
||||
jmouse_set_cursor(kSizeLCursor);
|
||||
else
|
||||
jmouse_set_cursor(JI_CURSOR_SIZE_T);
|
||||
jmouse_set_cursor(kSizeTCursor);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,14 @@
|
||||
|
||||
#include "ui/system.h"
|
||||
|
||||
#include "gfx/point.h"
|
||||
#include "she/display.h"
|
||||
#include "she/surface.h"
|
||||
#include "ui/cursor.h"
|
||||
#include "ui/intern.h"
|
||||
#include "ui/manager.h"
|
||||
#include "ui/overlay.h"
|
||||
#include "ui/overlay_manager.h"
|
||||
#include "ui/rect.h"
|
||||
#include "ui/region.h"
|
||||
#include "ui/theme.h"
|
||||
@ -37,16 +41,11 @@ int ji_screen_h = 0;
|
||||
|
||||
volatile int ji_clock = 0;
|
||||
|
||||
/* Current mouse cursor type. */
|
||||
// Current mouse cursor type.
|
||||
|
||||
static int m_cursor;
|
||||
static BITMAP *sprite_cursor = NULL;
|
||||
static int focus_x;
|
||||
static int focus_y;
|
||||
|
||||
static BITMAP *covered_area = NULL;
|
||||
static int covered_area_x;
|
||||
static int covered_area_y;
|
||||
static CursorType mouse_cursor_type = kNoCursor;
|
||||
static Cursor* mouse_cursor = NULL;
|
||||
static Overlay* mouse_cursor_overlay = NULL;
|
||||
|
||||
/* Mouse information (button and position). */
|
||||
|
||||
@ -60,13 +59,9 @@ static int mouse_scares = 0;
|
||||
|
||||
/* Local routines. */
|
||||
|
||||
static void set_cursor(BITMAP *bmp, int x, int y);
|
||||
static void clock_inc();
|
||||
static void update_mouse_position();
|
||||
|
||||
static void capture_covered_area();
|
||||
static void restore_covered_area();
|
||||
|
||||
static void clock_inc()
|
||||
{
|
||||
ji_clock++;
|
||||
@ -74,14 +69,27 @@ static void clock_inc()
|
||||
|
||||
END_OF_STATIC_FUNCTION(clock_inc);
|
||||
|
||||
static void set_cursor(BITMAP *bmp, int x, int y)
|
||||
static void set_mouse_cursor(Cursor* cursor)
|
||||
{
|
||||
sprite_cursor = bmp;
|
||||
focus_x = x;
|
||||
focus_y = y;
|
||||
mouse_cursor = cursor;
|
||||
|
||||
set_mouse_sprite(bmp);
|
||||
set_mouse_sprite_focus(x, y);
|
||||
if (mouse_cursor) {
|
||||
if (!mouse_cursor_overlay) {
|
||||
mouse_cursor_overlay = new Overlay(mouse_cursor->getSurface(),
|
||||
gfx::Point(), Overlay::MouseZOrder);
|
||||
OverlayManager::instance()->addOverlay(mouse_cursor_overlay);
|
||||
}
|
||||
else {
|
||||
mouse_cursor_overlay->setSurface(mouse_cursor->getSurface());
|
||||
UpdateCursorOverlay();
|
||||
}
|
||||
}
|
||||
else if (mouse_cursor_overlay) {
|
||||
OverlayManager::instance()->removeOverlay(mouse_cursor_overlay);
|
||||
mouse_cursor_overlay->setSurface(NULL);
|
||||
delete mouse_cursor_overlay;
|
||||
mouse_cursor_overlay = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int _ji_system_init()
|
||||
@ -98,7 +106,7 @@ int _ji_system_init()
|
||||
jmouse_poll();
|
||||
|
||||
moved = true;
|
||||
m_cursor = JI_CURSOR_NULL;
|
||||
mouse_cursor_type = kNoCursor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -106,15 +114,16 @@ int _ji_system_init()
|
||||
void _ji_system_exit()
|
||||
{
|
||||
SetDisplay(NULL);
|
||||
set_mouse_cursor(NULL);
|
||||
|
||||
remove_int(clock_inc);
|
||||
}
|
||||
|
||||
void SetDisplay(she::Display* display)
|
||||
{
|
||||
int cursor = jmouse_get_cursor();
|
||||
CursorType cursor = jmouse_get_cursor();
|
||||
|
||||
jmouse_set_cursor(JI_CURSOR_NULL);
|
||||
jmouse_set_cursor(kNoCursor);
|
||||
ji_screen = (display ? reinterpret_cast<BITMAP*>(display->getSurface()->nativeHandle()): NULL);
|
||||
ji_screen_w = (ji_screen ? ji_screen->w: 0);
|
||||
ji_screen_h = (ji_screen ? ji_screen->h: 0);
|
||||
@ -133,89 +142,43 @@ void SetDisplay(she::Display* display)
|
||||
}
|
||||
}
|
||||
|
||||
jmouse_set_cursor(cursor); /* restore mouse cursor */
|
||||
jmouse_set_cursor(cursor); // Restore mouse cursor
|
||||
}
|
||||
}
|
||||
|
||||
int jmouse_get_cursor()
|
||||
void UpdateCursorOverlay()
|
||||
{
|
||||
return m_cursor;
|
||||
if (mouse_cursor_overlay != NULL && mouse_scares == 0)
|
||||
mouse_cursor_overlay->moveOverlay(gfx::Point(m_x[0]-mouse_cursor->getFocus().x,
|
||||
m_y[0]-mouse_cursor->getFocus().y));
|
||||
}
|
||||
|
||||
int jmouse_set_cursor(int type)
|
||||
CursorType jmouse_get_cursor()
|
||||
{
|
||||
if (m_cursor == type)
|
||||
return type;
|
||||
return mouse_cursor_type;
|
||||
}
|
||||
|
||||
void jmouse_set_cursor(CursorType type)
|
||||
{
|
||||
if (mouse_cursor_type == type)
|
||||
return;
|
||||
|
||||
Theme* theme = CurrentTheme::get();
|
||||
mouse_cursor_type = type;
|
||||
|
||||
if (type == kNoCursor) {
|
||||
show_mouse(NULL);
|
||||
set_mouse_cursor(NULL);
|
||||
}
|
||||
else {
|
||||
Theme* theme = CurrentTheme::get();
|
||||
int old = m_cursor;
|
||||
m_cursor = type;
|
||||
|
||||
if (m_cursor == JI_CURSOR_NULL) {
|
||||
show_mouse(NULL);
|
||||
set_cursor(NULL, 0, 0);
|
||||
}
|
||||
else {
|
||||
show_mouse(NULL);
|
||||
|
||||
{
|
||||
BITMAP *sprite;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
sprite = theme->set_cursor(type, &x, &y);
|
||||
set_cursor(sprite, x, y);
|
||||
}
|
||||
|
||||
if (ji_screen == screen)
|
||||
show_mouse(ji_screen);
|
||||
}
|
||||
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this routine if your "ji_screen" isn't Allegro's "screen" so
|
||||
* you must to draw the cursor by your self using this routine.
|
||||
*/
|
||||
void jmouse_draw_cursor()
|
||||
{
|
||||
#if 0
|
||||
if (sprite_cursor != NULL && mouse_scares == 0) {
|
||||
int x = m_x[0]-focus_x;
|
||||
int y = m_y[0]-focus_y;
|
||||
JRect rect = jrect_new(x, y,
|
||||
x+sprite_cursor->w,
|
||||
y+sprite_cursor->h);
|
||||
|
||||
ji_get_default_manager()->invalidateRect(rect);
|
||||
/* rectfill(ji_screen, rect->x1, rect->y1, rect->x2-1, rect->y2-1, makecol(0, 0, 255)); */
|
||||
draw_sprite(ji_screen, sprite_cursor, x, y);
|
||||
jrect_free(rect);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sprite_cursor != NULL && mouse_scares == 0) {
|
||||
int x = m_x[0]-focus_x;
|
||||
int y = m_y[0]-focus_y;
|
||||
|
||||
restore_covered_area();
|
||||
capture_covered_area();
|
||||
|
||||
draw_sprite(ji_screen, sprite_cursor, x, y);
|
||||
show_mouse(NULL);
|
||||
set_mouse_cursor(theme->getCursor(type));
|
||||
}
|
||||
}
|
||||
|
||||
void jmouse_hide()
|
||||
{
|
||||
ASSERT(mouse_scares >= 0);
|
||||
|
||||
if (ji_screen == screen)
|
||||
scare_mouse();
|
||||
else if (mouse_scares == 0)
|
||||
restore_covered_area();
|
||||
|
||||
mouse_scares++;
|
||||
}
|
||||
|
||||
@ -223,9 +186,6 @@ void jmouse_show()
|
||||
{
|
||||
ASSERT(mouse_scares > 0);
|
||||
mouse_scares--;
|
||||
|
||||
if (ji_screen == screen)
|
||||
unscare_mouse();
|
||||
}
|
||||
|
||||
bool jmouse_is_hidden()
|
||||
@ -280,13 +240,8 @@ void jmouse_set_position(int x, int y)
|
||||
m_x[0] = m_x[1] = x;
|
||||
m_y[0] = m_y[1] = y;
|
||||
|
||||
if (ji_screen == screen) {
|
||||
position_mouse(x, y);
|
||||
}
|
||||
else {
|
||||
position_mouse(SCREEN_W * x / JI_SCREEN_W,
|
||||
SCREEN_H * y / JI_SCREEN_H);
|
||||
}
|
||||
position_mouse(SCREEN_W * x / JI_SCREEN_W,
|
||||
SCREEN_H * y / JI_SCREEN_H);
|
||||
}
|
||||
|
||||
void jmouse_capture()
|
||||
@ -346,19 +301,13 @@ bool jmouse_control_infinite_scroll(const gfx::Rect& rect)
|
||||
|
||||
static void update_mouse_position()
|
||||
{
|
||||
if (ji_screen == screen) {
|
||||
m_x[0] = mouse_x;
|
||||
m_y[0] = mouse_y;
|
||||
}
|
||||
else {
|
||||
m_x[0] = JI_SCREEN_W * mouse_x / SCREEN_W;
|
||||
m_y[0] = JI_SCREEN_H * mouse_y / SCREEN_H;
|
||||
}
|
||||
m_x[0] = JI_SCREEN_W * mouse_x / SCREEN_W;
|
||||
m_y[0] = JI_SCREEN_H * mouse_y / SCREEN_H;
|
||||
|
||||
if (is_windowed_mode()) {
|
||||
#ifdef ALLEGRO_WINDOWS
|
||||
/* this help us (in windows) to get mouse feedback when we capture
|
||||
the mouse but we are outside the Allegro window */
|
||||
// This help us (in windows) to get mouse feedback when we capture
|
||||
// the mouse but we are outside the window.
|
||||
POINT pt;
|
||||
RECT rc;
|
||||
|
||||
@ -366,25 +315,22 @@ static void update_mouse_position()
|
||||
MapWindowPoints(win_get_window(), NULL, (LPPOINT)&rc, 2);
|
||||
|
||||
if (!PtInRect(&rc, pt)) {
|
||||
/* if the mouse is free we can hide the cursor putting the
|
||||
mouse outside the screen (right-bottom corder) */
|
||||
// If the mouse is free we can hide the cursor putting the
|
||||
// mouse outside the screen (right-bottom corder).
|
||||
if (!Manager::getDefault()->getCapture()) {
|
||||
m_x[0] = JI_SCREEN_W+focus_x;
|
||||
m_y[0] = JI_SCREEN_H+focus_y;
|
||||
if (mouse_cursor) {
|
||||
m_x[0] = JI_SCREEN_W + mouse_cursor->getFocus().x;
|
||||
m_y[0] = JI_SCREEN_H + mouse_cursor->getFocus().y;
|
||||
}
|
||||
}
|
||||
/* if the mouse is captured we can put it in the edges of the screen */
|
||||
// If the mouse is captured we can put it in the edges of the
|
||||
// screen.
|
||||
else {
|
||||
pt.x -= rc.left;
|
||||
pt.y -= rc.top;
|
||||
|
||||
if (ji_screen == screen) {
|
||||
m_x[0] = pt.x;
|
||||
m_y[0] = pt.y;
|
||||
}
|
||||
else {
|
||||
m_x[0] = JI_SCREEN_W * pt.x / SCREEN_W;
|
||||
m_y[0] = JI_SCREEN_H * pt.y / SCREEN_H;
|
||||
}
|
||||
m_x[0] = JI_SCREEN_W * pt.x / SCREEN_W;
|
||||
m_y[0] = JI_SCREEN_H * pt.y / SCREEN_H;
|
||||
|
||||
m_x[0] = MID(0, m_x[0], JI_SCREEN_W-1);
|
||||
m_y[0] = MID(0, m_y[0], JI_SCREEN_H-1);
|
||||
@ -395,31 +341,4 @@ static void update_mouse_position()
|
||||
}
|
||||
}
|
||||
|
||||
static void capture_covered_area()
|
||||
{
|
||||
if (sprite_cursor != NULL && mouse_scares == 0) {
|
||||
ASSERT(covered_area == NULL);
|
||||
|
||||
covered_area = create_bitmap(sprite_cursor->w, sprite_cursor->h);
|
||||
covered_area_x = m_x[0]-focus_x;
|
||||
covered_area_y = m_y[0]-focus_y;
|
||||
|
||||
blit(ji_screen, covered_area,
|
||||
covered_area_x, covered_area_y, 0, 0,
|
||||
covered_area->w, covered_area->h);
|
||||
}
|
||||
}
|
||||
|
||||
static void restore_covered_area()
|
||||
{
|
||||
if (covered_area != NULL) {
|
||||
blit(covered_area, ji_screen,
|
||||
0, 0, covered_area_x, covered_area_y,
|
||||
covered_area->w, covered_area->h);
|
||||
|
||||
destroy_bitmap(covered_area);
|
||||
covered_area = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "gfx/rect.h"
|
||||
#include "ui/base.h"
|
||||
#include "ui/cursor_type.h"
|
||||
|
||||
struct BITMAP;
|
||||
|
||||
@ -36,37 +37,10 @@ namespace ui {
|
||||
/***********************************************************************/
|
||||
/* mouse related */
|
||||
|
||||
enum {
|
||||
JI_CURSOR_NULL,
|
||||
JI_CURSOR_NORMAL,
|
||||
JI_CURSOR_NORMAL_ADD,
|
||||
JI_CURSOR_FORBIDDEN,
|
||||
JI_CURSOR_HAND,
|
||||
JI_CURSOR_SCROLL,
|
||||
JI_CURSOR_MOVE,
|
||||
JI_CURSOR_SIZE_TL,
|
||||
JI_CURSOR_SIZE_T,
|
||||
JI_CURSOR_SIZE_TR,
|
||||
JI_CURSOR_SIZE_L,
|
||||
JI_CURSOR_SIZE_R,
|
||||
JI_CURSOR_SIZE_BL,
|
||||
JI_CURSOR_SIZE_B,
|
||||
JI_CURSOR_SIZE_BR,
|
||||
JI_CURSOR_ROTATE_TL,
|
||||
JI_CURSOR_ROTATE_T,
|
||||
JI_CURSOR_ROTATE_TR,
|
||||
JI_CURSOR_ROTATE_L,
|
||||
JI_CURSOR_ROTATE_R,
|
||||
JI_CURSOR_ROTATE_BL,
|
||||
JI_CURSOR_ROTATE_B,
|
||||
JI_CURSOR_ROTATE_BR,
|
||||
JI_CURSOR_EYEDROPPER,
|
||||
JI_CURSORS
|
||||
};
|
||||
void UpdateCursorOverlay();
|
||||
|
||||
int jmouse_get_cursor();
|
||||
int jmouse_set_cursor(int type);
|
||||
void jmouse_draw_cursor();
|
||||
CursorType jmouse_get_cursor();
|
||||
void jmouse_set_cursor(CursorType type);
|
||||
|
||||
void jmouse_hide();
|
||||
void jmouse_show();
|
||||
|
@ -99,7 +99,7 @@ bool TextBox::onProcessMessage(Message* msg)
|
||||
View* view = View::getView(this);
|
||||
if (view) {
|
||||
captureMouse();
|
||||
jmouse_set_cursor(JI_CURSOR_SCROLL);
|
||||
jmouse_set_cursor(kScrollCursor);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@ -125,7 +125,7 @@ bool TextBox::onProcessMessage(Message* msg)
|
||||
View* view = View::getView(this);
|
||||
if (view && hasCapture()) {
|
||||
releaseMouse();
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
@ -50,8 +50,8 @@ Theme::~Theme()
|
||||
|
||||
void Theme::regenerate()
|
||||
{
|
||||
int type = jmouse_get_cursor();
|
||||
jmouse_set_cursor(JI_CURSOR_NULL);
|
||||
CursorType type = jmouse_get_cursor();
|
||||
jmouse_set_cursor(kNoCursor);
|
||||
|
||||
onRegenerate();
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#define UI_THEME_H_INCLUDED
|
||||
|
||||
#include "ui/base.h"
|
||||
#include "ui/cursor_type.h"
|
||||
|
||||
struct BITMAP;
|
||||
struct FONT;
|
||||
@ -15,6 +16,7 @@ struct FONT;
|
||||
namespace ui {
|
||||
|
||||
class ButtonBase;
|
||||
class Cursor;
|
||||
class Entry;
|
||||
class Menu;
|
||||
class MenuItem;
|
||||
@ -37,7 +39,7 @@ namespace ui {
|
||||
|
||||
void regenerate();
|
||||
|
||||
virtual BITMAP* set_cursor(int type, int *focus_x, int *focus_y) = 0;
|
||||
virtual Cursor* getCursor(CursorType type) = 0;
|
||||
virtual void init_widget(Widget* widget) = 0;
|
||||
virtual ui::JRegion get_window_mask(ui::Widget* widget) = 0;
|
||||
virtual void map_decorative_widget(ui::Widget* widget) = 0;
|
||||
|
@ -1368,7 +1368,7 @@ bool Widget::onProcessMessage(Message* msg)
|
||||
if (getParent() != NULL)
|
||||
return getParent()->sendMessage(msg);
|
||||
else {
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ bool Window::onProcessMessage(Message* msg)
|
||||
case JM_BUTTONRELEASED:
|
||||
if (hasCapture()) {
|
||||
releaseMouse();
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
|
||||
if (click_pos != NULL) {
|
||||
jrect_free(click_pos);
|
||||
@ -403,44 +403,44 @@ bool Window::onProcessMessage(Message* msg)
|
||||
case JM_SETCURSOR:
|
||||
if (m_is_moveable) {
|
||||
HitTest ht = hitTest(gfx::Point(msg->mouse.x, msg->mouse.y));
|
||||
int cursor = JI_CURSOR_NORMAL;
|
||||
CursorType cursor = kArrowCursor;
|
||||
|
||||
switch (ht) {
|
||||
|
||||
case HitTestCaption:
|
||||
cursor = JI_CURSOR_NORMAL;
|
||||
cursor = kArrowCursor;
|
||||
break;
|
||||
|
||||
case HitTestBorderNW:
|
||||
cursor = JI_CURSOR_SIZE_TL;
|
||||
cursor = kSizeTLCursor;
|
||||
break;
|
||||
|
||||
case HitTestBorderW:
|
||||
cursor = JI_CURSOR_SIZE_L;
|
||||
cursor = kSizeLCursor;
|
||||
break;
|
||||
|
||||
case HitTestBorderSW:
|
||||
cursor = JI_CURSOR_SIZE_BL;
|
||||
cursor = kSizeBLCursor;
|
||||
break;
|
||||
|
||||
case HitTestBorderNE:
|
||||
cursor = JI_CURSOR_SIZE_TR;
|
||||
cursor = kSizeTRCursor;
|
||||
break;
|
||||
|
||||
case HitTestBorderE:
|
||||
cursor = JI_CURSOR_SIZE_R;
|
||||
cursor = kSizeRCursor;
|
||||
break;
|
||||
|
||||
case HitTestBorderSE:
|
||||
cursor = JI_CURSOR_SIZE_BR;
|
||||
cursor = kSizeBRCursor;
|
||||
break;
|
||||
|
||||
case HitTestBorderN:
|
||||
cursor = JI_CURSOR_SIZE_T;
|
||||
cursor = kSizeTCursor;
|
||||
break;
|
||||
|
||||
case HitTestBorderS:
|
||||
cursor = JI_CURSOR_SIZE_B;
|
||||
cursor = kSizeBCursor;
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ bool ColorButton::onProcessMessage(Message* msg)
|
||||
|
||||
case JM_SETCURSOR:
|
||||
if (hasCapture()) {
|
||||
jmouse_set_cursor(JI_CURSOR_EYEDROPPER);
|
||||
jmouse_set_cursor(kEyedropperCursor);
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
|
@ -131,10 +131,10 @@ bool DrawingState::onSetCursor(Editor* editor)
|
||||
{
|
||||
if (m_toolLoop->getInk()->isEyedropper()) {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(JI_CURSOR_EYEDROPPER);
|
||||
jmouse_set_cursor(kEyedropperCursor);
|
||||
}
|
||||
else {
|
||||
jmouse_set_cursor(JI_CURSOR_NULL);
|
||||
jmouse_set_cursor(kNoCursor);
|
||||
editor->showDrawingCursor();
|
||||
}
|
||||
return true;
|
||||
|
@ -1099,7 +1099,7 @@ void Editor::editor_setcursor()
|
||||
|
||||
if (!used) {
|
||||
hideDrawingCursor();
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL);
|
||||
jmouse_set_cursor(kArrowCursor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ bool MovingPixelsState::onSetCursor(Editor* editor)
|
||||
// Move selection
|
||||
if (m_pixelsMovement->isDragging()) {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(JI_CURSOR_MOVE);
|
||||
jmouse_set_cursor(kMoveCursor);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ bool ScrollingState::onMouseWheel(Editor* editor, Message* msg)
|
||||
bool ScrollingState::onSetCursor(Editor* editor)
|
||||
{
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(JI_CURSOR_SCROLL);
|
||||
jmouse_set_cursor(kScrollCursor);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -123,8 +123,8 @@ bool SelectBoxState::onSetCursor(Editor* editor)
|
||||
{
|
||||
if (m_movingRuler >= 0) {
|
||||
switch (m_rulers[m_movingRuler].getOrientation()) {
|
||||
case Ruler::Horizontal: jmouse_set_cursor(JI_CURSOR_SIZE_T); return true;
|
||||
case Ruler::Vertical: jmouse_set_cursor(JI_CURSOR_SIZE_L); return true;
|
||||
case Ruler::Horizontal: jmouse_set_cursor(kSizeTCursor); return true;
|
||||
case Ruler::Vertical: jmouse_set_cursor(kSizeLCursor); return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,10 +135,10 @@ bool SelectBoxState::onSetCursor(Editor* editor)
|
||||
if (touchRuler(editor, *it, x, y)) {
|
||||
switch (it->getOrientation()) {
|
||||
case Ruler::Horizontal:
|
||||
jmouse_set_cursor(JI_CURSOR_SIZE_T);
|
||||
jmouse_set_cursor(kSizeTCursor);
|
||||
return true;
|
||||
case Ruler::Vertical:
|
||||
jmouse_set_cursor(JI_CURSOR_SIZE_L);
|
||||
jmouse_set_cursor(kSizeLCursor);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -62,26 +62,26 @@ enum WHEEL_ACTION { WHEEL_NONE,
|
||||
WHEEL_BG,
|
||||
WHEEL_FRAME };
|
||||
|
||||
static int rotated_size_cursors[] = {
|
||||
JI_CURSOR_SIZE_R,
|
||||
JI_CURSOR_SIZE_TR,
|
||||
JI_CURSOR_SIZE_T,
|
||||
JI_CURSOR_SIZE_TL,
|
||||
JI_CURSOR_SIZE_L,
|
||||
JI_CURSOR_SIZE_BL,
|
||||
JI_CURSOR_SIZE_B,
|
||||
JI_CURSOR_SIZE_BR
|
||||
static CursorType rotated_size_cursors[] = {
|
||||
kSizeRCursor,
|
||||
kSizeTRCursor,
|
||||
kSizeTCursor,
|
||||
kSizeTLCursor,
|
||||
kSizeLCursor,
|
||||
kSizeBLCursor,
|
||||
kSizeBCursor,
|
||||
kSizeBRCursor
|
||||
};
|
||||
|
||||
static int rotated_rotate_cursors[] = {
|
||||
JI_CURSOR_ROTATE_R,
|
||||
JI_CURSOR_ROTATE_TR,
|
||||
JI_CURSOR_ROTATE_T,
|
||||
JI_CURSOR_ROTATE_TL,
|
||||
JI_CURSOR_ROTATE_L,
|
||||
JI_CURSOR_ROTATE_BL,
|
||||
JI_CURSOR_ROTATE_B,
|
||||
JI_CURSOR_ROTATE_BR
|
||||
static CursorType rotated_rotate_cursors[] = {
|
||||
kRotateRCursor,
|
||||
kRotateTRCursor,
|
||||
kRotateTCursor,
|
||||
kRotateTLCursor,
|
||||
kRotateLCursor,
|
||||
kRotateBLCursor,
|
||||
kRotateBCursor,
|
||||
kRotateBRCursor
|
||||
};
|
||||
|
||||
static inline bool has_shifts(Message* msg, int shift)
|
||||
@ -391,39 +391,39 @@ bool StandbyState::onSetCursor(Editor* editor)
|
||||
editor->hideDrawingCursor();
|
||||
|
||||
if (customization && customization->isCopySelectionKeyPressed())
|
||||
jmouse_set_cursor(JI_CURSOR_NORMAL_ADD);
|
||||
jmouse_set_cursor(kArrowPlusCursor);
|
||||
else
|
||||
jmouse_set_cursor(JI_CURSOR_MOVE);
|
||||
jmouse_set_cursor(kMoveCursor);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (current_ink->isEyedropper()) {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(JI_CURSOR_EYEDROPPER);
|
||||
jmouse_set_cursor(kEyedropperCursor);
|
||||
return true;
|
||||
}
|
||||
else if (current_ink->isScrollMovement()) {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(JI_CURSOR_SCROLL);
|
||||
jmouse_set_cursor(kScrollCursor);
|
||||
return true;
|
||||
}
|
||||
else if (current_ink->isCelMovement()) {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(JI_CURSOR_MOVE);
|
||||
jmouse_set_cursor(kMoveCursor);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw
|
||||
if (editor->canDraw()) {
|
||||
jmouse_set_cursor(JI_CURSOR_NULL);
|
||||
jmouse_set_cursor(kNoCursor);
|
||||
editor->showDrawingCursor();
|
||||
}
|
||||
// Forbidden
|
||||
else {
|
||||
editor->hideDrawingCursor();
|
||||
jmouse_set_cursor(JI_CURSOR_FORBIDDEN);
|
||||
jmouse_set_cursor(kForbiddenCursor);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -540,26 +540,26 @@ bool StandbyState::Decorator::onSetCursor(Editor* editor)
|
||||
gfx::Point(jmouse_x(0), jmouse_y(0)),
|
||||
transformation);
|
||||
|
||||
int newCursor = JI_CURSOR_NORMAL;
|
||||
CursorType newCursor = kArrowCursor;
|
||||
|
||||
switch (handle) {
|
||||
case ScaleNWHandle: newCursor = JI_CURSOR_SIZE_TL; break;
|
||||
case ScaleNHandle: newCursor = JI_CURSOR_SIZE_T; break;
|
||||
case ScaleNEHandle: newCursor = JI_CURSOR_SIZE_TR; break;
|
||||
case ScaleWHandle: newCursor = JI_CURSOR_SIZE_L; break;
|
||||
case ScaleEHandle: newCursor = JI_CURSOR_SIZE_R; break;
|
||||
case ScaleSWHandle: newCursor = JI_CURSOR_SIZE_BL; break;
|
||||
case ScaleSHandle: newCursor = JI_CURSOR_SIZE_B; break;
|
||||
case ScaleSEHandle: newCursor = JI_CURSOR_SIZE_BR; break;
|
||||
case RotateNWHandle: newCursor = JI_CURSOR_ROTATE_TL; break;
|
||||
case RotateNHandle: newCursor = JI_CURSOR_ROTATE_T; break;
|
||||
case RotateNEHandle: newCursor = JI_CURSOR_ROTATE_TR; break;
|
||||
case RotateWHandle: newCursor = JI_CURSOR_ROTATE_L; break;
|
||||
case RotateEHandle: newCursor = JI_CURSOR_ROTATE_R; break;
|
||||
case RotateSWHandle: newCursor = JI_CURSOR_ROTATE_BL; break;
|
||||
case RotateSHandle: newCursor = JI_CURSOR_ROTATE_B; break;
|
||||
case RotateSEHandle: newCursor = JI_CURSOR_ROTATE_BR; break;
|
||||
case PivotHandle: newCursor = JI_CURSOR_HAND; break;
|
||||
case ScaleNWHandle: newCursor = kSizeTLCursor; break;
|
||||
case ScaleNHandle: newCursor = kSizeTCursor; break;
|
||||
case ScaleNEHandle: newCursor = kSizeTRCursor; break;
|
||||
case ScaleWHandle: newCursor = kSizeLCursor; break;
|
||||
case ScaleEHandle: newCursor = kSizeRCursor; break;
|
||||
case ScaleSWHandle: newCursor = kSizeBLCursor; break;
|
||||
case ScaleSHandle: newCursor = kSizeBCursor; break;
|
||||
case ScaleSEHandle: newCursor = kSizeBRCursor; break;
|
||||
case RotateNWHandle: newCursor = kRotateTLCursor; break;
|
||||
case RotateNHandle: newCursor = kRotateTCursor; break;
|
||||
case RotateNEHandle: newCursor = kRotateTRCursor; break;
|
||||
case RotateWHandle: newCursor = kRotateLCursor; break;
|
||||
case RotateEHandle: newCursor = kRotateRCursor; break;
|
||||
case RotateSWHandle: newCursor = kRotateBLCursor; break;
|
||||
case RotateSHandle: newCursor = kRotateBCursor; break;
|
||||
case RotateSEHandle: newCursor = kRotateBRCursor; break;
|
||||
case PivotHandle: newCursor = kHandCursor; break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -571,7 +571,7 @@ bool StandbyState::Decorator::onSetCursor(Editor* editor)
|
||||
angle >>= 16;
|
||||
angle /= 32;
|
||||
|
||||
if (newCursor >= JI_CURSOR_SIZE_TL && newCursor <= JI_CURSOR_SIZE_BR) {
|
||||
if (newCursor >= kSizeTLCursor && newCursor <= kSizeBRCursor) {
|
||||
size_t num = sizeof(rotated_size_cursors) / sizeof(rotated_size_cursors[0]);
|
||||
size_t c;
|
||||
for (c=num-1; c>0; --c)
|
||||
@ -580,7 +580,7 @@ bool StandbyState::Decorator::onSetCursor(Editor* editor)
|
||||
|
||||
newCursor = rotated_size_cursors[(c+angle) % num];
|
||||
}
|
||||
else if (newCursor >= JI_CURSOR_ROTATE_TL && newCursor <= JI_CURSOR_ROTATE_BR) {
|
||||
else if (newCursor >= kRotateTLCursor && newCursor <= kRotateBRCursor) {
|
||||
size_t num = sizeof(rotated_rotate_cursors) / sizeof(rotated_rotate_cursors[0]);
|
||||
size_t c;
|
||||
for (c=num-1; c>0; --c)
|
||||
|
Loading…
x
Reference in New Issue
Block a user