示例#1
0
        /// <summary>
        /// Display a database table for editing in a LDControls.DataView control.
        /// Using this method the database is bound to the dataview conrol, reflecting the database.
        /// </summary>
        /// <param name="database">The existing database label (see ConnectSQLite, ConnectMySQL, ConnectSqlServer, ConnectOleDb or ConnectOdbc).</param>
        /// <param name="table">The table name to view and edit.</param>
        /// <param name="dataview">A DataView control.</param>
        /// <returns>"SUCCESS" or "FAILED".</returns>
        public static Primitive EditTable(Primitive database, Primitive table, Primitive dataview)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary <string, UIElement> _objectsMap;
            UIElement obj;

            try
            {
                string   query    = "SELECT * FROM " + table;
                DataBase dataBase = GetDataBase(database);
                if (null == dataBase)
                {
                    return("FAILED");
                }
                DataTable dataTable = GetDataTable(dataBase, query, null);
                dataTable.TableName = table;

                BindingSource SBind = new BindingSource();
                SBind.DataSource = dataTable;

                _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_objectsMap.TryGetValue((string)dataview, out obj))
                {
                    return("FAILED");
                }

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        WindowsFormsHost host = (WindowsFormsHost)obj;
                        DataGridView dataView = (DataGridView)host.Child;

                        dataView.Columns.Clear();
                        dataView.Tag        = dataTable;
                        dataView.DataSource = SBind;
                        dataView.Refresh();

                        return("SUCCESS");
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return("FAILED");
                    }
                });
                return(FastThread.InvokeWithReturn(ret).ToString());
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return("FAILED");
            }
        }
示例#2
0
        /// <summary>
        /// A yes no dialogue box
        /// </summary>
        /// <param name="title">Dialogue title</param>
        /// <param name="text">Dialogue text</param>
        /// <returns>the button clicked value, Yes or No</returns>
        public static Primitive YesNo(Primitive title, Primitive text)
        {
            DialogueYesNo dialogue = new DialogueYesNo();

            Type GraphicsWindowType = typeof(GraphicsWindow);
            Window _window = (Window)GraphicsWindowType.GetField("_window", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

            InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
            {
                return dialogue.Show(title, text, _window);
            });
            MethodInfo method = GraphicsWindowType.GetMethod("InvokeWithReturn", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
            return method.Invoke(null, new object[] { ret }).ToString();
        }
示例#3
0
        private static void CB_GetImage()
        {
            Type ImageListType      = typeof(ImageList);
            Type ShapesType         = typeof(Shapes);
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary <string, BitmapSource> _savedImages;

            InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
            {
                try
                {
                    BitmapImage image = new BitmapImage();
                    try
                    {
                        _savedImages          = (Dictionary <string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                        MethodInfo methodInfo = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                        string imageName      = methodInfo.Invoke(null, new object[] { "ImageList" }).ToString();

                        if (Clipboard.ContainsImage())
                        {
                            _savedImages[imageName] = Clipboard.GetImage();
                            return(imageName);
                        }
                        else
                        {
                            IDataObject dataObject = Clipboard.GetDataObject();
                            MemoryStream ms        = (MemoryStream)dataObject.GetData("PNG");
                            image.BeginInit();
                            image.StreamSource = ms;
                            image.EndInit();

                            _savedImages[imageName] = image;
                            return(imageName);
                        }
                    }
                    catch
                    {
                        return("FAILED");
                    }
                }
                catch (Exception ex)
                {
                    Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                }
                return("FAILED");
            });

            CB_imageName = FastThread.InvokeWithReturn(ret).ToString();
        }
示例#4
0
        /// <summary>
        /// A yes no dialogue box
        /// </summary>
        /// <param name="title">Dialogue title</param>
        /// <param name="text">Dialogue text</param>
        /// <returns>the button clicked value, Yes or No</returns>
        public static Primitive YesNo(Primitive title, Primitive text)
        {
            DialogueYesNo dialogue = new DialogueYesNo();

            Type   GraphicsWindowType = typeof(GraphicsWindow);
            Window _window            = (Window)GraphicsWindowType.GetField("_window", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);

            InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
            {
                return(dialogue.Show(title, text, _window));
            });
            MethodInfo method = GraphicsWindowType.GetMethod("InvokeWithReturn", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);

            return(method.Invoke(null, new object[] { ret }).ToString());
        }
示例#5
0
        /// <summary>
        /// Add a ListView to view database query results.
        /// This is a read only display of query results.
        /// </summary>
        /// <param name="width">The width of the ListView.</param>
        /// <param name="height">The height of the ListView.</param>
        /// <returns>The ListView control.</returns>
        public static Primitive AddListView(Primitive width, Primitive height)
        {
            Type   GraphicsWindowType = typeof(GraphicsWindow);
            Type   ShapesType         = typeof(Shapes);
            Canvas _mainCanvas;
            Dictionary <string, UIElement> _objectsMap;
            string shapeName;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method    = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "ListView" }).ToString();

                _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        System.Windows.Controls.ListView shape = new System.Windows.Controls.ListView();
                        shape.SelectionChanged += new SelectionChangedEventHandler(LDControls._ListViewSelectionChangedEvent);
                        shape.PreviewMouseDown += new MouseButtonEventHandler(LDControls._ListViewMouseButtonEvent);
                        shape.Name              = shapeName;
                        shape.Width             = width;
                        shape.Height            = height;

                        _objectsMap[shapeName] = shape;
                        _mainCanvas.Children.Add(shape);
                        return(shapeName);
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return("");
                    }
                });
                return(FastThread.InvokeWithReturn(ret).ToString());
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return("");
            }
        }
示例#6
0
        /// <summary>
        /// A message dialog with Yes, No and Cancel options.
        /// </summary>
        /// <param name="text">Text question for the dialog.</param>
        /// <param name="title">Title for the dialog.</param>
        /// <returns>"Yes", "No" or "Cancel"</returns>
        public static Primitive Confirm(Primitive text, Primitive title)
        {
            Type   GraphicsWindowType  = typeof(GraphicsWindow);
            Window _window             = (Window)GraphicsWindowType.GetField("_window", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
            InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
            {
                if (null != _window)
                {
                    return(MessageBox.Show(_window, text, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question).ToString());
                }
                else
                {
                    return(MessageBox.Show(text, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question).ToString());
                }
            });

            return(FastThread.InvokeWithReturn(ret).ToString());
        }
示例#7
0
        /// <summary>
        /// Create a chart control.
        /// The current GraphicsWindow.BackgroundColor will be used for the background.
        /// The current GraphicsWindow.PenColor and Font properties will be used for the label text.
        /// For Example:
        /// GraphicsWindow.FontName = "Segoe UI"
        /// GraphicsWindow.FontBold = "False"
        /// </summary>
        /// <param name="width">The width of the chart.</param>
        /// <param name="height">The height of the chart.</param>
        /// <returns>The chart shape name.</returns>
        public static Primitive AddChart(Primitive width, Primitive height)
        {
            GraphicsWindow.Show();
            Type   GraphicsWindowType = typeof(GraphicsWindow);
            Type   ShapesType         = typeof(Shapes);
            Canvas _mainCanvas;
            Dictionary <string, UIElement> _objectsMap;
            string chartName;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method    = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                chartName = method.Invoke(null, new object[] { "Control" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        Chart chart            = new Chart(width, height);
                        chart.Name             = chartName;
                        _objectsMap[chartName] = chart;
                        _mainCanvas.Children.Add(chart);
                        return(chartName);
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return("");
                    }
                });
                return(FastThread.InvokeWithReturn(ret).ToString());
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return("");
            }
        }
示例#8
0
 public static object InvokeWithReturn(InvokeHelperWithReturn helper)
 {
     if (UseDispatcher)
     {
         return(_dispatcher.Invoke(priority, helper));
     }
     else if (UseExpression)
     {
         if (null == _FuncInvoke)
         {
             _FuncInvoke = MagicFunc(methodInvokeWithReturn);
         }
         return(_FuncInvoke(helper));
     }
     else
     {
         return(methodInvokeWithReturn.Invoke(null, new object[] { helper }));
     }
 }
示例#9
0
文件: Text.cs 项目: levi1994/LitDev
        /// <summary>
        /// Get the height in pixels that text will be displayed in the GraphicsWindow with the current font.
        /// The GraphicsWindow must be open to use this method.
        /// </summary>
        /// <param name="text">The text to get the height.</param>
        /// <returns>The width in pixels.</returns>
        public static Primitive GetHeight(Primitive text)
        {
            try
            {
                Type       GraphicsWindowType = typeof(GraphicsWindow);
                FontFamily _fontFamily        = (FontFamily)GraphicsWindowType.GetField("_fontFamily", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                double     _fontSize          = (double)GraphicsWindowType.GetField("_fontSize", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                FontWeight _fontWeight        = (FontWeight)GraphicsWindowType.GetField("_fontWeight", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                FontStyle  _fontStyle         = (FontStyle)GraphicsWindowType.GetField("_fontStyle", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        TextBlock textblock = new TextBlock
                        {
                            Text       = text,
                            FontFamily = _fontFamily,
                            FontSize   = _fontSize,
                            FontWeight = _fontWeight,
                            FontStyle  = _fontStyle
                        };
                        Size size = new Size(double.MaxValue, double.MaxValue);
                        textblock.Measure(size);
                        return(textblock.DesiredSize.Height.ToString(CultureInfo.InvariantCulture));
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                    }
                    return("");
                });
                return(FastThread.InvokeWithReturn(ret).ToString());
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return(0);
            }
        }
示例#10
0
文件: Focus.cs 项目: levi1994/LitDev
        /// <summary>
        /// Gets the shape that has current focus.
        /// </summary>
        /// <returns>
        /// The shape name (usually a textbox) or "False".
        /// </returns>
        public static Primitive GetFocus()
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary <string, UIElement> _objectsMap;
            UIElement obj;
            Canvas    _mainCanvas;
            string    shapeName;

            try
            {
                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
                _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                foreach (KeyValuePair <String, UIElement> entry in _objectsMap)
                {
                    shapeName = entry.Key;
                    if (!_objectsMap.TryGetValue((string)shapeName, out obj))
                    {
                        Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                        return("False");
                    }

                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        return(_mainCanvas.Children.Contains(obj) && obj.IsFocused);
                    });
                    if (FastThread.InvokeWithReturn(ret).ToString() == "True")
                    {
                        return(shapeName);
                    }
                }
                return("False");
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return("False");
            }
        }
