Browse Source

Misc. tweaks on Editors and minor refactoring.

Yao Wei Tjong 姚伟忠 12 years ago
parent
commit
2565755905

BIN
Bin/Data/Textures/UI.png


+ 15 - 7
Bin/Data/UI/DefaultStyle.xml

@@ -177,6 +177,12 @@
         <attribute name="Border" value="4 4 4 4" />
         <attribute name="Border" value="4 4 4 4" />
         <attribute name="Resize Border" value="8 8 8 8" />
         <attribute name="Resize Border" value="8 8 8 8" />
     </element>
     </element>
+    <element type="DialogWindow" style="Window" auto="false">
+        <attribute name="Is Movable" value="true" />
+        <attribute name="Modal Shade Color" value="0.3 0.4 0.7 0.4" />
+        <attribute name="Modal Frame Color" value="0.3 0.4 0.7" />
+        <attribute name="Modal Frame Size" value="2 2" />
+    </element>
     <element type="ListRow">
     <element type="ListRow">
         <attribute name="Min Size" value="0 17" />
         <attribute name="Min Size" value="0 17" />
         <attribute name="Max Size" value="2147483647 17" />
         <attribute name="Max Size" value="2147483647 17" />
@@ -185,7 +191,7 @@
     <element type="PanelView" style="ListView" auto="false">    <!-- todo: rename this to PanelListView -->
     <element type="PanelView" style="ListView" auto="false">    <!-- todo: rename this to PanelListView -->
         <element type="BorderImage" internal="true">
         <element type="BorderImage" internal="true">
             <attribute name="Image Rect" value="48 16 64 32" />
             <attribute name="Image Rect" value="48 16 64 32" />
-            <attribute name="Hover Image Offset" value="16 0" />
+            <attribute name="Hover Image Offset" value="80 32" />
             <element internal="true">
             <element internal="true">
                 <attribute name="Layout Spacing" value="4" />
                 <attribute name="Layout Spacing" value="4" />
                 <attribute name="Layout Border" value="4 4 4 4" />
                 <attribute name="Layout Border" value="4 4 4 4" />
@@ -196,6 +202,10 @@
         <attribute name="Layout Mode" value="Vertical" />
         <attribute name="Layout Mode" value="Vertical" />
         <attribute name="Layout Spacing" value="4" />
         <attribute name="Layout Spacing" value="4" />
     </element>
     </element>
+    <element type="HorizontalPanel" auto="false">
+        <attribute name="Layout Mode" value="Horizontal" />
+        <attribute name="Layout Spacing" value="4" />
+    </element>
     <element type="Text">
     <element type="Text">
         <attribute name="Font" value="Font;Fonts/Anonymous Pro.ttf" />
         <attribute name="Font" value="Font;Fonts/Anonymous Pro.ttf" />
         <attribute name="Font Size" value="11" />
         <attribute name="Font Size" value="11" />
@@ -219,12 +229,6 @@
             <attribute name="Selection Color" value="0.3 0.4 0.7 0.75" />
             <attribute name="Selection Color" value="0.3 0.4 0.7 0.75" />
         </element>
         </element>
     </element>
     </element>
-    <element type="DialogWindow" style="Window" auto="false">
-        <attribute name="Is Movable" value="true" />
-        <attribute name="Modal Shade Color" value="0.3 0.4 0.7 0.05" />
-        <attribute name="Modal Frame Color" value="0.3 0.4 0.7" />
-        <attribute name="Modal Frame Size" value="2 2" />
-    </element>
     <element type="FileSelector" style="DialogWindow" auto="false">
     <element type="FileSelector" style="DialogWindow" auto="false">
         <attribute name="Size" value="400 300" />
         <attribute name="Size" value="400 300" />
         <attribute name="Is Resizable" value="true" />
         <attribute name="Is Resizable" value="true" />
