Beispiel #1
0
 public FontStyleGroupViewModel()
 {
     SetForegroundColorCommand = new DelegateCommand(OnSetForegroundColor);
     SetBackgroundColorCommand = new DelegateCommand(OnSetBackgroundColor);
     DecreaseFontSizeCommand   = new DelegateCommand(OnDecreaseFontSize);
     IncreaseFontSizeCommand   = new DelegateCommand(OnIncreaseFontSize);
     MainColorsList            = new ColorPalette();
     MainColorsList.Title      = "Standard colors";
     Colors = new ColorGroups();
     Colors.Add(MainColorsList);
     AddColorLine(MainColorsList, 0, 0, 0, 11, 2, 1);
     for (int x = 0; x < 1280; x += 128)
     {
         byte r = 0;
         byte g = 0;
         byte b = 0;
         if (x < 256)
         {
             r = 255;
             g = (byte)x;
         }
         if (x >= 256 && x < 512)
         {
             g = 255;
             r = (byte)(511 - x);
         }
         if (x >= 512 && x < 768)
         {
             g = 255;
             b = (byte)(x - 512);
         }
         if (x >= 768 && x < 1024)
         {
             b = 255;
             g = (byte)(1023 - x);
         }
         if (x >= 1024 && x < 1280)
         {
             b = 255;
             r = (byte)(x - 1024);
         }
         AddColorLine(MainColorsList, r, g, b, 9, -9, 2);
     }
     Foreground = MainColorsList.Items[15];
     Background = MainColorsList.Items[1];
 }
Beispiel #2
0
        public async Task LoadColors()
        {
            try
            {
                Status = "";

                if (ColorGroups != null)
                {
                    await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                                         () =>
                    {
                        ColorGroups.Clear();
                    }));
                }

                await Task.Factory.StartNew(async() =>
                {
                    using (var conn = new SQLiteConnection(Connection.ConnString))
                    {
                        await Task.Delay(500);
                        conn.Open();

                        using (var comm = new SQLiteCommand(conn))
                        {
                            comm.CommandText =
                                "SELECT color_lib_groups.rowid, color_lib_groups.title, color_lib_groups.desc, color_lib_groups.desc_prev, color_lib_groups.star " +
                                "FROM color_lib_groups " +
                                "WHERE color_lib_groups.userid = (SELECT userid FROM users WHERE active)";

                            using (var reader = comm.ExecuteReader())
                            {
                                if (reader.HasRows)
                                {
                                    var i = 0;
                                    while (reader.Read())
                                    {
                                        var groupadd = new ColorGroups()
                                        {
                                            RowId    = Convert.ToInt64(reader["rowid"]),
                                            Title    = reader["title"].ToString(),
                                            Desc     = reader["desc"].ToString(),
                                            DescPrev = reader["desc_prev"].ToString(),
                                            Star     = Convert.ToBoolean(Convert.ToInt32(reader["star"] != null ? reader["star"].ToString() : "0")),
                                            Colors   = new ObservableCollection <Color.CoColor>()
                                        };

                                        await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                                                             () =>
                                        {
                                            ColorGroups.Add(groupadd);
                                        }));

                                        using (var commforcolors = new SQLiteCommand(conn))
                                        {
                                            commforcolors.CommandText =
                                                "SELECT rowid,* FROM color_lib_colors " +
                                                "WHERE color_lib_colors.userid = (SELECT userid FROM users WHERE active) " +
                                                "AND color_lib_colors.groupid = '" + reader["rowid"] + "' " +
                                                "ORDER BY color_lib_colors.date";

                                            using (var readerforcolors = commforcolors.ExecuteReader())
                                            {
                                                if (readerforcolors.HasRows)
                                                {
                                                    var icolorcount = 0;
                                                    while (readerforcolors.Read())
                                                    {
                                                        icolorcount++;

                                                        var coloradd = new Color.CoColor()
                                                        {
                                                            RowId             = Convert.ToInt64(readerforcolors["rowid"]),
                                                            OrderNum          = icolorcount,
                                                            Title             = readerforcolors["title"].ToString(),
                                                            HexCode           = readerforcolors["hex"].ToString(),
                                                            RgbCode           = readerforcolors["rgb"].ToString(),
                                                            ArgbCode          = readerforcolors["argb"].ToString(),
                                                            GroupId           = Convert.ToInt64(readerforcolors["groupid"].ToString()),
                                                            InverseColorHex_1 = readerforcolors["invert_hex_1"].ToString(),
                                                            InverseColorHex_2 = readerforcolors["invert_hex_2"].ToString()
                                                        };

                                                        var ii = i;
                                                        await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(
                                                                                                             () =>
                                                        {
                                                            ColorGroups[ii].Colors.Add(coloradd);
                                                        }));
                                                    }
                                                }
                                            }
                                        }

                                        i++;
                                    }
                                }
                            }
                        }

                        SelectedColorGroup = ColorGroups[0];

                        conn.Close();
                    }
                });
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp.ToString());
            }
        }