示例#1
0
        public static Color_ Light(Color_ baseColor, float percOfLightLight)
        {
            if (baseColor.ToArgb() == ThemeEngine.Current.ColorControl.ToArgb())
            {
                int    r_sub, g_sub, b_sub;
                Color_ color;

                if (percOfLightLight <= 0f)
                {
                    return(ThemeEngine.Current.ColorControlLight);
                }

                if (percOfLightLight == 1.0f)
                {
                    return(ThemeEngine.Current.ColorControlLightLight);
                }

                r_sub = ThemeEngine.Current.ColorControlLightLight.R - ThemeEngine.Current.ColorControlLight.R;
                g_sub = ThemeEngine.Current.ColorControlLightLight.G - ThemeEngine.Current.ColorControlLight.G;
                b_sub = ThemeEngine.Current.ColorControlLightLight.B - ThemeEngine.Current.ColorControlLight.B;

                color = Color_.FromArgb(ThemeEngine.Current.ColorControlLight.A,
                                        (int)(ThemeEngine.Current.ColorControlLight.R + (r_sub * percOfLightLight)),
                                        (int)(ThemeEngine.Current.ColorControlLight.G + (g_sub * percOfLightLight)),
                                        (int)(ThemeEngine.Current.ColorControlLight.B + (b_sub * percOfLightLight)));
                return(color);
            }

            int H, I, S;

            ControlPaint.Color2HBS(baseColor, out H, out I, out S);
            int NewIntensity = Math.Min(255, I + (int)((255 - I) * 0.5f * percOfLightLight));

            return(ControlPaint.HBS2Color(H, NewIntensity, S));
        }
示例#2
0
        public static Color_ FromKnownColor(KnownColor kc)
        {
            Color_ c;
            short  n = (short)kc;

            if ((n <= 0) || (n >= ArgbValues.Length))
            {
                // This is what it returns!
                c = Color_.FromArgb(0, 0, 0, 0);
#if ONLY_1_1
                c.name = kc.ToString();
#endif
                c.state |= (short)Color_.ColorType.Named;
            }
            else
            {
                c       = new Color_();
                c.state = (short)(Color_.ColorType.ARGB | Color_.ColorType.Known | Color_.ColorType.Named);
                if ((n < 27) || (n > 169))
                {
                    c.state |= (short)Color_.ColorType.System;
                }
                c.Value = ArgbValues [n];
#if ONLY_1_1
                c.name = GetName(n);
#endif
            }
            c.knownColor = n;
            return(c);
        }
示例#3
0
 public DataGridViewLinkCell()
 {
     activeLinkColor    = Color_.Red;
     linkColor          = Color_.FromArgb(0, 0, 255);
     trackVisitedState  = true;
     visited_link_color = Color_.FromArgb(128, 0, 128);
 }
示例#4
0
        internal static Color_ HBS2Color(int hue, int lum, int sat)
        {
            int R;
            int G;
            int B;
            int Magic1;
            int Magic2;

            if (sat == 0)                          /* Achromatic */
            {
                R = G = B = (lum * RGBMax) / HLSMax;
                // FIXME : Should throw exception if hue!=0
            }
            else
            {
                if (lum <= (HLSMax / 2))
                {
                    Magic2 = (lum * (HLSMax + sat) + (HLSMax / 2)) / HLSMax;
                }
                else
                {
                    Magic2 = sat + lum - ((sat * lum) + (HLSMax / 2)) / HLSMax;
                }
                Magic1 = 2 * lum - Magic2;

                R = Math.Min(255, (HueToRGB(Magic1, Magic2, hue + (HLSMax / 3)) * RGBMax + (HLSMax / 2)) / HLSMax);
                G = Math.Min(255, (HueToRGB(Magic1, Magic2, hue) * RGBMax + (HLSMax / 2)) / HLSMax);
                B = Math.Min(255, (HueToRGB(Magic1, Magic2, hue - (HLSMax / 3)) * RGBMax + (HLSMax / 2)) / HLSMax);
            }
            return(Color_.FromArgb(R, G, B));
        }
示例#5
0
 private static Color_ ColorFromGdkColor(GdkColorStruct gtkcolor)
 {
     return(Color_.FromArgb(255,
                            (gtkcolor.red >> 8) & 0xff,
                            (gtkcolor.green >> 8) & 0xff,
                            (gtkcolor.blue >> 8) & 0xff));
 }