@@ -271,6 +275,10 @@
         <attribute name="Min Size" value="0 11" />
         <attribute name="Min Size" value="0 11" />
         <attribute name="Max Size" value="2147483647 11" />
         <attribute name="Max Size" value="2147483647 11" />
     </element>
     </element>
+    <element type="EditorSeparator" auto="false">
+        <attribute name="Min Size" value="0 2" />
+        <attribute name="Max Size" value="2147483647 2" />
+    </element>
     <element type="EditorMenuBar" style="BorderImage" auto="false">
     <element type="EditorMenuBar" style="BorderImage" auto="false">
         <attribute name="Image Rect" value="112 0 128 16" />
         <attribute name="Image Rect" value="112 0 128 16" />
         <attribute name="Border" value="4 4 4 4" />
         <attribute name="Border" value="4 4 4 4" />

+ 12 - 16
Bin/Data/UI/MessageBox.xml

@@ -7,10 +7,9 @@
 	<attribute name="Layout Spacing" value="4" />
 	<attribute name="Layout Spacing" value="4" />
 	<attribute name="Layout Border" value="6 6 6 6" />
 	<attribute name="Layout Border" value="6 6 6 6" />
 	<attribute name="Resize Border" value="6 6 6 6" />
 	<attribute name="Resize Border" value="6 6 6 6" />
-	<element>
-		<attribute name="Min Size" value="64 16" />
+	<element style="HorizontalPanel">
+		<attribute name="Min Size" value="60 16" />
 		<attribute name="Max Size" value="2147483647 16" />
 		<attribute name="Max Size" value="2147483647 16" />
-		<attribute name="Layout Mode" value="Horizontal" />
 		<element type="Text">
 		<element type="Text">
 			<attribute name="Name" value="TitleText" />
 			<attribute name="Name" value="TitleText" />
 			<attribute name="Text" value="Error" />
 			<attribute name="Text" value="Error" />
@@ -29,33 +28,30 @@
 			<attribute name="Text Alignment" value="Center" />
 			<attribute name="Text Alignment" value="Center" />
 		</element>
 		</element>
 	</element>
 	</element>
-	<element>
+    <element style="EditorSeparator" />
+	<element style="HorizontalPanel">
 		<attribute name="Min Size" value="74 17" />
 		<attribute name="Min Size" value="74 17" />
 		<attribute name="Max Size" value="2147483647 17" />
 		<attribute name="Max Size" value="2147483647 17" />
-		<attribute name="Layout Mode" value="Horizontal" />
-		<attribute name="Layout Spacing" value="4" />
 		<element />
 		<element />
 		<element type="Button">
 		<element type="Button">
 			<attribute name="Name" value="CancelButton" />
 			<attribute name="Name" value="CancelButton" />
-			<attribute name="Min Size" value="70 17" />
-			<attribute name="Max Size" value="70 17" />
+			<attribute name="Min Size" value="80 17" />
+			<attribute name="Max Size" value="80 17" />
 			<attribute name="Is Visible" value="false" />
 			<attribute name="Is Visible" value="false" />
-			<attribute name="Layout Mode" value="Horizontal" />
-			<attribute name="Layout Border" value="1 1 1 1" />
 			<element type="Text">
 			<element type="Text">
+				<attribute name="Horiz Alignment" value="Center" />
+				<attribute name="Vert Alignment" value="Center" />
 				<attribute name="Text" value="Cancel" />
 				<attribute name="Text" value="Cancel" />
-				<attribute name="Text Alignment" value="Center" />
 			</element>
 			</element>
 		</element>
 		</element>
 		<element type="Button">
 		<element type="Button">
 			<attribute name="Name" value="OkButton" />
 			<attribute name="Name" value="OkButton" />
-			<attribute name="Min Size" value="70 17" />
-			<attribute name="Max Size" value="70 17" />
-			<attribute name="Layout Mode" value="Horizontal" />
-			<attribute name="Layout Border" value="1 1 1 1" />
+			<attribute name="Min Size" value="80 17" />
+			<attribute name="Max Size" value="80 17" />
 			<element type="Text">
 			<element type="Text">
