示例#1
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            double step_width = Allocation.Width / (double)steps;
            double step_height = Allocation.Height / (double)steps;
            double h = 1.0;
            double s = 0.0;

            for (int xi = 0, i = 0; xi < steps; xi++) {
                for (int yi = 0; yi < steps; yi++, i++) {
                    double bg_b = (double)(i / 255.0);
                    double fg_b = 1.0 - bg_b;

                    double x = xi * step_width;
                    double y = yi * step_height;

                    cr.Rectangle (x, y, step_width, step_height);
                    cr.Color = CairoExtensions.ColorFromHsb (h, s, bg_b);
                    cr.Fill ();

                    int tw, th;
                    Pango.Layout layout = new Pango.Layout (PangoContext);
                    layout.SetText (((int)(bg_b * 255.0)).ToString ());
                    layout.GetPixelSize (out tw, out th);

                    cr.Translate (0.5, 0.5);
                    cr.MoveTo (x + (step_width - tw) / 2.0, y + (step_height - th) / 2.0);
                    cr.Color = CairoExtensions.ColorFromHsb (h, s, fg_b);
                    PangoCairoHelper.ShowLayout (cr, layout);
                    cr.Translate (-0.5, -0.5);
                }
            }

            return true;
        }
示例#2
0
        protected virtual void InitializeMultiLine()
        {
            var w          = 0;
            var lastHeight = -1;

            TextView.SizeRequested += (s, args) => {
                if (!MultiLine)
                {
                    args.Requisition = new Gtk.Requisition {
                        Width  = -1,
                        Height = lineHeight
                    }
                }
                ;
            };

            TextView.SizeAllocated += (s, e) => {
                if (!MultiLine && lastHeight != e.Allocation.Height)
                {
                    lastHeight = e.Allocation.Height;
                    XLayout.GetPixelSize(out w, out lineHeight);
                    lineHeight += frameMargin * 2;
                    if (lastHeight > lineHeight)
                    {
                        TextView.PixelsAboveLines = (int)((lastHeight - lineHeight) / 2d);
                    }
                }
            };

            TextView.Buffer.Changed += (s, e) => {
                bufferSizeRequest = true;
            };
        }
		public void InitCell (Widget container, bool diffMode, string[] lines, TreePath path)
		{
			if (isDisposed)
				return;
			this.lines = lines;
			this.diffMode = diffMode;
			this.path = path;
			
			if (diffMode) {
				if (lines != null && lines.Length > 0) {
					int maxlen = -1;
					int maxlin = -1;
					for (int n=0; n<lines.Length; n++) {
						if (lines [n].Length > maxlen) {
							maxlen = lines [n].Length;
							maxlin = n;
						}
					}
					DisposeLayout ();
					layout = CreateLayout (container, lines [maxlin]);
					layout.GetPixelSize (out width, out lineHeight);
					height = lineHeight * lines.Length;
				}
				else
					width = height = 0;
			}
			else {
				DisposeLayout ();
				layout = CreateLayout (container, string.Join (Environment.NewLine, lines));
				layout.GetPixelSize (out width, out height);
			}
		}
示例#4
0
        /// <summary>
        /// Same as GetPixelSize(), but return result as tuple.
        /// </summary>
        public static Tuple <int, int> GetDimension(this Pango.Layout value)
        {
            int width, height;

            value.GetPixelSize(out width, out height);
            return(new Tuple <int, int>(width, height));
        }
示例#5
0
        public static void DrawText(Cairo.Context cr, string text, int size, Cairo.Rectangle rect)
        {
            cr.Save();
            cr.Translate(rect.X, rect.Y);
            using (var context = Pango.CairoHelper.CreateContext(cr))
                using (var layout = new Pango.Layout(context)) {
                    layout.Width     = Pango.Units.FromPixels((int)rect.Width);
                    layout.Height    = Pango.Units.FromPixels((int)rect.Height);
                    layout.Alignment = Pango.Alignment.Center;

                    // TODO: install the font on the system
                    layout.FontDescription = Pango.FontDescription.FromString("ZeldaOracles " + size);
                    //layout.FontDescription.Weight = (Pango.Weight)10000;

                    layout.SetText(text);

                    // Center vertically
                    int pixelWidth, pixelHeight;
                    layout.GetPixelSize(out pixelWidth, out pixelHeight);
                    cr.Translate(0, ((int)rect.Height - pixelHeight) / 2.0);

                    Pango.CairoHelper.ShowLayout(cr, layout);
                }
            cr.Restore();
        }
        private static void DrawComment(Gtk.PrintContext context, double x, double y, double h, string comment, bool rotated)
        {
            if (comment == null || comment == String.Empty)
            {
                return;
            }

            Context cr = context.CairoContext;

            cr.Save();
            Pango.Layout          layout = context.CreatePangoLayout();
            Pango.FontDescription desc   = Pango.FontDescription.FromString("sans 14");
            layout.FontDescription = desc;
            layout.SetText(comment);
            int lay_w, lay_h;

            layout.GetPixelSize(out lay_w, out lay_h);
            double scale = h / lay_h;

            if (rotated)
            {
                cr.Translate(x - h, y + lay_w * scale);
                cr.Rotate(-Math.PI / 2);
            }
            else
            {
                cr.Translate(x - lay_w * scale, y - h);
            }
            cr.Scale(scale, scale);
            Pango.CairoHelper.ShowLayout(context.CairoContext, layout);
            cr.Restore();
        }
        void DrawString(string text, bool isMarkup, Cairo.Context context, int x, int y, int width, double opacity, Pango.Context pango, StatusArea.RenderArg arg)
        {
            Pango.Layout pl = new Pango.Layout(pango);
            if (isMarkup)
            {
                pl.SetMarkup(text);
            }
            else
            {
                pl.SetText(text);
            }
            pl.FontDescription = Styles.StatusFont;
            pl.FontDescription.AbsoluteSize = Pango.Units.FromPixels(Styles.StatusFontPixelHeight);
            pl.Ellipsize = Pango.EllipsizeMode.End;
            pl.Width     = Pango.Units.FromPixels(width);

            int w, h;

            pl.GetPixelSize(out w, out h);

            context.Save();
            // use widget height instead of message box height as message box does not have a true height when no widgets are packed in it
            // also ensures animations work properly instead of getting clipped
            context.Rectangle(new Rectangle(x, arg.Allocation.Y, width, arg.Allocation.Height));
            context.Clip();

            // Subtract off remainder instead of drop to prefer higher centering when centering an odd number of pixels
            context.MoveTo(x, y - h / 2 - (h % 2));
            context.Color = Styles.WithAlpha(FontColor(), opacity);

            Pango.CairoHelper.ShowLayout(context, pl);
            pl.Dispose();
            context.Restore();
        }
        protected override void OnSizeRequested(ref Gtk.Requisition requisition)
        {
            if (!IsRealized || layout == null)
            {
                return;
            }

            EnsureStyle();

            int width, height;

            layout.GetPixelSize(out width, out height);

            requisition.Width  = width;
            requisition.Height = height;
        }
示例#9
0
        public Tab(Tabstrip parent, string label, TabPosition tabPosition)
        {
            this.parent = parent;
            this.Label  = label;

            layout = PangoUtil.CreateLayout(parent);
            layout.FontDescription = FontService.SansFont.CopyModified(Styles.FontScale11);
            layout.SetText(label);
            layout.Alignment = Pango.Alignment.Center;
            layout.GetPixelSize(out w, out h);

            if (IsSeparator)
            {
                w = SpacerWidth * 2;
            }

            this.TabPosition = tabPosition;

            if (AccessibilityElementProxy.Enabled)
            {
                Accessible = AccessibilityElementProxy.ButtonElementProxy();
                Accessible.SetRole(AtkCocoa.Roles.AXRadioButton, "tab");
                Accessible.Title         = label;
                Accessible.GtkParent     = parent;
                Accessible.Identifier    = "Tabstrip.Tab";
                Accessible.PerformPress += OnTabPressed;
            }
        }