示例#11
0
文件: Focus.cs 项目: litdev1/LitDev
        /// <summary>
        /// Gets the shape that has current focus.
        /// </summary>
        /// <returns>
        /// The shape name (usually a textbox) or "False".
        /// </returns>
        public static Primitive GetFocus()
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary<string, UIElement> _objectsMap;
            UIElement obj;
            Canvas _mainCanvas;
            string shapeName;

            try
            {
                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                foreach (KeyValuePair<String, UIElement> entry in _objectsMap)
                {
                    shapeName = entry.Key;
                    if (!_objectsMap.TryGetValue((string)shapeName, out obj))
                    {
                        Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                        return "False";
                    }

                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        return _mainCanvas.Children.Contains(obj) && obj.IsFocused;
                    });
                    if (FastThread.InvokeWithReturn(ret).ToString() == "True")
                    {
                        return shapeName;
                    }
                }
                return "False";
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "False";
            }
        }
示例#12
0
文件: Focus.cs 项目: levi1994/LitDev
        /// <summary>
        /// Sets the named shape to have focus.
        /// </summary>
        /// <param name="shapeName">
        /// The shape name (usually a textbox).
        /// </param>
        /// <returns>
        /// "True" or "False" depending on success or failure.
        /// </returns>
        public static Primitive SetFocus(Primitive shapeName)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary <string, UIElement> _objectsMap;
            UIElement obj;

            try
            {
                _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                    return("False");
                }

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate { return(obj.Focus()); });
                return(FastThread.InvokeWithReturn(ret).ToString());
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return("False");
            }
        }
示例#13
0
文件: Shapes.cs 项目: litdev1/LitDev
        /// <summary>
        /// Creates a polygon shape.
        /// </summary>
        /// <param name="points">
        /// An array of coordinates for the polygon corners with the form points[i][1] = x, points[i][2] = y.
        /// 
        /// The number of points must be 3 or more.
        /// </param>
        /// <returns>
        /// The polygon shape name.
        /// </returns>
        public static Primitive AddPolygon(Primitive points)
        {
            GraphicsWindow.Show();
            Type ShapesType = typeof(Shapes);
            Canvas _mainCanvas;
            Pen _pen;
            Brush _brush;
            string shapeName;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "Polygon" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _pen = (Pen)GraphicsWindowType.GetField("_pen", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _brush = (Brush)GraphicsWindowType.GetField("_fillBrush", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        PointCollection _points = getPoints(points);
                        if (_points.Count < 3) return "";

                        Polygon shape = new Polygon
                        {
                            Name = shapeName,
                            Points = _points,
                            Fill = _brush,
                            Stroke = _pen.Brush,
                            StrokeThickness = _pen.Thickness
                        };

                        _objectsMap[shapeName] = shape;
                        _mainCanvas.Children.Add(shape);
                        return shapeName;
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#14
0
文件: Shapes.cs 项目: litdev1/LitDev
        /// <summary>
        /// Get the shape's visible (including zoom) width.
        /// </summary>
        /// <param name="shapeName">
        /// The shape or control name.
        /// </param>
        /// <returns>
        /// The shape visible width.
        /// </returns>
        public static Primitive Width(Primitive shapeName)
        {
            try
            {
                if (!_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                    return 0;
                }

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        FrameworkElement frameworkElement = obj as FrameworkElement;
                        return frameworkElement.ActualWidth.ToString(CultureInfo.InvariantCulture);
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                    }
                    return 0;
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return 0;
            }
        }
示例#15
0
文件: Shapes.cs 项目: litdev1/LitDev
 /// <summary>
 /// Get the top position of a shape (works for triangles, polygons and lines).
 /// Also works for shapes while animating.
 /// </summary>
 /// <param name="shapeName">
 /// The shape or control name.
 /// </param>
 /// <returns>
 /// The y coordinate of the top edge of the shape.
 /// </returns>
 public static Primitive GetTop(Primitive shapeName)
 {
     try
     {
         if (_objectsMap.TryGetValue((string)shapeName, out obj))
         {
             InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
             {
                 return Canvas.GetTop(obj).ToString(CultureInfo.InvariantCulture);
             });
             return FastThread.InvokeWithReturn(ret).ToString();
         }
         else
         {
             Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
         }
     }
     catch (Exception ex)
     {
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
     }
     return 0;
 }
示例#16
0
文件: Shapes.cs 项目: litdev1/LitDev
 /// <summary>
 /// Get a list of shape properties.  These are .Net UIElement properties.
 /// </summary>
 /// <param name="shapeName">The shape or control name.</param>
 /// <returns>An array of properties and their values.</returns>
 public static Primitive GetProperties(Primitive shapeName)
 {
     try
     {
         if (_objectsMap.TryGetValue((string)shapeName, out obj))
         {
             InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
             {
                 try
                 {
                     PropertyInfo[] properties = obj.GetType().GetProperties();
                     string result = "";
                     foreach (PropertyInfo property in properties)
                     {
                         Object value = property.GetValue(obj, null);
                         if (null != value)
                         {
                             if (TypeDescriptor.GetConverter(property.PropertyType).IsValid(value.ToString()))
                             {
                                 result += Utilities.ArrayParse(property.Name) + "=" + Utilities.ArrayParse(value.ToString()) + ";";
                             }
                         }
                     }
                     return Utilities.CreateArrayMap(result);
                 }
                 catch (Exception ex)
                 {
                     Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                     return "";
                 }
             });
             return FastThread.InvokeWithReturn(ret).ToString();
         }
         else
         {
             Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
             return "";
         }
     }
     catch (Exception ex)
     {
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
         return "";
     }
 }
示例#17
0
文件: Shapes.cs 项目: litdev1/LitDev
        /// <summary>
        /// Get an array of all of the shapes (if any) at the specified coordinates.
        /// The coordinates could be the mouse coordinates for example.
        /// </summary>
        /// <param name="x">The X coordinate</param>
        /// <param name="y">The Y coordinate</param>
        /// <returns>
        /// An array of shape names or "False".
        /// For multiple shapes, the returned array is ordered from top visual layer to bottom.
        /// </returns>
        public static Primitive GetAllShapesAt(Primitive x, Primitive y)
        {
            Canvas _mainCanvas;

            try
            {
                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    Point pt = new Point(x, y);
                    HitTestResults.Clear();
                    VisualTreeHelper.HitTest(_mainCanvas, null, new HitTestResultCallback(_HitTestResult), new PointHitTestParameters(pt));

                    Primitive result = "False";
                    int i = 0;
                    foreach (HitTestResult j in HitTestResults)
                    {
                        obj = (UIElement)j.VisualHit;
                        foreach (KeyValuePair<string, UIElement> k in _objectsMap)
                        {
                            if (obj == k.Value)
                            {
                                result[++i] = k.Key;
                                break;
                            }
                        }
                    }
                    return result;
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "False";
            }
        }
