Skip to content

Commit de0219d

Browse files
committed
Fixed Some Tab Issues
This fixes a number of issues with tabbing through the controls on the inspector. This adds a way to display when a check box and a drop down is the first responder. It also sets visibility of hidden direct children of an expand control to false when the expand control is collapsed and further makes it so non-visible controls cannot be tabbed to. It also fixes the focus code so that textboxes can lose focus when a click happens outside of the text box. When a textbox gains focus through tabbing, it now selects the contents of the box.
1 parent b55ea8a commit de0219d

16 files changed

+212
-69
lines changed

editor/EditorCore/Themes/BaseTheme/BaseTheme.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@
830830
fontColorNA = %this.setAlpha(%this.color4, 100);
831831
align = left;
832832
vAlign = middle;
833+
cursorColor = %this.color5;
833834

834835
borderLeft = %borderLight;
835836
borderRight = %borderDark;
@@ -1175,10 +1176,10 @@
11751176

11761177
%textBorderH = new GuiBorderProfile()
11771178
{
1178-
padding = 10;
1179-
paddingHL = 10;
1180-
paddingSL = 10;
1181-
paddingNA = 10;
1179+
padding = 5;
1180+
paddingHL = 5;
1181+
paddingSL = 5;
1182+
paddingNA = 5;
11821183

11831184
border = %this.borderSize;
11841185
borderHL = %this.borderSize;
@@ -1637,6 +1638,7 @@
16371638
fontColorNA = %this.setAlpha(%this.color1, 100);
16381639
align = left;
16391640
vAlign = middle;
1641+
cursorColor = %this.color5;
16401642

16411643
borderLeft = %borderLightH;
16421644
borderRight = %borderDarkH;

editor/EditorCore/Themes/TorqueSuit/TorqueSuitTheme.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@
373373
borderRight = %textBorderRight;
374374
borderLeft = %textBorderLeft;
375375

376-
tab = false;
376+
tab = true;
377377
canKeyFocus = true;
378378
returnTab = true;
379379
};

engine/source/gui/buttons/guiButtonCtrl.cc

+2
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ bool GuiButtonCtrl::onKeyDown(const GuiEvent &event)
208208
AUDIOHANDLE handle = alxCreateSource(mProfile->mSoundButtonDown);
209209
alxPlay(handle);
210210
}
211+
mDepressed = true;
211212
return true;
212213
}
213214
//otherwise, pass the event to it's parent
@@ -224,6 +225,7 @@ bool GuiButtonCtrl::onKeyUp(const GuiEvent &event)
224225
(event.keyCode == KEY_RETURN || event.keyCode == KEY_SPACE) &&
225226
event.modifier == 0)
226227
{
228+
mDepressed = false;
227229
onAction();
228230
return true;
229231
}

engine/source/gui/buttons/guiCheckBoxCtrl.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void GuiCheckBoxCtrl::onRender(Point2I offset, const RectI &updateRect)
7373
{
7474
currentState = mStateOn ? GuiControlState::SelectedStateOn : GuiControlState::SelectedState;
7575
}
76-
else if (mMouseOver)
76+
else if (mMouseOver || isFirstResponder())
7777
{
7878
currentState = mStateOn ? GuiControlState::HighlightStateOn : GuiControlState::HighlightState;
7979
}
@@ -119,6 +119,11 @@ void GuiCheckBoxCtrl::onRender(Point2I offset, const RectI &updateRect)
119119
void GuiCheckBoxCtrl::renderInnerControl(RectI &boxRect, const GuiControlState currentState)
120120
{
121121
renderUniversalRect(boxRect, mProfile, currentState);
122+
123+
if(isFirstResponder())
124+
{
125+
dglDrawRect(boxRect, mProfile->mCursorColor);
126+
}
122127
}
123128

124129
void GuiCheckBoxCtrl::onAction()

engine/source/gui/buttons/guiDropDownCtrl.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ GuiControlState GuiDropDownCtrl::getCurrentState()
162162
return GuiControlState::DisabledState;
163163
else if (mDepressed || mIsOpen)
164164
return GuiControlState::SelectedState;
165-
else if (mMouseOver)
165+
else if (mMouseOver || isFirstResponder())
166166
return GuiControlState::HighlightState;
167167
else
168168
return GuiControlState::NormalState;
@@ -206,6 +206,11 @@ void GuiDropDownCtrl::onRender(Point2I offset, const RectI& updateRect)
206206
}
207207
renderText(contentRect.point, contentRect.extent, mListBox->getItemText(index), mProfile);
208208
}
209+
210+
if (isFirstResponder())
211+
{
212+
dglDrawRect(ctrlRect, mProfile->mCursorColor);
213+
}
209214
}
210215

211216
bool GuiDropDownCtrl::onKeyDown(const GuiEvent &event)

engine/source/gui/containers/guiExpandCtrl.cc

+86
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ GuiExpandCtrl::GuiExpandCtrl()
3737
mEasingFunction = EasingFunction::Linear;
3838
mAnimationLength = 500;
3939
mCalcGuard = false;
40+
41+
setField("profile", "GuiDefaultProfile");
4042
}
4143