示例#10
0
        internal static int ComputeRowHeight(ListView widget, CellStyleProvider styleProvider)
        {
            int w_width, row_height;

            Pango.Layout layout = new Pango.Layout(widget.PangoContext);
            if (styleProvider != null)
            {
                CellStyleQueryEventArgs ret = new CellStyleQueryEventArgs(StateType.Normal, new CellPosition(0, 0));
                if (widget.Model != null && widget.Model.Count > 0)
                {
                    styleProvider(widget, ret);
                }

                if (ret.Style != null)
                {
                    layout.SetMarkup(ret.Style.GetMarkup("W"));
                }
                else
                {
                    layout.SetText("W");
                }
            }
            else
            {
                layout.SetText("W");
            }
            layout.GetPixelSize(out w_width, out row_height);
            layout.Dispose();
            return(row_height + 8);
        }
示例#11
0
        protected override void OnSizeRequested(ref Gtk.Requisition requisition)
        {
            base.OnSizeRequested(ref requisition);
            int descriptionWidth = 1;
            int totalHeight      = yTitleBorder * 2 + yDescriptionBorder * 2 + 1;

            int width, height;

            titleLayout.SetText(TitleText);
            titleLayout.GetPixelSize(out width, out height);
            totalHeight += height;
            xSpacer      = 0;

            int h2;
            int w2;

            descriptionLayout.GetPixelSize(out w2, out h2);
            totalHeight += h2;
            xSpacer      = System.Math.Max(width, w2);

            xSpacer += xDescriptionBorder * 2 + 1;

            requisition.Width  = triangleWidth + descriptionWidth + xSpacer;
            requisition.Height = totalHeight;
        }
        public async Task AddOverload(CompletionData data, CancellationToken cancelToken)
        {
            var tooltipInformation = await data.CreateTooltipInformation(false, cancelToken);

            if (tooltipInformation == null || tooltipInformation.IsEmpty || cancelToken.IsCancellationRequested)
            {
                return;
            }

            using (var layout = new Pango.Layout(PangoContext)) {
                layout.FontDescription = Theme.Font;
                layout.SetMarkup(tooltipInformation.SignatureMarkup);
                int w, h;
                layout.GetPixelSize(out w, out h);
                if (w >= Allocation.Width - 10)
                {
                    tooltipInformation = await data.CreateTooltipInformation(true, cancelToken);
                }
            }
            if (cancelToken.IsCancellationRequested)
            {
                return;
            }
            AddOverload(tooltipInformation);
        }
        internal void EnsureLayoutCreated(TextEditor editor)
        {
            if (colorMatrix == null && editor.ColorStyle != null)
            {
                bool isError = errors.Any(e => e.IsError);
                if (errorMatrix == null)
                {
                    errorGc       = (HslColor)(editor.ColorStyle.GetChunkStyle("bubble.error.text").Color);
                    warningGc     = (HslColor)(editor.ColorStyle.GetChunkStyle("bubble.warning.text").Color);
                    errorMatrix   = CreateColorMatrix(editor, true);
                    warningMatrix = CreateColorMatrix(editor, false);
                }
                colorMatrix = isError ? errorMatrix : warningMatrix;

                gc         = isError ? errorGc : warningGc;
                gcSelected = (HslColor)editor.ColorStyle.Selection.Color;
                gcLight    = new Cairo.Color(1, 1, 1);
            }

            if (layouts != null)
            {
                return;
            }

            layouts         = new List <LayoutDescriptor> ();
            fontDescription = FontService.GetFontDescription("MessageBubbles");
            if (fontDescription != null)
            {
                fontDescription.Size = (int)(fontDescription.Size * editor.Options.Zoom);
            }
            foreach (ErrorText errorText in errors)
            {
                Pango.Layout layout = new Pango.Layout(editor.PangoContext);
                layout.FontDescription = fontDescription;

                string firstLine = errorText.ErrorMessage ?? "";
                int    idx       = firstLine.IndexOfAny(new [] { '\n', '\r' });
                if (idx > 0)
                {
                    firstLine = firstLine.Substring(0, idx);
                }
                layout.SetText(firstLine);
                KeyValuePair <int, int> textSize;
                if (!textWidthDictionary.TryGetValue(errorText.ErrorMessage, out textSize))
                {
                    int w, h;
                    layout.GetPixelSize(out w, out h);
                    textSize = new KeyValuePair <int, int> (w, h);
                    textWidthDictionary [errorText.ErrorMessage] = textSize;
                }
                layouts.Add(new LayoutDescriptor(layout, textSize.Key, textSize.Value));
            }

            if (errorCountLayout == null && errors.Count > 1)
            {
                errorCountLayout = new Pango.Layout(editor.PangoContext);
                errorCountLayout.FontDescription = fontDescription;
                errorCountLayout.SetText(errors.Count.ToString());
            }
        }
        public override void Render(Drawable window,
                                     Widget widget,
                                     Rectangle cell_area,
                                     Rectangle expose_area,
                                     StateType cell_state,
                                     IPhoto photo)
        {
            string text = GetRenderText (photo);

            var layout = new Pango.Layout (widget.PangoContext);
            layout.SetText (text);

            Rectangle layout_bounds;
            layout.GetPixelSize (out layout_bounds.Width, out layout_bounds.Height);

            layout_bounds.Y = cell_area.Y;
            layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2;

            if (layout_bounds.IntersectsWith (expose_area)) {
                Style.PaintLayout (widget.Style, window, cell_state,
                                   true, expose_area, widget, "IconView",
                                   layout_bounds.X, layout_bounds.Y,
                                   layout);
            }
        }
示例#15
0
        public override void Render(Drawable window,
                                    Widget widget,
                                    Rectangle cell_area,
                                    Rectangle expose_area,
                                    StateType cell_state,
                                    IPhoto photo)
        {
            string text = GetRenderText(photo);

            var layout = new Pango.Layout(widget.PangoContext);

            layout.SetText(text);

            Rectangle layout_bounds;

            layout.GetPixelSize(out layout_bounds.Width, out layout_bounds.Height);

            layout_bounds.Y = cell_area.Y;
            layout_bounds.X = cell_area.X + (cell_area.Width - layout_bounds.Width) / 2;

            if (layout_bounds.IntersectsWith(expose_area))
            {
                Style.PaintLayout(widget.Style, window, cell_state,
                                  true, expose_area, widget, "IconView",
                                  layout_bounds.X, layout_bounds.Y,
                                  layout);
            }
        }
示例#16
0
        void HandleExposeEvent(object o, Gtk.ExposeEventArgs args)
        {
            if (!string.IsNullOrEmpty(Control.Text) || args.Event.Window == Control.GdkWindow)
            {
                return;
            }

            if (placeholderLayout == null)
            {
                placeholderLayout = new Pango.Layout(Control.PangoContext);
                placeholderLayout.FontDescription = Control.PangoContext.FontDescription.Copy();
            }
            placeholderLayout.SetText(placeholderText);

            int currentHeight, currentWidth;

            args.Event.Window.GetSize(out currentWidth, out currentHeight);

            int width, height;

            placeholderLayout.GetPixelSize(out width, out height);

            var style = Control.Style;
            var bc    = style.Base(Gtk.StateType.Normal);
            var tc    = style.Text(Gtk.StateType.Normal);

            using (var gc = new Gdk.GC(args.Event.Window)) {
                gc.Copy(style.TextGC(Gtk.StateType.Normal));

                gc.RgbFgColor = new Gdk.Color((byte)(((int)bc.Red + tc.Red) / 2 / 256), (byte)(((int)bc.Green + (int)tc.Green) / 2 / 256), (byte)((bc.Blue + tc.Blue) / 2 / 256));

                args.Event.Window.DrawLayout(gc, 2, (currentHeight - height) / 2 + 1, placeholderLayout);
            }
        }