示例#18
0
        public string createGraph(int width, int height)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Type ShapesType = typeof(Shapes);
            Dictionary<string, UIElement> _objectsMap;
            UIElement obj;
            Canvas _mainCanvas;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                string name = method.Invoke(null, new object[] { "Graph" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        // Remove any hanging plotData (Shapes.Remove) data stores
                        for (int i = plotInfo.Count - 1; i >= 0; i--)  //Reverse order to allow potential multiple deletions
                        {
                            if (!_objectsMap.TryGetValue(plotInfo[i].name, out obj))
                            {
                                for (int j = 0; j < plotInfo[i].series.Count; j++)
                                {
                                    plotInfo[i].series[j].dataX.Clear();
                                    plotInfo[i].series[j].dataY.Clear();
                                }
                                plotInfo[i].series.Clear();
                                plotInfo.RemoveAt(i);
                            }
                        }

                        Canvas _graph = new Canvas();
                        _graph.Name = name;
                        _graph.Width = width;
                        _graph.Height = height;
                        _graph.Background = getBrush(borderColour);
                        _graph.Tag = name;

                        _objectsMap[name] = _graph;
                        _mainCanvas.Children.Add(_graph);

                        // Creates the Excel Image.
                        System.Drawing.Bitmap dImg = global::LitDev.Properties.Resources.excel;
                        MemoryStream ms = new MemoryStream();
                        dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        BitmapImage bImg = new BitmapImage();
                        bImg.BeginInit();
                        bImg.StreamSource = ms;
                        bImg.EndInit();
                        Image imgExcel = new Image();
                        imgExcel.Source = bImg;

                        // Creates the CSV Image.
                        dImg = global::LitDev.Properties.Resources.csv;
                        ms = new MemoryStream();
                        dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        bImg = new BitmapImage();
                        bImg.BeginInit();
                        bImg.StreamSource = ms;
                        bImg.EndInit();
                        Image imgCSV = new Image();
                        imgCSV.Source = bImg;

                        // Creates the Save Image.
                        dImg = global::LitDev.Properties.Resources.save;
                        ms = new MemoryStream();
                        dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        bImg = new BitmapImage();
                        bImg.BeginInit();
                        bImg.StreamSource = ms;
                        bImg.EndInit();
                        Image imgSave = new Image();
                        imgSave.Source = bImg;

                        // Creates the zoom Image.
                        dImg = global::LitDev.Properties.Resources.zoom;
                        ms = new MemoryStream();
                        dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        bImg = new BitmapImage();
                        bImg.BeginInit();
                        bImg.StreamSource = ms;
                        bImg.EndInit();
                        Image imgZoom = new Image();
                        imgZoom.Source = bImg;

                        // Creates the Legend Image.
                        dImg = global::LitDev.Properties.Resources.legend;
                        ms = new MemoryStream();
                        dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        bImg = new BitmapImage();
                        bImg.BeginInit();
                        bImg.StreamSource = ms;
                        bImg.EndInit();
                        Image imgLegend = new Image();
                        imgLegend.Source = bImg;

                        //Right click popup menu
                        ContextMenu mnu = new ContextMenu();
                        MenuItem mnuExcel = new MenuItem();
                        mnuExcel.Icon = imgExcel;
                        mnuExcel.Header = "Export data to Excel";
                        mnuExcel.Click += new RoutedEventHandler(mnuExcel_Click);
                        mnuExcel.Tag = _graph;
                        mnu.Items.Add(mnuExcel);
                        MenuItem mnuCSV = new MenuItem();
                        mnuCSV.Icon = imgCSV;
                        mnuCSV.Header = "Export data to CSV file";
                        mnuCSV.Click += new RoutedEventHandler(mnuCSV_Click);
                        mnuCSV.Tag = _graph;
                        mnu.Items.Add(mnuCSV);
                        MenuItem mnuSave = new MenuItem();
                        mnuSave.Icon = imgSave;
                        mnuSave.Header = "Export graph to image file";
                        mnuSave.Click += new RoutedEventHandler(mnuSave_Click);
                        mnuSave.Tag = _graph;
                        mnu.Items.Add(mnuSave);
                        MenuItem mnuHoverVal = new MenuItem();
                        mnuHoverVal.IsChecked = false;
                        mnuHoverVal.Header = "Toggle show values at mouse";
                        mnuHoverVal.Click += new RoutedEventHandler(mnuHoverVal_Click);
                        mnuHoverVal.Tag = _graph;
                        mnu.Items.Add(mnuHoverVal);
                        MenuItem mnuLegend = new MenuItem();
                        mnuLegend.IsChecked = true;
                        mnuLegend.Header = "Toggle show legend";
                        mnuLegend.Click += new RoutedEventHandler(mnuLegend_Click);
                        mnuLegend.Tag = _graph;
                        mnu.Items.Add(mnuLegend);
                        MenuItem mnuResetLegend = new MenuItem();
                        mnuResetLegend.Icon = imgLegend;
                        mnuResetLegend.Header = "Reset legend position";
                        mnuResetLegend.Click += new RoutedEventHandler(mnuResetLegend_Click);
                        mnuResetLegend.Tag = _graph;
                        mnu.Items.Add(mnuResetLegend);
                        MenuItem mnuResetZoom = new MenuItem();
                        mnuResetZoom.Icon = imgZoom;
                        mnuResetZoom.Header = "Reset zoom";
                        mnuResetZoom.Click += new RoutedEventHandler(mnuResetZoom_Click);
                        mnuResetZoom.Tag = _graph;
                        mnu.Items.Add(mnuResetZoom);
                        _graph.ContextMenu = mnu;

                        return name;
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#19
0
文件: Dialogs.cs 项目: litdev1/LitDev
        private static void StartPosition(System.Windows.Forms.Form form, string title)
        {
            bool bValid = true;

            switch (eStartupMode)
            {
                case StartupMode.NONE:
                    bValid = false;
                    break;
                case StartupMode.GRAPHICSWINDOW:
                    Type GraphicsWindowType = typeof(GraphicsWindow);
                    Canvas _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        try
                        {
                            return _mainCanvas.PointToScreen(new System.Windows.Point(xPosInput, yPosInput));
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                            return null;
                        }
                    });
                    //MethodInfo method = GraphicsWindowType.GetMethod("InvokeWithReturn", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                    if (null == _mainCanvas)
                    {
                        bValid = false;
                    }
                    else
                    {
                        System.Windows.Point point = (System.Windows.Point)FastThread.InvokeWithReturn(ret);
                        if (null != point)
                        {
                            xPosDisplay = point.X;
                            yPosDisplay = point.Y;
                        }
                    }
                    break;
                case StartupMode.SCREEN:
                    xPosDisplay = xPosInput;
                    yPosDisplay = yPosInput;
                    break;
            }

            if (null != form)
            {
                if (bValid)
                {
                    form.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
                    form.Location = new System.Drawing.Point((int)xPosDisplay, (int)yPosDisplay);
                }
                else
                {
                    form.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation;
                }
            }
            else if (null != title)
            {
                if (bValid)
                {
                    IntPtr hWnd;
                    int count = 0;
                    while ((hWnd = User32.FindWindowByCaption((IntPtr)0, title)) == (IntPtr)0 && ++count < 100)
                    {
                        Thread.Sleep(5);
                    }
                    if (hWnd != IntPtr.Zero)
                    {
                        User32.SetWindowPos(hWnd, 0, (int)xPosDisplay, (int)yPosDisplay, 0, 0, User32.SWP_NOSIZE);
                    }
                }
            }
        }
示例#20
0
        /// <summary>
        /// Add a ListView to view database query results.
        /// This is a read only display of query results.
        /// </summary>
        /// <param name="width">The width of the ListView.</param>
        /// <param name="height">The height of the ListView.</param>
        /// <returns>The ListView control.</returns>
        public static Primitive AddListView(Primitive width, Primitive height)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Type ShapesType = typeof(Shapes);
            Canvas _mainCanvas;
            Dictionary<string, UIElement> _objectsMap;
            string shapeName;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "ListView" }).ToString();

                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        System.Windows.Controls.ListView shape = new System.Windows.Controls.ListView();
                        shape.Name = shapeName;
                        shape.Width = width;
                        shape.Height = height;

                        _objectsMap[shapeName] = shape;
                        _mainCanvas.Children.Add(shape);
                        return shapeName;
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#21
0
        /// <summary>
        /// Display a database table for editing in a LDControls.DataView control.
        /// Using this method the database is bound to the dataview conrol, reflecting the database.
        /// </summary>
        /// <param name="database">The existing database label (see ConnectSQLite, ConnectMySQL, ConnectSqlServer, ConnectOleDb or ConnectOdbc).</param>
        /// <param name="table">The table name to view and edit.</param>
        /// <param name="dataview">A DataView control.</param>
        /// <returns>"SUCCESS" or "FAILED".</returns>
        public static Primitive EditTable(Primitive database, Primitive table, Primitive dataview)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary<string, UIElement> _objectsMap;
            UIElement obj;

            try
            {
                string query = "SELECT * FROM " + table;
                DataBase dataBase = GetDataBase(database);
                if (null == dataBase) return "FAILED";
                DataTable dataTable = GetDataTable(dataBase, query, null);
                dataTable.TableName = table;

                BindingSource SBind = new BindingSource();
                SBind.DataSource = dataTable;

                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_objectsMap.TryGetValue((string)dataview, out obj)) return "FAILED";

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        WindowsFormsHost host = (WindowsFormsHost)obj;
                        DataGridView dataView = (DataGridView)host.Child;

                        dataView.Columns.Clear();
                        dataView.Tag = dataTable;
                        dataView.DataSource = SBind;
                        dataView.Refresh();

                        return "SUCCESS";
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "FAILED";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "FAILED";
            }
        }