4244
void GuiExpandCtrl::initPersistFields()
@@ -47,6 +49,13 @@ void GuiExpandCtrl::initPersistFields()
4749
addField("easeTimeExpand", TypeS32, Offset(mAnimationLength, GuiExpandCtrl));
4850
}
4951

52+
void GuiExpandCtrl::addObject(SimObject* obj)
53+
{
54+
Parent::addObject(obj);
55+
56+
toggleHiddenChildren();
57+
}
58+
5059
void GuiExpandCtrl::parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent)
5160
{
5261
Point2I newPosition = getPosition();
@@ -114,6 +123,7 @@ void GuiExpandCtrl::parentResized(const Point2I &oldParentExtent, const Point2I
114123
else
115124
{
116125
mBounds.extent = mCollapsedExtent;
126+
toggleHiddenChildren();
117127
}
118128
setUpdate();
119129
}
@@ -122,6 +132,7 @@ void GuiExpandCtrl::childResized(GuiControl* child)
122132
{
123133
calcExpandedExtent();
124134
Parent::childResized(child);
135+
toggleHiddenChildren();
125136
}
126137

127138
void GuiExpandCtrl::setCollapsedExtent(const Point2I &extent)
@@ -161,6 +172,15 @@ void GuiExpandCtrl::setExpanded(bool isExpanded)
161172
mAnimationProgress = 1 - mAnimationProgress;
162173
mExpanded = isExpanded;
163174
setProcessTicks(true);
175+
176+
if (mExpanded)
177+
{
178+
startExpand();
179+
}
180+
else
181+
{
182+
startCollapse();
183+
}
164184
}
165185

166186
bool GuiExpandCtrl::processExpansion()
@@ -205,6 +225,14 @@ bool GuiExpandCtrl::processExpansion()
205225
if (mAnimationProgress >= 1.0f)
206226
{
207227
mAnimationProgress = 1.0f;
228+
if (!mExpanded)
229+
{
230+
collapseComplete();
231+
}
232+
else
233+
{
234+
expandComplete();
235+
}
208236
return false;
209237
}
210238
return true;
@@ -221,4 +249,62 @@ void GuiExpandCtrl::processTick()
221249
{
222250
setProcessTicks(false);
223251
}
252+
}
253+
254+
void GuiExpandCtrl::startExpand()
255+
{
256+
if (isMethod("onStartExpand"))
257+
{
258+
Con::executef(this, 2, "onStartExpand");
259+
}
260+
261+
toggleHiddenChildren();
262+
}
263+
264+
void GuiExpandCtrl::startCollapse()
265+
{
266+
if (isMethod("onStartCollapse"))
267+
{
268+
Con::executef(this, 2, "onStartCollapse");
269+
}
270+
}
271+
272+
void GuiExpandCtrl::expandComplete()
273+
{
274+
if (isMethod("onExpandComplete"))
275+
{
276+
Con::executef(this, 2, "onExpandComplete");
277+
}
278+
}
279+
280+
void GuiExpandCtrl::collapseComplete()
281+
{
282+
if (isMethod("onCollapseComplete"))
283+
{
284+
Con::executef(this, 2, "onCollapseComplete");
285+
}
286+
287+
toggleHiddenChildren();
288+
}
289+
290+
void GuiExpandCtrl::toggleHiddenChildren()
291+
{
292+
RectI innerRect = getInnerRect();
293+
innerRect.point = Point2I::Zero;
294+
295+
for (iterator i = begin(); i != end(); i++)
296+
{
297+
GuiControl* ctrl = static_cast<GuiControl*>(*i);
298+
299+
RectI childBounds = ctrl->getBounds();
300+
RectI parentBounds = RectI(innerRect);
301+
if (!mExpanded && !parentBounds.intersect(childBounds))
302+
{
303+
ctrl->mVisible = false;
304+
}
305+
else
306+
{
307+
ctrl->mVisible = true;
308+
}
309+
}
224310
}

engine/source/gui/containers/guiExpandCtrl.h

+12-6
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,20 @@ class GuiExpandCtrl : public GuiControl, public Fluid
6060
public:
6161
GuiExpandCtrl();
6262

63-
virtual void parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent);
64-
virtual void childResized(GuiControl* child);
63+
virtual void addObject(SimObject* obj);
64+
virtual void parentResized(const Point2I &oldParentExtent, const Point2I &newParentExtent);
65+
virtual void childResized(GuiControl* child);
6566

66-
inline bool getExpanded() { return mExpanded; };
67-
void setExpanded(bool isExpanded);
67+
inline bool getExpanded() { return mExpanded; };
68+
void setExpanded(bool isExpanded);
69+
void startExpand();
70+
void startCollapse();
71+
void expandComplete();
72+
void collapseComplete();
73+
void toggleHiddenChildren();
6874