示例#17
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            if (!dropShadowVisible)
            {
                return(base.OnExposeEvent(evnt));
            }

            Pango.Layout la = new Pango.Layout(PangoContext);
            int          w, h;

            if (UseMarkup)
            {
                la.SetMarkup(Text);
            }
            else
            {
                la.SetText(Text);
            }

            la.GetPixelSize(out w, out h);

            int tx = Allocation.X + (int)Xpad + (int)((float)(Allocation.Width - (int)(Xpad * 2) - w) * Xalign);
            int ty = Allocation.Y + (int)Ypad + (int)((float)(Allocation.Height - (int)(Ypad * 2) - h) * Yalign);

            GdkWindow.DrawLayout(Style.TextGC(State), tx, ty, la);

            la.Dispose();
            return(true);
        }
        public async Task AddOverload(CompletionData data, CancellationToken cancelToken)
        {
            try {
                var tooltipInformation = await data.CreateTooltipInformation(false, cancelToken);

                if (tooltipInformation == null || tooltipInformation.IsEmpty || cancelToken.IsCancellationRequested)
                {
                    return;
                }

                using (var layout = new Pango.Layout(headLabel.PangoContext)) {
                    layout.FontDescription = Theme.Font.ToPangoFont();
                    layout.SetMarkup(tooltipInformation.SignatureMarkup);
                    int w, h;
                    layout.GetPixelSize(out w, out h);
                    if (w >= Size.Width - 10)
                    {
                        tooltipInformation = await data.CreateTooltipInformation(true, cancelToken);
                    }
                }
                if (cancelToken.IsCancellationRequested)
                {
                    return;
                }
                AddOverload(tooltipInformation);
            } catch (Exception e) {
                LoggingService.LogError("Error while adding overload : " + data, e);
            }
        }
示例#19
0
            protected override bool OnExposeEvent(Gdk.EventExpose evnt)
            {
                // The Entry's GdkWindow is the top level window onto which
                // the frame is drawn; the actual text entry is drawn into a
                // separate window, so we can ensure that for themes that don't
                // respect HasFrame, we never ever allow the base frame drawing
                // to happen
                if (evnt.Window == GdkWindow)
                {
                    return(true);
                }

                bool ret = base.OnExposeEvent(evnt);

                if (text_gc == null || evnt.Window != text_window)
                {
                    text_window = evnt.Window;
                    RefreshGC();
                }

                if (Text.Length > 0 || HasFocus || parent.EmptyMessage == null)
                {
                    return(ret);
                }

                int width, height;

                layout.SetMarkup(parent.EmptyMessage);
                layout.GetPixelSize(out width, out height);
                evnt.Window.DrawLayout(text_gc, 2, (SizeRequest().Height - height) / 2, layout);

                return(ret);
            }
示例#20
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            bool res = base.OnExposeEvent(evnt);

            if (Text.Length == 0 && !string.IsNullOrEmpty(EmptyMessage))
            {
                if (text_gc == null)
                {
                    text_gc = new Gdk.GC(evnt.Window);
                    text_gc.Copy(Style.TextGC(Gtk.StateType.Normal));
                    Gdk.Color color_a = Style.Base(Gtk.StateType.Normal);
                    Gdk.Color color_b = Style.Text(Gtk.StateType.Normal);
                    text_gc.RgbFgColor = ColorBlend(color_a, color_b);
                }

                if (layout == null)
                {
                    layout = new Pango.Layout(PangoContext);
                    layout.FontDescription = PangoContext.FontDescription.Copy();
                }

                int width, height;
                layout.SetMarkup(EmptyMessage);
                layout.GetPixelSize(out width, out height);
                evnt.Window.DrawLayout(text_gc, 2, 2, layout);
            }
            return(res);
        }
        Tuple <int, int> GetErrorCountBounds(TextViewMargin.LayoutWrapper wrapper = null)
        {
            EnsureLayoutCreated(editor);
            var layout = wrapper ?? editor.TextViewMargin.GetLayout(lineSegment);

            try {
                var lineTextPx = editor.TextViewMargin.XOffset + editor.TextViewMargin.TextStartPosition + layout.PangoWidth / Pango.Scale.PangoScale;
                if (errors.Count > 1 && errorCountLayout != null || editor.Allocation.Width < lineTextPx + layouts [0].Width)
                {
                    int ew = 0, eh = 0;
                    if (errorCountLayout != null)
                    {
                        errorCountLayout.GetPixelSize(out ew, out eh);
                    }
                    else
                    {
                        ew = 10;
                    }
                    return(Tuple.Create(ew + 10, eh));
                }
                return(Tuple.Create(0, 0));
            } finally {
                if (wrapper == null && layout.IsUncached)
                {
                    layout.Dispose();
                }
            }
        }
