|
|
@@ -57,6 +57,19 @@
|
|
|
namespace Urho3D
|
|
|
{
|
|
|
|
|
|
+/// OS cursor shape lookup table matching the %Cursor CursorShape enumeration
|
|
|
+static const int osCursorLookup[CS_MAX_SHAPES] =
|
|
|
+{
|
|
|
+ SDL_SYSTEM_CURSOR_ARROW, // CS_NORMAL
|
|
|
+ SDL_SYSTEM_CURSOR_SIZENS, // CS_RESIZEVERTICAL
|
|
|
+ SDL_SYSTEM_CURSOR_SIZENESW, // CS_RESIZEDIAGONAL_TOPRIGHT
|
|
|
+ SDL_SYSTEM_CURSOR_SIZEWE, // CS_RESIZEHORIZONTAL
|
|
|
+ SDL_SYSTEM_CURSOR_SIZENWSE, // CS_RESIZEDIAGONAL_TOPLEFT
|
|
|
+ SDL_SYSTEM_CURSOR_HAND, // CS_ACCEPTDROP
|
|
|
+ SDL_SYSTEM_CURSOR_NO, // CS_REJECTDROP
|
|
|
+ SDL_SYSTEM_CURSOR_WAIT // CS_BUSY
|
|
|
+};
|
|
|
+
|
|
|
ShortStringHash VAR_ORIGIN("Origin");
|
|
|
const ShortStringHash VAR_ORIGINAL_PARENT("OriginalParent");
|
|
|
const ShortStringHash VAR_ORIGINAL_CHILD_INDEX("OriginalChildIndex");
|
|
|
@@ -85,6 +98,12 @@ UI::UI(Context* context) :
|
|
|
rootElement_->SetTraversalMode(TM_DEPTH_FIRST);
|
|
|
rootModalElement_->SetTraversalMode(TM_DEPTH_FIRST);
|
|
|
clickTimer_ = new Timer();
|
|
|
+
|
|
|
+ // Nullify OS cursor shapes
|
|
|
+ for (unsigned i = 0; i < CS_MAX_SHAPES; ++i)
|
|
|
+ {
|
|
|
+ osCursorShapes_[i] = 0;
|
|
|
+ }
|
|
|
|
|
|
// Register UI library object factories
|
|
|
RegisterUILibrary(context_);
|
|
|
@@ -107,6 +126,16 @@ UI::UI(Context* context) :
|
|
|
UI::~UI()
|
|
|
{
|
|
|
delete clickTimer_;
|
|
|
+
|
|
|
+ for (unsigned i = 0; i < CS_MAX_SHAPES; ++i)
|
|
|
+ {
|
|
|
+ if (osCursorShapes_[i])
|
|
|
+ {
|
|
|
+ // Free OS cursor and nullify
|
|
|
+ SDL_FreeCursor(osCursorShapes_[i]);
|
|
|
+ osCursorShapes_[i] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void UI::SetCursor(Cursor* cursor)
|
|
|
@@ -466,6 +495,11 @@ void UI::SetNonFocusedMouseWheel(bool nonFocusedMouseWheel)
|
|
|
nonFocusedMouseWheel_ = nonFocusedMouseWheel;
|
|
|
}
|
|
|
|
|
|
+IntVector2 UI::GetCursorPosition() const
|
|
|
+{
|
|
|
+ return cursor_ ? cursor_->GetPosition() : GetSubsystem<Input>()->GetMousePosition();
|
|
|
+}
|
|
|
+
|
|
|
UIElement* UI::GetElementAt(const IntVector2& position, bool enabledOnly)
|
|
|
{
|
|
|
UIElement* result = 0;
|
|
|
@@ -501,11 +535,6 @@ UIElement* UI::GetFrontElement() const
|
|
|
return front;
|
|
|
}
|
|
|
|
|
|
-IntVector2 UI::GetCursorPosition() const
|
|
|
-{
|
|
|
- return cursor_ ? cursor_->GetPosition() : GetSubsystem<Input>()->GetMousePosition();
|
|
|
-}
|
|
|
-
|
|
|
bool UI::HasModalElement() const
|
|
|
{
|
|
|
return rootModalElement_->GetNumChildren() > 0;
|
|
|
@@ -790,6 +819,22 @@ void UI::SetCursorShape(CursorShape shape)
|
|
|
{
|
|
|
if (cursor_)
|
|
|
cursor_->SetShape(shape);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Check now: Cursor's SetShape does this check too, so avoids checking twice.
|
|
|
+ if (shape < CS_NORMAL || shape >= CS_MAX_SHAPES)
|
|
|
+ return;
|
|
|
+
|
|
|
+ if (!osCursorShapes_[shape])
|
|
|
+ {
|
|
|
+ // Create OS cursor corresponding to specified CursorShape
|
|
|
+ osCursorShapes_[shape] = SDL_CreateSystemCursor((SDL_SystemCursor)osCursorLookup[shape]);
|
|
|
+ if (!osCursorShapes_[shape])
|
|
|
+ LOGERROR("Could not create system cursor!");
|
|
|
+ }
|
|
|
+
|
|
|
+ SDL_SetCursor(osCursorShapes_[shape]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void UI::SendDragEvent(StringHash eventType, UIElement* element, const IntVector2& screenPos)
|