source: trunk/CrypPlugins/WorkspaceManager/View/VisualComponents/ColorPickPopUp.xaml.cs @ 2388

Last change on this file since 2388 was 1991, checked in by matkovic, 11 years ago

-fixed pathfinding
-fixed line drawing
-added Colorpicker
-fixed lock/unlock at TextInputWrapper
-feature: Background and TextForeground in TextInputWrapper added
-fixed a issue With loading and such
-WorkspaceModel doesn't throw exception anymore (Samples functional again)
-fixed some Styles
-Startable implemented and loaded right
-Startable Logo moved

File size: 3.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows;
6using System.Windows.Controls;
7using System.Windows.Data;
8using System.Windows.Documents;
9using System.Windows.Input;
10using System.Windows.Media;
11using System.Windows.Media.Imaging;
12using System.Windows.Navigation;
13using System.Windows.Shapes;
14using System.Windows.Media.Animation;
15using System.Collections;
16using System.ComponentModel;
17using System.Windows.Controls.Primitives;
18using System.Reflection;
19using System.IO;
20using System.Threading;
21
22namespace WorkspaceManager.View.VisualComponents
23{
24    public partial class ColorPickPopUp : Popup
25    {
26        public Rectangle invoker;
27        public event EventHandler<EventArgs> ColorPickerColorChanged;
28
29        public ColorPickPopUp()
30        {
31            InitializeComponent();
32            invoker = null; 
33        }
34
35        public ColorPickPopUp(Rectangle invoker)
36        {
37            InitializeComponent();
38            this.invoker = invoker;
39            Type t = typeof(Brushes);
40            PropertyInfo[] colors = t.GetProperties();
41
42            WrapPanel colorWrap = new WrapPanel();
43            colorWrap.Width = 450;
44            colorWrap.Height = 300;
45            foreach (PropertyInfo color in colors)
46            {
47                BrushConverter convertor = new BrushConverter();
48                Brush brush = convertor.ConvertFromString(color.Name) as Brush;
49                string hex = string.Format("#{0}", brush.ToString().Substring(3));
50
51                Rectangle rectangle = new Rectangle();
52
53                if (color.Name == "Transparent")
54                    rectangle.Fill = this.Resources["transparent"] as VisualBrush;
55                else
56                    rectangle.Fill = brush;
57
58                rectangle.ToolTip = hex;
59                rectangle.Height = 20;
60                rectangle.Width = 20;
61                rectangle.Margin = new Thickness(5, 5, 5, 5);
62                rectangle.Stroke = Brushes.WhiteSmoke;
63
64                rectangle.MouseDown += new MouseButtonEventHandler(rectangle_MouseDown);
65
66                colorWrap.Children.Add(rectangle);
67            }
68
69            root.Children.Add(colorWrap);
70        }
71
72        private Rectangle makeRec(Uri uri)
73        {
74            Rectangle rect = new Rectangle();
75            ImageBrush imgBrush = new ImageBrush();
76
77            rect.Height = 20;
78            rect.Width = 20;
79            rect.Margin = new Thickness(5, 5, 5, 5);
80            rect.Stroke = Brushes.WhiteSmoke;
81
82            rect.MouseDown += new MouseButtonEventHandler(rectangle_MouseDown);
83
84            BitmapImage img = new BitmapImage(uri);
85            imgBrush.ImageSource = img;
86            imgBrush.Stretch = Stretch.UniformToFill;
87            rect.Fill = imgBrush;
88
89            return rect;
90        }
91
92
93        void rectangle_MouseDown(object sender, MouseButtonEventArgs e)
94        {
95            invoker.Fill = (sender as Rectangle).Fill;
96            if (ColorPickerColorChanged != null)
97                ColorPickerColorChanged.Invoke(null, null);
98            this.IsOpen = false;
99        }
100    }
101}
Note: See TracBrowser for help on using the repository browser.