示例#22
0
            public override void GetSize(Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)
            {
                base.GetSize(widget, ref cell_area, out x_offset, out y_offset, out width, out height);
                x_offset = y_offset = 0;
                if (string.IsNullOrEmpty(Text))
                {
                    width  = 0;
                    height = 0;
                    return;
                }

                using (var layout = new Pango.Layout(widget.PangoContext)) {
                    height = 0;
                    width  = (int)Xpad;
                    int w, h, buttonWidth;
                    foreach (var key in Text.Split(new char [] { ' ' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        layout.SetText(KeyBindingManager.BindingToDisplayLabel(key, false));
                        layout.FontDescription = KeySymbolFont;
                        layout.GetPixelSize(out w, out h);
                        if (height == 0)
                        {
                            height = h + (KeyVPadding * 2) + 1;
                        }

                        buttonWidth = w + (2 * KeyHPadding);
                        width      += buttonWidth + Spacing;
                    }
                }
            }
        /// <summary>
        /// Paints cell on cairo context
        /// </summary>
        /// <param name="aArgs">
        /// A <see cref="CellExposeEventArgs"/>
        /// </param>
        public override void Paint(CellExposeEventArgs aArgs)
        {
            if (Area.IsInsideArea(aArgs.ClippingArea) == false)
            {
                return;
            }
            Pango.Context pContext = PangoContext;
            if ((DisplayText == "") || (pContext == null))
            {
                return;
            }
            Pango.Layout layout = SetLayout();
            layout.Width = Pango.Units.FromPixels(System.Convert.ToInt32(aArgs.CellArea.Width));

            layout.SetMarkup(DisplayText);
            int width, height;

            layout.GetPixelSize(out width, out height);
            double xdiff = Area.Width - width;
            double ydiff = Area.Height - ySize;

            aArgs.Context.Color = Color;
            aArgs.Context.MoveTo(aArgs.CellArea.X + (xdiff * XPos), aArgs.CellArea.Y + (ydiff * YPos));

            Pango.CairoHelper.ShowLayout(aArgs.Context, layout);
            layout.SetMarkup("");
            FreeLayout(layout);
        }
        protected override void RenderTrackInfo(Context cr, TrackInfo track, bool renderTrack, bool renderArtistAlbum)
        {
            if (track == null)
            {
                return;
            }

            double offset = ArtworkSizeRequest + ArtworkSpacing, y = 0;
            double x = Allocation.X + offset;
            double width = Allocation.Width - offset;
            int    fl_width, fl_height, sl_width, sl_height;
            int    pango_width = (int)(width * Pango.Scale.PangoScale);

            if (first_line_layout == null)
            {
                first_line_layout           = CairoExtensions.CreateLayout(this, cr);
                first_line_layout.Ellipsize = Pango.EllipsizeMode.End;
            }

            if (second_line_layout == null)
            {
                second_line_layout           = CairoExtensions.CreateLayout(this, cr);
                second_line_layout.Ellipsize = Pango.EllipsizeMode.End;
            }

            // Set up the text layouts
            first_line_layout.Width  = pango_width;
            second_line_layout.Width = pango_width;

            // Compute the layout coordinates
            first_line_layout.SetMarkup(GetFirstLineText(track));
            first_line_layout.GetPixelSize(out fl_width, out fl_height);
            second_line_layout.SetMarkup(GetSecondLineText(track));
            second_line_layout.GetPixelSize(out sl_width, out sl_height);

            if (fl_height + sl_height > Allocation.Height)
            {
                SetSizeRequest(-1, fl_height + sl_height);
            }

            y = Allocation.Y + (Allocation.Height - (fl_height + sl_height)) / 2;

            // Render the layouts
            cr.Antialias = Cairo.Antialias.Default;

            if (renderTrack)
            {
                cr.MoveTo(x, y);
                cr.Color = TextColor;
                PangoCairoHelper.ShowLayout(cr, first_line_layout);
            }

            if (!renderArtistAlbum)
            {
                return;
            }

            cr.MoveTo(x, y + fl_height);
            PangoCairoHelper.ShowLayout(cr, second_line_layout);
        }
示例#25
0
        public void DrawTick(Rectangle area, int item)
        {
            Rectangle tick = TickBounds(item);

            Pango.Layout layout = null;

            if (item < tick_layouts.Length)
            {
                layout = tick_layouts [item];

                if (layout != null)
                {
                    int width, height;
                    layout.GetPixelSize(out width, out height);

                    Style.PaintLayout(Style, GdkWindow, State, true, area, this,
                                      "GroupSelector:Tick", tick.X + 3, tick.Y + tick.Height, layout);
                }
            }

            if (layout == null)
            {
                tick.Height /= 2;
            }

            if (tick.Intersect(area, out area))
            {
                GdkWindow.DrawRectangle(Style.ForegroundGC(State), true, area);
            }
        }
示例#26
0
        /// <summary>
        /// Renders the pager.
        /// </summary>
        public virtual void RenderPager(Cairo.Context context, Pango.Context pangoContext, Gdk.Rectangle region)
        {
            //set global clip to avoid going outside general rendering area
            CairoExtensions.RoundedRectangle(context, region.X, region.Y, region.Width, region.Height, CornerRadius);
            context.Clip();

            Pango.Layout layout = SetupPagerText(context, pangoContext);
            int          textWidth, textHeight;

            layout.GetPixelSize(out textWidth, out textHeight);

            int width  = textWidth + Styles.PopoverWindow.PagerTriangleSize * 2 + 20;
            int height = Styles.PopoverWindow.PagerHeight;

            Gdk.Rectangle boundingBox = new Gdk.Rectangle(region.X + region.Width - width, 0, width, height);
            RenderPagerBackground(context, boundingBox);

            int arrowPadding = 4;

            Gdk.Rectangle arrowRect = new Gdk.Rectangle(boundingBox.X + arrowPadding,
                                                        boundingBox.Y + (boundingBox.Height - Styles.PopoverWindow.PagerTriangleSize) / 2,
                                                        Styles.PopoverWindow.PagerTriangleSize,
                                                        Styles.PopoverWindow.PagerTriangleSize);

            RenderPagerArrow(context, arrowRect, PagerVertical ? ArrowType.Up : ArrowType.Left);
            arrowRect.X = boundingBox.X + boundingBox.Width - (arrowPadding + Styles.PopoverWindow.PagerTriangleSize);
            RenderPagerArrow(context, arrowRect, PagerVertical ? ArrowType.Down : ArrowType.Right);

            RenderPagerText(context, layout, boundingBox);
        }
示例#27
0
            protected override void OnSizeRequested(ref Gtk.Requisition requisition)
            {
                base.OnSizeRequested(ref requisition);
                double y = verticalTextBorder * 2 - verticalTextSpace + (MonoDevelop.Core.Platform.IsWindows ? 10 : 2);

                using (var drawingLayout = new Pango.Layout(this.PangoContext)) {
                    drawingLayout.FontDescription = cache.tooltipFontDescription;

                    foreach (var msg in marker.Errors)
                    {
                        if (marker.Layouts.Count == 1)
                        {
                            drawingLayout.Width = maxTextWidth;
                        }
                        drawingLayout.SetText(GetFirstLine(msg));
                        int w;
                        int h;
                        drawingLayout.GetPixelSize(out w, out h);
                        if (marker.Layouts.Count > 1)
                        {
                            w += (int)cache.warningPixbuf.Width + iconTextSpacing;
                        }

                        requisition.Width = Math.Max(w + textBorder * 2, requisition.Width);
                        y += h + verticalTextSpace;
                    }
                }

                requisition.Height = (int)y;
            }
示例#28
0
        protected override void OnSizeRequested(ref Requisition requisition)
        {
            base.OnSizeRequested(ref requisition);

            int lw, lh;

            lbl_layout.GetPixelSize(out lw, out lh);

            double frameSize = 2 * lineWidth + childPadding;

            barHeight = lh + 2 * space;
            if (expandButton != null && expandButton.Visible)
            {
                expandButton.SetSizeRequest(lh, lh);
                expandButton.SizeRequest();
            }

            Requisition childRequisition = new Requisition();

            if (Child != null && Child.Visible)
            {
                if (HeightRequest != -1)
                {
                    int left = HeightRequest - (int)(2 * frameSize + barHeight);
                    Child.HeightRequest = left;
                }
                if (WidthRequest != -1)
                {
                    int left = WidthRequest - (int)(2 * frameSize);
                    Child.WidthRequest = left;
                }
                childRequisition = Child.SizeRequest();
            }

            if (WidthRequest == -1)
            {
                if (Child != null && Child.Visible)
                {
                    requisition.Width = childRequisition.Width + (int)(2 * frameSize);
                }
                else
                {
                    requisition.Width = lw + (int)(2 * (2 * lineWidth + space));
                    if (expandButton != null && expandButton.Visible)
                    {
                        requisition.Width += expandButton.WidthRequest + (int)space;
                    }
                }
            }

            if (HeightRequest == -1)
            {
                requisition.Height = (int)(2 * frameSize + barHeight);
                if (Child != null && Child.Visible)
                {
                    requisition.Height += childRequisition.Height;
                }
            }
        }
        public Size GetSize(object backend)
        {
            Pango.Layout tl = (Pango.Layout)backend;
            int          w, h;

            tl.GetPixelSize(out w, out h);
            return(new Size((double)w, (double)h));
        }
示例#30
0
文件: list.cs 项目: lulzzz/ifolder
        int currentWidth = 50; // pixels

        public BigList(IListModel provider)
        {
            this.provider = provider;

            //Accessibility
            RefAccessible().Role = Atk.Role.List;

            hAdjustment = new Gtk.Adjustment(0, 0, currentWidth, 1, 1, 1);
            hAdjustment.ValueChanged += new EventHandler(HAdjustmentValueChangedHandler);

            vAdjustment = new Gtk.Adjustment(0, 0, provider.Rows, 1, 1, 1);
            vAdjustment.ValueChanged += new EventHandler(VAdjustmentValueChangedHandler);

            layout = new Pango.Layout(PangoContext);

            ExposeEvent        += new ExposeEventHandler(ExposeHandler);
            ButtonPressEvent   += new ButtonPressEventHandler(ButtonPressEventHandler);
            ButtonReleaseEvent += new ButtonReleaseEventHandler(ButtonReleaseEventHandler);
            KeyPressEvent      += new KeyPressEventHandler(KeyHandler);
            Realized           += new EventHandler(RealizeHandler);
            Unrealized         += new EventHandler(UnrealizeHandler);
            ScrollEvent        += new ScrollEventHandler(ScrollHandler);
            SizeAllocated      += new SizeAllocatedHandler(SizeAllocatedHandler);
            MotionNotifyEvent  += new MotionNotifyEventHandler(MotionNotifyEventHandler);

            AddEvents((int)EventMask.ButtonPressMask | (int)EventMask.ButtonReleaseMask | (int)EventMask.KeyPressMask | (int)EventMask.PointerMotionMask);
            CanFocus = true;

            style_widget           = new EventBox();
            style_widget.StyleSet += new StyleSetHandler(StyleHandler);

            //
            // Compute the height and ellipsis width of the font,
            // and the en_width for our ellipsizing algorithm
            //
            layout.SetMarkup(ellipsis);
            layout.GetPixelSize(out ellipsis_width, out line_height);

            layout.SetMarkup("n");
            layout.GetPixelSize(out en_width, out line_height);

            layout.SetMarkup("W");
            layout.GetPixelSize(out en_width, out line_height);

            old_width = Allocation.Width;
        }
示例#31
0
        public static int TextWidth(Widget widget, string text, int margins)
        {
            Pango.Layout layout = widget.CreatePangoLayout(text);
            int          width, height;

            layout.GetPixelSize(out width, out height);
            return(width + margins);
        }
示例#32
0
        public override void GetSize(Gtk.Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int width, out int height)
        {
            if (text_layout == null)
            {
                UpdateLayout(widget);
            }

            int text_width, text_height;

            text_layout.GetPixelSize(out text_width, out text_height);

            width  = (int)(2 * Xpad + Math.Max(progress_width, text_width));
            height = (int)(3 * Ypad + progress_height + text_height);

            x_offset = Math.Max((int)(Xalign * (cell_area.Width - width)), 0);
            y_offset = Math.Max((int)(Yalign * (cell_area.Height - height)), 0);
        }
示例#33
0
 public int ComputeRowHeight(Widget widget)
 {
     int w_width, row_height;
     using (var layout = new Pango.Layout (widget.PangoContext)) {
         layout.SetText ("W");
         layout.GetPixelSize (out w_width, out row_height);
         return row_height + 8;
     }
 }
示例#34
0
 public override Gdk.Size Measure(Widget widget)
 {
     using (var layout = new Pango.Layout (widget.PangoContext)) {
         int lw, lh;
         layout.SetMarkup ("<b>W</b>\n<small><i>W</i></small>");
         layout.GetPixelSize (out lw, out lh);
         return new Gdk.Size (0, lh + 8);
     }
 }
		internal protected override void OptionsChanged ()
		{
			Pango.Layout layout = new Pango.Layout (Editor.PangoContext);
			layout.FontDescription = Editor.Options.Font;
			layout.SetText (string.Format ("0{0:X}", Data.Length) + "_");
			int height;
			layout.GetPixelSize (out this.width, out height);
			layout.Dispose ();
		}
示例#36
0
 public int ComputeRowHeight(Widget widget)
 {
     int lw, lh;
     Pango.Layout layout = new Pango.Layout (widget.PangoContext);
     layout.SetMarkup ("<big>W</big>");
     layout.GetPixelSize (out lw, out lh);
     layout.Dispose ();
     return lh + 8;
 }
        Size GetLayoutSize(Pango.Layout layout)
        {
            int width;
            int height;

            layout.GetPixelSize(out width, out height);

            return(new Size(width, height));
        }
示例#38
0
	public BigList (IListModel provider)
	{
		this.provider = provider;

		//Accessibility
		RefAccessible ().Role = Atk.Role.List;

		adjustment = new Gtk.Adjustment (0, 0, provider.Rows, 1, 1, 1);
		adjustment.ValueChanged += new EventHandler (ValueChangedHandler);

		layout = new Pango.Layout (PangoContext);

		ExposeEvent += new ExposeEventHandler (ExposeHandler);
		ButtonPressEvent += new ButtonPressEventHandler (ButtonPressEventHandler);
		ButtonReleaseEvent += new ButtonReleaseEventHandler (ButtonReleaseEventHandler);
		KeyPressEvent += new KeyPressEventHandler (KeyHandler);
		Realized += new EventHandler (RealizeHandler);
		Unrealized += new EventHandler (UnrealizeHandler);
		ScrollEvent += new ScrollEventHandler (ScrollHandler);
                SizeAllocated += new SizeAllocatedHandler (SizeAllocatedHandler);
		MotionNotifyEvent += new MotionNotifyEventHandler (MotionNotifyEventHandler);

		AddEvents ((int) EventMask.ButtonPressMask | (int) EventMask.ButtonReleaseMask | (int) EventMask.KeyPressMask | (int) EventMask.PointerMotionMask);
		CanFocus = true;

		style_widget = new EventBox ();
		style_widget.StyleSet += new StyleSetHandler (StyleHandler);

		//
		// Compute the height and ellipsis width of the font,
		// and the en_width for our ellipsizing algorithm
		//
		layout.SetMarkup (ellipsis);
		layout.GetPixelSize (out ellipsis_width, out line_height);

		layout.SetMarkup ("n");
		layout.GetPixelSize (out en_width, out line_height);
		
		layout.SetMarkup ("W");
		layout.GetPixelSize (out en_width, out line_height);

		old_width = Allocation.Width;
	}
		internal protected override void OptionsChanged ()
		{
			Pango.Layout layout = new Pango.Layout (Editor.PangoContext);
			layout.FontDescription = Editor.Options.Font;
			layout.SetText (".");
			int height;
			layout.GetPixelSize (out charWidth, out height);
			layout.Dispose ();
			bgGC = GetGC (Style.HexDigitBg);
			fgGC = GetGC (Style.HexDigit);
		}
		internal protected override void OptionsChanged ()
		{
			Pango.Layout layout = new Pango.Layout (Editor.PangoContext);
			layout.FontDescription = Editor.Options.Font;
			string groupString = new string ('0', Editor.Options.GroupBytes * 2);
			layout.SetText (groupString + " ");
			int lineHeight;
			layout.GetPixelSize (out groupWidth, out lineHeight);
			Data.LineHeight = lineHeight;
			
			layout.SetText ("00");
			layout.GetPixelSize (out byteWidth, out lineHeight);
			
			layout.Dispose ();
			
			tabArray = new Pango.TabArray (1, true);
			tabArray.SetTab (0, Pango.TabAlign.Left, groupWidth);
			
			bgGC = GetGC (Style.HexDigitBg);
			fgGC = GetGC (Style.HexDigit);
		}
		internal protected override void OptionsChanged ()
		{
			backgroundGC = GetGC (Style.IconBarBg);
			separatorGC = GetGC (Style.IconBarSeperator);
			
			Pango.Layout layout = new Pango.Layout (Editor.PangoContext);
			layout.FontDescription = Editor.Options.Font;
			layout.SetText ("!");
			int tmp;
			layout.GetPixelSize (out tmp, out this.marginWidth);
			marginWidth *= 12;
			marginWidth /= 10;
			layout.Dispose ();
		}
		protected override bool OnExposeEvent (Gdk.EventExpose evt)
		{
			if (bitmap != null) {
				Gdk.GC gc = Style.LightGC (StateType.Normal);
				GdkWindow.DrawPixbuf (gc, bitmap, 0, 0, 0, 0, bitmap.Width, bitmap.Height, Gdk.RgbDither.None, 0, 0);

				using (Pango.Layout pl = new Pango.Layout (PangoContext)) {
					Pango.FontDescription des = this.Style.FontDescription.Copy();
					pl.FontDescription = des;
					//pl.SetMarkup("<b><span foreground='#cccccc'>" + BuildVariables.PackageVersionLabel + "</span></b>");
					int w,h;
					pl.GetPixelSize (out w, out h);
					GdkWindow.DrawLayout (gc, bitmap.Width - w - 75, 90, pl);
					des.Dispose ();
				}
			}
			return base.OnExposeEvent (evt);
		}
示例#43
0
		protected override bool OnExposeEvent (Gdk.EventExpose evnt)
		{
			Pango.Layout la = new Pango.Layout (PangoContext);
			int w, h;
			if (UseMarkup)
				la.SetMarkup (Text);
			else
				la.SetText (Text);

			la.GetPixelSize (out w, out h);

			int tx = Allocation.X + (int) Xpad + (int) ((float)(Allocation.Width - (int)(Xpad*2) - w) * Xalign);
			int ty = Allocation.Y + (int) Ypad + (int) ((float)(Allocation.Height - (int)(Ypad*2) - h) * Yalign);

			using (var ctx = CairoHelper.Create (evnt.Window)) {
				ctx.SetSourceColor (Style.Text (State).ToCairoColor ());
				ctx.MoveTo (tx, ty);

				// In order to get the same result as in MonoDevelop.Components.DockNotebook.TabStrip.DrawTab()
				// (document tabs) we need to draw using a LinearGradient (because of issues below),
				// but we don't want to mask the actual text here, like in the doc tabs.
				// Therefore we use a LinearGradient and mask only the last vertical pixel line
				// of the label with 0.99 alpha, which forces Cairo to render the whole layout
				// in the desired way.

				// Semi-transparent gradient disables sub-pixel rendering of the label (reverting to grayscale antialiasing).
				// As Mac sub-pixel font rendering looks stronger than grayscale rendering, the label used in pad tabs
				// looked different. We need to simulate same gradient treatment as we have in document tabs.

				using (var lg = new LinearGradient (tx + w - 1, 0, tx + w, 0)) {
					var color = Style.Text (State).ToCairoColor ();
					lg.AddColorStop (0, color);
					color.A = 0.99;
					lg.AddColorStop (1, color);
					ctx.SetSource (lg);
					Pango.CairoHelper.ShowLayout (ctx, la);
				}
			}
			
			la.Dispose ();
			return true;
		}
		public void InitCell (Widget container, bool diffMode, string[] lines, TreePath path)
		{
			if (isDisposed)
				return;
			if (lines == null)
				throw new ArgumentNullException ("lines");
			this.lines = lines;
			this.diffMode = diffMode;
			this.path = path;

			if (diffMode) {
				if (lines != null && lines.Length > 0) {
					int maxlen = -1;
					int maxlin = -1;
					for (int n=0; n<lines.Length; n++) {
						string line = ProcessLine (lines [n]);
						if (line == null)
							throw new Exception ("Line " + n + " from diff was null.");
						if (line.Length > maxlen) {
							maxlen = lines [n].Length;
							maxlin = n;
						}
					}
					DisposeLayout ();
					layout = CreateLayout (container, lines [maxlin]);
					layout.GetPixelSize (out width, out lineHeight);
					height = lineHeight * lines.Length;
					width += LeftPaddingBlock + RightPadding;
				}
				else
					width = height = 0;
			}
			else {
				DisposeLayout ();
				layout = CreateLayout (container, string.Join (Environment.NewLine, lines));
				layout.GetPixelSize (out width, out height);
			}
			FontService.RegisterFontChangedCallback ("Editor", OnDiffFontChanged);
			IdeApp.Preferences.CustomOutputPadFont.Changed += OnTextFontChanged;
		}
示例#45
0
		protected override bool OnExposeEvent (Gdk.EventExpose evnt)
		{
			if (!dropShadowVisible)
				return base.OnExposeEvent (evnt);

			Pango.Layout la = new Pango.Layout (PangoContext);
			int w, h;
			if (UseMarkup)
				la.SetMarkup (Text);
			else
				la.SetText (Text);

			la.GetPixelSize (out w, out h);

			int tx = Allocation.X + (int) Xpad + (int) ((float)(Allocation.Width - (int)(Xpad*2) - w) * Xalign);
			int ty = Allocation.Y + (int) Ypad + (int) ((float)(Allocation.Height - (int)(Ypad*2) - h) * Yalign);
			
			GdkWindow.DrawLayout (Style.TextGC (State), tx, ty, la);
			
			la.Dispose ();
			return true;
		}
示例#46
0
        public virtual int ComputeRowHeight(Widget widget)
        {
            int height;
            int text_w, text_h;

            Pango.Layout layout = new Pango.Layout (widget.PangoContext);
            layout.FontDescription = widget.PangoContext.FontDescription;

            layout.FontDescription.Weight = Pango.Weight.Bold;
            layout.SetText ("W");
            layout.GetPixelSize (out text_w, out text_h);
            height = text_h;

            layout.FontDescription.Weight = Pango.Weight.Normal;
            layout.FontDescription.Size = (int)(layout.FontDescription.Size * Pango.Scale.Small);
            layout.FontDescription.Style = Pango.Style.Italic;
            layout.SetText ("W");
            layout.GetPixelSize (out text_w, out text_h);
            height += text_h;

            layout.Dispose ();

            return (height < image_size ? image_size : height) + 6;
        }
示例#47
0
        void DrawCursorLabel(ChartCursor cursor)
        {
            Gdk.GC gc = new Gdk.GC (GdkWindow);
               		gc.RgbFgColor = cursor.Color;

            int x, y;
            GetPoint (cursor.Value, cursor.Value, out x, out y);

            if (cursor.Dimension == AxisDimension.X) {

                string text;

                if (cursor.LabelAxis != null) {
                    double minStep = GetMinTickStep (cursor.Dimension);
                    TickEnumerator tenum = cursor.LabelAxis.GetTickEnumerator (minStep);
                    tenum.Init (cursor.Value);
                    text = tenum.CurrentLabel;
                } else {
                    text = GetValueLabel (cursor.Dimension, cursor.Value);
                }

                if (text != null && text.Length > 0) {
                    Pango.Layout layout = new Pango.Layout (this.PangoContext);
                    layout.FontDescription = Pango.FontDescription.FromString ("Tahoma 8");
                    layout.SetMarkup (text);

                    int tw, th;
                    layout.GetPixelSize (out tw, out th);
                    int tl = x - tw/2;
                    int tt = top + 4;
                    if (tl + tw + 2 >= left + width) tl = left + width - tw - 1;
                    if (tl < left + 1) tl = left + 1;
                    GdkWindow.DrawRectangle (Style.WhiteGC, true, tl - 1, tt - 1, tw + 2, th + 2);
                    GdkWindow.DrawRectangle (Style.BlackGC, false, tl - 2, tt - 2, tw + 3, th + 3);
                    GdkWindow.DrawLayout (gc, tl, tt, layout);
                }
            } else {
                throw new NotSupportedException ();
            }
        }
示例#48
0
		internal LayoutDescriptor CreateLayoutDescriptor (ErrorText errorText)
		{
			LayoutDescriptor result;
			if (!textWidthDictionary.TryGetValue (errorText.ErrorMessage, out result)) {
				Pango.Layout layout = new Pango.Layout (editor.PangoContext);
				layout.FontDescription = fontDescription;
				layout.SetText (GetFirstLine (errorText));
				int w, h;
				layout.GetPixelSize (out w, out h);
				textWidthDictionary[errorText.ErrorMessage] = result = new LayoutDescriptor (layout, w, h);
			}
			return result;
		}
示例#49
0
		void DrawString (string text, bool isMarkup, Cairo.Context context, int x, int y, int width, double opacity, Pango.Context pango, StatusArea.RenderArg arg)
		{
			Pango.Layout pl = new Pango.Layout (pango);
			if (isMarkup)
				pl.SetMarkup (text);
			else
				pl.SetText (text);
			pl.FontDescription = Styles.StatusFont;
			pl.FontDescription.AbsoluteSize = Pango.Units.FromPixels (Styles.StatusFontPixelHeight);
			pl.Ellipsize = Pango.EllipsizeMode.End;
			pl.Width = Pango.Units.FromPixels(width);

			int w, h;
			pl.GetPixelSize (out w, out h);

			context.Save ();
			// use widget height instead of message box height as message box does not have a true height when no widgets are packed in it
			// also ensures animations work properly instead of getting clipped
			context.Rectangle (new Rectangle (x, arg.Allocation.Y, width, arg.Allocation.Height));
			context.Clip ();

			// Subtract off remainder instead of drop to prefer higher centering when centering an odd number of pixels
			context.MoveTo (x, y - h / 2 - (h % 2));
			context.Color = Styles.WithAlpha (FontColor (), opacity);

			Pango.CairoHelper.ShowLayout (context, pl);
			pl.Dispose ();
			context.Restore ();
		}
示例#50
0
			protected override void OnDrawContent (Gdk.EventExpose evnt, Cairo.Context g)
			{
				g.Rectangle (0, 0, Allocation.Width, Allocation.Height);
				g.SetSourceColor (marker.TooltipColor.Color);
				g.Fill ();

				using (var drawingLayout = new Pango.Layout (this.PangoContext)) {
					drawingLayout.FontDescription = cache.tooltipFontDescription;

					double y = verticalTextBorder;
					var showBulletedList = marker.Errors.Count > 1;

					foreach (var msg in marker.Errors) {
						var icon = msg.IsError ? errorPixbuf : warningPixbuf;
						int w, h;

						if (!showBulletedList)
							drawingLayout.Width = maxTextWidth;

						drawingLayout.SetText (GetFirstLine (msg));
						drawingLayout.GetPixelSize (out w, out h);

						if (showBulletedList) {
							g.Save ();

							g.Translate (textBorder, y + verticalTextSpace / 2 + Math.Max (0, (h - icon.Height) / 2));
							g.DrawImage (this, icon, 0, 0);
							g.Restore ();
						}

						g.Save ();

						g.Translate (showBulletedList ? textBorder + iconTextSpacing + icon.Width: textBorder, y + verticalTextSpace / 2);
						g.SetSourceColor (marker.TagColor.SecondColor);
						g.ShowLayout (drawingLayout);

						g.Restore ();

						y += h + verticalTextSpace;
					}
				}
			}
		public override void DrawAfterEol (TextEditor textEditor, Cairo.Context g, double y, EndOfLineMetrics metrics)
		{
			if (!IsVisible)
				return;
			EnsureLayoutCreated (editor);
			int errorCounterWidth = 0, eh = 0;
			if (errorCountLayout != null) {
				errorCountLayout.GetPixelSize (out errorCounterWidth, out eh);
				errorCounterWidth = Math.Max (15, Math.Max (errorCounterWidth + 3, (int)(editor.LineHeight * 3 / 4)));
			}

			var sx = metrics.TextRenderEndPosition;
			var width = LayoutWidth + errorCounterWidth + editor.LineHeight;
			var drawLayout = layouts[0].Layout;
			int ex = 0 , ey = 0;
			bool customLayout = true; //sx + width > editor.Allocation.Width;
			bool hideText = false;
			bubbleIsReduced = customLayout;
			var showErrorCount = errorCounterWidth > 0 && errorCountLayout != null;
			if (customLayout) {
				width = editor.Allocation.Width - sx;
				string text = layouts[0].Layout.Text;
				drawLayout = new Pango.Layout (editor.PangoContext);
				drawLayout.FontDescription = cache.fontDescription;
				var paintWidth = (width - errorCounterWidth - editor.LineHeight + 4);
				var minWidth = Math.Max (17, errorCounterWidth) + editor.LineHeight;
				if (paintWidth < minWidth) {
					hideText = true;
					drawLayout.SetMarkup ("<span weight='heavy'>···</span>");
					width = minWidth;
					showErrorCount = false;
					sx = Math.Min (sx, editor.Allocation.Width - width);
				} else {
					drawLayout.Ellipsize = Pango.EllipsizeMode.End;
					drawLayout.Width = (int)(paintWidth * Pango.Scale.PangoScale);
					drawLayout.SetText (text);
					int w2, h2;
					drawLayout.GetPixelSize (out w2, out h2);
					width = w2 + errorCounterWidth + editor.LineHeight;
				}
			}
			bubbleDrawX = sx - editor.TextViewMargin.XOffset;
			bubbleDrawY = y;
			bubbleWidth = width;

			var bubbleHeight = editor.LineHeight - 1;
			g.RoundedRectangle (sx, y + 1, width, bubbleHeight, editor.LineHeight / 2 - 1);
			g.SetSourceColor (TagColor.Color);
			g.Fill ();

			// Draw error count icon
			if (showErrorCount) {
				var errorCounterHeight = bubbleHeight - 2;
				var errorCounterX = sx + width - errorCounterWidth - 3;
				var errorCounterY = y + 1 + (bubbleHeight - errorCounterHeight) / 2;

				g.RoundedRectangle (
					errorCounterX - 1, 
					errorCounterY - 1, 
					errorCounterWidth + 2, 
					errorCounterHeight + 2, 
					editor.LineHeight / 2 - 3
				);

				g.SetSourceColor (new Cairo.Color (0, 0, 0, 0.081));
				g.Fill ();

				g.RoundedRectangle (
					errorCounterX, 
					errorCounterY, 
					errorCounterWidth, 
					errorCounterHeight, 
					editor.LineHeight / 2 - 3
				);
				using (var lg = new Cairo.LinearGradient (errorCounterX, errorCounterY, errorCounterX, errorCounterY + errorCounterHeight)) {
					lg.AddColorStop (0, CounterColor.Color);
					lg.AddColorStop (1, CounterColor.Color.AddLight (-0.1));
					g.Pattern = lg;
					g.Fill ();
				}

				g.Save ();

				int ew;
				errorCountLayout.GetPixelSize (out ew, out eh);

				g.Translate (
					errorCounterX + (errorCounterWidth - ew) / 2,
					errorCounterY + (errorCounterHeight - eh) / 2
				);
				g.SetSourceColor (CounterColor.SecondColor);
				g.ShowLayout (errorCountLayout);
				g.Restore ();
			}

			// Draw label text
			if (!showErrorCount || !hideText) {
				g.Save ();
				g.Translate (sx + editor.LineHeight / 2, y + (editor.LineHeight - layouts [0].Height) / 2 + 1);

				// draw shadow
				g.SetSourceColor (MessageBubbleCache.ShadowColor);
				g.ShowLayout (drawLayout);
				g.Translate (0, -1);

				g.SetSourceColor (TagColor.SecondColor);
				g.ShowLayout (drawLayout);
				g.Restore ();
			}

			if (customLayout)
				drawLayout.Dispose ();

		}
示例#52
0
		protected override bool OnExposeEvent (EventExpose evnt)
		{
			var ret = base.OnExposeEvent (evnt);
			if (image.Pixbuf != null)
				return ret;
			
			using (var cr = CairoHelper.Create (evnt.Window)) {
				cr.Rectangle (evnt.Region.Clipbox.X, evnt.Region.Clipbox.Y, evnt.Region.Clipbox.Width, evnt.Region.Clipbox.Height);
				cr.Clip ();
				var imgAlloc = image.Allocation;
				cr.Translate (imgAlloc.X, imgAlloc.Y);
				
				using (var layout = new Pango.Layout (PangoContext)) {
					layout.SetText (GettextCatalog.GetString ("No image"));
				
					layout.Width = (int)((imgAlloc.Width - 20) * Pango.Scale.PangoScale);
					layout.Wrap = Pango.WrapMode.WordChar;
					layout.Alignment = Pango.Alignment.Center;
					int pw, ph;
					layout.GetPixelSize (out pw, out ph);
					cr.MoveTo ((imgAlloc.Width - layout.Width / Pango.Scale.PangoScale) / 2, (imgAlloc.Height - ph) / 2);
					cr.Color = new Cairo.Color (0.5, 0.5, 0.5);
					cr.ShowLayout (layout);
				}
				
				CairoExtensions.RoundedRectangle (cr, 5, 5, imgAlloc.Width - 10, imgAlloc.Height - 10, 5);
				cr.LineWidth = 3;
				cr.Color = new Cairo.Color (0.8, 0.8, 0.8);
				cr.SetDash (new double[] { 12, 2 }, 0);
				cr.Stroke ();
			}
			return ret;
		}
示例#53
0
			protected override void OnSizeRequested (ref Gtk.Requisition requisition)
			{
				base.OnSizeRequested (ref requisition);
				double y = verticalTextBorder * 2 - verticalTextSpace + (MonoDevelop.Core.Platform.IsWindows ? 10 : 2);

				using (var drawingLayout = new Pango.Layout (this.PangoContext)) {
					drawingLayout.FontDescription = cache.tooltipFontDescription;

					foreach (var msg in marker.Errors) {
						if (marker.Layouts.Count == 1) 
							drawingLayout.Width = maxTextWidth;
						drawingLayout.SetText (GetFirstLine (msg));
						int w;
						int h;
						drawingLayout.GetPixelSize (out w, out h);
						if (marker.Layouts.Count > 1) 
							w += (int)warningPixbuf.Width + iconTextSpacing;

						requisition.Width = Math.Max (w + textBorder * 2, requisition.Width);
						y += h + verticalTextSpace - 3;
					}
				}

				requisition.Height = (int)y;
			}
		void EnsureLayoutCreated (TextEditor editor)
		{
			if (editor.ColorStyle != null) {
				bool isError = errors.Any (e => e.IsError);
				
				string typeString = isError ? "error" : "warning";
				
				gc = (HslColor)(editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".text").Color);
				
				gcSelected = (HslColor)editor.ColorStyle.Selection.Color;
				
				gcLight = new Cairo.Color (1, 1, 1);
				
				
				colorMatrix[0, 0, 0, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".light.color1").Color);
				colorMatrix[0, 1, 0, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".light.color2").Color);
				
				colorMatrix[0, 0, 1, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".dark.color1").Color);
				colorMatrix[0, 1, 1, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".dark.color2").Color);
				
				colorMatrix[0, 0, 2, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".line.top").Color);
				colorMatrix[0, 1, 2, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble." + typeString + ".line.bottom").Color);
				
				colorMatrix[1, 0, 0, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".light.color1").Color);
				colorMatrix[1, 1, 0, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".light.color2").Color);
				
				colorMatrix[1, 0, 1, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".dark.color1").Color);
				colorMatrix[1, 1, 1, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".dark.color2").Color);
				
				colorMatrix[1, 0, 2, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".line.top").Color);
				colorMatrix[1, 1, 2, 0, 0] = Mono.TextEditor.Highlighting.Style.ToCairoColor (editor.ColorStyle.GetChunkStyle ("bubble.inactive." + typeString + ".line.bottom").Color);
				
				double factor = 1.03;
				for (int i = 0; i < 2; i++) {
					for (int j = 0; j < 2; j++) {
						for (int k = 0; k < 3; k++) {
							HslColor color = colorMatrix[i, j, k, 0, 0];
							color.L *= factor;
							colorMatrix[i, j, k, 1, 0] = color;
						}
					}
				}
				var selectionColor = Style.ToCairoColor (editor.ColorStyle.Selection.BackgroundColor);
				for (int i = 0; i < 2; i++) {
					for (int j = 0; j < 2; j++) {
						for (int k = 0; k < 3; k++) {
							for (int l = 0; l < 2; l++) {
								var color = colorMatrix[i, j, k, l, 0];
								colorMatrix[i, j, k, l, 1] = new Cairo.Color ((color.R + selectionColor.R * 1.5) / 2.5, (color.G + selectionColor.G * 1.5) / 2.5, (color.B + selectionColor.B * 1.5) / 2.5);
							}
						}
					}
				}
			}
			
			if (layouts != null)
				return;
			
			layouts = new List<LayoutDescriptor> ();
			fontDescription = Pango.FontDescription.FromString (editor.Options.FontName);
			var label = new Gtk.Label ("");
			fontDescription.Family = label.Style.FontDescription.Family;
			label.Destroy ();
			fontDescription.Size = (int)(fontDescription.Size * 0.9f * editor.Options.Zoom);
			foreach (ErrorText errorText in errors) {
				Pango.Layout layout = new Pango.Layout (editor.PangoContext);
				layout.FontDescription = fontDescription;
				layout.SetText (errorText.ErrorMessage);
				
				KeyValuePair<int, int> textSize;
				if (!textWidthDictionary.TryGetValue (errorText.ErrorMessage, out textSize)) {
					int w, h;
					layout.GetPixelSize (out w, out h);
					textSize = new KeyValuePair<int, int> (w, h);
					textWidthDictionary[errorText.ErrorMessage] = textSize;
				}
				layouts.Add (new LayoutDescriptor (layout, textSize.Key, textSize.Value));
			}
			
			if (errorCountLayout == null && errors.Count > 1) {
				errorCountLayout = new Pango.Layout (editor.PangoContext);
				errorCountLayout.FontDescription = fontDescription;
				errorCountLayout.SetText (errors.Count.ToString ());
			}
		}
