Beispiel #1
0
        /// <summary>
        /// Adds a new element to the currently active template.
        /// </summary>
        /// <param name="parameter"></param>
        private void AddElement(object parameter)
        {
            if (ActiveTemplate == null)
            {
                return;
            }
            string name = parameter as string;

            BaseElement element = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(name) as BaseElement;

            if (element != null)
            {
                element.XPos           = TemplateMousePosition.X - (element.Width / 2);
                element.YPos           = TemplateMousePosition.Y - (element.Height / 2);
                element.RefreshLayout += new RefreshLayoutEvent(OnRefreshLayout);
                ActiveTemplate.AddElement(element);
                SelectedElement = element;
                RestoreLayoutView(ActiveTemplate);

                if (element.LastLayoutInstance != null)
                {
                    SelectedDecorator = element.LastLayoutInstance as IDesignItemDecorator;
                    ((ElementUserControl)element.LastLayoutInstance).CanManipulate = true;
                    ((ElementUserControl)element.LastLayoutInstance).ShowDecorator = true;
                }
            }
            else
            {
                MessageBox.Show("There was an error while creating a template of the type '" + parameter + "'.");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Removes currently active template from the workspace and instantiates a fresh new one.
        /// </summary>
        /// <param name="parameter"></param>
        private void NewTemplate(object parameter)
        {
            ClearDesignerWorkspace();

            Game      game     = _Workspace.Game;
            ITemplate template = null;

            try
            {
                template      = game.AddTemplate(game.GetDefaultTemplateName());
                template.XPos = 0.25 * TemplateUserControl.DPI;
                template.YPos = 0.25 * TemplateUserControl.DPI;
            }
            catch (InvalidOperationException e)
            {
                MessageBox.Show(e.Message);
                return;
            }

            //this implicitly creates the layout view of the template
            ActiveTemplate    = template;
            SelectedDecorator = template as IDesignItemDecorator;
        }
Beispiel #3
0
        private void elementsMouseClick(object sender, MouseEventArgs e)
        {
            Keyboard.ClearFocus();

            WorkspaceMousePosition = e.GetPosition(canvasWorkspace);
            TemplateMousePosition  = e.GetPosition((UIElement)sender);
            HitList.Clear();
            VisualTreeHelper.HitTest(canvasWorkspace,
                                     null,
                                     new HitTestResultCallback(OnHitResults),
                                     new PointHitTestParameters(WorkspaceMousePosition));

            UserControl parent = null;

            if (HitList.Count > 0)
            {
                foreach (FrameworkElement result in HitList)
                {
                    if (result.Name.Equals(TemplateUserControl.LayoutSurfaceId))
                    {
                        ContentControl content = result.Parent as ContentControl;
                        parent = content.Parent as UserControl;
                        //check if is element and can be manipulated, if not pass right through it
                        if (parent is ElementUserControl && !((ElementUserControl)parent).CanManipulate)
                        {
                            parent = null;
                            continue;
                        }
                        break;
                    }
                }
            }

            if (SelectedDecorator != null)
            {
                SelectedDecorator.ShowDecorator = false;
            }
            SelectedElement = null;

            //find out what we hit and hi-light it if applicable.
            if (parent != null)
            {
                TemplateUserControl temp = parent as TemplateUserControl;
                if (temp == null)
                {
                    ElementUserControl elm = parent as ElementUserControl;
                    if (elm != null)
                    {
                        if (!elm.CanManipulate)
                        {
                            return;
                        }
                        SelectedElement   = elm.Creator;
                        SelectedDecorator = elm;
                    }
                }
                else
                {
                    if (!temp.CanManipulate)
                    {
                        return;
                    }
                    SelectedElement   = temp.Creator;
                    SelectedDecorator = temp;
                }

                SelectedDecorator.ShowDecorator = true;
            }
        }