示例#6
0
 private Color_ ParseColor(string color)
 {
     if (color.IndexOf ("#") >= 0) {
         return Color_.FromArgb (int.Parse (color.Substring (color.IndexOf ("#") + 1), NumberStyles.HexNumber));
     }
     return Color_.FromName (color);
 }
示例#7
0
 public SwitchCheckBox()
 {
     AutoCheck      = true;
     ThumbColor     = Color.WhiteSmoke;
     UncheckedColor = Color_.FromArgb(0xFF808080);
     CheckedColor   = Color_.FromArgb(0xFF1C76FF);
     Padding        = new Padding(3);
 }
示例#8
0
        internal SolidBrush(IntPtr ptr)
            : base(ptr)
        {
            int    val;
            Status status = GDIPlus.GdipGetSolidFillColor(ptr, out val);

            GDIPlus.CheckStatus(status);
            color = Color_.FromArgb(val);
        }
示例#9
0
 public ToolStripLabel(string text, Image image, bool isLink, EventHandler onClick, string name)
     : base(text, image, onClick, name)
 {
     this.active_link_color  = Color_.Red;
     this.is_link            = isLink;
     this.link_behavior      = LinkBehavior.SystemDefault;
     this.link_color         = Color_.FromArgb(0, 0, 255);
     this.link_visited       = false;
     this.visited_link_color = Color_.FromArgb(128, 0, 128);
 }
示例#10
0
        private void CreateCursor(Stream stream)
        {
            InitFromStream(stream);
            this.shape = ToBitmap(true, false);
            this.mask  = ToBitmap(false, false);
            handle     = XplatUI.DefineCursor(shape, mask, Color_.FromArgb(255, 255, 255), Color_.FromArgb(255, 255, 255), cursor_dir.idEntries[id].xHotspot, cursor_dir.idEntries[id].yHotspot);
            this.shape.Dispose();
            this.shape = null;
            this.mask.Dispose();
            this.mask = null;

            if (handle != IntPtr.Zero)
            {
                this.cursor = ToBitmap(true, true);
            }
        }
