@@ -53,7 +53,7 @@ private static PointF GetBezierPoint(float t, PointF[] controlPoints, int index,
53
53
var P1 = GetBezierPoint ( t , controlPoints , index + 1 , count - 1 ) ;
54
54
return new PointF ( ( 1 - t ) * P0 . X + t * P1 . X , ( 1 - t ) * P0 . Y + t * P1 . Y ) ;
55
55
}
56
- private static int GUI_SetLabelFont ( Font font )
56
+ private static int GUI_SetFont ( GUIStyle style , Font font )
57
57
{
58
58
int guiSkinFontSizeBuffer = GUI . skin . label . fontSize ;
59
59
if ( font != null )
@@ -62,36 +62,36 @@ private static int GUI_SetLabelFont(Font font)
62
62
font . UFont = System . Windows . Forms . ApplicationBehaviour . Resources . Fonts . Find ( f => f . fontNames [ 0 ] == font . Name ) ;
63
63
64
64
if ( font . UFont != null )
65
- GUI . skin . label . font = font . UFont ;
65
+ style . font = font . UFont ;
66
66
else
67
67
{
68
- GUI . skin . label . font = null ;
68
+ style . font = null ;
69
69
UnityEngine . Debug . LogError ( "Font not found: " + font . Name ) ;
70
70
}
71
71
72
- GUI . skin . label . fontSize = ( int ) ( font . Size ) ;
72
+ style . fontSize = ( int ) ( font . Size ) ;
73
73
bool styleBold = ( font . Style & FontStyle . Bold ) == FontStyle . Bold ;
74
74
bool styleItalic = ( font . Style & FontStyle . Italic ) == FontStyle . Italic ;
75
75
if ( styleBold )
76
76
{
77
77
if ( styleItalic )
78
- GUI . skin . label . fontStyle = UnityEngine . FontStyle . BoldAndItalic ;
78
+ style . fontStyle = UnityEngine . FontStyle . BoldAndItalic ;
79
79
else
80
- GUI . skin . label . fontStyle = UnityEngine . FontStyle . Bold ;
80
+ style . fontStyle = UnityEngine . FontStyle . Bold ;
81
81
}
82
82
else if ( styleItalic )
83
- GUI . skin . label . fontStyle = UnityEngine . FontStyle . Italic ;
84
- else GUI . skin . label . fontStyle = UnityEngine . FontStyle . Normal ;
83
+ style . fontStyle = UnityEngine . FontStyle . Italic ;
84
+ else style . fontStyle = UnityEngine . FontStyle . Normal ;
85
85
}
86
86
else
87
87
{
88
88
if ( ApplicationBehaviour . Resources . Fonts . Count > 0 )
89
89
{
90
90
var _font = ApplicationBehaviour . Resources . Fonts [ 0 ] ;
91
91
if ( _font != null )
92
- GUI . skin . label . font = _font ;
93
- GUI . skin . label . fontSize = ( int ) ( 12 ) ;
94
- GUI . skin . label . fontStyle = UnityEngine . FontStyle . Normal ;
92
+ style . font = _font ;
93
+ style . fontSize = ( int ) ( 12 ) ;
94
+ style . fontStyle = UnityEngine . FontStyle . Normal ;
95
95
}
96
96
}
97
97
return guiSkinFontSizeBuffer ;
@@ -339,6 +339,34 @@ public void DrawPolygon(Pen pen, Point[] points)
339
339
GL . End ( ) ;
340
340
}
341
341
}
342
+ public void DrawRectangle ( Color color , float x , float y , float width , float height )
343
+ {
344
+ if ( NoRects ) return ;
345
+ if ( color . A <= 0 ) return ;
346
+
347
+ GUI . color = color . ToUColor ( ) ;
348
+
349
+ if ( Control != null )
350
+ Control . Batches += 2 ;
351
+
352
+ GUI . DrawTexture ( new Rect ( x , y , width , 1 ) , System . Windows . Forms . ApplicationBehaviour . DefaultSprite ) ;
353
+ GUI . DrawTexture ( new Rect ( x + width - 1 , y + 1 , 1 , height - 2 ) , System . Windows . Forms . ApplicationBehaviour . DefaultSprite ) ;
354
+ FillRate += width + height - 2 ;
355
+ if ( height > 1 )
356
+ {
357
+ if ( Control != null )
358
+ Control . Batches ++ ;
359
+ GUI . DrawTexture ( new Rect ( x , y + height - 1 , width , 1 ) , System . Windows . Forms . ApplicationBehaviour . DefaultSprite ) ;
360
+ FillRate += width * 1 + 1 ;
361
+ }
362
+ if ( width > 1 )
363
+ {
364
+ if ( Control != null )
365
+ Control . Batches ++ ;
366
+ GUI . DrawTexture ( new Rect ( x , y + 1 , 1 , height - 2 ) , System . Windows . Forms . ApplicationBehaviour . DefaultSprite ) ;
367
+ FillRate += height - 2 ;
368
+ }
369
+ }
342
370
public void DrawRectangle ( Pen pen , Rectangle rect )
343
371
{
344
372
DrawRectangle ( pen , rect . X , rect . Y , rect . Width , rect . Height ) ;
@@ -475,7 +503,7 @@ public void DrawString(string s, Font font, Color color, float x, float y, float
475
503
break ;
476
504
}
477
505
478
- int guiSkinFontSizeBuffer = GUI_SetLabelFont ( font ) ;
506
+ int guiSkinFontSizeBuffer = GUI_SetFont ( GUI . skin . label , font ) ;
479
507
GUI . color = color . ToUColor ( ) ;
480
508
GUI . Label ( new Rect ( x , y , width , height ) , s ) ;
481
509
@@ -545,6 +573,10 @@ public void DrawString(string s, Font font, SolidBrush brush, RectangleF layoutR
545
573
DrawString ( s , font , brush , layoutRectangle . X , layoutRectangle . Y , layoutRectangle . Width , layoutRectangle . Height , format ) ;
546
574
}
547
575
public string DrawTextArea ( string s , Font font , SolidBrush brush , float x , float y , float width , float height )
576
+ {
577
+ return DrawTextArea ( s , font , brush . Color , x , y , width , height ) ;
578
+ }
579
+ public string DrawTextArea ( string s , Font font , Color color , float x , float y , float width , float height )
548
580
{
549
581
if ( Control == null ) return s ;
550
582
if ( s == null ) s = "" ;
@@ -553,55 +585,28 @@ public string DrawTextArea(string s, Font font, SolidBrush brush, float x, float
553
585
554
586
GUI . skin . textArea . alignment = TextAnchor . UpperLeft ;
555
587
556
- GUI . color = brush . Color . ToUColor ( ) ;
588
+ GUI . color = color . ToUColor ( ) ;
557
589
//GUI.skin.textArea.hover.textColor = brush.Color.ToUColor();
558
- if ( font != null )
559
- {
560
- var _font = System . Windows . Forms . ApplicationBehaviour . Resources . Fonts . Find ( f => f . fontNames [ 0 ] == font . Name ) ;
561
- if ( _font != null )
562
- GUI . skin . textArea . font = _font ;
563
- else
564
- GUI . skin . textArea . font = null ;
565
- GUI . skin . textArea . fontSize = ( int ) font . Size ;
566
- bool styleBold = ( font . Style & FontStyle . Bold ) == FontStyle . Bold ;
567
- bool styleItalic = ( font . Style & FontStyle . Italic ) == FontStyle . Italic ;
568
- if ( styleBold )
569
- {
570
- if ( styleItalic )
571
- GUI . skin . textArea . fontStyle = UnityEngine . FontStyle . BoldAndItalic ;
572
- else
573
- GUI . skin . textArea . fontStyle = UnityEngine . FontStyle . Bold ;
574
- }
575
- else if ( styleItalic )
576
- GUI . skin . textArea . fontStyle = UnityEngine . FontStyle . Italic ;
577
- else GUI . skin . textArea . fontStyle = UnityEngine . FontStyle . Normal ;
578
- }
579
- else
580
- {
581
- var _font = System . Windows . Forms . ApplicationBehaviour . Resources . Fonts . Find ( f => f . fontNames [ 0 ] == "Arial" ) ;
582
- if ( _font != null )
583
- GUI . skin . textArea . font = _font ;
584
- GUI . skin . textArea . fontSize = 12 ;
585
- }
590
+
591
+ GUI_SetFont ( GUI . skin . textArea , font ) ;
586
592
587
593
GUI . skin . textArea . hover . background = null ;
588
594
GUI . skin . textArea . active . background = null ;
589
595
GUI . skin . textArea . focused . background = null ;
590
596
GUI . skin . textArea . normal . background = null ;
591
597
592
- if ( ! _group )
598
+ if ( Control . shouldFocus )
599
+ FocusNext ( ) ;
600
+
601
+ var val = GUI . TextArea ( new Rect ( x , y , width , height ) , s ) ;
602
+
603
+ if ( Control . shouldFocus )
593
604
{
594
- var c_position = Control . PointToScreen ( Point . Zero ) ;
595
- return GUI . TextArea ( new Rect ( c_position . X + x , c_position . Y + y , width , height ) , s ) ;
605
+ Focus ( ) ;
606
+ Control . shouldFocus = false ;
596
607
}
597
- else
598
- {
599
- var c_position = Control . PointToScreen ( Point . Zero ) ;
600
- var g_position = _groupControlLast . PointToScreen ( Point . Zero ) ;
601
- var position = c_position - g_position + new PointF ( x , y ) ;
602
608
603
- return GUI . TextArea ( new Rect ( position . X , position . Y , width , height ) , s ) ;
604
- }
609
+ return val ;
605
610
}
606
611
public string DrawTextField ( string s , Font font , SolidBrush brush , RectangleF layoutRectangle , HorizontalAlignment alignment )
607
612
{
@@ -628,54 +633,26 @@ public string DrawTextField(string s, Font font, Color color, float x, float y,
628
633
break ;
629
634
}
630
635
631
- if ( font != null )
632
- {
633
- var _font = System . Windows . Forms . ApplicationBehaviour . Resources . Fonts . Find ( f => f . fontNames [ 0 ] == font . Name ) ;
634
- if ( _font != null )
635
- GUI . skin . textField . font = _font ;
636
- else
637
- GUI . skin . textField . font = null ;
638
- GUI . skin . textField . fontSize = ( int ) font . Size ;
639
- bool styleBold = ( font . Style & FontStyle . Bold ) == FontStyle . Bold ;
640
- bool styleItalic = ( font . Style & FontStyle . Italic ) == FontStyle . Italic ;
641
- if ( styleBold )
642
- {
643
- if ( styleItalic )
644
- GUI . skin . textField . fontStyle = UnityEngine . FontStyle . BoldAndItalic ;
645
- else
646
- GUI . skin . textField . fontStyle = UnityEngine . FontStyle . Bold ;
647
- }
648
- else if ( styleItalic )
649
- GUI . skin . textField . fontStyle = UnityEngine . FontStyle . Italic ;
650
- else GUI . skin . textField . fontStyle = UnityEngine . FontStyle . Normal ;
651
- }
652
- else
653
- {
654
- var _font = System . Windows . Forms . ApplicationBehaviour . Resources . Fonts . Find ( f => f . fontNames [ 0 ] == "Arial" ) ;
655
- if ( _font != null )
656
- GUI . skin . textField . font = _font ;
657
- GUI . skin . textField . fontSize = 12 ;
658
- }
636
+ GUI_SetFont ( GUI . skin . textField , font ) ;
659
637
660
638
GUI . color = color . ToUColor ( ) ;
661
639
GUI . skin . textField . hover . background = null ;
662
640
GUI . skin . textField . active . background = null ;
663
641
GUI . skin . textField . focused . background = null ;
664
642
GUI . skin . textField . normal . background = null ;
665
643
666
- if ( ! _group )
644
+ if ( Control . shouldFocus )
645
+ FocusNext ( ) ;
646
+
647
+ var val = GUI . TextField ( new Rect ( x , y , width , height ) , s ) ;
648
+
649
+ if ( Control . shouldFocus )
667
650
{
668
- var c_position = Control . PointToScreen ( Point . Zero ) ;
669
- return GUI . TextField ( new Rect ( c_position . X + x , c_position . Y + y , width , height ) , s ) ;
651
+ Focus ( ) ;
652
+ Control . shouldFocus = false ;
670
653
}
671
- else
672
- {
673
- var c_position = Control . PointToScreen ( Point . Zero ) ;
674
- var g_position = _groupControlLast . PointToScreen ( Point . Zero ) ;
675
- var position = c_position - g_position + new PointF ( x , y ) ;
676
654
677
- return GUI . TextField ( new Rect ( position . X , position . Y , width , height ) , s ) ;
678
- }
655
+ return val ;
679
656
}
680
657
public string DrawTextField ( string s , Font font , SolidBrush brush , float x , float y , float width , float height , HorizontalAlignment alignment )
681
658
{
@@ -835,7 +812,7 @@ public SizeF MeasureString(string text, Font font)
835
812
}
836
813
public static SizeF MeasureStringStatic ( string text , Font font )
837
814
{
838
- int guiSkinFontSizeBuffer = GUI_SetLabelFont ( font ) ;
815
+ int guiSkinFontSizeBuffer = GUI_SetFont ( GUI . skin . label , font ) ;
839
816
840
817
var size = GUI . skin . label . CalcSize ( new GUIContent ( text ) ) ;
841
818
0 commit comments