+				<attribute name="Horiz Alignment" value="Center" />
+				<attribute name="Vert Alignment" value="Center" />
 				<attribute name="Text" value="OK" />
 				<attribute name="Text" value="OK" />
-				<attribute name="Text Alignment" value="Center" />
 			</element>
 			</element>
 		</element>
 		</element>
 	</element>
 	</element>

+ 2 - 5
Source/Engine/Input/Input.cpp

@@ -393,10 +393,7 @@ JoystickState* Input::GetJoystick(unsigned index)
 
 
 bool Input::GetScreenKeyboardSupport() const
 bool Input::GetScreenKeyboardSupport() const
 {
 {
-    if (graphics_)
-        return SDL_HasScreenKeyboardSupport() ? true : false;
-    else
-        return false;
+    return graphics_ ? SDL_HasScreenKeyboardSupport() : false;
 }
 }
 
 
 bool Input::IsScreenKeyboardVisible() const
 bool Input::IsScreenKeyboardVisible() const
@@ -404,7 +401,7 @@ bool Input::IsScreenKeyboardVisible() const
     if (graphics_)
     if (graphics_)
     {
     {
         SDL_Window* window = graphics_->GetImpl()->GetWindow();
         SDL_Window* window = graphics_->GetImpl()->GetWindow();
-        return SDL_IsScreenKeyboardShown(window) ? true : false;
+        return SDL_IsScreenKeyboardShown(window);
     }
     }
     else
     else
         return false;
         return false;

+ 9 - 9
Source/Engine/UI/FileSelector.cpp

@@ -85,26 +85,25 @@ FileSelector::FileSelector(Context* context) :
 
 
     window_->AddChild(fileNameLayout_);
     window_->AddChild(fileNameLayout_);
 
 
+    separatorLayout_ = new UIElement(context_);
+    window_->AddChild(separatorLayout_);
+
     buttonLayout_ = new UIElement(context_);
     buttonLayout_ = new UIElement(context_);
     buttonLayout_->SetLayout(LM_HORIZONTAL);
     buttonLayout_->SetLayout(LM_HORIZONTAL);
 
 
     buttonLayout_->AddChild(new UIElement(context_)); // Add spacer
     buttonLayout_->AddChild(new UIElement(context_)); // Add spacer
 
 
-    okButton_ = new Button(context_);
-    okButtonText_ = new Text(context_);
-    okButtonText_->SetAlignment(HA_CENTER, VA_CENTER);
-    okButton_->AddChild(okButtonText_);
-    buttonLayout_->AddChild(okButton_);
-
-    buttonLayout_->AddChild(new UIElement(context_)); // Add spacer
-
     cancelButton_ = new Button(context_);
     cancelButton_ = new Button(context_);
     cancelButtonText_ = new Text(context_);
     cancelButtonText_ = new Text(context_);
     cancelButtonText_->SetAlignment(HA_CENTER, VA_CENTER);
     cancelButtonText_->SetAlignment(HA_CENTER, VA_CENTER);
     cancelButton_->AddChild(cancelButtonText_);
     cancelButton_->AddChild(cancelButtonText_);
     buttonLayout_->AddChild(cancelButton_);
     buttonLayout_->AddChild(cancelButton_);
 
 
-    buttonLayout_->AddChild(new UIElement(context_)); // Add spacer
+    okButton_ = new Button(context_);
+    okButtonText_ = new Text(context_);
+    okButtonText_->SetAlignment(HA_CENTER, VA_CENTER);
+    okButton_->AddChild(okButtonText_);
+    buttonLayout_->AddChild(okButton_);
 
 
     window_->AddChild(buttonLayout_);
     window_->AddChild(buttonLayout_);
 
 