示例#55
0
		public Tab (Tabstrip parent, string label, TabPosition tabPosition)
		{
			this.parent = parent;
			this.Label = label;
			layout = PangoUtil.CreateLayout (parent);
			layout.SetText (label);
			layout.GetPixelSize (out w, out h);

			if (IsSeparator)
				w = SpacerWidth * 2;
			
			this.TabPosition = tabPosition;
		}
示例#56
0
 private int ComputeWidgetHeight()
 {
     int width, height;
     Pango.Layout layout = new Pango.Layout (PangoContext);
     layout.SetText ("W");
     layout.GetPixelSize (out width, out height);
     layout.Dispose ();
     return 2 * height;
 }
		public override void DrawAfterEol (TextEditor textEditor, Cairo.Context g, double y, EndOfLineMetrics metrics)
		{
			EnsureLayoutCreated (editor);
			int errorCounterWidth = 0, eh = 0;
			if (errorCountLayout != null) 
				errorCountLayout.GetPixelSize (out errorCounterWidth, out eh);

			var sx = metrics.TextRenderEndPosition;
			var width = LayoutWidth + errorCounterWidth + editor.LineHeight;
			var drawLayout = layouts[0].Layout;
			int ex = 0 , ey = 0;
			bool customLayout = sx + width > editor.Allocation.Width;
			bool hideText = false;
			bubbleIsReduced = customLayout;
			if (customLayout) {
				width = editor.Allocation.Width - sx;
				string text = layouts[0].Layout.Text;
				drawLayout = new Pango.Layout (editor.PangoContext);
				drawLayout.FontDescription = cache.fontDescription;
				for (int j = text.Length - 4; j > 0; j--) {
					drawLayout.SetText (text.Substring (0, j) + "...");
					drawLayout.GetPixelSize (out ex, out ey);
					if (ex + (errorCountLayout != null ? errorCounterWidth : 0) + editor.LineHeight < width)
						break;
				}
				if (ex + (errorCountLayout != null ? errorCounterWidth : 0) + editor.LineHeight > width) {
					hideText = true;
					drawLayout.SetMarkup ("<span weight='heavy'>···</span>");
					width = Math.Max (17, errorCounterWidth) + editor.LineHeight;
					sx = Math.Min (sx, editor.Allocation.Width - width);
				}
			}
			bubbleDrawX = sx - editor.TextViewMargin.XOffset;
			bubbleDrawY = y;
			bubbleWidth = width;
			g.RoundedRectangle (sx, y + 1, width, editor.LineHeight - 2, editor.LineHeight / 2 - 1);
			g.Color = TagColor.Color;
			g.Fill ();

			if (errorCounterWidth > 0 && errorCountLayout != null) {
				g.RoundedRectangle (sx + width - errorCounterWidth - editor.LineHeight / 2, y + 2, errorCounterWidth, editor.LineHeight - 4, editor.LineHeight / 2 - 3);
				g.Color = CounterColor.Color;
				g.Fill ();

				g.Save ();
				g.Translate (sx + width - errorCounterWidth - editor.LineHeight / 2 + (errorCounterWidth - errorCounterWidth) / 2, y + 1);
				g.Color = CounterColor.SecondColor;
				g.ShowLayout (errorCountLayout);
				g.Restore ();
			}

			if (errorCounterWidth <= 0 || errorCountLayout == null || !hideText) {
				g.Save ();
				g.Translate (sx + editor.LineHeight / 2, y + (editor.LineHeight - layouts [0].Height) / 2 + layouts [0].Height % 2);
				g.Color = TagColor.SecondColor;
				g.ShowLayout (drawLayout);
				g.Restore ();
			}

			if (customLayout)
				drawLayout.Dispose ();

		}
		public void AddOverload (CompletionData data)
		{
			var tooltipInformation = data.CreateTooltipInformation (false);
			if (string.IsNullOrEmpty (tooltipInformation.SignatureMarkup))
				return;

			using (var layout = new Pango.Layout (PangoContext)) {
				var des = FontService.GetFontDescription ("Editor");
				layout.FontDescription = des;
				layout.SetMarkup (tooltipInformation.SignatureMarkup);
				int w, h;
				layout.GetPixelSize (out w, out h);
				if (w >= Allocation.Width - 10) {
					tooltipInformation = data.CreateTooltipInformation (true);
				}
			}
			AddOverload (tooltipInformation);
		}
