public Card(TextureImage faceDownImage, TextureImage faceUpImage) { this.faceDownImage = faceDownImage; this.faceUpImage = faceUpImage; this.CardImage = this.faceDownImage; }
public Card(TextureImage faceDownImage, TextureImage faceUpImage) { this.faceDownImage = faceDownImage; this.faceUpImage = faceUpImage; this.isCardFaceUp.Subscribe(this.OnIsCardFaceUpChanged); this.cardImage.OnNext(this.faceDownImage); this.isCardFaceUp.OnNext(false); }
protected override void LoadContent() { this.spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice)); var primitivesService = new PrimitivesService(this.GraphicsDevice); var renderer = new Renderer(this.spriteBatchAdapter, primitivesService); var spriteFontAdapter = new SpriteFontAdapter(this.Game.Content.Load<SpriteFont>("Segoe18")); var largeFont = new SpriteFontAdapter(this.Game.Content.Load<SpriteFont>("Segoe30")); var addButtonImageTexture = new TextureImage(new Texture2DAdapter(this.Game.Content.Load<Texture2D>("AddButton"))); var trashButtonImageTexture = new TextureImage(new Texture2DAdapter(this.Game.Content.Load<Texture2D>("TrashButton"))); this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager()); var buttonClickResults = new ObservableCollection<string>(); var header1 = new TextBlock(spriteFontAdapter) { Text = "MY APPLICATION", Foreground = new SolidColorBrush(Colors.White), Margin = new Thickness(10) }; var header2 = new TextBlock(largeFont) { Text = "XNA Application Bar", Foreground = new SolidColorBrush(Colors.White), Margin = new Thickness(10) }; var itemsControl = new ItemsControl { ItemsSource = buttonClickResults, ItemTemplate = _ => { var textBlock = new TextBlock(spriteFontAdapter) { Foreground = new SolidColorBrush(Colors.White) }; textBlock.Bind( TextBlock.TextProperty, BindingFactory.CreateOneWay<string>()); return textBlock; } }; var scrollViewer = new ScrollViewer { Content = itemsControl }; var applicationBar = new ApplicationBar { Buttons = { new ApplicationBarIconButton("Add", addButtonImageTexture), new ApplicationBarIconButton("Delete", trashButtonImageTexture) } }; var grid = new Grid { Background = new SolidColorBrush(Colors.Black), RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition(), new RowDefinition { Height = new GridLength(70) } }, Children = { header1, header2, scrollViewer, applicationBar } }; applicationBar.Clicks.Subscribe( Observer.Create<ApplicationBarIconButton>(s => buttonClickResults.Add(s.Text))); Grid.SetRow(header1, 0); Grid.SetRow(header2, 1); Grid.SetRow(scrollViewer, 2); Grid.SetRow(applicationBar, 3); this.rootElement.Content = grid; }
protected override void LoadContent() { var spriteBatchAdapter = new SpriteBatchAdapter(new SpriteBatch(this.GraphicsDevice)); var spriteFontAdapter = new SpriteFontAdapter(this.Game.Content.Load<SpriteFont>("SpriteFont")); var renderer = new Renderer(spriteBatchAdapter, new PrimitivesService(this.GraphicsDevice)); this.rootElement = new RootElement(this.GraphicsDevice.Viewport.ToRect(), renderer, new InputManager()); // Setup Layout var cardImage = new Image { Stretch = Stretch.None }; var cardToggleButton = new ToggleButton { Content = cardImage, Margin = new Thickness(10) }; var resetButton = new Button { Content = new Border { Background = new SolidColorBrush(Colors.LightGray), Child = new TextBlock(spriteFontAdapter) { Text = "Reset", Margin = new Thickness(10) } }, Margin = new Thickness(10), HorizontalAlignment = HorizontalAlignment.Center }; var stackPanel = new StackPanel { Children = { cardToggleButton, resetButton } }; this.rootElement.Content = stackPanel; // Setup Data Binding var faceDownImage = new TextureImage(new Texture2DAdapter(this.Game.Content.Load<Texture2D>("FaceDown"))); var faceUpImage = new TextureImage(new Texture2DAdapter(this.Game.Content.Load<Texture2D>("FaceUp"))); var card = new Card(faceDownImage, faceUpImage); cardImage.Bind( Image.SourceProperty, card.CardImage); cardToggleButton.Bind( ToggleButton.IsCheckedProperty, card.IsCardFaceUp, card.IsCardFaceUp); resetButton.Click += (sender, args) => card.Reset(); }