@@ -53,7 +53,7 @@ private static PointF GetBezierPoint(float t, PointF[] controlPoints, int index,
5353 var P1 = GetBezierPoint ( t , controlPoints , index + 1 , count - 1 ) ;
5454 return new PointF ( ( 1 - t ) * P0 . X + t * P1 . X , ( 1 - t ) * P0 . Y + t * P1 . Y ) ;
5555 }
56- private static int GUI_SetLabelFont ( Font font )
56+ private static int GUI_SetFont ( GUIStyle style , Font font )
5757 {
5858 int guiSkinFontSizeBuffer = GUI . skin . label . fontSize ;
5959 if ( font != null )
@@ -62,36 +62,36 @@ private static int GUI_SetLabelFont(Font font)
6262 font . UFont = System . Windows . Forms . ApplicationBehaviour . Resources . Fonts . Find ( f => f . fontNames [ 0 ] == font . Name ) ;
6363
6464 if ( font . UFont != null )
65- GUI . skin . label . font = font . UFont ;
65+ style . font = font . UFont ;
6666 else
6767 {
68- GUI . skin . label . font = null ;
68+ style . font = null ;
6969 UnityEngine . Debug . LogError ( "Font not found: " + font . Name ) ;
7070 }
7171
72- GUI . skin . label . fontSize = ( int ) ( font . Size ) ;
72+ style . fontSize = ( int ) ( font . Size ) ;
7373 bool styleBold = ( font . Style & FontStyle . Bold ) == FontStyle . Bold ;
7474 bool styleItalic = ( font . Style & FontStyle . Italic ) == FontStyle . Italic ;
7575 if ( styleBold )
7676 {
7777 if ( styleItalic )
78- GUI . skin . label . fontStyle = UnityEngine . FontStyle . BoldAndItalic ;
78+ style . fontStyle = UnityEngine . FontStyle . BoldAndItalic ;
7979 else
80- GUI . skin . label . fontStyle = UnityEngine . FontStyle . Bold ;
80+ style . fontStyle = UnityEngine . FontStyle . Bold ;
8181 }
8282 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 ;
8585 }
8686 else
8787 {
8888 if ( ApplicationBehaviour . Resources . Fonts . Count > 0 )
8989 {
9090 var _font = ApplicationBehaviour . Resources . Fonts [ 0 ] ;
9191 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 ;
9595 }
9696 }
9797 return guiSkinFontSizeBuffer ;
@@ -339,6 +339,34 @@ public void DrawPolygon(Pen pen, Point[] points)
339339 GL . End ( ) ;
340340 }
341341 }
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+ }
342370 public void DrawRectangle ( Pen pen , Rectangle rect )
343371 {
344372 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
475503 break ;
476504 }
477505
478- int guiSkinFontSizeBuffer = GUI_SetLabelFont ( font ) ;
506+ int guiSkinFontSizeBuffer = GUI_SetFont ( GUI . skin . label , font ) ;
479507 GUI . color = color . ToUColor ( ) ;
480508 GUI . Label ( new Rect ( x , y , width , height ) , s ) ;
481509
@@ -545,6 +573,10 @@ public void DrawString(string s, Font font, SolidBrush brush, RectangleF layoutR
545573 DrawString ( s , font , brush , layoutRectangle . X , layoutRectangle . Y , layoutRectangle . Width , layoutRectangle . Height , format ) ;
546574 }
547575 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 )
548580 {
549581 if ( Control == null ) return s ;
550582 if ( s == null ) s = "" ;
@@ -553,55 +585,28 @@ public string DrawTextArea(string s, Font font, SolidBrush brush, float x, float
553585
554586 GUI . skin . textArea . alignment = TextAnchor . UpperLeft ;
555587
556- GUI . color = brush . Color . ToUColor ( ) ;
588+ GUI . color = color . ToUColor ( ) ;
557589 //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 ) ;
586592
587593 GUI . skin . textArea . hover . background = null ;
588594 GUI . skin . textArea . active . background = null ;
589595 GUI . skin . textArea . focused . background = null ;
590596 GUI . skin . textArea . normal . background = null ;
591597
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 )
593604 {
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 ;
596607 }
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 ) ;
602608
603- return GUI . TextArea ( new Rect ( position . X , position . Y , width , height ) , s ) ;
604- }
609+ return val ;
605610 }
606611 public string DrawTextField ( string s , Font font , SolidBrush brush , RectangleF layoutRectangle , HorizontalAlignment alignment )
607612 {
@@ -628,54 +633,26 @@ public string DrawTextField(string s, Font font, Color color, float x, float y,
628633 break ;
629634 }
630635
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 ) ;
659637
660638 GUI . color = color . ToUColor ( ) ;
661639 GUI . skin . textField . hover . background = null ;
662640 GUI . skin . textField . active . background = null ;
663641 GUI . skin . textField . focused . background = null ;
664642 GUI . skin . textField . normal . background = null ;
665643
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 )
667650 {
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 ;
670653 }
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 ) ;
676654
677- return GUI . TextField ( new Rect ( position . X , position . Y , width , height ) , s ) ;
678- }
655+ return val ;
679656 }
680657 public string DrawTextField ( string s , Font font , SolidBrush brush , float x , float y , float width , float height , HorizontalAlignment alignment )
681658 {
@@ -835,7 +812,7 @@ public SizeF MeasureString(string text, Font font)
835812 }
836813 public static SizeF MeasureStringStatic ( string text , Font font )
837814 {
838- int guiSkinFontSizeBuffer = GUI_SetLabelFont ( font ) ;
815+ int guiSkinFontSizeBuffer = GUI_SetFont ( GUI . skin . label , font ) ;
839816
840817 var size = GUI . skin . label . CalcSize ( new GUIContent ( text ) ) ;
841818
0 commit comments