コード例 #1
0
ファイル: PickerWidget.cs プロジェクト: jassmith/ColorMaker
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            using (var context = Gdk.CairoHelper.Create(evnt.Window)) {
                if (pickerCircle == null || pickerCircle.Width != Radius * 2 + 100 || pickerCircle.Height != Radius * 2 + 100)
                {
                    pickerCircle = new Cairo.ImageSurface(Cairo.Format.ARGB32, Radius * 2 + 100, Radius * 2 + 100);
                    using (var g = new Cairo.Context(pickerCircle)) {
                        // apparently quartz needs the surface initialized
                        g.Color = new Color(0, 0, 0);
                        g.Paint();
                    }
                    DrawPickerCircle(pickerCircle, Radius);
                }

                Gdk.Point center = PickerCenter();

                context.Arc(center.X, center.Y, Radius, 0, Math.PI * 2);
                context.Clip();
                pickerCircle.Show(context, center.X - pickerCircle.Width / 2, center.Y - pickerCircle.Height / 2);

                context.ResetClip();
                context.Arc(center.X, center.Y, Radius + 5, 0, Math.PI * 2);
                context.LineWidth = 10;

                using (var lg = new Cairo.LinearGradient(0, center.Y - (Radius + 30), 0, center.Y + (Radius + 30))) {
                    lg.AddColorStop(0, new Color(0, 0, 0, 0.3));
                    lg.AddColorStop(1, new Color(0, 0, 0, 0.1));
                    context.Pattern = lg;
                    context.Stroke();
                }

                context.Arc(center.X, center.Y, Radius + 15, 0, Math.PI * 2);
                context.LineWidth = 10;

                using (var lg = new Cairo.LinearGradient(0, center.Y - (Radius + 30), 0, center.Y + (Radius + 30))) {
                    lg.AddColorStop(0, new Color(0, 0, 0, 0.1));
                    lg.AddColorStop(1, new Color(0, 0, 0, 0.3));
                    context.Pattern = lg;
                    context.Stroke();
                }

                if (HighlightColor.HasValue)
                {
                    DrawColorOverlay(context, center, HighlightColor.Value);
                }

                Gdk.Rectangle selectedRegion = new Gdk.Rectangle(Allocation.X + 40, Allocation.Bottom - 100, Allocation.Width - 80, 50);
                DrawSelectedColorBox(context, selectedRegion);
            }
            return(base.OnExposeEvent(evnt));
        }