瀏覽代碼

GuiInspector With GuiDropDownCtrl

This code causes GuiInspector to use the GuiDropDownCtrl instead of the popup.
Peter Robinson 4 年之前
父節點
當前提交
f70647b52f

+ 4 - 15
engine/source/gui/editor/guiInspector.cc

@@ -26,11 +26,6 @@
 //////////////////////////////////////////////////////////////////////////
 // GuiInspector
 //////////////////////////////////////////////////////////////////////////
-// The GuiInspector Control houses the body of the inspector.
-// It is not exposed as a conobject because it merely does the grunt work
-// and is only meant to be used when housed by a scroll control.  Therefore
-// the GuiInspector control is a scroll control that creates it's own 
-// content.  That content being of course, the GuiInspector control.
 IMPLEMENT_CONOBJECT(GuiInspector);
 
 GuiInspector::GuiInspector()
@@ -51,9 +46,6 @@ bool GuiInspector::onAdd()
    if( !Parent::onAdd() )
       return false;
 
-   // we only need to worry about the width.
-   setWidth(getExtent().x);
-
    return true;
 }
 
@@ -1110,22 +1102,19 @@ void GuiInspectorDatablockField::setClassName( StringTableEntry className )
 
 GuiControl* GuiInspectorDatablockField::constructEditControl()
 {
-   GuiControl* retCtrl = new GuiPopUpMenuCtrl();
+   GuiControl* retCtrl = new GuiDropDownCtrl();
 
    // If we couldn't construct the control, bail!
    if( retCtrl == NULL )
       return retCtrl;
 
-   GuiPopUpMenuCtrl *menu = dynamic_cast<GuiPopUpMenuCtrl*>(retCtrl);
-
-   // Let's make it look pretty.
-   retCtrl->setField( "profile", "GuiPopUpMenuProfile2" );
+   GuiDropDownCtrl *menu = dynamic_cast<GuiDropDownCtrl*>(retCtrl);
 
    menu->setField("text", getData());
 
    registerEditControl( retCtrl );
 
-   // Configure it to update our value when the popup is closed
+   // Configure it to update our value when the dropdown is closed
    char szBuffer[512];
    dSprintf( szBuffer, 512, "%d.%s = %d.getText();%d.inspect(%d);",mTarget->getId(), mField->pFieldname, menu->getId(), mParent->mParent->getId(), mTarget->getId() );
    menu->setField("Command", szBuffer );
@@ -1151,7 +1140,7 @@ GuiControl* GuiInspectorDatablockField::constructEditControl()
 
    // add them to our enum
    for(U32 j = 0; j < (U32)entries.size(); j++)
-      menu->addEntry(entries[j], 0);
+      menu->getList()->addItem(entries[j]);
 
    return retCtrl;
 }

+ 2 - 4
engine/source/gui/editor/guiInspector.h

@@ -50,8 +50,8 @@
 #include "gui/buttons/guiButtonCtrl.h"
 #endif
 
-#ifndef _GUIPOPUPCTRL_H_
-#include "gui/guiPopUpCtrl.h"
+#ifndef _GUIDROPDOWNCTRL_H_
+#include "gui/buttons/guiDropDownCtrl.h"
 #endif
 
 #ifndef _GUICHAINCTRL_H_
@@ -163,8 +163,6 @@ public:
 protected:
    // overridable method that creates our inner controls.
    virtual bool createContent();
-
-
 };
 
 class GuiInspectorDynamicField : public GuiInspectorField

+ 19 - 22
engine/source/gui/editor/guiInspectorTypes.cc

@@ -28,17 +28,16 @@ IMPLEMENT_CONOBJECT(GuiInspectorTypeEnum);
 
 GuiControl* GuiInspectorTypeEnum::constructEditControl()
 {
-   GuiControl* retCtrl = new GuiPopUpMenuCtrl();
+   GuiControl* retCtrl = new GuiDropDownCtrl();
 
    // If we couldn't construct the control, bail!
    if( retCtrl == NULL )
       return retCtrl;
 
-   GuiPopUpMenuCtrl *menu = dynamic_cast<GuiPopUpMenuCtrl*>(retCtrl);
+   GuiDropDownCtrl *menu = dynamic_cast<GuiDropDownCtrl*>(retCtrl);
 
    // Let's make it look pretty.
-   retCtrl->setField( "profile", "GuiPopUpMenuProfile2" );
-   retCtrl->setExtent(Point2I((mParent->getWidth() / 2) - 20, 18));
+   retCtrl->setExtent(Point2I((mParent->getWidth() / 2) - 20, 24));
    menu->setField("text", getData());
 
    registerEditControl( retCtrl );
@@ -50,7 +49,7 @@ GuiControl* GuiInspectorTypeEnum::constructEditControl()
 
    //now add the entries
    for(S32 i = 0; i < mField->table->size; i++)
-      menu->addEntry(mField->table->table[i].label, mField->table->table[i].index);
+      menu->getList()->addItemWithID(mField->table->table[i].label, mField->table->table[i].index);
 
    return retCtrl;
 }
