Changeset 16

Show
Ignore:
Timestamp:
02/02/2012 04:02:08 PM (2 years ago)
Author:
acarter
Message:

Working on adding different images to RadioGroup?

Location:
Code/oMaE/oMaE
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • Code/oMaE/oMaE/MiniGames/Match.cs

    r14 r16  
    3030            for (int i = 0; i < 2; ++i) 
    3131                for (int j = 0; j < 5; ++j) 
    32                     radioGroup.addRadioButton(new Rectangle(i == 0 ? 165 : 590, 40 * j + 106, 10, 10), energies[i], i == 0 ? TextLocation.LEFT : TextLocation.RIGHT); 
     32                    radioGroup.addRadioButton(new Vector2(i == 0 ? 165 : 590, 40 * j + 106), energies[i], i == 0 ? TextLocation.LEFT : TextLocation.RIGHT); 
    3333            return base.Initialize(); 
    3434        } 
  • Code/oMaE/oMaE/Widgets/RadioButton.cs

    r10 r16  
    1616    { 
    1717        private RadioGroup Parent; 
    18         private Rectangle Location; 
    1918        private String text; 
    2019 
    21         public Vector2 Center { get { return new Vector2(Location.Center.X, Location.Center.Y); } } 
     20        public Vector2 Center{ get { return new Vector2(Location.X, Location.Y); } } 
     21        public Rectangle Location { get { return Active ? ClickedLocation : UnclickedLocation; } } 
     22        public Texture2D Picture { get { return Active ? ClickedImg : UnclickedImg; } } 
    2223 
    23         public static Texture2D UnclickedImg, ClickedImg; 
    24          
    25         public RadioButton(Rectangle Location, String text, TextLocation textLocation, RadioGroup Parent) 
     24 
     25 
     26        public static readonly Vector2 DefaultSize = new Vector2(10, 10); 
     27        public static Texture2D DefaultUnclickedImg, DefaultClickedImg; 
     28        protected Texture2D UnclickedImg, ClickedImg; 
     29        protected Rectangle UnclickedLocation, ClickedLocation; 
     30 
     31        public RadioButton(Vector2 Location, String text, TextLocation textLocation, RadioGroup Parent, 
     32                            Texture2D UnclickedImg = null, Nullable<Vector2> UnclickedDim = null, 
     33                            Texture2D ClickedImg = null, Nullable<Vector2> ClickedDim = null) 
    2634        { 
    27             this.Location = Location; 
     35            Vector2 vUnclickedDim = UnclickedDim ?? DefaultSize; 
     36            Vector2 vClickedDim = ClickedDim ?? DefaultSize; 
     37            this.UnclickedLocation = new Rectangle((int)Location.X, (int)Location.Y, (int)vUnclickedDim.X, (int)vUnclickedDim.Y); 
     38            this.ClickedLocation = new Rectangle((int)Location.X, (int)Location.Y, (int)vClickedDim.X, (int)vClickedDim.Y); 
    2839            this.text = text; 
    2940            this.Parent = Parent; 
     41            this.UnclickedImg = UnclickedImg; 
     42            this.ClickedImg = ClickedImg; 
    3043        } 
     44 
    3145        public override bool LoadContent(ContentManager Content) 
    3246        { 
    33             UnclickedImg = Content.Load<Texture2D>("Interface/RadioButton_Unclicked"); 
    34             ClickedImg = Content.Load<Texture2D>("Interface/RadioButton_Clicked"); 
     47            if(DefaultUnclickedImg == null) 
     48                DefaultUnclickedImg = Content.Load<Texture2D>("Interface/RadioButton_Unclicked"); 
     49            if(DefaultClickedImg == null) 
     50                DefaultClickedImg = Content.Load<Texture2D>("Interface/RadioButton_Clicked"); 
     51            this.UnclickedImg = UnclickedImg ?? DefaultUnclickedImg; 
     52            this.ClickedImg = ClickedImg ?? DefaultClickedImg; 
    3553            return base.LoadContent(Content); 
    3654        } 
     
    5775        { 
    5876            spritebatch.Begin(); 
    59             spritebatch.Draw(Active ? ClickedImg : UnclickedImg, Location, Color.White); 
     77            spritebatch.Draw(Picture, Location, Color.White); 
    6078            spritebatch.End(); 
    6179        } 
  • Code/oMaE/oMaE/Widgets/RadioGroup.cs

    r9 r16  
    2525        } 
    2626 
    27         public void addRadioButton(Rectangle location, String text = "", TextLocation textLocation = TextLocation.RIGHT) 
     27        public void addRadioButton(Vector2 location, String text = "", TextLocation textLocation = TextLocation.RIGHT) 
    2828        { 
    2929            group.Add(new RadioButton(location, text, textLocation, this)); 
    3030        } 
     31 
    3132 
    3233        public override bool Initialize()