示例#22
0
        private static Primitive propertyScrollBars(string action, Primitive value)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);

            try
            {
                Window _window = (Window)GraphicsWindowType.GetField("_window", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        Object content = _window.Content;
                        if (content.GetType() != typeof(ScrollViewer)) return "";
                        ScrollViewer scrollViewer = (ScrollViewer)content;

                        switch (action.ToLower())
                        {
                            case "gethorizontaloffset":
                                return scrollViewer.HorizontalOffset.ToString(CultureInfo.InvariantCulture);
                            case "sethorizontaloffset":
                                scrollViewer.ScrollToHorizontalOffset(value);
                                break;
                            case "getverticaloffset":
                                return scrollViewer.VerticalOffset.ToString(CultureInfo.InvariantCulture);
                            case "setverticaloffset":
                                scrollViewer.ScrollToVerticalOffset(value);
                                break;
                            case "getvisibility":
                                return scrollViewer.VerticalScrollBarVisibility == ScrollBarVisibility.Auto;
                            case "setvisibility":
                                scrollViewer.VerticalScrollBarVisibility = value ? ScrollBarVisibility.Auto : ScrollBarVisibility.Hidden;
                                scrollViewer.HorizontalScrollBarVisibility = scrollViewer.VerticalScrollBarVisibility;
                                break;
                            case "getpanningratio":
                                return scrollViewer.PanningRatio.ToString(CultureInfo.InvariantCulture);
                            case "setpanningratio":
                                scrollViewer.PanningRatio = value;
                                break;
                        }

                        return "";
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#23
0
        public string GetProperty(Primitive objectPath)
        {
            string[] objectList = objectPath.ToString().Split(new char[] { '.' });

            try
            {
                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        Object obj = null;
                        foreach (string key in objectList)
                        {
                            if (key == objectList.First())
                            {
                                obj = (Object)GetType("GraphicsWindow").GetField(key, BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
                                continue;
                            }
                            if (null == obj || key == objectList.Last())
                            {
                                break;
                            }
                            if (obj is IEnumerable && !Utilities.isBulitin(obj))
                            {
                                bool bFound = false;
                                foreach (Object objChild in (obj as IEnumerable))
                                {
                                    if (objChild.GetType().GetProperty("Name").GetValue(objChild, null).ToString() == key)
                                    {
                                        obj    = objChild;
                                        bFound = true;
                                        break;
                                    }
                                }
                                if (!bFound)
                                {
                                    return("");
                                }
                            }
                            else
                            {
                                obj = obj.GetType().GetProperty(key).GetValue(obj, null);
                            }
                        }

                        if (null == obj)
                        {
                            return("");
                        }

                        Object propObject = obj.GetType().GetProperty(objectList.Last()).GetValue(obj, null);
                        return(propObject.ToString());
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                    }
                    return("");
                });

                return(mInvokeWithReturn.Invoke(null, new object[] { ret }).ToString());
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return("");
        }
示例#24
0
        public string GetProperty(Primitive objectPath)
        {
            string[] objectList = objectPath.ToString().Split(new char[] { '.' });

            try
            {
                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        Object obj = null;
                        foreach (string key in objectList)
                        {
                            if (key == objectList.First())
                            {
                                obj = (Object)GetType("GraphicsWindow").GetField(key, BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
                                continue;
                            }
                            if (null == obj || key == objectList.Last()) break;
                            if (obj is IEnumerable && !Utilities.isBulitin(obj))
                            {
                                bool bFound = false;
                                foreach (Object objChild in (obj as IEnumerable))
                                {
                                    if (objChild.GetType().GetProperty("Name").GetValue(objChild, null).ToString() == key)
                                    {
                                        obj = objChild;
                                        bFound = true;
                                        break;
                                    }
                                }
                                if (!bFound) return "";
                            }
                            else
                            {
                                obj = obj.GetType().GetProperty(key).GetValue(obj, null);
                            }
                        }

                        if (null == obj) return "";

                        Object propObject = obj.GetType().GetProperty(objectList.Last()).GetValue(obj, null);
                        return propObject.ToString();
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                    }
                    return "";
                });

                return mInvokeWithReturn.Invoke(null, new object[] { ret }).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "";
        }
示例#25
0
        private static string AddFigure(eFigure figure, double width, double height, Primitive[] properties)
        {
            Type   GraphicsWindowType = typeof(GraphicsWindow);
            Type   ShapesType         = typeof(Shapes);
            Canvas _mainCanvas;
            Dictionary <string, UIElement> _objectsMap;
            string shapeName;

            try
            {
                ExtractDll();

                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method    = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "Figure" }).ToString();

                _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        switch (figure)
                        {
                        case eFigure.ARC:
                            {
                                Arc shape              = new Arc();
                                shape.Name             = shapeName;
                                shape.Width            = width;
                                shape.Height           = height;
                                _objectsMap[shapeName] = shape;
                                _mainCanvas.Children.Add(shape);

                                shape.Fill            = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                shape.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                shape.StrokeThickness = GraphicsWindow.PenWidth;

                                shape.StartAngle       = properties[0];
                                shape.EndAngle         = properties[1];
                                shape.ArcThickness     = properties[2];
                                shape.ArcThicknessUnit = Microsoft.Expression.Media.UnitType.Pixel;
                            }
                            break;

                        case eFigure.BLOCKARROW:
                            {
                                BlockArrow shape       = new BlockArrow();
                                shape.Name             = shapeName;
                                shape.Width            = width;
                                shape.Height           = height;
                                _objectsMap[shapeName] = shape;
                                _mainCanvas.Children.Add(shape);

                                shape.Fill            = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                shape.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                shape.StrokeThickness = GraphicsWindow.PenWidth;

                                shape.ArrowBodySize  = properties[0];
                                shape.ArrowheadAngle = properties[1];
                                switch (((string)properties[2]).ToLower())
                                {
                                case "up":
                                    shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Up;
                                    break;

                                case "down":
                                    shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Down;
                                    break;

                                case "left":
                                    shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Left;
                                    break;

                                case "right":
                                    shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Right;
                                    break;
                                }
                            }
                            break;

                        case eFigure.REGULARPOLYGON:
                            {
                                RegularPolygon shape   = new RegularPolygon();
                                shape.Name             = shapeName;
                                shape.Width            = width;
                                shape.Height           = height;
                                _objectsMap[shapeName] = shape;
                                _mainCanvas.Children.Add(shape);

                                shape.Fill            = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                shape.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                shape.StrokeThickness = GraphicsWindow.PenWidth;

                                shape.PointCount  = properties[0];
                                shape.InnerRadius = properties[1];
                            }
                            break;

                        case eFigure.CALLOUT:
                            {
                                Callout shape          = new Callout();
                                shape.Name             = shapeName;
                                shape.Width            = width;
                                shape.Height           = height;
                                _objectsMap[shapeName] = shape;
                                _mainCanvas.Children.Add(shape);

                                shape.Fill            = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                shape.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                shape.StrokeThickness = GraphicsWindow.PenWidth;
                                shape.FontFamily      = new FontFamily(GraphicsWindow.FontName);
                                shape.FontSize        = GraphicsWindow.FontSize;
                                shape.FontStyle       = GraphicsWindow.FontItalic ? FontStyles.Italic : FontStyles.Normal;
                                shape.FontWeight      = GraphicsWindow.FontBold ? FontWeights.Bold : FontWeights.Normal;
                                shape.Foreground      = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                shape.Background      = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));

                                shape.Content = properties[0];
                                switch (((string)properties[1]).ToLower())
                                {
                                case "cloud":
                                    shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Cloud;
                                    break;

                                case "oval":
                                    shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Oval;
                                    break;

                                case "rectangle":
                                    shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Rectangle;
                                    break;

                                case "roundedrectangle":
                                    shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.RoundedRectangle;
                                    break;
                                }
                                Primitive anchor = properties[2];
                                Point point      = new Point(0, 1.25);
                                if (SBArray.GetItemCount(anchor) == 2)
                                {
                                    Primitive indices = SBArray.GetAllIndices(anchor);
                                    point.X           = anchor[indices[1]];
                                    point.Y           = anchor[indices[2]];
                                }
                                shape.AnchorPoint = point;
                            }
                            break;

                        case eFigure.LINEARROW:
                            {
                                LineArrow shape        = new LineArrow();
                                shape.Name             = shapeName;
                                shape.Width            = width;
                                shape.Height           = height;
                                _objectsMap[shapeName] = shape;
                                _mainCanvas.Children.Add(shape);

                                shape.Fill            = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                shape.Stroke          = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                shape.StrokeThickness = GraphicsWindow.PenWidth;

                                shape.ArrowSize  = properties[0];
                                shape.BendAmount = properties[1];
                                switch (((string)properties[2]).ToLower())
                                {
                                case "none":
                                    shape.StartArrow = Microsoft.Expression.Media.ArrowType.NoArrow;
                                    break;

                                case "arrow":
                                    shape.StartArrow = Microsoft.Expression.Media.ArrowType.Arrow;
                                    break;

                                case "open":
                                    shape.StartArrow = Microsoft.Expression.Media.ArrowType.OpenArrow;
                                    break;

                                case "oval":
                                    shape.StartArrow = Microsoft.Expression.Media.ArrowType.OvalArrow;
                                    break;

                                case "stealth":
                                    shape.StartArrow = Microsoft.Expression.Media.ArrowType.StealthArrow;
                                    break;
                                }
                                switch (((string)properties[3]).ToLower())
                                {
                                case "none":
                                    shape.EndArrow = Microsoft.Expression.Media.ArrowType.NoArrow;
                                    break;

                                case "arrow":
                                    shape.EndArrow = Microsoft.Expression.Media.ArrowType.Arrow;
                                    break;

                                case "open":
                                    shape.EndArrow = Microsoft.Expression.Media.ArrowType.OpenArrow;
                                    break;

                                case "oval":
                                    shape.EndArrow = Microsoft.Expression.Media.ArrowType.OvalArrow;
                                    break;

                                case "stealth":
                                    shape.EndArrow = Microsoft.Expression.Media.ArrowType.StealthArrow;
                                    break;
                                }
                                switch (((string)properties[4]).ToLower())
                                {
                                case "bottomleft":
                                    shape.StartCorner = Microsoft.Expression.Media.CornerType.BottomLeft;
                                    break;

                                case "bottomright":
                                    shape.StartCorner = Microsoft.Expression.Media.CornerType.BottomRight;
                                    break;

                                case "topleft":
                                    shape.StartCorner = Microsoft.Expression.Media.CornerType.TopLeft;
                                    break;

                                case "topright":
                                    shape.StartCorner = Microsoft.Expression.Media.CornerType.TopRight;
                                    break;
                                }
                            }
                            break;
                        }
                        return(shapeName);
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return("");
                    }
                });
                return(FastThread.InvokeWithReturn(ret).ToString());
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return("");
            }
        }