@@ -160,6 +159,7 @@ void FileSelector::SetDefaultStyle(XMLFile* style)
     titleLayout->SetStyle("FileSelectorLayout");
     titleLayout->SetStyle("FileSelectorLayout");
     fileNameLayout_->SetStyle("FileSelectorLayout");
     fileNameLayout_->SetStyle("FileSelectorLayout");
     buttonLayout_->SetStyle("FileSelectorLayout");
     buttonLayout_->SetStyle("FileSelectorLayout");
+    separatorLayout_->SetStyle("EditorSeparator");
 
 
     fileList_->SetStyle("FileSelectorListView");
     fileList_->SetStyle("FileSelectorListView");
     fileNameEdit_->SetStyle("FileSelectorLineEdit");
     fileNameEdit_->SetStyle("FileSelectorLineEdit");

+ 15 - 13
Source/Engine/UI/FileSelector.h

@@ -135,31 +135,33 @@ private:
     /// Fileselector window.
     /// Fileselector window.
     SharedPtr<Window> window_;
     SharedPtr<Window> window_;
     /// Title layout.
     /// Title layout.
-    SharedPtr<UIElement> titleLayout;
+    UIElement* titleLayout;
     /// Window title text.
     /// Window title text.
-    SharedPtr<Text> titleText_;
+    Text* titleText_;
     /// File list.
     /// File list.
-    SharedPtr<ListView> fileList_;
+    ListView* fileList_;
     /// Path editor.
     /// Path editor.
-    SharedPtr<LineEdit> pathEdit_;
+    LineEdit* pathEdit_;
     /// Filename editor.
     /// Filename editor.
-    SharedPtr<LineEdit> fileNameEdit_;
+    LineEdit* fileNameEdit_;
     /// Filter dropdown.
     /// Filter dropdown.
-    SharedPtr<DropDownList> filterList_;
+    DropDownList* filterList_;
     /// OK button.
     /// OK button.
-    SharedPtr<Button> okButton_;
+    Button* okButton_;
     /// OK button text.
     /// OK button text.
-    SharedPtr<Text> okButtonText_;
+    Text* okButtonText_;
     /// Cancel button.
     /// Cancel button.
-    SharedPtr<Button> cancelButton_;
+    Button* cancelButton_;
     /// Cancel button text.
     /// Cancel button text.
-    SharedPtr<Text> cancelButtonText_;
+    Text* cancelButtonText_;
     /// Close button.
     /// Close button.
-    SharedPtr<Button> closeButton_;
+    Button* closeButton_;
     /// Filename and filter layout.
     /// Filename and filter layout.
-    SharedPtr<UIElement> fileNameLayout_;
+    UIElement* fileNameLayout_;
+    /// Separator layout.
+    UIElement* separatorLayout_;
     /// Button layout.
     /// Button layout.
-    SharedPtr<UIElement> buttonLayout_;
+    UIElement* buttonLayout_;
     /// Current directory.
     /// Current directory.
     String path_;
     String path_;
     /// Filters.
     /// Filters.

+ 2 - 4
Source/Engine/UI/ListView.cpp

@@ -205,9 +205,8 @@ void ListView::OnKey(int key, int buttons, int qualifiers)
 
 
     // If either shift or ctrl held down, add to selection if multiselect enabled
     // If either shift or ctrl held down, add to selection if multiselect enabled
     bool additive = multiselect_ && qualifiers & (QUAL_SHIFT | QUAL_CTRL);
     bool additive = multiselect_ && qualifiers & (QUAL_SHIFT | QUAL_CTRL);
-    int delta = 0;
+    int delta = M_MAX_INT;
     int pageDirection = 1;
     int pageDirection = 1;
-    bool acceptZeroDelta = false;
 
 
     if (numItems)
     if (numItems)
     {
     {
@@ -270,7 +269,6 @@ void ListView::OnKey(int key, int buttons, int qualifiers)
                     newSelection += pageDirection;
                     newSelection += pageDirection;
                 }
                 }
                 delta = okSelection - selection - pageDirection * invisible;
                 delta = okSelection - selection - pageDirection * invisible;