@@ -64,9 +63,11 @@ void GuiInspectorTypeEnum::consoleInit()
 
 void GuiInspectorTypeEnum::updateValue( StringTableEntry newValue )
 {
-   GuiPopUpMenuCtrl *ctrl = dynamic_cast<GuiPopUpMenuCtrl*>( mEdit );
-   if( ctrl != NULL )
-      ctrl->setText( newValue );
+	GuiDropDownCtrl *ctrl = dynamic_cast<GuiDropDownCtrl*>( mEdit );
+	if (ctrl != NULL)
+	{
+		ctrl->getList()->setSelectionInternal(newValue);
+	}
 }
 
 void GuiInspectorTypeEnum::setData( StringTableEntry data )
@@ -151,17 +152,16 @@ static S32 QSORT_CALLBACK stringCompare(const void *a,const void *b)
 
 GuiControl* GuiInspectorTypeGuiProfile::constructEditControl()
 {
-   GuiControl* retCtrl = new GuiPopUpMenuCtrl();
+   GuiControl* retCtrl = new GuiDropDownCtrl();
 
    // If we couldn't construct the control, bail!
    if( retCtrl == NULL )
       return retCtrl;
 
-   GuiPopUpMenuCtrl *menu = dynamic_cast<GuiPopUpMenuCtrl*>(retCtrl);
+   GuiDropDownCtrl *menu = dynamic_cast<GuiDropDownCtrl*>(retCtrl);
 
    // Let's make it look pretty.
-   retCtrl->setField( "profile", "GuiPopUpMenuProfile2" );
-   retCtrl->setExtent(Point2I((mParent->getWidth() / 2) - 20, 18));
+   retCtrl->setExtent(Point2I((mParent->getWidth() / 2) - 20, 24));
    menu->setField("text", getData());
 
    registerEditControl( retCtrl );
@@ -183,11 +183,9 @@ GuiControl* GuiInspectorTypeGuiProfile::constructEditControl()
       }
    }
 
-   menu->sort();
-   // sort the entries
-   //dQsort(entries.address(), entries.size(), sizeof(StringTableEntry), stringCompare);
+   menu->getList()->sortByText();
    for(U32 j = 0; j < (U32)entries.size(); j++)
-      menu->addEntry(entries[j], 0);
+      menu->getList()->addItem(entries[j]);
 
    return retCtrl;
 }
@@ -206,17 +204,16 @@ void GuiInspectorTypeGuiBorderProfile::consoleInit()
 
 GuiControl* GuiInspectorTypeGuiBorderProfile::constructEditControl()
 {
-   GuiControl* retCtrl = new GuiPopUpMenuCtrl();
+   GuiControl* retCtrl = new GuiDropDownCtrl();
 
    // If we couldn't construct the control, bail!
    if (retCtrl == NULL)
       return retCtrl;
 
-   GuiPopUpMenuCtrl *menu = dynamic_cast<GuiPopUpMenuCtrl*>(retCtrl);
+   GuiDropDownCtrl *menu = dynamic_cast<GuiDropDownCtrl*>(retCtrl);
 
    // Let's make it look pretty.
-   retCtrl->setField("profile", "GuiPopUpMenuProfile2");
-   retCtrl->setExtent(Point2I((mParent->getWidth() / 2) - 20, 18));
+   retCtrl->setExtent(Point2I((mParent->getWidth() / 2) - 20, 24));
    menu->setField("text", getData());
 
    registerEditControl(retCtrl);
@@ -238,9 +235,9 @@ GuiControl* GuiInspectorTypeGuiBorderProfile::constructEditControl()
       }
    }
 
-   menu->sort();
+   menu->getList()->sortByText();
    for (U32 j = 0; j < (U32)entries.size(); j++)
-      menu->addEntry(entries[j], 0);
+      menu->getList()->addItem(entries[j]);
 
    return retCtrl;
 }

+ 2 - 2
engine/source/gui/editor/guiInspectorTypes.h

@@ -55,8 +55,8 @@
 #include "gui/guiTextEditCtrl.h"
 #endif
 
-#ifndef _GUIPOPUPCTRL_H_
-#include "gui/guiPopUpCtrl.h"
+#ifndef _GUIDROPDOWNCTRL_H_
+#include "gui/buttons/guiDropDownCtrl.h"
 #endif
 
 #ifndef _GUIGRIDCTRL_H_

+ 11 - 11
engine/source/gui/editor/guiMenuBarCtrl.cc

@@ -56,7 +56,7 @@ GuiMenuBarCtrl::GuiMenuBarCtrl()
 	setField("ThumbProfile", "GuiScrollThumbProfile");
 
 	mArrowProfile = NULL;
-	setField("ArrowProfile", "GuiSrollArrowProfile");
+	setField("ArrowProfile", "GuiScrollArrowProfile");
 
 	mTrackProfile = NULL;
 	setField("TrackProfile", "GuiScrollTrackProfile");
