1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include <assert.h>
#include <vgui/IScheme.h>
#include <vgui/ISystem.h>
#include <vgui/IInput.h>
#include <vgui/IImage.h>
#include <KeyValues.h>
#include <vgui_controls/ScrollBar.h>
#include <vgui_controls/ScrollBarSlider.h>
#include <vgui_controls/Button.h>
#include <vgui_controls/Controls.h>
#include <vgui_controls/ImagePanel.h>
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
namespace
{
enum
{ // scroll bar will scroll a little, then continuous scroll like in windows
SCROLL_BAR_DELAY = 400, // default delay for all scroll bars
SCROLL_BAR_SPEED = 50, // this is how fast the bar scrolls when you hold down the arrow button
SCROLLBAR_DEFAULT_WIDTH = 17,
};
//-----------------------------------------------------------------------------
// Purpose: Scroll bar button-the arrow button that moves the slider up and down.
//-----------------------------------------------------------------------------
class ScrollBarButton : public Button
{
public:
ScrollBarButton(Panel *parent, const char *panelName, const char *text) : Button(parent, panelName, text)
{
SetButtonActivationType(ACTIVATE_ONPRESSED);
SetContentAlignment(Label::a_center);
}
void OnMouseFocusTicked()
{
// pass straight up to parent
CallParentFunction(new KeyValues("MouseFocusTicked"));
}
virtual void ApplySchemeSettings(IScheme *pScheme)
{
Button::ApplySchemeSettings(pScheme);
SetFont(pScheme->GetFont("Marlett", IsProportional() ));
SetDefaultBorder(pScheme->GetBorder("ScrollBarButtonBorder"));
SetDepressedBorder(pScheme->GetBorder("ScrollBarButtonDepressedBorder"));
SetDefaultColor(GetSchemeColor("ScrollBarButton.FgColor", pScheme), GetSchemeColor("ScrollBarButton.BgColor", pScheme));
SetArmedColor(GetSchemeColor("ScrollBarButton.ArmedFgColor", pScheme), GetSchemeColor("ScrollBarButton.ArmedBgColor", pScheme));
SetDepressedColor(GetSchemeColor("ScrollBarButton.DepressedFgColor", pScheme), GetSchemeColor("ScrollBarButton.DepressedBgColor", pScheme));
}
// Don't request focus.
// This will keep cursor focus in main window in text entry windows.
virtual void OnMousePressed(MouseCode code)
{
if (!IsEnabled())
return;
if (!IsMouseClickEnabled(code))
return;
if (IsUseCaptureMouseEnabled())
{
{
SetSelected(true);
Repaint();
}
// lock mouse input to going to this button
input()->SetMouseCapture(GetVPanel());
}
}
virtual void OnMouseReleased(MouseCode code)
{
if (!IsEnabled())
return;
if (!IsMouseClickEnabled(code))
return;
if (IsUseCaptureMouseEnabled())
{
{
SetSelected(false);
Repaint();
}
// lock mouse input to going to this button
input()->SetMouseCapture(NULL);
}
if( input()->GetMouseOver() == GetVPanel() )
{
SetArmed( true );
}
}
};
}
vgui::Panel *ScrollBar_Vertical_Factory()
{
return new ScrollBar(NULL, NULL, true );
}
vgui::Panel *ScrollBar_Horizontal_Factory()
{
return new ScrollBar(NULL, NULL, false );
}
DECLARE_BUILD_FACTORY_CUSTOM_ALIAS( ScrollBar, ScrollBar_Vertical, ScrollBar_Vertical_Factory );
DECLARE_BUILD_FACTORY_CUSTOM_ALIAS( ScrollBar, ScrollBar_Horizontal, ScrollBar_Horizontal_Factory );
// Default is a horizontal one
DECLARE_BUILD_FACTORY_CUSTOM( ScrollBar, ScrollBar_Horizontal_Factory );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
ScrollBar::ScrollBar(Panel *parent, const char *panelName, bool vertical) : Panel(parent, panelName)
{
_slider=null;
_button[0]=null;
_button[1]=null;
_scrollDelay = SCROLL_BAR_DELAY;
_respond = true;
m_pUpArrow = NULL;
m_pLine = NULL;
m_pDownArrow = NULL;
m_pBox = NULL;
m_bNoButtons = false;
m_pOverriddenButtons[0] = NULL;
m_pOverriddenButtons[1] = NULL;
if (vertical)
{
// FIXME: proportional changes needed???
SetSlider(new ScrollBarSlider(NULL, "Slider", true));
SetButton(new ScrollBarButton(NULL, "UpButton", "t"), 0);
SetButton(new ScrollBarButton(NULL, "DownButton", "u"), 1);
_button[0]->SetTextInset(0, 1);
_button[1]->SetTextInset(0, -1);
SetSize(SCROLLBAR_DEFAULT_WIDTH, 64);
}
else
{
SetSlider(new ScrollBarSlider(NULL, NULL, false));
SetButton(new ScrollBarButton(NULL, NULL, "w"), 0);
SetButton(new ScrollBarButton(NULL, NULL, "4"), 1);
_button[0]->SetTextInset(0, 0);
_button[1]->SetTextInset(0, 0);
SetSize(64, SCROLLBAR_DEFAULT_WIDTH);
}
Panel::SetPaintBorderEnabled(true);
Panel::SetPaintBackgroundEnabled(false);
Panel::SetPaintEnabled(true);
SetButtonPressedScrollValue(20);
SetBlockDragChaining( true );
Validate();
}
//-----------------------------------------------------------------------------
// Purpose: sets up the width of the scrollbar according to the scheme
//-----------------------------------------------------------------------------
void ScrollBar::ApplySchemeSettings(IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
const char *resourceString = pScheme->GetResourceString("ScrollBar.Wide");
if (resourceString)
{
int value = atoi(resourceString);
if (IsProportional())
{
value = scheme()->GetProportionalScaledValueEx(GetScheme(), value);
}
if (_slider && _slider->IsVertical())
{
// we're vertical, so reset the width
SetSize( value, GetTall() );
}
else
{
// we're horizontal, so the width means the height
SetSize( GetWide(), value );
}
}
UpdateButtonsForImages();
}
//-----------------------------------------------------------------------------
// Purpose: Set the slider's Paint border enabled.
//-----------------------------------------------------------------------------
void ScrollBar::SetPaintBorderEnabled(bool state)
{
if ( _slider )
{
_slider->SetPaintBorderEnabled( state );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ScrollBar::SetPaintBackgroundEnabled(bool state)
{
if ( _slider )
{
_slider->SetPaintBackgroundEnabled( state );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ScrollBar::SetPaintEnabled(bool state)
{
if ( _slider )
{
_slider->SetPaintEnabled( state );
}
}
//-----------------------------------------------------------------------------
// Purpose: Layout the scroll bar and buttons on screen
//-----------------------------------------------------------------------------
void ScrollBar::PerformLayout()
{
if (_slider)
{
int wide, tall;
GetPaintSize(wide,tall);
if(_slider->IsVertical())
{
if ( m_bNoButtons )
{
_slider->SetBounds(0, 0, wide, tall + 1);
}
else
{
_slider->SetBounds(0, wide, wide, tall-(wide*2)+1);
_button[0]->SetBounds(0,0, wide, wide );
_button[1]->SetBounds(0,tall-wide ,wide, wide );
}
}
else
{
if ( m_bNoButtons )
{
_slider->SetBounds(tall, 0, wide, tall + 1);
}
else
{
_slider->SetBounds(tall, -1, wide-(tall*2)+1, tall + 1 );
_button[0]->SetBounds(0, 0, tall, tall);
_button[1]->SetBounds(wide-tall, 0, tall, tall);
}
}
// Place the images over the appropriate controls
int x,y;
if ( m_pUpArrow )
{
_button[0]->GetBounds( x,y,wide,tall );
m_pUpArrow->SetBounds( x,y,wide,tall );
}
if ( m_pDownArrow )
{
_button[1]->GetBounds( x,y,wide,tall );
m_pDownArrow->SetBounds( x,y,wide,tall );
}
if ( m_pLine )
{
_slider->GetBounds( x,y,wide,tall );
m_pLine->SetBounds( x,y,wide,tall );
}
if ( m_pBox )
{
m_pBox->SetBounds( 0, wide, wide, wide );
}
_slider->MoveToFront();
// after resizing our child, we should remind it to perform a layout
_slider->InvalidateLayout();
UpdateSliderImages();
}
if ( m_bAutoHideButtons )
{
SetScrollbarButtonsVisible( _slider->IsSliderVisible() );
}
// get tooltips to draw
Panel::PerformLayout();
}
//-----------------------------------------------------------------------------
// Purpose: Set the value of the scroll bar slider.
//-----------------------------------------------------------------------------
void ScrollBar::SetValue(int value)
{
_slider->SetValue(value);
}
//-----------------------------------------------------------------------------
// Purpose: Get the value of the scroll bar slider.
//-----------------------------------------------------------------------------
int ScrollBar::GetValue()
{
return _slider->GetValue();
}
//-----------------------------------------------------------------------------
// Purpose: Set the range of the scroll bar slider.
// This the range of numbers the slider can scroll through.
//-----------------------------------------------------------------------------
void ScrollBar::SetRange(int min,int max)
{
_slider->SetRange(min,max);
}
//-----------------------------------------------------------------------------
// Purpose: Gets the range of the scroll bar slider.
// This the range of numbers the slider can scroll through.
//-----------------------------------------------------------------------------
void ScrollBar::GetRange(int &min, int &max)
{
_slider->GetRange(min, max);
}
//-----------------------------------------------------------------------------
// Purpose: Send a message when the slider is moved.
// Input : value -
//-----------------------------------------------------------------------------
void ScrollBar::SendSliderMoveMessage(int value)
{
PostActionSignal(new KeyValues("ScrollBarSliderMoved", "position", value));
}
//-----------------------------------------------------------------------------
// Purpose: Called when the Slider is dragged by the user
// Input : value -
//-----------------------------------------------------------------------------
void ScrollBar::OnSliderMoved(int value)
{
SendSliderMoveMessage(value);
UpdateSliderImages();
}
//-----------------------------------------------------------------------------
// Purpose: Check if the scrollbar is vertical (true) or horizontal (false)
//-----------------------------------------------------------------------------
bool ScrollBar::IsVertical()
{
return _slider->IsVertical();
}
//-----------------------------------------------------------------------------
// Purpose: Check if the the scrollbar slider has full range.
// Normally if you have a scroll bar and the range goes from a to b and
// the slider is sized to c, the range will go from a to b-c.
// This makes it so the slider goes from a to b fully.
//-----------------------------------------------------------------------------
bool ScrollBar::HasFullRange()
{
return _slider->HasFullRange();
}
//-----------------------------------------------------------------------------
// Purpose: Setup the indexed scroll bar button with the input params.
//-----------------------------------------------------------------------------
//LEAK: new and old slider will leak
void ScrollBar::SetButton(Button *button, int index)
{
if(_button[index]!=null)
{
_button[index]->SetParent((Panel *)NULL);
}
_button[index]=button;
_button[index]->SetParent(this);
_button[index]->AddActionSignalTarget(this);
_button[index]->SetCommand(new KeyValues("ScrollButtonPressed", "index", index));
Validate();
}
//-----------------------------------------------------------------------------
// Purpose: Return the indexed scroll bar button
//-----------------------------------------------------------------------------
Button* ScrollBar::GetButton(int index)
{
return _button[index];
}
//-----------------------------------------------------------------------------
// Purpose: Set up the slider.
//-----------------------------------------------------------------------------
//LEAK: new and old slider will leak
void ScrollBar::SetSlider(ScrollBarSlider *slider)
{
if(_slider!=null)
{
_slider->SetParent((Panel *)NULL);
}
_slider=slider;
_slider->AddActionSignalTarget(this);
_slider->SetParent(this);
Validate();
}
//-----------------------------------------------------------------------------
// Purpose: Return a pointer to the slider.
//-----------------------------------------------------------------------------
ScrollBarSlider *ScrollBar::GetSlider()
{
return _slider;
}
Button *ScrollBar::GetDepressedButton( int iIndex )
{
if ( iIndex == 0 )
return ( m_pOverriddenButtons[0] ? m_pOverriddenButtons[0] : _button[0] );
return ( m_pOverriddenButtons[1] ? m_pOverriddenButtons[1] : _button[1] );
}
//-----------------------------------------------------------------------------
// Purpose: Scrolls in response to clicking and holding on up or down arrow
// The idea is to have the slider move one step then delay a bit and then
// the bar starts moving at normal speed. This gives a stepping feeling
// to just clicking an arrow once.
//-----------------------------------------------------------------------------
void ScrollBar::OnMouseFocusTicked()
{
int direction = 0;
// top button is down
if ( GetDepressedButton(0)->IsDepressed() )
{
direction = -1;
}
// bottom top button is down
else if (GetDepressedButton(1)->IsDepressed())
{
direction = 1;
}
// a button is down
if ( direction != 0 )
{
RespondToScrollArrow(direction);
if (_scrollDelay < system()->GetTimeMillis())
{
_scrollDelay = system()->GetTimeMillis() + SCROLL_BAR_SPEED;
_respond = true;
}
else
{
_respond = false;
}
}
// a button is not down.
else
{
// if neither button is down keep delay at max
_scrollDelay = system()->GetTimeMillis() + SCROLL_BAR_DELAY;
_respond = true;
}
}
//-----------------------------------------------------------------------------
// Purpose: move scroll bar in response to the first button
// Input: button and direction to move scroll bar when that button is pressed
// direction can only by +/- 1
// Output: whether button is down or not
//-----------------------------------------------------------------------------
void ScrollBar::RespondToScrollArrow(int const direction)
{
if (_respond)
{
int newValue = _slider->GetValue() + (direction * _buttonPressedScrollValue);
_slider->SetValue(newValue);
SendSliderMoveMessage(newValue);
}
}
//-----------------------------------------------------------------------------
// Purpose: Trigger layout changes when the window size is changed.
//-----------------------------------------------------------------------------
void ScrollBar::OnSizeChanged(int wide, int tall)
{
InvalidateLayout();
_slider->InvalidateLayout();
}
//-----------------------------------------------------------------------------
// Purpose: Set how far the scroll bar slider moves when a scroll bar button is
// pressed.
//-----------------------------------------------------------------------------
void ScrollBar::SetButtonPressedScrollValue(int value)
{
_buttonPressedScrollValue=value;
}
//-----------------------------------------------------------------------------
// Purpose: Set the range of the rangewindow. This is how many
// lines are displayed at one time
// in the window the scroll bar is attached to.
// This also controls the size of the slider, its size is proportional
// to the number of lines displayed / total number of lines.
//-----------------------------------------------------------------------------
void ScrollBar::SetRangeWindow(int rangeWindow)
{
_slider->SetRangeWindow(rangeWindow);
}
//-----------------------------------------------------------------------------
// Purpose: Get the range of the rangewindow. This is how many
// lines are displayed at one time
// in the window the scroll bar is attached to.
// This also controls the size of the slider, its size is proportional
// to the number of lines displayed / total number of lines.
//-----------------------------------------------------------------------------
int ScrollBar::GetRangeWindow()
{
return _slider->GetRangeWindow();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ScrollBar::Validate()
{
if ( _slider != null )
{
int buttonOffset = 0;
for( int i=0; i<2; i++ )
{
if( _button[i] != null )
{
if( _button[i]->IsVisible() )
{
if( _slider->IsVertical() )
{
buttonOffset += _button[i]->GetTall();
}
else
{
buttonOffset += _button[i]->GetWide();
}
}
}
}
_slider->SetButtonOffset(buttonOffset);
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ScrollBar::SetScrollbarButtonsVisible(bool visible)
{
for( int i=0; i<2; i++ )
{
if( _button[i] != null )
{
_button[i]->SetShouldPaint( visible );
_button[i]->SetEnabled( visible );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ScrollBar::UseImages( const char *pszUpArrow, const char *pszDownArrow, const char *pszLine, const char *pszBox )
{
if ( pszUpArrow )
{
if ( !m_pUpArrow )
{
m_pUpArrow = new vgui::ImagePanel( this, "UpArrow" );
if ( m_pUpArrow )
{
m_pUpArrow->SetImage( pszUpArrow );
m_pUpArrow->SetShouldScaleImage( true );
m_pUpArrow->SetFgColor( Color( 255, 255, 255, 255 ) );
m_pUpArrow->SetAlpha( 255 );
m_pUpArrow->SetZPos( -1 );
}
}
m_pUpArrow->SetImage( pszUpArrow );
m_pUpArrow->SetRotation( IsVertical() ? ROTATED_UNROTATED : ROTATED_CLOCKWISE_90 );
}
else if ( m_pUpArrow )
{
m_pUpArrow->DeletePanel();
m_pUpArrow = NULL;
}
if ( pszDownArrow )
{
if ( !m_pDownArrow )
{
m_pDownArrow = new vgui::ImagePanel( this, "DownArrow" );
if ( m_pDownArrow )
{
m_pDownArrow->SetShouldScaleImage( true );
m_pDownArrow->SetFgColor( Color( 255, 255, 255, 255 ) );
m_pDownArrow->SetAlpha( 255 );
m_pDownArrow->SetZPos( -1 );
}
}
m_pDownArrow->SetImage( pszDownArrow );
m_pDownArrow->SetRotation( IsVertical() ? ROTATED_UNROTATED : ROTATED_CLOCKWISE_90 );
}
else if ( m_pDownArrow )
{
m_pDownArrow->DeletePanel();
m_pDownArrow = NULL;
}
if ( pszLine )
{
if ( !m_pLine )
{
m_pLine = new ImagePanel( this, "Line" );
if ( m_pLine )
{
m_pLine->SetShouldScaleImage( true );
m_pLine->SetZPos( -1 );
}
}
m_pLine->SetImage( pszLine );
m_pLine->SetRotation( IsVertical() ? ROTATED_UNROTATED : ROTATED_CLOCKWISE_90 );
}
else if ( m_pLine )
{
m_pLine->DeletePanel();
m_pLine = NULL;
}
if ( pszBox )
{
if ( !m_pBox )
{
m_pBox = new ImagePanel( this, "Box" );
if ( m_pBox )
{
m_pBox->SetShouldScaleImage( true );
m_pBox->SetZPos( -1 );
}
}
m_pBox->SetImage( pszBox );
m_pBox->SetRotation( IsVertical() ? ROTATED_UNROTATED : ROTATED_CLOCKWISE_90 );
}
else if ( m_pBox )
{
m_pBox->DeletePanel();
m_pBox = NULL;
}
UpdateButtonsForImages();
InvalidateLayout();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ScrollBar::UpdateButtonsForImages( void )
{
// Turn off parts of our drawing based on which images we're replacing it with
if ( m_pUpArrow || m_pDownArrow )
{
SetScrollbarButtonsVisible( false );
_button[0]->SetPaintBorderEnabled( false );
_button[1]->SetPaintBorderEnabled( false );
m_bAutoHideButtons = false;
}
if ( m_pLine || m_pBox )
{
SetPaintBackgroundEnabled( false );
SetPaintBorderEnabled( false );
if ( _slider )
{
_slider->SetPaintEnabled( false );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void ScrollBar::UpdateSliderImages( void )
{
if ( m_pUpArrow && m_pDownArrow )
{
// set the alpha on the up arrow
int nMin, nMax;
GetRange( nMin, nMax );
int nScrollPos = GetValue();
int nRangeWindow = GetRangeWindow();
int nBottom = nMax - nRangeWindow;
if ( nBottom < 0 )
{
nBottom = 0;
}
// set the alpha on the up arrow
int nAlpha = ( nScrollPos - nMin <= 0 ) ? 90 : 255;
m_pUpArrow->SetAlpha( nAlpha );
// set the alpha on the down arrow
nAlpha = ( nScrollPos >= nBottom ) ? 90 : 255;
m_pDownArrow->SetAlpha( nAlpha );
}
if ( m_pLine && m_pBox )
{
ScrollBarSlider *pSlider = GetSlider();
if ( pSlider && pSlider->GetRangeWindow() > 0 )
{
int x, y, w, t, min, max;
m_pLine->GetBounds( x, y, w, t );
// If our slider needs layout, force it to do it now
if ( pSlider->IsLayoutInvalid() )
{
pSlider->InvalidateLayout( true );
}
pSlider->GetNobPos( min, max );
if ( IsVertical() )
{
m_pBox->SetBounds( x, y + min, w, ( max - min ) );
}
else
{
m_pBox->SetBounds( x + min, 0, (max-min), t );
}
}
}
}
void ScrollBar::ApplySettings( KeyValues *pInResourceData )
{
BaseClass::ApplySettings( pInResourceData );
m_bNoButtons = pInResourceData->GetBool( "nobuttons", false );
KeyValues *pSliderKV = pInResourceData->FindKey( "Slider" );
if ( pSliderKV && _slider )
{
_slider->ApplySettings( pSliderKV );
}
KeyValues *pDownButtonKV = pInResourceData->FindKey( "DownButton" );
if ( pDownButtonKV && _button[0] )
{
_button[0]->ApplySettings( pDownButtonKV );
}
KeyValues *pUpButtonKV = pInResourceData->FindKey( "UpButton" );
if ( pUpButtonKV && _button[0] )
{
_button[1]->ApplySettings( pUpButtonKV );
}
}
|