示例#11
0
        public virtual void DrawPressedCheckBox(Graphics g, Rectangle_ bounds, Color_ backColor, Color_ foreColor, CheckState state)
        {
            int check_box_visible_size = (bounds.Height > bounds.Width) ? bounds.Width : bounds.Height;
            int x_pos = Math.Max(0, bounds.X + (bounds.Width / 2) - check_box_visible_size / 2);
            int y_pos = Math.Max(0, bounds.Y + (bounds.Height / 2) - check_box_visible_size / 2);

            Rectangle_ rect = new Rectangle_(x_pos, y_pos, check_box_visible_size, check_box_visible_size);

            g.FillRectangle(ResPool.GetHatchBrush(HatchStyle.Percent50,
                                                  Color_.FromArgb(Clamp(ColorControl.R + 3, 0, 255),
                                                                  ColorControl.G, ColorControl.B),
                                                  ColorControl), rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);

            Pen pen = SystemPens.ControlDark;

            g.DrawLine(pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
            g.DrawLine(pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);

            pen = SystemPens.ControlDarkDark;
            g.DrawLine(pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 3);
            g.DrawLine(pen, rect.X + 2, rect.Y + 1, rect.Right - 3, rect.Y + 1);

            pen = SystemPens.ControlLightLight;
            g.DrawLine(pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 1);
            g.DrawLine(pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);

            // oh boy, matching ms is like fighting against windmills
            using (Pen h_pen = new Pen(ResPool.GetHatchBrush(HatchStyle.Percent50,
                                                             Color_.FromArgb(Clamp(ColorControl.R + 3, 0, 255),
                                                                             ColorControl.G, ColorControl.B), ColorControl))) {
                g.DrawLine(h_pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
                g.DrawLine(h_pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 2);
            }

            if (state == CheckState.Checked)
            {
                DrawCheck(g, bounds, Color_.Black);
            }
            else if (state == CheckState.Indeterminate)
            {
                DrawCheck(g, bounds, SystemColors.ControlDarkDark);
            }
        }
示例#12
0
        internal void setFromGDIPalette(IntPtr palette)
        {
            IntPtr ptr = palette;
            int    cnt, color;
            int    offset;

            flags = Marshal.ReadInt32(ptr); ptr = (IntPtr)(ptr.ToInt64() + 4);
            cnt   = Marshal.ReadInt32(ptr); ptr = (IntPtr)(ptr.ToInt64() + 4);

            entries = new Color_ [cnt];

            offset = 0;
            for (int i = 0; i < cnt; i++)
            {
                color      = Marshal.ReadInt32(ptr, offset);
                entries[i] = Color_.FromArgb(color);
                offset    += 4;
            }
        }
示例#13
0
        private static Color_ GetColorFromKDEString(string line)
        {
            string[] split = line.Split(new char[] { '=' });

            if (split.Length > 0)
            {
                line = split[1];

                split = line.Split(new char[] { ',' });

                if (split.Length == 3)
                {
                    int r = System.Convert.ToInt32(split[0]);
                    int g = System.Convert.ToInt32(split[1]);
                    int b = System.Convert.ToInt32(split[2]);

                    return(Color_.FromArgb(r, g, b));
                }
            }

            return(Color_.Empty);
        }
示例#14
0
        public static Color_ Dark(Color_ baseColor, float percOfDarkDark)
        {
            if (baseColor.ToArgb() == ThemeEngine.Current.ColorControl.ToArgb())
            {
                int    r_sub, g_sub, b_sub;
                Color_ color;

                if (percOfDarkDark <= 0f)
                {
                    return(ThemeEngine.Current.ColorControlDark);
                }

                if (percOfDarkDark == 1.0f)
                {
                    return(ThemeEngine.Current.ColorControlDarkDark);
                }

                r_sub = ThemeEngine.Current.ColorControlDarkDark.R - ThemeEngine.Current.ColorControlDark.R;
                g_sub = ThemeEngine.Current.ColorControlDarkDark.G - ThemeEngine.Current.ColorControlDark.G;
                b_sub = ThemeEngine.Current.ColorControlDarkDark.B - ThemeEngine.Current.ColorControlDark.B;

                color = Color_.FromArgb(ThemeEngine.Current.ColorControlDark.A,
                                        (int)(ThemeEngine.Current.ColorControlDark.R + (r_sub * percOfDarkDark)),
                                        (int)(ThemeEngine.Current.ColorControlDark.G + (g_sub * percOfDarkDark)),
                                        (int)(ThemeEngine.Current.ColorControlDark.B + (b_sub * percOfDarkDark)));
                return(color);
            }

            int H, I, S;

            ControlPaint.Color2HBS(baseColor, out H, out I, out S);
            int PreIntensity = Math.Max(0, I - (int)(I * 0.333f));
            int NewIntensity = Math.Max(0, PreIntensity - (int)(PreIntensity * percOfDarkDark));

            return(ControlPaint.HBS2Color(H, NewIntensity, S));
        }
示例#15
0
        public LinkLabel()
        {
            LinkArea      = new LinkArea(0, -1);
            link_behavior = LinkBehavior.SystemDefault;
            link_visited  = false;
            pieces        = null;
            focused_index = -1;

            string_format.FormatFlags |= StringFormatFlags.NoClip;

            ActiveLinkColor   = Color_.Red;
            DisabledLinkColor = ThemeEngine.Current.ColorGrayText;
            LinkColor         = Color_.FromArgb(255, 0, 0, 255);
            VisitedLinkColor  = Color_.FromArgb(255, 128, 0, 128);
            SetStyle(ControlStyles.Selectable, false);
            SetStyle(ControlStyles.ResizeRedraw |
                     ControlStyles.UserPaint |
                     ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.SupportsTransparentBackColor |
                     ControlStyles.Opaque |
                     ControlStyles.OptimizedDoubleBuffer
                     , true);
            CreateLinkPieces();
        }
示例#16
0
 private void DrawGripBox(Graphics g, int x, int y)
 {
     g.DrawRectangle(Pens.White, x + 1, y + 1, 1, 1);
     g.DrawRectangle(ThemeEngine.Current.ResPool.GetPen(Color_.FromArgb(172, 168, 153)), x, y, 1, 1);
 }
示例#17
0
        /// <summary>Draw the bluetooth device item in the list view</summary>
        private void DrawBtDevice(DrawItemEventArgs a)
        {
            if (a.Index < 0 || a.Index >= m_lb_devices.Items.Count)
            {
                return;
            }
            var device = (Bluetooth.Device)m_lb_devices.Items[a.Index];
            var x      = a.Bounds.Left + 1;
            var y      = a.Bounds.Top + 1;

            // Get the image key for the device type
            var img_key = GetDeviceImageKey != null
                                ? GetDeviceImageKey(device)
                                : device.ClassOfDeviceMajor.ToString();

            var img = DeviceImageList.Images.ContainsKey(img_key)
                                ? DeviceImageList.Images[img_key]
                                : DeviceImageList.Images[Bluetooth.EClassOfDeviceMajor.Miscellaneous.ToString()];

            // Cell background
            if (a.State.HasFlag(DrawItemState.Selected))
            {
                using (var bsh = new SolidBrush(Color_.FromArgb(0xfff0fafe)))
                    a.Graphics.FillRectangle(bsh, a.Bounds);
            }
            else
            {
                a.DrawBackground();
            }

            // Device image
            using (a.Graphics.SaveState())
            {
                a.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                a.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                a.Graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;

                var aspect = (float)img.Width / img.Height;
                var cx     = aspect * (a.Bounds.Height - 2);
                var cy     = 1f * (a.Bounds.Height - 2);

                a.Graphics.DrawImage(img, new RectangleF(x, y, cx, cy));
                x = (int)(x + cx + 4);
            }

            // Device name
            using (var font = m_lb_devices.Font.Dup(em_size: 12f, style: FontStyle.Bold))
            {
                a.Graphics.DrawString(device.Name, font, Brushes.Black, new Point(x, y));
                y += font.Height;
            }

            // Device state
            using (var font = m_lb_devices.Font.Dup(em_size: 8f))
            {
                a.Graphics.DrawString(device.StatusString, font, Brushes.Blue, new Point(x, y));
                y += font.Height;
            }

            // Last used/seen
            using (var font = m_lb_devices.Font.Dup(em_size: 8f))
            {
                var s = $"Last Used: {device.LastUsed.ToString("G", CultureInfo.CurrentCulture)}";
                a.Graphics.DrawString(s, font, Brushes.Gray, new Point(x, y));
                y += font.Height;

                s = $"Last Seen: {device.LastSeen.ToString("G", CultureInfo.CurrentCulture)}";
                a.Graphics.DrawString(s, font, Brushes.Gray, new Point(x, y));
                y += font.Height;
            }

            // Focus rect
            a.DrawFocusRectangle();
        }
示例#18
0
 public LdrBuilder Axis(m4x4 basis)
 {
     return(Axis(string.Empty, Color_.FromArgb(0xFFFFFFFF), basis));
 }
示例#19
0
        private ImageListStreamer(SerializationInfo info, StreamingContext context)
        {
            byte [] data = (byte [])info.GetValue("Data", typeof(byte []));
            if (data == null || data.Length <= 4)               // 4 is the signature
            {
                return;
            }

            // check the signature ( 'MSFt' )
            if (data [0] != 77 || data [1] != 83 || data [2] != 70 || data [3] != 116)
            {
                return;
            }

            MemoryStream decoded = GetDecodedStream(data, 4, data.Length - 4);

            decoded.Position = 4;             // jumps over 'magic' and 'version', which are 16-bits each

            BinaryReader reader  = new BinaryReader(decoded);
            ushort       nimages = reader.ReadUInt16();

            reader.ReadUInt16();                  // cMaxImage
            ushort grow    = reader.ReadUInt16(); // cGrow
            ushort cx      = reader.ReadUInt16();
            ushort cy      = reader.ReadUInt16();
            uint   bkcolor = reader.ReadUInt32();

            back_color = Color_.FromArgb((int)bkcolor);
            reader.ReadUInt16();                // flags

            short [] ovls = new short [4];
            for (int i = 0; i < 4; i++)
            {
                ovls[i] = reader.ReadInt16();
            }

            byte[] decoded_buffer = decoded.ToArray();
            int    bmp_offset     = 28;
            // FileSize field from the bitmap file header
            int filesize = decoded_buffer [bmp_offset + 2] + (decoded_buffer [bmp_offset + 3] << 8) +
                           (decoded_buffer [bmp_offset + 4] << 16) + (decoded_buffer [bmp_offset + 5] << 24);
            // ImageSize field from the info header (can be 0)
            int imagesize = decoded_buffer [bmp_offset + 34] + (decoded_buffer [bmp_offset + 35] << 8) +
                            (decoded_buffer [bmp_offset + 36] << 16) + (decoded_buffer [bmp_offset + 37] << 24);

            int          bmp_length = imagesize + filesize;
            MemoryStream bmpms      = new MemoryStream(decoded_buffer, bmp_offset, bmp_length);
            Bitmap       bmp        = null;
            Bitmap       mask       = null;

            bmp = new Bitmap(bmpms);
            MemoryStream mask_stream = new MemoryStream(decoded_buffer,
                                                        bmp_offset + bmp_length,
                                                        (int)(decoded.Length - bmp_offset - bmp_length));

            if (mask_stream.Length > 0)
            {
                mask = new Bitmap(mask_stream);
            }

            if (bkcolor == 0xFFFFFFFF)
            {
                back_color = bmp.GetPixel(0, 0);
            }

            if (mask != null)
            {
                int    width  = bmp.Width;
                int    height = bmp.Height;
                Bitmap newbmp = new Bitmap(bmp);
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        Color_ mcolor = mask.GetPixel(x, y);
                        if (mcolor.B != 0)
                        {
                            newbmp.SetPixel(x, y, Color_.Transparent);
                        }
                    }
                }
                bmp.Dispose();
                bmp = newbmp;
                mask.Dispose();
                mask = null;
            }
            images     = new Image [nimages];
            image_size = new Size_(cx, cy);
            Rectangle_ dest_rect = new Rectangle_(0, 0, cx, cy);

            if (grow * bmp.Width > cx)             // Some images store a wrong 'grow' factor
            {
                grow = (ushort)(bmp.Width / cx);
            }

            for (int r = 0; r < nimages; r++)
            {
                int        col  = r % grow;
                int        row  = r / grow;
                Rectangle_ area = new Rectangle_(col * cx, row * cy, cx, cy);
                Bitmap     b    = new Bitmap(cx, cy);
                using (Graphics g = Graphics.FromImage(b)) {
                    g.DrawImage(bmp, dest_rect, area, GraphicsUnit.Pixel);
                }

                images [r] = b;
            }
            bmp.Dispose();
        }