示例#26
0
        private static void StartPosition(System.Windows.Forms.Form form, string title)
        {
            bool bValid = true;

            switch (eStartupMode)
            {
            case StartupMode.NONE:
                bValid = false;
                break;

            case StartupMode.GRAPHICSWINDOW:
                Type   GraphicsWindowType  = typeof(GraphicsWindow);
                Canvas _mainCanvas         = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        return(_mainCanvas.PointToScreen(new System.Windows.Point(xPosInput, yPosInput)));
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return(null);
                    }
                });
                //MethodInfo method = GraphicsWindowType.GetMethod("InvokeWithReturn", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                if (null == _mainCanvas)
                {
                    bValid = false;
                }
                else
                {
                    System.Windows.Point point = (System.Windows.Point)FastThread.InvokeWithReturn(ret);
                    if (null != point)
                    {
                        xPosDisplay = point.X;
                        yPosDisplay = point.Y;
                    }
                }
                break;

            case StartupMode.SCREEN:
                xPosDisplay = xPosInput;
                yPosDisplay = yPosInput;
                break;
            }

            if (null != form)
            {
                if (bValid)
                {
                    form.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
                    form.Location      = new System.Drawing.Point((int)xPosDisplay, (int)yPosDisplay);
                }
                else
                {
                    form.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation;
                }
            }
            else if (null != title)
            {
                if (bValid)
                {
                    IntPtr hWnd;
                    int    count = 0;
                    while ((hWnd = User32.FindWindowByCaption((IntPtr)0, title)) == (IntPtr)0 && ++count < 100)
                    {
                        Thread.Sleep(5);
                    }
                    if (hWnd != IntPtr.Zero)
                    {
                        User32.SetWindowPos(hWnd, 0, (int)xPosDisplay, (int)yPosDisplay, 0, 0, User32.SWP_NOSIZE);
                    }
                }
            }
        }
示例#27
0
        private static Primitive propertyScrollBars(string action, Primitive value)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);

            try
            {
                Window _window             = (Window)GraphicsWindowType.GetField("_window", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        Object content = _window.Content;
                        if (content.GetType() != typeof(ScrollViewer))
                        {
                            return("");
                        }
                        ScrollViewer scrollViewer = (ScrollViewer)content;

                        switch (action.ToLower())
                        {
                        case "gethorizontaloffset":
                            return(scrollViewer.HorizontalOffset.ToString(CultureInfo.InvariantCulture));

                        case "sethorizontaloffset":
                            scrollViewer.ScrollToHorizontalOffset(value);
                            break;

                        case "getverticaloffset":
                            return(scrollViewer.VerticalOffset.ToString(CultureInfo.InvariantCulture));

                        case "setverticaloffset":
                            scrollViewer.ScrollToVerticalOffset(value);
                            break;

                        case "getvisibility":
                            return(scrollViewer.VerticalScrollBarVisibility == ScrollBarVisibility.Auto);

                        case "setvisibility":
                            scrollViewer.VerticalScrollBarVisibility   = value ? ScrollBarVisibility.Auto : ScrollBarVisibility.Hidden;
                            scrollViewer.HorizontalScrollBarVisibility = scrollViewer.VerticalScrollBarVisibility;
                            break;

                        case "getpanningratio":
                            return(scrollViewer.PanningRatio.ToString(CultureInfo.InvariantCulture));

                        case "setpanningratio":
                            scrollViewer.PanningRatio = value;
                            break;
                        }

                        return("");
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return("");
                    }
                });
                return(FastThread.InvokeWithReturn(ret).ToString());
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return("");
            }
        }
示例#28
0
文件: Chart.cs 项目: litdev1/LitDev
        /// <summary>
        /// Create a chart control.
        /// The current GraphicsWindow.BackgroundColor will be used for the background.
        /// The current GraphicsWindow.PenColor and Font properties will be used for the label text.
        /// For Example:
        /// GraphicsWindow.FontName = "Segoe UI"
        /// GraphicsWindow.FontBold = "False"
        /// </summary>
        /// <param name="width">The width of the chart.</param>
        /// <param name="height">The height of the chart.</param>
        /// <returns>The chart shape name.</returns>
        public static Primitive AddChart(Primitive width, Primitive height)
        {
            GraphicsWindow.Show();
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Type ShapesType = typeof(Shapes);
            Canvas _mainCanvas;
            Dictionary<string, UIElement> _objectsMap;
            string chartName;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                chartName = method.Invoke(null, new object[] { "Control" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        Chart chart = new Chart(width, height);
                        chart.Name = chartName;
                        _objectsMap[chartName] = chart;
                        _mainCanvas.Children.Add(chart);
                        return chartName;
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#29
0
文件: Dialogs.cs 项目: litdev1/LitDev
 /// <summary>
 /// A message dialog with Yes, No and Cancel options.
 /// </summary>
 /// <param name="text">Text question for the dialog.</param>
 /// <param name="title">Title for the dialog.</param>
 /// <returns>"Yes", "No" or "Cancel"</returns>
 public static Primitive Confirm(Primitive text, Primitive title)
 {
     Type GraphicsWindowType = typeof(GraphicsWindow);
     Window _window = (Window)GraphicsWindowType.GetField("_window", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
     InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
     {
         if (null != _window) return MessageBox.Show(_window, text, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question).ToString();
         else return MessageBox.Show(text, title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question).ToString();
     });
     return FastThread.InvokeWithReturn(ret).ToString();
 }
示例#30
0
        /// <summary>
        /// Save the GraphicsWindow as an image file (png, jpg, bmp, gif, tiff or ico).
        /// 
        /// The window must be visible and a short delay may be required after updating the window before calling.
        /// </summary>
        /// <param name="fileName">
        /// The file to save the image to (*.png, *.jpg, *.bmp, *.gif, *.tiff or *.ico).
        /// If this is set to "", then the image is created internally as an ImageList.
        /// </param>
        /// <param name="border">
        /// Include the window border ("True" or "False").
        /// </param>
        /// <returns>
        /// The ImageList image if fileName is "", otherwise if output to a file, then "" is returned.
        /// </returns>
        public static Primitive Capture(Primitive fileName, Primitive border)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Type ShapesType = typeof(Shapes);
            Type ImageListType = typeof(Microsoft.SmallBasic.Library.ImageList);
            Dictionary<string, BitmapSource> _savedImages;
            GraphicsWindow.Show();
            Utilities.bTextWindow = false;
            Utilities.bBorder = border;
            try
            {
                IntPtr _hWnd = User32.FindWindow(null, GraphicsWindow.Title);
                DrawingImage img = Utilities.captureWindow(_hWnd);

                string _fileName = ((string)fileName).ToLower();

                if (fileName == "")
                {
                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        try
                        {
                            _savedImages = (Dictionary<string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                            string shapeName = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).Invoke(null, new object[] { "ImageList" }).ToString();
                            _savedImages[shapeName] = FastPixel.GetBitmapImage((Bitmap)img);
                            return shapeName;
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }
                        return "";
                    });
                    return FastThread.InvokeWithReturn(ret).ToString();
                }
                else if (_fileName.EndsWith(".png"))
                {
                    img.Save(fileName, ImageFormat.Png);
                }
                else if (_fileName.EndsWith(".jpg") || _fileName.EndsWith(".jpeg"))
                {
                    img.Save(fileName, ImageFormat.Jpeg);
                }
                else if (_fileName.EndsWith(".bmp"))
                {
                    img.Save(fileName, ImageFormat.Bmp);
                }
                else if (_fileName.EndsWith(".gif"))
                {
                    img.Save(fileName, ImageFormat.Gif);
                }
                else if (_fileName.EndsWith(".tiff"))
                {
                    img.Save(fileName, ImageFormat.Tiff);
                }
                else if (_fileName.EndsWith(".ico"))
                {
                    img.Save(fileName, ImageFormat.Icon);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "";
        }
示例#31
0
文件: 3DView.cs 项目: litdev1/LitDev
        /// <summary>
        /// Add a revolute geometry object.  This is a surface starting at (0,0,0) and pointing up.
        /// Its shape is defined by a set points (Y,Z) where Y is the vertical distance along the surface from 0 and Z is the radius of revolution.
        /// </summary>
        /// <param name="shapeName">The 3DView object.</param>
        /// <param name="path">A space or colon deliminated list of 2D point coordinates describing the revolute shape.</param>
        /// <param name="divisions">The radial divisions, default 10 (affects number of triangles and smoothness).</param>
        /// <param name="colour">A colour or gradient brush for the object.</param>
        /// <param name="materialType">A material for the object.
        /// The available options are:
        /// "E" Emmissive - constant brightness.
        /// "D" Diffusive - affected by lights.
        /// "S" Specular  - specular highlights.
        /// </param>
        /// <returns>The 3DView Geometry name.</returns>
        public static Primitive AddRevolute(Primitive shapeName, Primitive path, Primitive divisions, Primitive colour, Primitive materialType)
        {
            UIElement obj;

            try
            {
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        try
                        {
                            if (obj.GetType() == typeof(Viewport3D))
                            {
                                MeshBuilder builder = new MeshBuilder(true, true);
                                List<Point> points = new List<Point>();
                                string[] s = Utilities.getString(path).Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
                                for (int i = 0; i < s.Length; i += 2)
                                {
                                    points.Add(new Point(Utilities.getDouble(s[i]), Utilities.getDouble(s[i + 1])));
                                }
                                int thetaDiv = divisions < 2 ? 10 : (int)divisions;
                                builder.AddRevolvedGeometry(points, new Point3D(0, 0, 0), new Vector3D(0, 1, 0), thetaDiv);
                                MeshGeometry3D mesh = builder.ToMesh();

                                Viewport3D viewport3D = (Viewport3D)obj;
                                return AddGeometry(viewport3D, mesh.Positions, mesh.TriangleIndices, mesh.Normals, mesh.TextureCoordinates, colour, materialType);
                            }
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }
                        return "";
                    });
                    return FastThread.InvokeWithReturn(ret).ToString();
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "";
        }
示例#32
0
文件: 3DView.cs 项目: litdev1/LitDev
        /// <summary>
        /// Add a rectangle geometry object centred at (0,0,0).
        /// </summary>
        /// <param name="shapeName">The 3DView object.</param>
        /// <param name="width">The width of the rectangle.</param>
        /// <param name="height">The height of the rectangle.</param>
        /// <param name="colour">A colour or gradient brush for the object.</param>
        /// <param name="materialType">A material for the object.
        /// The available options are:
        /// "E" Emmissive - constant brightness.
        /// "D" Diffusive - affected by lights.
        /// "S" Specular  - specular highlights.
        /// </param>
        /// <returns>The 3DView Geometry name.</returns>
        public static Primitive AddRectangle(Primitive shapeName, Primitive width, Primitive height, Primitive colour, Primitive materialType)
        {
            UIElement obj;

            try
            {
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        try
                        {
                            if (obj.GetType() == typeof(Viewport3D))
                            {
                                Viewport3D viewport3D = (Viewport3D)obj;
                                ProjectionCamera camera = (ProjectionCamera)viewport3D.Camera;

                                MeshBuilder builder = new MeshBuilder(true, true);
                                builder.AddCubeFace(new Point3D(0, 0, 0), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0), 0, width, height);
                                MeshGeometry3D mesh = builder.ToMesh();

                                return AddGeometry(viewport3D, mesh.Positions, mesh.TriangleIndices, mesh.Normals, mesh.TextureCoordinates, colour, materialType);
                            }
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }
                        return "";
                    });
                    return FastThread.InvokeWithReturn(ret).ToString();
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "";
        }
