Merge pull request #5533 from Hinsbart/cursor_atex

Can use AtlasTextures as custom mouse cursor.
This commit is contained in:
Juan Linietsky 2016-07-10 12:41:57 -03:00 committed by GitHub
commit 0e6e0ed0e5
5 changed files with 18 additions and 7 deletions

View file

@ -30,6 +30,7 @@
#include "servers/visual_server.h"
#include "os/os.h"
#include "input_map.h"
#include "scene/resources/texture.h"
void InputDefault::SpeedTrack::update(const Vector2& p_delta_p) {
@ -463,9 +464,11 @@ void InputDefault::set_custom_mouse_cursor(const RES& p_cursor,const Vector2& p_
set_mouse_mode(MOUSE_MODE_VISIBLE);
VisualServer::get_singleton()->cursor_set_visible(false);
} else {
Ref<AtlasTexture> atex = custom_cursor;
Rect2 region = atex.is_valid() ? atex->get_region() : Rect2();
set_mouse_mode(MOUSE_MODE_HIDDEN);
VisualServer::get_singleton()->cursor_set_visible(true);
VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(),p_hotspot);
VisualServer::get_singleton()->cursor_set_texture(custom_cursor->get_rid(),p_hotspot, 0, region);
VisualServer::get_singleton()->cursor_set_pos(get_mouse_pos());
}
}

View file

@ -4448,12 +4448,13 @@ void VisualServerRaster::cursor_set_rotation(float p_rotation, int p_cursor) {
cursors[p_cursor].rot = p_rotation;
};
void VisualServerRaster::cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor) {
void VisualServerRaster::cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor, const Rect2 &p_region) {
VS_CHANGED;
ERR_FAIL_INDEX(p_cursor, MAX_CURSORS);
cursors[p_cursor].texture = p_texture;
cursors[p_cursor].center = p_center_offset;
cursors[p_cursor].region = p_region;
};
void VisualServerRaster::cursor_set_visible(bool p_visible, int p_cursor) {
@ -7530,8 +7531,13 @@ void VisualServerRaster::_draw_cursors_and_margins() {
RID tex = cursors[i].texture?cursors[i].texture:default_cursor_texture;
ERR_CONTINUE( !tex );
Point2 size(texture_get_width(tex), texture_get_height(tex));
rasterizer->canvas_draw_rect(Rect2(cursors[i].pos, size), 0, Rect2(), tex, Color(1, 1, 1, 1));
if (cursors[i].region.has_no_area()) {
Point2 size(texture_get_width(tex), texture_get_height(tex));
rasterizer->canvas_draw_rect(Rect2(cursors[i].pos, size), 0, Rect2(), tex, Color(1, 1, 1, 1));
} else {
Point2 size = cursors[i].region.size;
rasterizer->canvas_draw_rect(Rect2(cursors[i].pos, size), Rasterizer::CANVAS_RECT_REGION, cursors[i].region, tex, Color(1, 1, 1, 1));
}
};

View file

@ -544,10 +544,12 @@ class VisualServerRaster : public VisualServer {
RID texture;
Point2 center;
bool visible;
Rect2 region;
Cursor() {
rot = 0;
visible = false;
region = Rect2();
};
};
@ -1240,7 +1242,7 @@ public:
/* CURSOR */
virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0); // radians
virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor=0);
virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset, int p_cursor=0, const Rect2 &p_region=Rect2());
virtual void cursor_set_visible(bool p_visible, int p_cursor = 0);
virtual void cursor_set_pos(const Point2& p_pos, int p_cursor = 0);

View file

@ -680,7 +680,7 @@ public:
/* CURSOR */
FUNC2(cursor_set_rotation,float , int ); // radians
FUNC3(cursor_set_texture,RID , const Point2 &, int );
FUNC4(cursor_set_texture,RID , const Point2 &, int, const Rect2 &);
FUNC2(cursor_set_visible,bool , int );
FUNC2(cursor_set_pos,const Point2& , int );

View file

@ -1110,7 +1110,7 @@ public:
/* CURSOR */
virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0)=0; // radians
virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset = Point2(0, 0), int p_cursor=0)=0;
virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset = Point2(0, 0), int p_cursor=0, const Rect2 &p_region=Rect2())=0;
virtual void cursor_set_visible(bool p_visible, int p_cursor = 0)=0;
virtual void cursor_set_pos(const Point2& p_pos, int p_cursor = 0)=0;