示例#20
0
        static X11DesktopColors()
        {
            FindDesktopEnvironment();

            switch (desktop)
            {
            case Desktop.Gtk: {
                //IntPtr		dispmgr;
                //IntPtr		gdkdisplay;
                IntPtr         widget;
                IntPtr         style_ptr;
                GtkStyleStruct style;

                try {
                    GtkInit();
                    //dispmgr =  gdk_display_manager_get ();
                    //gdkdisplay =  gdk_display_manager_get_default_display (dispmgr);

                    widget = gtk_invisible_new();
                    gtk_widget_ensure_style(widget);
                    style_ptr = gtk_widget_get_style(widget);

                    style = (GtkStyleStruct)Marshal.PtrToStructure(style_ptr, typeof(GtkStyleStruct));

                    ThemeEngine.Current.ColorControl           = ColorFromGdkColor(style.bg[0]);
                    ThemeEngine.Current.ColorControlText       = ColorFromGdkColor(style.fg[0]);
                    ThemeEngine.Current.ColorControlDark       = ColorFromGdkColor(style.dark[0]);
                    ThemeEngine.Current.ColorControlLight      = ColorFromGdkColor(style.light[0]);
                    ThemeEngine.Current.ColorControlLightLight = ControlPaint.Light(ThemeEngine.Current.ColorControlLight);
                    ThemeEngine.Current.ColorControlDarkDark   = ControlPaint.Dark(ThemeEngine.Current.ColorControlDark);

                    // We don't want ControlLight to disappear on a white background!
                    if (ThemeEngine.Current.ColorControlLight.ToArgb() == Color_.White.ToArgb())
                    {
                        ThemeEngine.Current.ColorControlLight = Color_.FromArgb(255, 227, 227, 227);
                    }
                    widget = gtk_menu_new();
                    gtk_widget_ensure_style(widget);
                    style_ptr = gtk_widget_get_style(widget);

                    style = (GtkStyleStruct)Marshal.PtrToStructure(style_ptr, typeof(GtkStyleStruct));

                    ThemeEngine.Current.ColorMenu     = ColorFromGdkColor(style.bg [0]);
                    ThemeEngine.Current.ColorMenuText = ColorFromGdkColor(style.text [0]);
                }

                catch (DllNotFoundException) {
                    Console.Error.WriteLine("Gtk not found (missing LD_LIBRARY_PATH to libgtk-x11-2.0.so.0?), using built-in colorscheme");
                }

                catch {
                    Console.Error.WriteLine("Gtk colorscheme read failure, using built-in colorscheme");
                }
                break;
            }

            case Desktop.KDE: {
                if (!ReadKDEColorsheme())
                {
                    Console.Error.WriteLine("KDE colorscheme read failure, using built-in colorscheme");
                }
                break;
            }

            default: {
                break;
            }
            }
        }