示例#33
0
文件: Shapes.cs 项目: litdev1/LitDev
        /// <summary>
        /// Get shape Brush and Pen colours.
        /// </summary>
        /// <param name="shapeName">
        /// The shape or control name.
        /// </param>
        /// <returns>
        /// A 3 element array
        /// 1) shape brush (or background) colour in hex format
        /// 2) shape opacity (0 to 100)
        /// 3) shape pen (or foreground) colour in hex format
        /// </returns>
        public static Primitive GetColour(Primitive shapeName)
        {
            try
            {
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                    {
                        string result = "";
                        Brush brush = null;
                        Brush pen = null;
                        try
                        {
                            if (obj.GetType() == typeof(Ellipse))
                            {
                                Ellipse shape = (Ellipse)obj;
                                brush = shape.Fill;
                                pen = shape.Stroke;
                            }
                            else if (obj.GetType() == typeof(Rectangle))
                            {
                                Rectangle shape = (Rectangle)obj;
                                brush = shape.Fill;
                                pen = shape.Stroke;
                            }
                            else if (obj.GetType() == typeof(Polygon))
                            {
                                Polygon shape = (Polygon)obj;
                                brush = shape.Fill;
                                pen = shape.Stroke;
                            }
                            else if (obj.GetType() == typeof(Button))
                            {
                                Button shape = (Button)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(TextBlock))
                            {
                                TextBlock shape = (TextBlock)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(TextBox))
                            {
                                TextBox shape = (TextBox)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(PasswordBox))
                            {
                                PasswordBox shape = (PasswordBox)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(CheckBox))
                            {
                                CheckBox shape = (CheckBox)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(ComboBox))
                            {
                                ComboBox shape = (ComboBox)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(RadioButton))
                            {
                                RadioButton shape = (RadioButton)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(RichTextBox))
                            {
                                RichTextBox shape = (RichTextBox)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(TreeView))
                            {
                                TreeView shape = (TreeView)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(DocumentViewer))
                            {
                                DocumentViewer shape = (DocumentViewer)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(ListBox))
                            {
                                ListBox shape = (ListBox)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(ListView))
                            {
                                ListView shape = (ListView)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(WindowsFormsHost))
                            {
                                WindowsFormsHost shape = (WindowsFormsHost)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                                if (shape.Child.GetType() == typeof(System.Windows.Forms.DataGridView))
                                {
                                    System.Windows.Forms.DataGridView dataView = (System.Windows.Forms.DataGridView)shape.Child;
                                }
                            }
                            else if (obj.GetType() == typeof(ProgressBar))
                            {
                                ProgressBar shape = (ProgressBar)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(Slider))
                            {
                                Slider shape = (Slider)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                            else if (obj.GetType() == typeof(Menu))
                            {
                                Menu shape = (Menu)obj;
                                brush = shape.Background;
                                pen = shape.Foreground;
                            }
                        }
                        catch (Exception ex)
                        {
                            Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        }

                        if (null != brush && null != pen)
                        {
                            result += "1=" + brush.ToString() + ";";
                            result += "2=" + (obj.Opacity * 100).ToString(CultureInfo.InvariantCulture) + ";";
                            result += "3=" + pen.ToString() + ";";
                        }
                        return Utilities.CreateArrayMap(result);
                    });
                    return FastThread.InvokeWithReturn(ret).ToString();
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return "";
        }
示例#34
0
文件: Image.cs 项目: litdev1/LitDev
        /// <summary>
        /// Creates an array of subdivided images from an input image.
        /// </summary>
        /// <param name="imageName">
        /// The image file (local or network) to load.
        /// Can also be an ImageList image.
        /// </param>
        /// <param name="countX">
        /// The number of sub-images in the X direction.
        /// </param>
        /// <param name="countY">
        /// The number of sub-images in the Y direction.
        /// </param>
        /// <returns>
        /// A 2D array of resulting images saved in ImageList.
        /// </returns>
        public static Primitive SplitImage(Primitive imageName, Primitive countX, Primitive countY)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Type ShapesType = typeof(Shapes);
            Type ImageListType = typeof(ImageList);
            BitmapSource img;
            Primitive result = "";

            try
            {
                _savedImages = (Dictionary<string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_savedImages.TryGetValue((string)imageName, out img))
                {
                    imageName = ImageList.LoadImage(imageName);
                    if (!_savedImages.TryGetValue((string)imageName, out img))
                    {
                        return "";
                    }
                }

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        Bitmap bitmap;
                        using (MemoryStream outStream = new MemoryStream())
                        {
                            BitmapEncoder enc = new PngBitmapEncoder();
                            enc.Frames.Add(BitmapFrame.Create(img));
                            enc.Save(outStream);
                            bitmap = new Bitmap(outStream);
                        }

                        int frameCount = countX * countY;
                        int w = bitmap.Width / countX;
                        int h = bitmap.Height / countY;

                        MethodInfo method1 = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);

                        if (frameCount > 1)
                        {
                            for (int i = 0; i < countX; i++)
                            {
                                Primitive resultRow = "";
                                for (int j = 0; j < countY; j++)
                                {
                                    RectangleF cloneRect = new RectangleF(w * i, h * j, w, h);
                                    Bitmap crop = bitmap.Clone(cloneRect, bitmap.PixelFormat);

                                    MemoryStream stream = new MemoryStream();
                                    new Bitmap(crop).Save(stream, System.Drawing.Imaging.ImageFormat.Png);

                                    BitmapImage bi = new BitmapImage();
                                    bi.BeginInit();
                                    bi.StreamSource = stream;
                                    bi.EndInit();

                                    string cropName = method1.Invoke(null, new object[] { "ImageList" }).ToString();
                                    _savedImages[cropName] = bi;
                                    resultRow[j + 1] = cropName;
                                }
                                result[i + 1] = resultRow;
                            }
                            return result;
                        }
                        return "";
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#35
0
文件: Shapes.cs 项目: litdev1/LitDev
 /// <summary>
 /// Get a shape property.  This is a .Net UIElement property.
 /// </summary>
 /// <param name="shapeName">The shape or control name.</param>
 /// <param name="property">The property name to get.</param>
 /// <returns>The value of the property.</returns>
 public static Primitive GetProperty(Primitive shapeName, Primitive property)
 {
     try
     {
         if (_objectsMap.TryGetValue((string)shapeName, out obj))
         {
             InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
             {
                 try
                 {
                     return obj.GetType().GetProperty(property).GetValue(obj, null).ToString();
                 }
                 catch (Exception ex)
                 {
                     Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                     return "";
                 }
             });
             return FastThread.InvokeWithReturn(ret).ToString();
         }
         else
         {
             Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
             return "";
         }
     }
     catch (Exception ex)
     {
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
         return "";
     }
 }
