コード例 #1
0
ファイル: MemMapWidget.cs プロジェクト: schustercp/MemMap
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            Gdk.Window    win  = args.Window;
            Gdk.Rectangle area = args.Area;


            win.DrawRectangle(Style.DarkGC(StateType.Normal), true, area);
            win.DrawRectangle(Style.BlackGC, false, area);
            win.DrawRectangle(Style.MidGC(StateType.Normal), true, 0, 15, 1000, 1000);
            win.DrawLine(Style.BlackGC, 0, 15, 1000, 15);
            //win.DrawLayout(Style.BlackGC,2,2,titleLayout);

            if (!string.IsNullOrEmpty(body))
            {
                win.DrawLayout(Style.BlackGC, 2, 17, GetLayout(body));
            }
            return(true);
        }
        public static void DrawLayout(Gdk.Window win, Gdk.GC gc, Pango.Layout layout, float x, float y, Origin vertical = Origin.Far, Origin horizontal = Origin.Center)
        {
            if (horizontal != Origin.Near || vertical != Origin.Near)
            {
                int width, height;
                layout.GetPixelSize(out width, out height);

                switch (horizontal)
                {
                case Origin.Near:  /*nothing to do*/
                    break;

                case Origin.Center:
                    x -= width / 2;
                    break;

                case Origin.Far:
                    x -= width;
                    break;
                }

                switch (vertical)
                {
                case Origin.Near:  /*nothing to do*/
                    break;

                case Origin.Center:
                    y -= height / 2;
                    break;

                case Origin.Far:
                    y -= height;
                    break;
                }
            }
            win.DrawLayout(gc, (int)x, (int)y, layout);
        }
コード例 #3
0
        protected void OnDrawingareaExposeEvent(object o, Gtk.ExposeEventArgs args)
        {
            Gdk.EventExpose expose = args.Args[0] as Gdk.EventExpose;
            Gdk.Window      win = expose.Window;
            int             width, height;

            win.GetSize(out width, out height);
            Gdk.Rectangle exposeRect = expose.Area;
            bool          fulldraw   = width == exposeRect.Width && height == exposeRect.Height;

            win.DrawRectangle(Style.LightGC(StateType.Normal), true, exposeRect);
            if (GetContentDelegate == null)
            {
                return; // todo: an error message could be displayed
            }
            int offset = (int)vscrollbar1.Value;

            if (fulldraw)
            {
                TopVisibleRow    = offset;
                BottomVisibleRow = offset;
            }
            int hscrollRange = 0;
            int dy           = exposeRect.Top;

            offset += dy / ConstantHeight;
            dy     -= dy % ConstantHeight;

            Gdk.GC backgound = new Gdk.GC((Gdk.Drawable)base.GdkWindow);
            Gdk.GC text      = new Gdk.GC((Gdk.Drawable)base.GdkWindow);

            ColumnControl.Column[] columns = mColumnControl.GetVisibleColumnsInDrawOrder();

            for (int row = offset; row < RowCount; row++)
            {
                int           dx   = -(int)hscrollbar1.Value;
                Gdk.Rectangle rect = new Gdk.Rectangle(dx, dy, 0, ConstantHeight);

                System.Drawing.Color backColor = System.Drawing.Color.WhiteSmoke;
                System.Drawing.Color textColor = System.Drawing.Color.Black;

                if (isRowSelected(row))
                {
                    if (HasFocus)
                    {
                        backColor = System.Drawing.Color.DarkGray;
                    }
                    else
                    {
                        backColor = System.Drawing.Color.LightGray;
                    }
                }
                else
                {
                    if (GetColorDelegate != null)
                    {
                        GetColorDelegate(row, ref backColor, ref textColor);
                    }
                }

                backgound.RgbFgColor = new Gdk.Color(backColor.R, backColor.G, backColor.B);
                text.RgbFgColor      = new Gdk.Color(textColor.R, textColor.G, textColor.B);

                for (int c = 0; c < columns.Length; c++)
                {
                    ColumnControl.Column column = columns[c];
                    int columnIndex             = column.SortOrder;
                    int xwidth = column.Width;
                    if (dx > exposeRect.Right)
                    {
                        break;
                    }
                    rect = new Gdk.Rectangle(rect.Left, rect.Top, xwidth + mColumnControl.GripperWidth, ConstantHeight);
                    if (c == columns.Length - 1)
                    {
                        rect.Width = Math.Max(rect.Width, exposeRect.Right - rect.Left + 1);
                    }
                    object content = GetContentDelegate(row, columnIndex);
                    if (content is Gdk.Pixbuf)
                    {
                        Gdk.Pixbuf image = (Gdk.Pixbuf)content;
                        win.DrawRectangle(backgound, true, rect);
                        dx += 2;
                        image.RenderToDrawable(win, text, 0, 0, dx, dy, image.Width, image.Height, Gdk.RgbDither.Normal, 0, 0);
                        dx += xwidth + mColumnControl.GripperWidth - 2;
                        rect.Offset(xwidth + mColumnControl.GripperWidth, 0);
                    }
                    else
                    {
                        LineLayout.SetText(content.ToString());
                        win.DrawRectangle(backgound, true, rect);
                        dx += 2;
                        win.DrawLayout(text, dx, dy, LineLayout);
                        dx += xwidth + mColumnControl.GripperWidth - 2;
                        rect.Offset(xwidth + mColumnControl.GripperWidth, 0);
                    }
                }
                hscrollRange = Math.Max(hscrollRange, dx + rect.Width);
                dy          += ConstantHeight;
                if (dy > exposeRect.Bottom)
                {
                    break;
                }
                if (fulldraw && exposeRect.Height - dy >= ConstantHeight)
                {
                    BottomVisibleRow++;
                }
            }

            if (fulldraw)
            {
                int pageSize = BottomVisibleRow - TopVisibleRow;
                if (vscrollbar1.Adjustment.PageSize != pageSize)
                {
                    vscrollbar1.Adjustment.PageSize      = pageSize;
                    vscrollbar1.Adjustment.PageIncrement = pageSize;
                }
                hscrollRange += (int)hscrollbar1.Value;
                if (hscrollRange > 0)
                {
                    hscrollbar1.SetRange(0, hscrollRange);
                }

                // position current row inside visible area
                // TODO: please think about, because of double redraw a more sophisticated solution could be possible
                if (CurrentRow >= 0 && CurrentRow < RowCount)
                {
                    if (CurrentRow < TopVisibleRow)
                    {
                        OffsetCursor(TopVisibleRow - CurrentRow);
                    }
                    else if (CurrentRow > BottomVisibleRow)
                    {
                        OffsetCursor(BottomVisibleRow - CurrentRow);
                    }
                }
            }

#if DEBUG2
            if (ComponentManager != null)
            {
                String t1 = String.Format("Expose.Area={0}, size={1}.{2}",
                                          expose.Area.ToString(), width, height);
                String t2 = String.Format("{0} T={1} B={2}", fulldraw ? "FULL" : "PART", TopVisibleRow, BottomVisibleRow);
                ComponentManager.MessageWriteLineInvoke(String.Format("{0} {1}", t1, t2));
            }
#endif
        }