@@ -184,13 +184,13 @@ void GuiMenuBarCtrl::processHover(const GuiEvent &event)
 
 void GuiMenuBarCtrl::setHoverTarget(GuiMenuItemCtrl *ctrl)
 {
-	if (mHoverTarget != ctrl) 
+	if (mHoverTarget != ctrl)
 	{
-		if (mHoverTarget != NULL) 
+		if (mHoverTarget != NULL)
 		{
 			mHoverTarget->mIsHover = false;
 		}
-		if(ctrl != NULL) 
+		if(ctrl != NULL)
 		{
 			ctrl->mIsHover = true;
 		}
@@ -422,7 +422,7 @@ bool GuiMenuBarCtrl::onKeyDown(const GuiEvent &event)
 			return true;
 		}
 	}
-		
+
 	return false;
 }
 
@@ -712,7 +712,7 @@ void GuiMenuItemCtrl::onChildAdded(GuiControl *child)
 		}
 
 		if(mList == NULL)
-		{ 
+		{
 			mList = new GuiMenuListCtrl(this);
 			AssertFatal(mList, "GuiMenuItemCtrl::onChildAdded Failed to initialize GuiMenuListCtrl!");
 			mScroll->addObject(mList);
@@ -1171,7 +1171,7 @@ void GuiMenuListCtrl::onPreRender()
 	U32 currentTime = Platform::getVirtualMilliseconds();
 	if (mArmSubMenu && mHoveredItem != NULL && mHoveredItem != mMenu->mOpenSubMenu && (currentTime - mEnterItemTime) > mSubMenuStallTime)
 	{
-		//Close an open sub menu 
+		//Close an open sub menu
 		if (mMenu->mOpenSubMenu != NULL)
 		{
 			mMenu->mOpenSubMenu->closeMenu();
@@ -1277,7 +1277,7 @@ bool GuiMenuListCtrl::onRenderItem(RectI &itemRect, GuiMenuItemCtrl *item)
 		currentState = GuiControlState::DisabledState;
 	else if (item->mDisplayType == GuiMenuItemCtrl::DisplayType::Spacer)
 		currentState = GuiControlState::SelectedState;
-	else if (mHoveredItem == item || 
+	else if (mHoveredItem == item ||
 		(item->mIsOpen && (mMenu->mMenuBar->mUseKeyMode || !mMenu->mScroll->mBounds.pointInRect(cursorPt) || mMenu->mOpenSubMenu->mScroll->mBounds.pointInRect(cursorPt))))
 		currentState = GuiControlState::HighlightState;
 	RectI ctrlRect = applyMargins(itemRect.point, itemRect.extent, currentState, profile);
@@ -1375,7 +1375,7 @@ void GuiMenuListCtrl::updateSize()
 				width += font->getStrWidth(hotKey) + 30;
 			}
 		}
-		
+
 		if (width > maxWidth)
 			maxWidth = width;
 
@@ -1393,7 +1393,7 @@ void GuiMenuListCtrl::updateSize()
 
 	mItemSize = this->getOuterExtent(contentSize, NormalState, profile);
 	mSpacerSize = this->getOuterExtent(spacerSize, SelectedState, profile);
-	
+
 	//Add a square of space at both ends for icons
 	mItemSize.x += (2 * mItemSize.y);
 	mSpacerSize.x += (2 * mItemSize.y);
@@ -1438,4 +1438,4 @@ void GuiMenuListCtrl::processMenuItem(GuiMenuItemCtrl *ctrl)
 	}
 }
 
-#pragma endregion
+#pragma endregion

+ 12 - 1
engine/source/gui/guiListBoxCtrl.cc

@@ -249,6 +249,18 @@ S32 GuiListBoxCtrl::findItemText( StringTableEntry text, bool caseSensitive )
    return -1;
 }
 
+void GuiListBoxCtrl::setSelectionInternal(StringTableEntry text)
+{
+	S32 index = findItemText(text);
+	if (index != -1)
+	{
+		mSelectedItems.clear();
+		LBItem *item = mItems[index];
+		item->isSelected = true;
+		mSelectedItems.push_front(item);
+	}
+}
+
 void GuiListBoxCtrl::setCurSel( S32 index )
 {
    // Range Check
@@ -267,7 +279,6 @@ void GuiListBoxCtrl::setCurSel( S32 index )
 
    // Add the selection
    addSelection( mItems[ index ], index );
-
 }
 
 void GuiListBoxCtrl::setCurSelRange( S32 start, S32 stop )

+ 1 - 0
engine/source/gui/guiListBoxCtrl.h

@@ -106,6 +106,7 @@ public:
    S32               getItemIndex( LBItem *item );
    StringTableEntry  getItemText( S32 index );
    
+   void				 setSelectionInternal(StringTableEntry text);
    virtual void      setCurSel( S32 index );
    void              setCurSelRange( S32 start, S32 stop );
    void              setItemText( S32 index, StringTableEntry text );