private List <PanoramaChild> GetCurrentChildren() { var result = new List <PanoramaChild>(); var index = SelectedIndex; // Our "first" element is the element that is selected PanoramaChild lastChild = null; for (var counter = 0; counter < Children.Count; counter++) { if (index > Children.Count - 1) { index = 0; // We wrap back to item 0 when we shoot out the back } if (Children[index].Visibility == Visibility.Visible) { var currentChild = Children[index]; if (lastChild != null && SimpleView.GetFlowsWithPrevious(currentChild)) { lastChild.FloatingElements.Add(currentChild); } else { lastChild = new PanoramaChild { Child = currentChild, ActualChildIndex = index }; result.Add(lastChild); } } index++; } return(result); }
/// <summary>Sets the size strategy on host.</summary> /// <param name="view">The view.</param> /// <param name="viewContent">Content of the view.</param> private static void SetSizeStrategyOnHost(DependencyObject view, ViewContentControl viewContent) { if (view == null) { return; } if (viewContent == null) { return; } var host = viewContent.SizeStrategyHost; if (host == null) { return; } var gridHost = host as SizeStrategyAwareGrid; if (gridHost == null) { return; } gridHost.SizeStrategy = SimpleView.GetSizeStrategy(view); }
/// <summary> /// Draws the content of a <see cref="T:System.Windows.Media.DrawingContext" /> object during the render pass of a <see cref="T:System.Windows.Controls.Panel" /> element. /// </summary> /// <param name="dc">The <see cref="T:System.Windows.Media.DrawingContext" /> object to draw.</param> protected override void OnRender(DrawingContext dc) { base.OnRender(dc); if (!ShowGroupHeaders || GroupHeaderRenderer == null) { return; } var offsetTop = 0d; if (_scrollVertical.Visibility == Visibility.Visible) { offsetTop = _scrollVertical.Value * -1; } var currentTop = offsetTop + Padding.Top; var currentGroupIsExpanded = true; foreach (var control in _lastControls) { var lineHeight = 0d; if (control.Label != null) { lineHeight = control.Label.DesiredSize.Height; } if (control.Edit != null) { lineHeight = Math.Max(lineHeight, control.Edit.DesiredSize.Height); } lineHeight = SnapToPixel(lineHeight); if (control.Label != null && SimpleView.GetGroupBreak(control.Label)) { var groupTitle = SimpleView.GetGroupTitle(control.Label); if (_renderedGroups.ContainsKey(groupTitle)) { currentGroupIsExpanded = _renderedGroups[groupTitle].IsExpanded; var group = _renderedGroups[groupTitle]; var width = ActualWidth - Padding.Left - Padding.Right; if (_scrollVertical.Visibility == Visibility.Visible) { width -= SystemParameters.VerticalScrollBarWidth; } dc.PushTransform(new TranslateTransform(Padding.Left, currentTop)); GroupHeaderRenderer.RenderHeader(dc, currentTop, width, groupTitle, group.IsExpanded); dc.Pop(); group.LastRenderTopPosition = currentTop; currentTop += _renderedGroups[groupTitle].Height; } } if (currentGroupIsExpanded) { currentTop += lineHeight + VerticalElementSpacing; } } }
/// <summary> /// Invoked when an unhandled MouseDown attached event reaches an element in its route that is derived from this class. Implement this method to add class handling for this event. /// </summary> /// <param name="e">The <see cref="T:System.Windows.Input.MouseButtonEventArgs" /> that contains the event data. This event data reports details about the mouse button that was pressed and the handled state.</param> protected override void OnMouseDown(MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed && e.ClickCount == 1) { foreach (var control in _lastControls) { if (control.Label != null && SimpleView.GetGroupBreak(control.Label)) { var groupTitle = SimpleView.GetGroupTitle(control.Label); if (_renderedGroups.ContainsKey(groupTitle)) { var group = _renderedGroups[groupTitle]; var y = group.LastRenderTopPosition; var positionY = e.GetPosition(this).Y; if (positionY >= y && positionY <= y + group.Height) { e.Handled = true; group.IsExpanded = !group.IsExpanded; InvalidateMeasure(); InvalidateArrange(); InvalidateVisual(); return; } } } } } base.OnMouseDown(e); }
/// <summary> /// Initializes a new instance of the <see cref="UndockedHierarchicalViewWindow"/> class. /// </summary> /// <param name="viewResult">The view result.</param> /// <param name="hierarchicalViewHostTabItem">The hierarchical view host tab item.</param> public UndockedHierarchicalViewWindow(ViewResult viewResult, HierarchicalViewHostTabItem hierarchicalViewHostTabItem) { Closing += (s, e) => { DockContent(); }; DataContext = viewResult; _hierarchicalViewHostTabItem = hierarchicalViewHostTabItem; if (hierarchicalViewHostTabItem.UndockWindowStyle != null) { Style = hierarchicalViewHostTabItem.UndockWindowStyle; } if (viewResult != null) { Title = viewResult.ViewTitle; if (viewResult.View != null) { var viewColor = SimpleView.GetViewThemeColor(viewResult.View); if (viewColor != Colors.Transparent) { Background = new SolidColorBrush(viewColor); } } } }
/// <summary> /// Called when the button is clicked /// </summary> protected override void OnClick() { if (TabControl == null) { return; } var menu = new ContextMenu(); var counter = -1; foreach (var view in Shell.Current.NormalViews) { counter++; var menuItem = new SelectViewMenuItem(TabControl, counter); menuItem.Header = SimpleView.GetTitle(view.View); var viewColor = SimpleView.GetViewThemeColor(view.View); if (viewColor.A == 0) { var viewColorResource = FindResource("CODE.Framework-Application-ThemeColor1"); if (viewColorResource != null) { viewColor = (Color)viewColorResource; } } if (viewColor.A != 0) { menuItem.Background = new SolidColorBrush(viewColor); } menu.Items.Add(menuItem); } menu.Placement = PlacementMode.Bottom; menu.HorizontalOffset = ActualWidth; menu.PlacementTarget = this; menu.IsOpen = true; }
public static void QuitGame() { Shipwreck.CurrentGame.Status = GameStatus.Over; var view = new SimpleView(); view.Message = "GAME OVER"; view.Display(); }
private static void WinGame(string message) { Shipwreck.CurrentGame.Status = GameStatus.Over; var view = new SimpleView(); view.Message = message; view.Display(); }
public static void WinGame() { Shipwreck.CurrentGame.Status = GameStatus.Over; var view = new SimpleView(); view.Message = "YOU WON!"; view.Display(); }
public static void LoseGame() { Shipwreck.CurrentGame.Player.Die(); // TODO Do I actually need this method? Shipwreck.CurrentGame.Status = GameStatus.Over; var view = new SimpleView(); view.Message = "You Died. Sucks to suck\n GAME OVER"; view.Display(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); SimpleView app = new SimpleView(); ViewModel context = new ViewModel(); app.DataContext = context; app.Show(); }
static void Main(string[] args) { Game game = new Game(); IView view = new SimpleView(); // new view.SwedishView(); PlayGame controller = new PlayGame(game, view); while (controller.Play()) { ; } }
/// <summary> /// Gets the controls in pairs. /// </summary> /// <returns>List<ControlPair>.</returns> private List <ControlPair> GetControls() { var controls = new List <ControlPair>(); for (var controlCounter = 0; controlCounter < Children.Count; controlCounter++) { var child = Children[controlCounter]; if (child.Visibility == Visibility.Collapsed) { continue; } var controlPair = new ControlPair(0d); if (SimpleView.GetIsStandAloneEditControl(child)) { controlPair.Edit = child; } else { controlPair.Label = child; if (SimpleView.GetSpanFullWidth(child)) { controlPair.LabelSpansFullWidth = true; } else if (!SimpleView.GetIsStandAloneLabel(child)) { var editControlIndex = controlCounter + 1; if (Children.Count > editControlIndex) { controlPair.Edit = Children[editControlIndex]; } controlCounter++; // We are skipping the next control since we already accounted for it while (true) // We check if the next control might flow with the current edit control { if (Children.Count <= controlCounter + 1) { break; } if (!SimpleView.GetFlowsWithPrevious(Children[controlCounter + 1])) { break; } controlPair.AdditionalEditControls.Add(Children[controlCounter + 1]); controlCounter++; } } } controls.Add(controlPair); } return(controls); }
public PropertySheetTest() { InitializeComponent(); Loaded += (s, e) => { var exampleType = GetType(); var properties = exampleType.GetProperties(); var categories = new List <string> { string.Empty }; foreach (var property in properties) { var categoryName = GetCategory(property); if (!string.IsNullOrEmpty(categoryName) && !categories.Contains(categoryName)) { categories.Add(categoryName); } } categories = categories.OrderBy(c => c).ToList(); foreach (var category in categories) { var first = true; foreach (var property in properties.OrderBy(p => p.Name)) { if (GetCategory(property) != category) { continue; } var text = new TextBlock { Text = property.Name }; SimpleView.SetGroupTitle(text, !string.IsNullOrEmpty(category) ? category : " -- Uncategorized"); if (first) { SimpleView.SetGroupBreak(text, true); } first = false; var nativeValue = property.GetValue(this, null); var editText = nativeValue == null ? string.Empty : nativeValue.ToString(); var edit = new TextBox { Text = editText }; PropertySheet.Children.Add(text); PropertySheet.Children.Add(edit); } } }; }
public PEngine(SimpleView view) { this.view = view; emitters = new List <AbstractEmitter>(MAXEMITTERS); tex = view.content.Load <Texture2D>("particle"); App.Instance.Model.NewEnemy += new EventHandler <SurfaceTower.Model.EventArguments.EnemyArgs>(NewEnemy); App.Instance.Model.DeadEnemy += new EventHandler <SurfaceTower.Model.EventArguments.EnemyArgs>(Model_DeadEnemy); App.Instance.Model.AddTurret += new EventHandler <SurfaceTower.Model.EventArguments.TurretArgs>(Model_AddTurret); foreach (Model.Gun.Turret t in App.Instance.Model.Turrets) { t.NewBullet += new EventHandler <SurfaceTower.Model.EventArguments.BulletArgs>(t_NewBullet); } }
public PEngine(SimpleView view) { this.view = view; emitters = new List<AbstractEmitter>(MAXEMITTERS); tex = view.content.Load<Texture2D>("particle"); App.Instance.Model.NewEnemy += new EventHandler<SurfaceTower.Model.EventArguments.EnemyArgs>(NewEnemy); App.Instance.Model.DeadEnemy += new EventHandler<SurfaceTower.Model.EventArguments.EnemyArgs>(Model_DeadEnemy); App.Instance.Model.AddTurret += new EventHandler<SurfaceTower.Model.EventArguments.TurretArgs>(Model_AddTurret); foreach (Model.Gun.Turret t in App.Instance.Model.Turrets) { t.NewBullet += new EventHandler<SurfaceTower.Model.EventArguments.BulletArgs>(t_NewBullet); } }
public void Init() { Console.WriteLine("HomeVM Init"); Banner_src = Path.GetFullPath("../../Images/banner.png"); Img_src = Path.GetFullPath("../../Images/ci.png"); Console.WriteLine(Img_src); Items = new ObservableCollection <SimpleView>(); //디바이스 수만큼 오버뷰 생성 foreach (TabViewModel vm in MainViewModel.Dev_list) { SimpleView tmp_view = new SimpleView(); tmp_view.DataContext = vm; Items.Add(tmp_view); } }
/// <summary> /// Shows data to SimpleView. /// </summary> /// <param name="view">The SimpleView which renders the data.</param> public void Show(SimpleView view) { if (view == null) { throw new ArgumentNullException(nameof(view)); } if (view.Presenter != null && view.Presenter != this) { throw new ArgumentException(DiagnosticMessages.DataPresenter_InvalidDataView, nameof(view)); } var dataSet = DataSet <DummyModel> .Create(); AttachView(view); Mount(dataSet); OnViewChanged(); }
/// <summary> /// Opens a normal view in a separate window. /// </summary> /// <param name="context">The context.</param> /// <param name="viewResult">The view result.</param> private static void OpenNormalViewInWindow(RequestContext context, ViewResult viewResult) { var window = new Window { Title = viewResult.ViewTitle, SizeToContent = SizeToContent.WidthAndHeight, Content = viewResult.View, DataContext = viewResult.Model, WindowStartupLocation = WindowStartupLocation.CenterScreen }; window.SetBinding(TitleProperty, new Binding("ViewTitle") { Source = viewResult }); var simpleView = viewResult.View as SimpleView; if (simpleView != null) { if (SimpleView.GetSizeStrategy(simpleView) == ViewSizeStrategies.UseMaximumSizeAvailable) { window.SizeToContent = SizeToContent.Manual; } } viewResult.TopLevelWindow = window; if (context.Result is MessageBoxResult) { window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-TopLevelMessageBoxWindowStyle"); } else { window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-NormalLevelWindowStyle"); } if (viewResult.IsModal) { window.ShowDialog(); } else { window.Show(); } }
/// <summary> /// Draws the content of a <see cref="T:System.Windows.Media.DrawingContext" /> object during the render pass of a <see cref="T:System.Windows.Controls.Panel" /> element. /// </summary> /// <param name="dc">The <see cref="T:System.Windows.Media.DrawingContext" /> object to draw.</param> protected override void OnRender(DrawingContext dc) { base.OnRender(dc); var children = GetCurrentChildren(); if (children.Count < 1) { return; } _hitZones.Clear(); var headerHeight = GetHeaderHeight() + 5; var currentLeft = HorizontalHeaderRenderingOffset; var index = SelectedIndex; // Our "first" element is the element that is selected again var isFirst = true; foreach (var child in children) { var title = SimpleView.GetTitle(child.Child); if (string.IsNullOrEmpty(title)) { title = "Item"; } var ft = isFirst ? new FormattedText(title, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(HeaderFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), HeaderFontSize, SelectedHeaderForeground) : new FormattedText(title, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(HeaderFontFamily, FontStyles.Normal, FontWeights.Light, FontStretches.Normal), HeaderFontSize, UnselectedHeaderForeground); dc.DrawText(ft, new Point(currentLeft, 0d)); if (index > Children.Count - 1) { index = 0; // We wrap back to item 0 when we shoot out the back } _hitZones.Add(new PanoramaHeaderHitZone { Index = child.ActualChildIndex, Rect = GeometryHelper.NewRect(currentLeft - 10, 0d, ft.Width + 15, headerHeight) }); currentLeft += ft.Width + 25; index++; isFirst = false; } }
public void IndexView() { // Create simple view var viewPhysicalPath = testContextInstance.TestDir + @"\..\..\MvcApplication1\Views\Simple\Index.simple"; var indexView = new SimpleView(viewPhysicalPath); // Create view context var viewContext = new ViewContext(); // Create view data var viewData = new ViewDataDictionary(); viewData["message"] = "Hello World!"; viewContext.ViewData = viewData; // Render simple view var writer = new StringWriter(); indexView.Render(viewContext, writer); // Assert StringAssert.Contains(writer.ToString(), "<h1>Hello World!</h1>"); }
/// <summary> /// Adds new views into the tabs. /// </summary> /// <param name="groups">The groups.</param> private void PopulateNewViews(Dictionary <string, List <ViewResult> > groups) { // Adding new items into the tabs foreach (var groupName in groups.Keys) { var group = groups[groupName]; if (group.Count < 1) { continue; } var groupTab = GetNewOrExistingGroupTab(group, groupName); if (groupTab.Content == null) { continue; } var subTabs = groupTab.Content as TabControl; if (subTabs == null) { continue; } foreach (var view in group) { var newSubTab = new HierarchicalViewHostTabItem { Content = view }; var foregroundBrush2 = SimpleView.GetTitleColor2(group[0].View); if (foregroundBrush2 != null) { newSubTab.Foreground = foregroundBrush2; } subTabs.Items.Add(newSubTab); subTabs.SelectedItem = newSubTab; } } }
/// <summary> /// Creates a new tab, or returns the existing tab for the group /// </summary> /// <param name="group">The group.</param> /// <param name="groupName">Name of the group.</param> /// <returns>TabItem.</returns> private TabItem GetNewOrExistingGroupTab(IList <ViewResult> group, string groupName) { var tab = Items.OfType <TabItem>().FirstOrDefault(t => GetAssociatedGroupName(t) == groupName); if (tab != null) { SelectedItem = tab; return(tab); } var newTab = new TabItem(); SetAssociatedGroupName(newTab, groupName); var backgroundColor = SimpleView.GetViewThemeColor(group[0].View); if (backgroundColor != Colors.Transparent) { newTab.Background = new SolidColorBrush(backgroundColor); } var foregroundBrush = SimpleView.GetTitleColor(group[0].View); if (foregroundBrush != null) { newTab.Foreground = foregroundBrush; } newTab.DataContext = group; // We assign the whole collection here so we can reference to it later var subTabs = new TabControl(); if (SubTabControlStyle != null) { subTabs.Style = SubTabControlStyle; } newTab.Content = subTabs; Items.Add(newTab); SelectedItem = newTab; return(newTab); }
/// <summary> /// Returns a list of grouped views. /// </summary> /// <param name="views">The views.</param> /// <returns>Dictionary<System.String, List<ViewResult>>.</returns> private Dictionary <string, List <ViewResult> > GetGroupedViews(IEnumerable <ViewResult> views) { var groups = new Dictionary <string, List <ViewResult> >(); foreach (var view in views.Where(v => v.View != null)) { var group = SimpleView.GetGroup(view.View).Trim(); if (string.IsNullOrEmpty(group) && !CombineAllEmptyGroups) { group = SimpleView.GetTitle(view.View); } if (!groups.ContainsKey(group)) { groups.Add(group, new List <ViewResult> { view }); } else { groups[group].Add(view); } } return(groups); }
/// <summary> /// Populates the list of items from actions and views. /// </summary> private void Repopulate() { var newItems = new List <ViewActionAndOpenViewItem>(); if (Actions != null) { foreach (var action in Actions.Actions) { if (!string.IsNullOrEmpty(action.GroupTitle)) { var found = false; foreach (var otherAction in newItems) { if (otherAction.Group == action.GroupTitle) { otherAction.SubItems.Add(new ViewActionAndOpenViewItem(action, ViewTabs)); found = true; } } if (!found) { newItems.Add(new ViewActionAndOpenViewItem(action, ViewTabs)); } } else { newItems.Add(new ViewActionAndOpenViewItem(action, ViewTabs)); } } } if (Views != null) { var viewIndex = -1; foreach (var view in Views) { viewIndex++; var groupTitle = string.Empty; if (view.View != null) { groupTitle = SimpleView.GetGroup(view.View); } if (!string.IsNullOrEmpty(groupTitle)) { var found = false; foreach (var otherAction in newItems) { if (otherAction.Group == groupTitle) { otherAction.SubItems.Add(new ViewActionAndOpenViewItem(view, viewIndex, ViewTabs)); found = true; } } if (!found) { newItems.Add(new ViewActionAndOpenViewItem(view, viewIndex, ViewTabs)); } } else { newItems.Add(new ViewActionAndOpenViewItem(view, viewIndex, ViewTabs)); } } } ItemsSource = newItems; }
/// <summary> /// This method draws additional elements into the main display area /// </summary> /// <param name="dc">Drawing context</param> protected override void CustomRender(DrawingContext dc) { var primaryTitle = string.Empty; var secondaryTitle = string.Empty; foreach (UIElement element in Children) { var elementType = SimpleView.GetUIElementType(element); if (elementType == UIElementTypes.Primary) { primaryTitle = SimpleView.GetUIElementTitle(element); break; } } foreach (UIElement element in Children) { var elementType = SimpleView.GetUIElementType(element); if (elementType == UIElementTypes.Secondary) { secondaryTitle = SimpleView.GetUIElementTitle(element); break; } } var primaryTitleFont = PrimaryTitleFont; var primaryTitleFontSize = PrimaryTitleFontSize; var primaryTitleBrush1 = PrimaryTitleHeaderBrush; var primaryTitleBrush2 = PrimaryTitleFooterBrush; var primaryHeaderBackgroundBrush = PrimaryAreaHeaderBackgroundBrush; var secondaryTitleFont = SecondaryTitleFont; var secondaryTitleFontSize = PrimaryTitleFontSize; var secondaryTitleBrush1 = SecondaryTitleHeaderBrush; var secondaryTitleBrush2 = SecondaryTitleFooterBrush; var secondaryHeaderBackgroundBrush = SecondaryAreaHeaderBackgroundBrush; // Calculating the general areas var primaryRect = new Rect(); switch (CalculatedLayout) { case PrimarySecondaryLayout.PrimaryTopSecondaryBottom: primaryRect.Y = 0d; primaryRect.X = 0d; primaryRect.Height = RowDefinitions[0].ActualHeight + RowDefinitions[1].ActualHeight; primaryRect.Width = ActualWidth; break; case PrimarySecondaryLayout.SecondaryTopPrimaryBottom: primaryRect.Y = RowDefinitions[0].ActualHeight; primaryRect.X = 0d; primaryRect.Height = RowDefinitions[1].ActualHeight + RowDefinitions[2].ActualHeight; primaryRect.Width = ActualWidth; break; case PrimarySecondaryLayout.PrimaryLeftSecondaryRight: primaryRect.Y = 0d; primaryRect.X = 0d; primaryRect.Height = ActualHeight; primaryRect.Width = ColumnDefinitions[0].ActualWidth + ColumnDefinitions[1].ActualWidth; break; case PrimarySecondaryLayout.SecondaryLeftPrimaryRight: primaryRect.Y = 0d; primaryRect.X = ColumnDefinitions[0].ActualWidth; primaryRect.Height = ActualHeight; primaryRect.Width = ColumnDefinitions[1].ActualWidth + ColumnDefinitions[2].ActualWidth; break; } var secondaryRect = new Rect(); switch (CalculatedLayout) { case PrimarySecondaryLayout.PrimaryTopSecondaryBottom: secondaryRect.Y = RowDefinitions[0].ActualHeight + RowDefinitions[1].ActualHeight; secondaryRect.X = 0d; secondaryRect.Height = RowDefinitions[2].ActualHeight; secondaryRect.Width = ActualWidth; break; case PrimarySecondaryLayout.SecondaryTopPrimaryBottom: secondaryRect.Y = 0d; secondaryRect.X = 0d; secondaryRect.Height = RowDefinitions[0].ActualHeight; secondaryRect.Width = ActualWidth; break; case PrimarySecondaryLayout.PrimaryLeftSecondaryRight: secondaryRect.Y = 0d; secondaryRect.X = ColumnDefinitions[0].ActualWidth + ColumnDefinitions[1].ActualWidth; secondaryRect.Height = ActualHeight; secondaryRect.Width = ColumnDefinitions[2].ActualWidth; break; case PrimarySecondaryLayout.SecondaryLeftPrimaryRight: secondaryRect.Y = 0d; secondaryRect.X = 0d; secondaryRect.Height = ActualHeight; secondaryRect.Width = ColumnDefinitions[0].ActualWidth; break; } if (!string.IsNullOrEmpty(primaryTitle)) { var primaryFormattedText1 = new FormattedText(primaryTitle, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(primaryTitleFont, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), primaryTitleFontSize, primaryTitleBrush1) { MaxTextWidth = secondaryRect.Width - 4, Trimming = TextTrimming.CharacterEllipsis }; var primaryFormattedText2 = new FormattedText(primaryTitle, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(primaryTitleFont, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), primaryTitleFontSize, primaryTitleBrush2) { MaxTextWidth = secondaryRect.Width - 4, Trimming = TextTrimming.CharacterEllipsis }; var headerRect = new Rect(primaryRect.X + 2, primaryRect.Y + 2, primaryRect.Width - 4, primaryFormattedText1.Height + 4); dc.DrawRectangle(primaryHeaderBackgroundBrush, null, headerRect); dc.DrawText(primaryFormattedText1, new Point(primaryRect.X + 4, primaryRect.Y + 3)); var mainAreaRect = new Rect(primaryRect.X + 2, primaryRect.Y + headerRect.Height + 4, primaryRect.Width - 4, primaryRect.Height - 2 - headerRect.Height - primaryFormattedText2.Height - 4); dc.DrawRectangle(PrimaryAreaBackgroundBrush, null, mainAreaRect); var tabRect = new Rect(primaryRect.X + 2, primaryRect.Y + primaryRect.Height - primaryFormattedText2.Height - 4, Math.Min(primaryRect.Width, primaryFormattedText2.Width + 10), primaryFormattedText2.Height + 4); dc.DrawRectangle(PrimaryAreaBackgroundBrush, null, tabRect); dc.DrawText(primaryFormattedText2, new Point(tabRect.X + 4, tabRect.Y + 2)); } else if (PrimaryAreaBackgroundBrush != null) { dc.DrawRectangle(PrimaryAreaBackgroundBrush, null, primaryRect); } if (!string.IsNullOrEmpty(secondaryTitle)) { var secondaryFormattedText1 = new FormattedText(secondaryTitle, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(secondaryTitleFont, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), secondaryTitleFontSize, secondaryTitleBrush1) { MaxTextWidth = secondaryRect.Width - 4, Trimming = TextTrimming.CharacterEllipsis }; var secondaryFormattedText2 = new FormattedText(secondaryTitle, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface(secondaryTitleFont, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), secondaryTitleFontSize, secondaryTitleBrush2) { MaxTextWidth = secondaryRect.Width - 4, Trimming = TextTrimming.CharacterEllipsis }; var headerRect = new Rect(secondaryRect.X + 2, secondaryRect.Y + 2, secondaryRect.Width - 4, secondaryFormattedText1.Height + 4); dc.DrawRectangle(secondaryHeaderBackgroundBrush, null, headerRect); dc.DrawText(secondaryFormattedText1, new Point(secondaryRect.X + 4, secondaryRect.Y + 3)); var mainAreaRect = new Rect(secondaryRect.X + 2, secondaryRect.Y + headerRect.Height + 4, secondaryRect.Width - 4, secondaryRect.Height - 2 - headerRect.Height - secondaryFormattedText2.Height - 4); dc.DrawRectangle(SecondaryAreaBackgroundBrush, null, mainAreaRect); var tabRect = new Rect(secondaryRect.X + 2, secondaryRect.Y + secondaryRect.Height - secondaryFormattedText2.Height - 4, Math.Min(secondaryRect.Width, secondaryFormattedText2.Width + 10), secondaryFormattedText2.Height + 4); dc.DrawRectangle(SecondaryAreaBackgroundBrush, null, tabRect); dc.DrawText(secondaryFormattedText2, new Point(tabRect.X + 4, tabRect.Y + 2)); } else if (SecondaryAreaBackgroundBrush != null) { dc.DrawRectangle(SecondaryAreaBackgroundBrush, null, secondaryRect); } }
/// <summary> /// Opens the top level view in a separate window. /// </summary> /// <param name="context">The context.</param> /// <param name="messageBoxResult">The message box result.</param> /// <param name="viewResult">The view result.</param> /// <returns>True if successfully opened</returns> private bool OpenTopLevelView(RequestContext context, MessageBoxResult messageBoxResult, ViewResult viewResult) { if (messageBoxResult != null && string.IsNullOrEmpty(viewResult.ViewIconResourceKey)) { viewResult.ViewIconResourceKey = messageBoxResult.ModelMessageBox.IconResourceKey; } //Brush iconBrush = Brushes.Transparent; //if (!string.IsNullOrEmpty(viewResult.ViewIconResourceKey)) // try // { // var resource = Application.Current.FindResource(viewResult.ViewIconResourceKey); // if (resource != null) // iconBrush = (Brush) resource; // } // catch // { // iconBrush = Brushes.Transparent; // } // If we respect local views and the view is in fact a local view, and we have a normal view already open, then we open it in a local way only. if (viewResult.ViewScope == ViewScope.Local && HandleLocalViewsSpecial && SelectedNormalView > -1) { var selectedView = NormalViews[SelectedNormalView]; if (selectedView == null) { return(false); } selectedView.LocalViews.Add(viewResult); if (viewResult.MakeViewVisibleOnLaunch) { selectedView.SelectedLocalViewIndex = selectedView.LocalViews.Count - 1; } return(true); } //Need to make sure we do not open more than allowed - Popups should not close underlying views. if (viewResult.ViewLevel != ViewLevel.Popup && MaximumTopLevelViewCount > -1) { var inplaceTopLevelviews = TopLevelViews.Where(v => v.TopLevelWindow == null).ToList(); while (inplaceTopLevelviews.Count + 1 > MaximumTopLevelViewCount) { CloseViewForModel(inplaceTopLevelviews[0].Model); inplaceTopLevelviews.RemoveAt(0); } } TopLevelViews.Add(viewResult); if (viewResult.MakeViewVisibleOnLaunch && !(TopLevelViewLaunchMode == ViewLaunchMode.Popup || (TopLevelViewLaunchMode == ViewLaunchMode.InPlaceExceptPopups && viewResult.ViewLevel == ViewLevel.Popup))) { SelectedTopLevelView = TopLevelViews.Count - 1; SelectedTopLevelViewResult = SelectedTopLevelView > -1 ? TopLevelViews[SelectedTopLevelView] : null; if (viewResult.View != null) { if (!FocusHelper.FocusFirstControlDelayed(viewResult.View)) { FocusHelper.FocusDelayed(viewResult.View); } } } TopLevelViewCount = TopLevelViews.Count; if (TopLevelViewLaunchMode == ViewLaunchMode.Popup || (TopLevelViewLaunchMode == ViewLaunchMode.InPlaceExceptPopups && viewResult.ViewLevel == ViewLevel.Popup)) { var window = new Window { Title = viewResult.ViewTitle, Content = viewResult.View, DataContext = viewResult.Model, WindowStartupLocation = WindowStartupLocation.CenterScreen, Owner = this }; window.SetBinding(TitleProperty, new Binding("ViewTitle") { Source = viewResult }); // Setting the size strategy var strategy = SimpleView.GetSizeStrategy(viewResult.View); switch (strategy) { case ViewSizeStrategies.UseMinimumSizeRequired: window.SizeToContent = SizeToContent.WidthAndHeight; break; case ViewSizeStrategies.UseMaximumSizeAvailable: window.SizeToContent = SizeToContent.Manual; window.Height = SystemParameters.WorkArea.Height; window.Width = SystemParameters.WorkArea.Width; break; case ViewSizeStrategies.UseSuggestedSize: window.SizeToContent = SizeToContent.Manual; window.Height = SimpleView.GetSuggestedHeight(viewResult.View); window.Width = SimpleView.GetSuggestedWidth(viewResult.View); break; } viewResult.TopLevelWindow = window; if (context.Result is MessageBoxResult) { window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-TopLevelMessageBoxWindowStyle"); } else { window.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-TopLevelWindowStyle"); } if (viewResult.View != null) { foreach (InputBinding binding in viewResult.View.InputBindings) { window.InputBindings.Add(binding); } } if (!FocusHelper.FocusFirstControlDelayed(window)) { FocusHelper.FocusDelayed(window); } if (viewResult.IsModal) { window.ShowDialog(); } else { window.Show(); } } //if (iconBrush != null) //{ // try // { // // TODO: Implement the icon logic // //var iconRect = new Canvas {Height = 96, Width = 96, Background = iconBrush}; // //window.Icon = iconRect.ToIconSource(); // } // catch // { // } //} return(true); }
/// <summary> /// This method is invoked when a view is opened /// </summary> /// <param name="context">Request context (contains information about the view)</param> /// <returns> /// True if handled successfully /// </returns> public bool OpenView(RequestContext context) { if (context.Result is StatusMessageResult) { return(HandleStatusMessage(context)); } if (context.Result is NotificationMessageResult) { var result = context.Result as NotificationMessageResult; return(HandleNotificationMessage(context, result.Model.OverrideTimeout)); } var viewResult = context.Result as ViewResult; if (viewResult != null && viewResult.ForceNewShell) { if ((viewResult.ViewLevel == ViewLevel.Normal && NormalViewCount > 0) || (viewResult.ViewLevel == ViewLevel.TopLevel && TopLevelViewCount > 0)) { // A new shell should be opened, so we try to create another shell and then hand off view opening duties to it, rather than handling it directly var shellLauncher = Controller.GetShellLauncher() as WindowShellLauncher <Shell>; if (shellLauncher != null) { if (shellLauncher.OpenAnotherShellInstance()) { return(Current.OpenView(context)); } } } } var messageBoxResult = context.Result as MessageBoxResult; if (messageBoxResult != null) { if (messageBoxResult.View == null) { var messageBoxViewModel = messageBoxResult.Model as MessageBoxViewModel; if (messageBoxViewModel != null) { var textBlock = new TextBlock { TextWrapping = TextWrapping.Wrap, Text = messageBoxViewModel.Text }; textBlock.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-MessageBox-Text"); if (!string.IsNullOrEmpty(messageBoxViewModel.IconResourceKey)) { var grid = new Grid(); grid.ColumnDefinitions.Clear(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); var rect = new Rectangle { Fill = messageBoxViewModel.IconBrush }; rect.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-MessageBox-Image"); grid.Children.Add(rect); grid.Children.Add(textBlock); Grid.SetColumn(textBlock, 1); SimpleView.SetSizeStrategy(grid, ViewSizeStrategies.UseMinimumSizeRequired); messageBoxResult.View = grid; } else { messageBoxResult.View = textBlock; } } } if (messageBoxResult.View != null) { var messageBoxModelAction = messageBoxResult.Model as IHaveActions; if (messageBoxModelAction != null) { messageBoxResult.View.InputBindings.Clear(); foreach (var action in messageBoxModelAction.Actions) { if (action.ShortcutKey != Key.None) { messageBoxResult.View.InputBindings.Add(new KeyBinding(action, action.ShortcutKey, action.ShortcutModifiers)); } } } } } if (viewResult != null && viewResult.View != null && !viewResult.IsPartial) { if (viewResult.ViewLevel == ViewLevel.Popup || viewResult.ViewLevel == ViewLevel.StandAlone || viewResult.ViewLevel == ViewLevel.TopLevel) { return(OpenTopLevelView(context, messageBoxResult, viewResult)); } // This is an normal (main) view // Need to make sure we do not open more than allowed if (MaximumNormalViewCount > -1) { var inplaceNormalViews = NormalViews.Where(v => v.TopLevelWindow == null).ToList(); while (inplaceNormalViews.Count + 1 > MaximumNormalViewCount) { CloseViewForModel(inplaceNormalViews[0].Model); inplaceNormalViews.RemoveAt(0); } } NormalViews.Add(viewResult); if (viewResult.MakeViewVisibleOnLaunch) { FocusManager.SetFocusedElement(this, viewResult.View); SelectedNormalView = NormalViews.Count - 1; SelectedNormalViewResult = SelectedNormalView > -1 ? NormalViews[SelectedNormalView] : null; } NormalViewCount = NormalViews.Count; if (NormalViewLaunchMode == ViewLaunchMode.Popup) { OpenNormalViewInWindow(context, viewResult); } return(true); } return(false); }
/// <summary> /// Renders the actual tabs /// </summary> /// <param name="dc">The dc.</param> /// <param name="tabItemsPanel">The tab items panel.</param> public void Render(DrawingContext dc, TabItemsPanel tabItemsPanel) { // Making sure we have a selected page. if (tabItemsPanel.SelectedPage < 0) { var visibleCounter = -1; foreach (var element in tabItemsPanel.Children.OfType <UIElement>()) { visibleCounter++; if (TabItemsPanel.GetTabVisibility(element) == Visibility.Visible) { tabItemsPanel.SelectedPage = visibleCounter; break; } } return; } // Making sure the selected page is in fact visible var allPages = tabItemsPanel.Children.OfType <UIElement>().ToList(); if (TabItemsPanel.GetTabVisibility(allPages[tabItemsPanel.SelectedPage]) != Visibility.Visible) { var visibleCounter = -1; foreach (var element in tabItemsPanel.Children.OfType <UIElement>()) { visibleCounter++; if (TabItemsPanel.GetTabVisibility(element) == Visibility.Visible) { tabItemsPanel.SelectedPage = visibleCounter; break; } } return; } _pageHeaders.Clear(); foreach (var element in tabItemsPanel.Children.OfType <UIElement>()) { var header = SimpleView.GetTitle(element).Trim(); if (string.IsNullOrEmpty(header)) { header = "Item"; } _pageHeaders.Add(header); } _headerRectangles.Clear(); var boldType = new Typeface(FontFamily, FontStyles.Normal, FontWeights.Bold, FontStretches.Normal); var regularType = new Typeface(new FontFamily("Segoe UI"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal); var linePen = new Pen(Brushes.Gray, 1d); var highlightPen = new Pen(Brushes.RoyalBlue, 2d); dc.DrawLine(linePen, new Point(0, 29.5), new Point(tabItemsPanel.ActualWidth, 29.5)); var counter = -1; var left = 5d; foreach (var element in tabItemsPanel.Children.OfType <UIElement>()) { counter++; if (TabItemsPanel.GetTabVisibility(element) != Visibility.Visible) { _headerRectangles.Add(Rect.Empty); continue; } if (counter == tabItemsPanel.SelectedPage) { var ft = new FormattedText(_pageHeaders[counter], CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, boldType, 11d, Brushes.Black); var textWidth = ft.Width; var headerRect = new Rect(left, 0, textWidth + 20, 30); _headerRectangles.Add(headerRect); dc.DrawRectangle(Brushes.White, null, headerRect); dc.DrawLine(linePen, new Point(left, 3), new Point(left, 30)); dc.DrawLine(linePen, new Point(left + textWidth + 20, 3), new Point(left + textWidth + 20, 30)); dc.DrawLine(highlightPen, new Point(left, 2), new Point(left + textWidth + 20, 2)); dc.DrawText(ft, new Point(left + 10, 7)); left += textWidth + 20; } else { var ft = new FormattedText(_pageHeaders[counter], CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, regularType, 11d, Brushes.Black); var textWidth = ft.Width; var headerRect = new Rect(left, 0, textWidth + 20, 30); _headerRectangles.Add(headerRect); dc.DrawRectangle(Brushes.Transparent, null, headerRect); // Makes the area hit-test visible dc.DrawText(ft, new Point(left + 10, 7)); left += textWidth + 20; } } }
void ReleaseDesignerOutlets() { if (OtherButton6 != null) { OtherButton6.Dispose(); OtherButton6 = null; } if (OtherButton5 != null) { OtherButton5.Dispose(); OtherButton5 = null; } if (AddMonsterButton != null) { AddMonsterButton.Dispose(); AddMonsterButton = null; } if (RacialView != null) { RacialView.Dispose(); RacialView = null; } if (SimpleView != null) { SimpleView.Dispose(); SimpleView = null; } if (OtherView != null) { OtherView.Dispose(); OtherView = null; } if (SimpleHeaderView != null) { SimpleHeaderView.Dispose(); SimpleHeaderView = null; } if (RacialHeaderView != null) { RacialHeaderView.Dispose(); RacialHeaderView = null; } if (OtherHeaderView != null) { OtherHeaderView.Dispose(); OtherHeaderView = null; } if (AdvancedButton != null) { AdvancedButton.Dispose(); AdvancedButton = null; } if (SimpleSizeButton != null) { SimpleSizeButton.Dispose(); SimpleSizeButton = null; } if (OutsiderButton != null) { OutsiderButton.Dispose(); OutsiderButton = null; } if (AugmentSummoningButton != null) { AugmentSummoningButton.Dispose(); AugmentSummoningButton = null; } if (RacialHitDieButton != null) { RacialHitDieButton.Dispose(); RacialHitDieButton = null; } if (RacialBonusButton != null) { RacialBonusButton.Dispose(); RacialBonusButton = null; } if (RacialSizeButton != null) { RacialSizeButton.Dispose(); RacialSizeButton = null; } if (OtherTemplateButton != null) { OtherTemplateButton.Dispose(); OtherTemplateButton = null; } if (AdvancerHeaderView != null) { AdvancerHeaderView.Dispose(); AdvancerHeaderView = null; } if (ResetButton != null) { ResetButton.Dispose(); ResetButton = null; } if (OtherTemplateOptionView != null) { OtherTemplateOptionView.Dispose(); OtherTemplateOptionView = null; } if (OtherButton1 != null) { OtherButton1.Dispose(); OtherButton1 = null; } if (OtherButton2 != null) { OtherButton2.Dispose(); OtherButton2 = null; } if (OtherButton3 != null) { OtherButton3.Dispose(); OtherButton3 = null; } if (OtherButton4 != null) { OtherButton4.Dispose(); OtherButton4 = null; } }
/// <summary> /// When overridden in a derived class, positions child elements and determines a size for a <see cref="T:System.Windows.FrameworkElement" /> derived class. /// </summary> /// <param name="finalSize">The final area within the parent that this element should use to arrange itself and its children.</param> /// <returns>The actual size used.</returns> protected override Size ArrangeOverride(Size finalSize) { foreach (UIElement element in Children) { if (SimpleView.GetUIElementType(element) == UIElementTypes.Primary) { if (CanCollapseSecondary && IsSecondaryElementCollapsed) { var minimumCollapsedWidth = 0d; var mainAreaLeft = 0d; if (HeaderRenderer != null) { minimumCollapsedWidth = HeaderRenderer.GetMinimumCollapsedAreaWidth(this); if (SecondaryAreaLocation == SecondaryAreaLocation.Left) { mainAreaLeft = minimumCollapsedWidth + (minimumCollapsedWidth > 0d ? ElementSpacing : 0d); } } var primaryArea = new Rect(mainAreaLeft, 0d, finalSize.Width - minimumCollapsedWidth - (minimumCollapsedWidth > 0d ? ElementSpacing : 0d), finalSize.Height); if (HeaderRenderer != null) { primaryArea = HeaderRenderer.GetPrimaryClientArea(primaryArea, this); } _currentPrimaryArea = primaryArea; element.Arrange(primaryArea); } else { var currentX = 0d; if (SecondaryAreaLocation == SecondaryAreaLocation.Left) { currentX = SecondaryElementWidth + ElementSpacing; } var primaryArea = new Rect(currentX, 0d, Math.Max(finalSize.Width - SecondaryElementWidth - ElementSpacing, 0), finalSize.Height); if (HeaderRenderer != null) { primaryArea = HeaderRenderer.GetPrimaryClientArea(primaryArea, this); } _currentPrimaryArea = primaryArea; element.Arrange(primaryArea); } } else { if (CanCollapseSecondary && IsSecondaryElementCollapsed) { _currentSecondaryArea = new Rect(-100000d, -100000d, 0d, finalSize.Height); element.Arrange(_currentSecondaryArea); } else { var secondaryArea = SecondaryAreaLocation == SecondaryAreaLocation.Left ? new Rect(0d, 0d, SecondaryElementWidth, finalSize.Height) : new Rect(finalSize.Width - SecondaryElementWidth, 0d, SecondaryElementWidth, finalSize.Height); if (HeaderRenderer != null) { secondaryArea = HeaderRenderer.GetSecondaryClientArea(secondaryArea, this); } _currentSecondaryArea = secondaryArea; element.Arrange(secondaryArea); } } } return(base.ArrangeOverride(finalSize)); }