示例#36
0
文件: Figures.cs 项目: litdev1/LitDev
        private static string AddFigure(eFigure figure, double width, double height, Primitive[] properties)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Type ShapesType = typeof(Shapes);
            Canvas _mainCanvas;
            Dictionary<string, UIElement> _objectsMap;
            string shapeName;

            try
            {
                ExtractDll();

                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "Figure" }).ToString();

                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        switch (figure)
                        {
                            case eFigure.ARC:
                                {
                                    Arc shape = new Arc();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;

                                    shape.StartAngle = properties[0];
                                    shape.EndAngle = properties[1];
                                    shape.ArcThickness = properties[2];
                                    shape.ArcThicknessUnit = Microsoft.Expression.Media.UnitType.Pixel;
                                }
                                break;
                            case eFigure.BLOCKARROW:
                                {
                                    BlockArrow shape = new BlockArrow();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;

                                    shape.ArrowBodySize = properties[0];
                                    shape.ArrowheadAngle = properties[1];
                                    switch (((string)properties[2]).ToLower())
                                    {
                                        case "up":
                                            shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Up;
                                            break;
                                        case "down":
                                            shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Down;
                                            break;
                                        case "left":
                                            shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Left;
                                            break;
                                        case "right":
                                            shape.Orientation = Microsoft.Expression.Media.ArrowOrientation.Right;
                                            break;
                                    }
                                }
                                break;
                            case eFigure.REGULARPOLYGON:
                                {
                                    RegularPolygon shape = new RegularPolygon();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;

                                    shape.PointCount = properties[0];
                                    shape.InnerRadius = properties[1];
                                }
                                break;
                            case eFigure.CALLOUT:
                                {
                                    Callout shape = new Callout();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;
                                    shape.FontFamily = new FontFamily(GraphicsWindow.FontName);
                                    shape.FontSize = GraphicsWindow.FontSize;
                                    shape.FontStyle = GraphicsWindow.FontItalic ? FontStyles.Italic : FontStyles.Normal;
                                    shape.FontWeight = GraphicsWindow.FontBold ? FontWeights.Bold : FontWeights.Normal;
                                    shape.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));

                                    shape.Content = properties[0];
                                    switch (((string)properties[1]).ToLower())
                                    {
                                        case "cloud":
                                            shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Cloud;
                                            break;
                                        case "oval":
                                            shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Oval;
                                            break;
                                        case "rectangle":
                                            shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.Rectangle;
                                            break;
                                        case "roundedrectangle":
                                            shape.CalloutStyle = Microsoft.Expression.Media.CalloutStyle.RoundedRectangle;
                                            break;
                                    }
                                    Primitive anchor = properties[2];
                                    Point point = new Point(0,1.25);
                                    if (SBArray.GetItemCount(anchor) == 2)
                                    {
                                        Primitive indices = SBArray.GetAllIndices(anchor);
                                        point.X = anchor[indices[1]];
                                        point.Y = anchor[indices[2]];
                                    }
                                    shape.AnchorPoint = point;
                                }
                                break;
                            case eFigure.LINEARROW:
                                {
                                    LineArrow shape = new LineArrow();
                                    shape.Name = shapeName;
                                    shape.Width = width;
                                    shape.Height = height;
                                    _objectsMap[shapeName] = shape;
                                    _mainCanvas.Children.Add(shape);

                                    shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.BrushColor));
                                    shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString(GraphicsWindow.PenColor));
                                    shape.StrokeThickness = GraphicsWindow.PenWidth;

                                    shape.ArrowSize = properties[0];
                                    shape.BendAmount = properties[1];
                                    switch (((string)properties[2]).ToLower())
                                    {
                                        case "none":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.NoArrow;
                                            break;
                                        case "arrow":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.Arrow;
                                            break;
                                        case "open":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.OpenArrow;
                                            break;
                                        case "oval":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.OvalArrow;
                                            break;
                                        case "stealth":
                                            shape.StartArrow = Microsoft.Expression.Media.ArrowType.StealthArrow;
                                            break;
                                    }
                                    switch (((string)properties[3]).ToLower())
                                    {
                                        case "none":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.NoArrow;
                                            break;
                                        case "arrow":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.Arrow;
                                            break;
                                        case "open":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.OpenArrow;
                                            break;
                                        case "oval":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.OvalArrow;
                                            break;
                                        case "stealth":
                                            shape.EndArrow = Microsoft.Expression.Media.ArrowType.StealthArrow;
                                            break;
                                    }
                                    switch (((string)properties[4]).ToLower())
                                    {
                                        case "bottomleft":
                                            shape.StartCorner = Microsoft.Expression.Media.CornerType.BottomLeft;
                                            break;
                                        case "bottomright":
                                            shape.StartCorner = Microsoft.Expression.Media.CornerType.BottomRight;
                                            break;
                                        case "topleft":
                                            shape.StartCorner = Microsoft.Expression.Media.CornerType.TopLeft;
                                            break;
                                        case "topright":
                                            shape.StartCorner = Microsoft.Expression.Media.CornerType.TopRight;
                                            break;
                                    }
                                }
                                break;
                        }
                        return shapeName;
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#37
0
文件: Shapes.cs 项目: litdev1/LitDev
        /// <summary>
        /// Creates an animated gif shape.  
        /// Do not add a very large number of these or performance may be degraded.
        /// </summary>
        /// <param name="imageName">
        /// The animated gif file (local or network) to load.
        /// </param>
        /// <param name="repeat">
        /// Continuously repeat the animation "True" or "False".
        /// </param>
        /// <returns>
        /// The animated gif shape name.
        /// </returns>
        public static Primitive AddAnimatedGif(Primitive imageName, Primitive repeat)
        {
            if (((string)imageName).StartsWith("http")) imageName = Network.DownloadFile(imageName);
            GraphicsWindow.Show();
            Type ShapesType = typeof(Shapes);
            Canvas _mainCanvas;
            string shapeName;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "Image" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imageName);
                        System.Drawing.Imaging.FrameDimension fd = new System.Drawing.Imaging.FrameDimension(bitmap.FrameDimensionsList[0]);
                        int frameCount = bitmap.GetFrameCount(fd);

                        if (frameCount > 1)
                        {
                            Animated anim = new Animated();
                            animated.Add(anim);
                            anim.name = shapeName;
                            anim.frames = new Frame[frameCount];
                            anim.repeat = repeat;

                            //0x5100 is the property id of the GIF frame's durations
                            //this property does not exist when frameCount <= 1
                            byte[] times = bitmap.GetPropertyItem(0x5100).Value;

                            for (int i = 0; i < frameCount; i++)
                            {
                                //selects GIF frame based on FrameDimension and frameIndex
                                bitmap.SelectActiveFrame(fd, i);

                                //length in milliseconds of display duration
                                int length = BitConverter.ToInt32(times, 4 * i) * 10;

                                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                                new System.Drawing.Bitmap(bitmap).Save(stream, System.Drawing.Imaging.ImageFormat.Png);

                                BitmapImage bi = new BitmapImage();
                                bi.BeginInit();
                                bi.StreamSource = stream;
                                bi.EndInit();

                                anim.frames[i] = new Frame(length, bi);
                            }

                            Image shape = new Image();
                            shape.Source = anim.frames[0].bi;
                            shape.Stretch = Stretch.Fill;
                            shape.Name = shapeName;
                            shape.Width = shape.Source.Width;
                            shape.Height = shape.Source.Height;
                            anim.shape = shape;

                            if (null == animationTimer)
                            {
                                animationTimer = new System.Windows.Forms.Timer();
                                animationTimer.Enabled = animationInterval > 0;
                                if (animationInterval > 0) animationTimer.Interval = animationInterval;
                                animationTimer.Tick += new System.EventHandler(animation_Tick);
                            }

                            _objectsMap[shapeName] = shape;
                            _mainCanvas.Children.Add(shape);
                            return shapeName;
                        }
                        return "";
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#38
0
 /// <summary>
 /// Save the TextWindow as an image file (png, jpg, bmp, gif, tiff or ico).
 /// 
 /// The window must be visible and a short delay may be required after updating the window before calling.
 /// </summary>
 /// <param name="fileName">
 /// The file to save the image to (*.png, *.jpg, *.bmp, *.gif, *.tiff or *.ico).
 /// If this is set to "", then the image is created internally as an ImageList.
 /// </param>
 /// <param name="border">
 /// Include the window border ("True" or "False").
 /// </param>
 /// <returns>
 /// The ImageList image if fileName is "", otherwise if output to a file, then "" is returned.
 /// </returns>
 public static Primitive Capture(Primitive fileName, Primitive border)
 {
     Type GraphicsWindowType = typeof(GraphicsWindow);
     Type ShapesType = typeof(Shapes);
     Type ImageListType = typeof(Microsoft.SmallBasic.Library.ImageList);
     Dictionary<string, BitmapSource> _savedImages;
     TextWindow.Show();
     Utilities.bTextWindow = true;
     Utilities.bBorder = border;
     try
     {
         IntPtr _hWnd = User32.FindWindow(null, TextWindow.Title);
         Image img = Utilities.captureWindow(_hWnd);
         if (fileName == "")
         {
             InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
             {
                 try
                 {
                     _savedImages = (Dictionary<string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                     string shapeName = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).Invoke(null, new object[] { "ImageList" }).ToString();
                     _savedImages[shapeName] = FastPixel.GetBitmapImage((Bitmap)img);
                     return shapeName;
                 }
                 catch (Exception ex)
                 {
                     Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                 }
                 return "";
             });
             return FastThread.InvokeWithReturn(ret).ToString();
         }
         else
         {
             Utilities.saveImage(img, fileName);
         }
     }
     catch (Exception ex)
     {
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
     }
     return "";
 }