示例#21
0
        private Bitmap ToBitmap(bool xor, bool transparent)
        {
            CursorImage      ci;
            CursorInfoHeader cih;
            int          ncolors;
            Bitmap       bmp;
            BitmapData   bits;
            ColorPalette pal;
            int          biHeight;
            int          bytesPerLine;

            if (cursor_data == null)
            {
                return(new Bitmap(32, 32));
            }

            ci       = cursor_data[this.id];
            cih      = ci.cursorHeader;
            biHeight = cih.biHeight / 2;

            if (!xor)
            {
                // The AND mask is 1bit - very straightforward
                bmp            = new Bitmap(cih.biWidth, biHeight, PixelFormat.Format1bppIndexed);
                pal            = bmp.Palette;
                pal.Entries[0] = Color_.FromArgb(0, 0, 0);
                pal.Entries[1] = Color_.FromArgb(unchecked ((int)0xffffffffff));
                bits           = bmp.LockBits(new Rectangle_(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);

                for (int y = 0; y < biHeight; y++)
                {
                    Marshal.Copy(ci.cursorAND, bits.Stride * y, (IntPtr)(bits.Scan0.ToInt64() + bits.Stride * (biHeight - 1 - y)), bits.Stride);
                }

                bmp.UnlockBits(bits);
            }
            else
            {
                ncolors = (int)cih.biClrUsed;
                if (ncolors == 0)
                {
                    if (cih.biBitCount < 24)
                    {
                        ncolors = (int)(1 << cih.biBitCount);
                    }
                }

                switch (cih.biBitCount)
                {
                case 1: {                       // Monochrome
                    bmp = new Bitmap(cih.biWidth, biHeight, PixelFormat.Format1bppIndexed);
                    break;
                }

                case 4: {                       // 4bpp
                    bmp = new Bitmap(cih.biWidth, biHeight, PixelFormat.Format4bppIndexed);
                    break;
                }

                case 8: {                       // 8bpp
                    bmp = new Bitmap(cih.biWidth, biHeight, PixelFormat.Format8bppIndexed);
                    break;
                }

                case 24:
                case 32: {                      // 32bpp
                    bmp = new Bitmap(cih.biWidth, biHeight, PixelFormat.Format32bppArgb);
                    break;
                }

                default:
                    throw new Exception("Unexpected number of bits:" + cih.biBitCount.ToString());
                }

                if (cih.biBitCount < 24)
                {
                    pal = bmp.Palette;                                                  // Managed palette
                    for (int i = 0; i < ci.cursorColors.Length; i++)
                    {
                        pal.Entries[i] = Color_.FromArgb((int)ci.cursorColors[i] | unchecked ((int)0xff000000));
                    }
                    bmp.Palette = pal;
                }

                bytesPerLine = (int)((((cih.biWidth * cih.biBitCount) + 31) & ~31) >> 3);
                bits         = bmp.LockBits(new Rectangle_(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);

                for (int y = 0; y < biHeight; y++)
                {
                    Marshal.Copy(ci.cursorXOR, bytesPerLine * y, (IntPtr)(bits.Scan0.ToInt64() + bits.Stride * (biHeight - 1 - y)), bytesPerLine);
                }

                bmp.UnlockBits(bits);
            }

            if (transparent)
            {
                bmp = new Bitmap(bmp);                  // This makes a 32bpp image out of an indexed one
                // Apply the mask to make properly transparent
                for (int y = 0; y < biHeight; y++)
                {
                    for (int x = 0; x < cih.biWidth / 8; x++)
                    {
                        for (int bit = 7; bit >= 0; bit--)
                        {
                            if (((ci.cursorAND[y * cih.biWidth / 8 + x] >> bit) & 1) != 0)
                            {
                                bmp.SetPixel(x * 8 + 7 - bit, biHeight - y - 1, Color_.Transparent);
                            }
                        }
                    }
                }
            }

            return(bmp);
        }
示例#22
0
 public void Axis(m4x4 basis)
 {
     Axis(string.Empty, Color_.FromArgb(0xFFFFFFFF), basis);
 }