69-
static void initPersistFields();
70-
DECLARE_CONOBJECT(GuiExpandCtrl);
75+
static void initPersistFields();
76+
DECLARE_CONOBJECT(GuiExpandCtrl);
7177

7278
protected:
7379
virtual void processTick();

engine/source/gui/containers/guiWindowCtrl.cc

+4-9
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void GuiWindowCtrl::onTouchDown(const GuiEvent &event)
251251
curHitRegion = findHitRegion(localPoint);
252252
mDepressed = true;
253253

254-
//select this window - move it to the front, and set the first responder
254+
//select this window - move it to the front
255255
selectWindow();
256256

257257
//if we clicked within the title bar
@@ -669,30 +669,25 @@ bool GuiWindowCtrl::onKeyDown(const GuiEvent &event)
669669
return Parent::onKeyDown(event);
670670
}
671671

672-
void GuiWindowCtrl::onFocus()
672+
void GuiWindowCtrl::onFocus(bool foundFirstResponder)
673673
{
674674
//bubble the focus up
675675
GuiControl *parent = getParent();
676676
if (parent)
677677
{
678678
parent->pushObjectToBack(this);
679-
parent->onFocus();
679+
parent->onFocus(foundFirstResponder);
680680
}
681-
682-
setFirstResponder(mFirstResponder);
683681
}
684682

685683
void GuiWindowCtrl::selectWindow(void)
686684
{
687-
//first make sure this window is the front most of its siblings
685+
//make sure this window is the front most of its siblings
688686
GuiControl *parent = getParent();
689687
if (parent)
690688
{
691689
parent->pushObjectToBack(this);
692690
}
693-
694-
//also set the first responder to be the one within this window
695-
setFirstResponder(mFirstResponder);
696691
}
697692

698693
void GuiWindowCtrl::ResizeComplete()

engine/source/gui/containers/guiWindowCtrl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class GuiWindowCtrl : public GuiControl
132132
void onTouchUp(const GuiEvent &event);
133133
void onTouchLeave(const GuiEvent &event);
134134

135-
virtual void onFocus();
135+
virtual void onFocus(bool foundFirstResponder);
136136

137137
//only cycle tabs through the current window, so overwrite the method
138138
GuiControl* findNextTabable(GuiControl *curResponder, bool firstCall = true);

engine/source/gui/editor/guiInspector.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,7 @@ void GuiInspector::inspectPostApply()
237237

238238
if (mTarget)
239239
{
240-
SimObjectPtr<SimObject> oldTarget = mTarget;
241-
mTarget = NULL;
242-
inspectObject(oldTarget);
240+
inspectObject(mTarget);
243241
}
244242
}
245243

engine/source/gui/guiCanvas.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ void GuiCanvas::rootMouseDown(const GuiEvent &event)
629629
GuiControl* controlHit = ctrl->findHitControl(event.mousePoint);
630630

631631
//Regardless of what the control does, it has the user's focus.
632-
controlHit->onFocus();
632+
controlHit->onFocus(false);
633633

634634
if (controlHit->mUseInput)
635635
{
@@ -733,7 +733,7 @@ void GuiCanvas::rootScreenTouchDown(const GuiEvent &event)
733733
}
734734

735735
//Regardless of what the control does, it has the user's focus.
736-
controlHit->onFocus();
736+
controlHit->onFocus(false);
737737

738738
if (controlHit->mUseInput)
739739
{
@@ -1521,6 +1521,15 @@ void GuiCanvas::resetUpdateRegions()
15211521
mCurUpdateRect = mOldUpdateRects[0];
15221522
}
15231523

1524+
void GuiCanvas::onFocus(bool foundFirstResponder)
1525+
{
1526+
if (!foundFirstResponder && mFirstResponder)
1527+
{
1528+
mFirstResponder->onLoseFirstResponder();
1529+
mFirstResponder = NULL;
1530+
}
1531+
}
1532+
15241533
void GuiCanvas::setFirstResponder( GuiControl* newResponder )
15251534
{
15261535
GuiControl* oldResponder = mFirstResponder;

engine/source/gui/guiCanvas.h

+2
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ class GuiCanvas : public GuiControl
397397
/// @param modifier Shift, ctrl, etc.
398398
virtual void addAcceleratorKey(GuiControl *ctrl, U32 index, U32 keyCode, U32 modifier);
399399

400+
virtual void onFocus(bool foundFirstResponder);
401+
400402
/// Sets the first responder.
401403
/// @param firstResponder Control to designate as first responder
402404
virtual void setFirstResponder(GuiControl *firstResponder);

engine/source/gui/guiConsoleEditCtrl.cc

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ void GuiConsoleEditCtrl::onLoseFirstResponder()
183183

184184
if (isMethod("onLoseFirstResponder"))
185185
Con::executef(this, 2, "onLoseFirstResponder");
186+
if (isMethod("onBlur"))
187+
Con::executef(this, 2, "onBlur");
186188

187189
mSelector.setFirstResponder(false);
188190
mTextOffsetY = 0;

0 commit comments

Comments
 (0)