-                acceptZeroDelta = true;     // Ensure Page Up and Down are being treated as handled key even though they generate zero delta
             }
             }
             break;
             break;
 
 
@@ -284,7 +282,7 @@ void ListView::OnKey(int key, int buttons, int qualifiers)
         }
         }
     }
     }
 
 
-    if (delta || acceptZeroDelta)
+    if (delta != M_MAX_INT)
     {
     {
         ChangeSelection(delta, additive);
         ChangeSelection(delta, additive);
         return;
         return;

+ 3 - 5
Source/Engine/UI/MessageBox.cpp

@@ -24,6 +24,7 @@
 #include "Button.h"
 #include "Button.h"
 #include "Context.h"
 #include "Context.h"
 #include "Graphics.h"
 #include "Graphics.h"
+#include "Log.h"
 #include "MessageBox.h"
 #include "MessageBox.h"
 #include "ResourceCache.h"
 #include "ResourceCache.h"
 #include "Text.h"
 #include "Text.h"
@@ -67,6 +68,8 @@ MessageBox::MessageBox(Context* context, const String& messageString, const Stri
             const IntVector2& size = window->GetSize();
             const IntVector2& size = window->GetSize();
             window->SetPosition((graphics->GetWidth() - size.x_) / 2, (graphics->GetHeight() - size.y_) / 2);
             window->SetPosition((graphics->GetWidth() - size.x_) / 2, (graphics->GetHeight() - size.y_) / 2);
         }
         }
+        else
+            LOGWARNING("Instantiating a modal window in headless mode!");
         window->SetModal(true);
         window->SetModal(true);
     }
     }
 
 
@@ -92,11 +95,6 @@ MessageBox::~MessageBox()
     window_->Remove();
     window_->Remove();
 }
 }
 
 
-void MessageBox::RegisterObject(Context* context)
-{
-    context->RegisterFactory<MessageBox>();
-}
-
 void MessageBox::SetTitle(const String& text)
 void MessageBox::SetTitle(const String& text)
 {
 {
     if (titleText_)
     if (titleText_)

+ 4 - 6
Source/Engine/UI/MessageBox.h

@@ -42,8 +42,6 @@ public:
     MessageBox(Context* context, const String& messageString = String::EMPTY, const String& titleString = String::EMPTY, XMLFile* layoutFile = 0, XMLFile* styleFile = 0);
     MessageBox(Context* context, const String& messageString = String::EMPTY, const String& titleString = String::EMPTY, XMLFile* layoutFile = 0, XMLFile* styleFile = 0);
     /// Destruct.
     /// Destruct.
     virtual ~MessageBox();
     virtual ~MessageBox();
-    /// Register object factory.
-    static void RegisterObject(Context* context);
 
 
     /// Set title text. No-ops if there is no title text element.
     /// Set title text. No-ops if there is no title text element.
     void SetTitle(const String& text);
     void SetTitle(const String& text);
@@ -61,13 +59,13 @@ private:
     /// Handle events that dismiss the message box.
     /// Handle events that dismiss the message box.
     void HandleMessageAcknowledged(StringHash eventType, VariantMap& eventData);
     void HandleMessageAcknowledged(StringHash eventType, VariantMap& eventData);
 
 
-    /// UI window layout.
+    /// UI element containing the whole UI layout. Typically it is a Window element type.
     SharedPtr<UIElement> window_;
     SharedPtr<UIElement> window_;
-    /// UI title text element.
+    /// Title text element.
     Text* titleText_;
     Text* titleText_;
-    /// UI message text element.
+    /// Message text element.
     Text* messageText_;
     Text* messageText_;
-    /// UI OK button element.
+    /// OK button element.
     Button* okButton_;
     Button* okButton_;
 };
 };