示例#59
0
        int MeasureTicksSize(TickEnumerator e, AxisDimension ad)
        {
            int max = 0;
            Pango.Layout layout = new Pango.Layout (this.PangoContext);
            layout.FontDescription = Pango.FontDescription.FromString ("Tahoma 8");

            double start = GetStart (ad);
            double end = GetEnd (ad);

            e.Init (GetOrigin (ad));

            while (e.CurrentValue > start)
                e.MovePrevious ();

            for ( ; e.CurrentValue <= end; e.MoveNext ())
            {
                int tw = 0, th = 0;

                layout.SetMarkup (e.CurrentLabel);
                layout.GetPixelSize (out tw, out th);

                if (ad == AxisDimension.X) {
                    if (th > max)
                        max = th;
                } else {
                    if (tw > max)
                        max = tw;
                }
            }
            return max;
        }
        protected virtual void OnTvFontsDrawItem(object sender, HollyLibrary.DrawItemEventArgs args)
        {
            //draw each font
            String font_name     = TvFonts.Items[ args.ItemIndex ].ToString();

            Pango.Layout l = new Pango.Layout( this.PangoContext );
            l.SetText( font_name );
            l.FontDescription = Pango.FontDescription.FromString( font_name );
            int width, height;
            l.GetPixelSize( out width, out height );

            args.Drawable.DrawLayout( this.Style.TextGC( this.State ) , args.CellArea.X, args.CellArea.Y + (height/2), l );
        }