示例#39
0
文件: Shapes.cs 项目: litdev1/LitDev
        /// <summary>
        /// Creates an animation from a single image with multiple images on one layer.  
        /// Do not add a very large number of these or performance may be degraded.
        /// </summary>
        /// <param name="imageName">
        /// The image file (local or network) to load.
        /// Can also be an ImageList image.
        /// </param>
        /// <param name="repeat">
        /// Continuously repeat the animation "True" or "False".
        /// </param>
        /// <param name="countX">
        /// The number of sub-images in the X direction.
        /// </param>
        /// <param name="countY">
        /// The number of sub-images in the Y direction.
        /// </param>
        /// <returns>
        /// The animated shape name.
        /// </returns>
        public static Primitive AddAnimatedImage(Primitive imageName, Primitive repeat, Primitive countX, Primitive countY)
        {
            GraphicsWindow.Show();
            Type ShapesType = typeof(Shapes);
            Type ImageListType = typeof(ImageList);
            Dictionary<string, BitmapSource> _savedImages;
            BitmapSource img;
            Canvas _mainCanvas;
            string shapeName;

            try
            {
                _savedImages = (Dictionary<string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (!_savedImages.TryGetValue((string)imageName, out img))
                {
                    imageName = ImageList.LoadImage(imageName);
                    if (!_savedImages.TryGetValue((string)imageName, out img))
                    {
                        return "";
                    }
                }

                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "Image" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        //System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imageName);
                        System.Drawing.Bitmap bitmap;
                        using (MemoryStream outStream = new MemoryStream())
                        {
                            BitmapEncoder enc = new PngBitmapEncoder();
                            enc.Frames.Add(BitmapFrame.Create(img));
                            enc.Save(outStream);
                            bitmap = new System.Drawing.Bitmap(outStream);
                        }

                        int frameCount = countX * countY;

                        if (frameCount > 1)
                        {
                            Animated anim = new Animated();
                            animated.Add(anim);
                            anim.name = shapeName;
                            anim.frames = new Frame[frameCount];
                            anim.repeat = repeat;

                            int w = bitmap.Width / countX;
                            int h = bitmap.Height / countY;

                            for (int j = 0; j < countY; j++)
                            {
                                for (int i = 0; i < countX; i++)
                                {
                                    System.Drawing.RectangleF cloneRect = new System.Drawing.RectangleF(w * i, h * j, w, h);
                                    System.Drawing.Bitmap crop = bitmap.Clone(cloneRect, bitmap.PixelFormat);

                                    System.IO.MemoryStream stream = new System.IO.MemoryStream();
                                    new System.Drawing.Bitmap(crop).Save(stream, System.Drawing.Imaging.ImageFormat.Png);

                                    BitmapImage bi = new BitmapImage();
                                    bi.BeginInit();
                                    bi.StreamSource = stream;
                                    bi.EndInit();

                                    anim.frames[j * countX + i] = new Frame(0, bi);
                                }
                            }

                            Image shape = new Image();
                            shape.Source = anim.frames[0].bi;
                            shape.Stretch = Stretch.Fill;
                            shape.Name = shapeName;
                            shape.Width = shape.Source.Width;
                            shape.Height = shape.Source.Height;
                            anim.shape = shape;

                            if (null == animationTimer)
                            {
                                animationTimer = new System.Windows.Forms.Timer();
                                animationTimer.Enabled = animationInterval > 0;
                                if (animationInterval > 0) animationTimer.Interval = animationInterval;
                                animationTimer.Tick += new System.EventHandler(animation_Tick);
                            }

                            _objectsMap[shapeName] = shape;
                            _mainCanvas.Children.Add(shape);
                            return shapeName;
                        }
                        return "";
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
 internal static object InvokeWithReturn(InvokeHelperWithReturn invokeDelegate)
 {
     return SmallBasicApplication._dispatcher.Invoke(DispatcherPriority.Render, invokeDelegate);
 }
示例#41
0
文件: Shapes.cs 项目: litdev1/LitDev
        /// <summary>
        /// Creates a star shape.
        /// Fun effects can be created with negative distances.
        /// </summary>
        /// <param name="numPoint">The number of star points.</param>
        /// <param name="innerRadius">The centre to inner points' distance.</param>
        /// <param name="outerRadius">The centre to outer points' distance.</param>
        /// <returns>
        /// The star shape name.
        /// </returns>
        public static Primitive AddStar(Primitive numPoint, Primitive innerRadius, Primitive outerRadius)
        {
            GraphicsWindow.Show();
            Type ShapesType = typeof(Shapes);
            Canvas _mainCanvas;
            Pen _pen;
            Brush _brush;
            string shapeName;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "Polygon" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _pen = (Pen)GraphicsWindowType.GetField("_pen", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _brush = (Brush)GraphicsWindowType.GetField("_fillBrush", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        PointCollection _points = new PointCollection();
                        double angle;
                        Point _point;
                        double x = 0;
                        double y = 0;
                        for (int i = 0; i < numPoint; i++)
                        {
                            angle = i * 2.0 * System.Math.PI / (double)numPoint;
                            _point = new Point(outerRadius * System.Math.Sin(angle), -outerRadius * System.Math.Cos(angle));
                            x = System.Math.Min(x, _point.X);
                            y = System.Math.Min(y, _point.Y);
                            _points.Add(_point);
                            angle = (i + 0.5) * 2.0 * System.Math.PI / (double)numPoint;
                            _point = new Point(innerRadius * System.Math.Sin(angle), -innerRadius * System.Math.Cos(angle));
                            x = System.Math.Min(x, _point.X);
                            y = System.Math.Min(y, _point.Y);
                            _points.Add(_point);
                        }

                        // Muck around to start at 0,0 in top left of the shape to be consistent with other GW shapes
                        for (int i = 0; i < _points.Count; i++)
                        {
                            _point = _points[i];
                            _point.X -= x;
                            _point.Y -= y;
                            _points[i] = _point;
                        }

                        Polygon shape = new Polygon
                        {
                            Name = shapeName,
                            Points = _points,
                            Fill = _brush,
                            Stroke = _pen.Brush,
                            StrokeThickness = _pen.Thickness
                        };

                        _objectsMap[shapeName] = shape;
                        _mainCanvas.Children.Add(shape);
                        return shapeName;
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#42
0
 internal static object InvokeWithReturn(InvokeHelperWithReturn invokeDelegate)
 {
     return SmallBasicApplication.InvokeWithReturn(invokeDelegate);
 }
示例#43
0
文件: WebCam.cs 项目: litdev1/LitDev
        /// <summary>
        /// Start a webcam display object (SmallBasic shape).  If this is called more than once, multiple copies af the same webcam image are be generated.
        /// 
        /// This object can be moved, zommed, rotated etc using the standard Shapes methods.
        /// 
        /// Maximum resolution usually at 640 x 480 pixels, smaller may be faster.
        /// </summary>
        /// <param name="width">The width of the webcam display object.</param>
        /// <param name="height">The height of the webcam display object.</param>
        /// <returns>The name of the webcam display object.</returns>
        public static Primitive Start(Primitive width, Primitive height)
        {
            _width = width;
            _height = height;
            GraphicsWindow.Show();

            Canvas _mainCanvas;
            Dictionary<string, UIElement> _objectsMap;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                shapeName = method3.Invoke(null, new object[] { "Image" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        Image image = new Image();
                        images.Add(image);
                        image.Name = shapeName;
                        image.Width = _width;
                        image.Height = _height;
                        image.Stretch = System.Windows.Media.Stretch.Fill;

                        _objectsMap[shapeName] = (UIElement)image;
                        _mainCanvas.Children.Add(image);

                        if (!connected) Connect();

                        return shapeName;
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
示例#44
0
文件: Text.cs 项目: litdev1/LitDev
        /// <summary>
        /// Get the height in pixels that text will be displayed in the GraphicsWindow with the current font.
        /// The GraphicsWindow must be open to use this method.
        /// </summary>
        /// <param name="text">The text to get the height.</param>
        /// <returns>The width in pixels.</returns>
        public static Primitive GetHeight(Primitive text)
        {
            try
            {
                Type GraphicsWindowType = typeof(GraphicsWindow);
                FontFamily _fontFamily = (FontFamily)GraphicsWindowType.GetField("_fontFamily", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                double _fontSize = (double)GraphicsWindowType.GetField("_fontSize", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                FontWeight _fontWeight = (FontWeight)GraphicsWindowType.GetField("_fontWeight", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                FontStyle _fontStyle = (FontStyle)GraphicsWindowType.GetField("_fontStyle", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        TextBlock textblock = new TextBlock
                        {
                            Text = text,
                            FontFamily = _fontFamily,
                            FontSize = _fontSize,
                            FontWeight = _fontWeight,
                            FontStyle = _fontStyle
                        };
                        Size size = new Size(double.MaxValue, double.MaxValue);
                        textblock.Measure(size);
                        return textblock.DesiredSize.Height.ToString(CultureInfo.InvariantCulture);
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                    }
                    return "";
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return 0;
            }
        }