示例#1
0
        public override void Draw(ChartRenderer gfx)
        {
            if (gfx == null)
            {
                return;
            }

            /* Render the top icon without scaling. */
            ExtRect sourceRect      = ExtRect.CreateBounds(0, 0, Width, SCALE_Y1 + SHADOW_TOP);
            ExtRect destinationRect = ExtRect.CreateBounds(fDestRect.Left, fDestRect.Top,
                                                           Width, SCALE_Y1 + SHADOW_TOP);

            gfx.DrawImage(fControlsImage, destinationRect, sourceRect);
            /* Render the bottom icon without scaling. */
            sourceRect      = ExtRect.CreateBounds(0, SCALE_Y2, Width, Height - (SCALE_Y2 + SHADOW_BOTTOM));
            destinationRect = ExtRect.CreateBounds(fDestRect.Left,
                                                   fDestRect.Bottom - (Height - (SCALE_Y2 + SHADOW_BOTTOM)),
                                                   Width, Height - (SCALE_Y2 + SHADOW_BOTTOM));
            gfx.DrawImage(fControlsImage, destinationRect, sourceRect);

            /* Render the vertical bar with scaling of Y's (there's still no
             * scaling for X's). Image source must ignore some shadows at the
             * top and bottom. */
            sourceRect      = ExtRect.CreateBounds(0, SCALE_Y1 + SHADOW_TOP, Width, Height - (SCALE_Y2 + SHADOW_BOTTOM));
            destinationRect = ExtRect.CreateBounds(fDestRect.Left, fDestRect.Top + SCALE_Y1 + SHADOW_TOP, Width,
                                                   fDestRect.Bottom - (Height - (SCALE_Y2 + SHADOW_BOTTOM)) - (fDestRect.Top + SCALE_Y1 + SHADOW_TOP));
            gfx.DrawImage(fControlsImage, destinationRect, sourceRect);
            if (fDCount > 0)
            {
                gfx.DrawImage(fControlsImage, GetDRect(fThumbPos), THUMB_RECT);
            }
        }
示例#2
0
        private void InternalDraw(ChartDrawMode drawMode, BackgroundMode background)
        {
            // drawing relative offset of tree on graphics
            int spx = 0;
            int spy = 0;

            Size     clientSize = ClientSize;
            ExtPoint scrollPos  = new ExtPoint(Math.Abs(AutoScrollPosition.X), Math.Abs(AutoScrollPosition.Y));

            if (drawMode == ChartDrawMode.dmInteractive)
            {
                spx += -scrollPos.X;
                spy += -scrollPos.Y;

                Rectangle viewPort = GetImageViewPort();
                fModel.VisibleArea = ExtRect.CreateBounds(scrollPos.X, scrollPos.Y, viewPort.Width, viewPort.Height);
            }
            else
            {
                fModel.VisibleArea = ExtRect.CreateBounds(0, 0, fModel.ImageWidth, fModel.ImageHeight);
            }

            if (drawMode == ChartDrawMode.dmInteractive || drawMode == ChartDrawMode.dmStaticCentered)
            {
                if (fModel.ImageWidth < clientSize.Width)
                {
                    spx += (clientSize.Width - fModel.ImageWidth) / 2;
                }

                if (fModel.ImageHeight < clientSize.Height)
                {
                    spy += (clientSize.Height - fModel.ImageHeight) / 2;
                }
            }

            fModel.SetOffsets(spx, spy);

            DrawBackground(background);

            #if DEBUG_IMAGE
            using (Pen pen = new Pen(Color.Red)) {
                fRenderer.DrawRectangle(pen, Color.Transparent, fSPX, fSPY, fImageWidth, fImageHeight);
            }
            #endif

            bool hasDeep = (fSelected != null && fSelected != fModel.Root && fSelected.Rec != null);

            if (hasDeep && fOptions.DeepMode == DeepMode.Background)
            {
                DrawDeep(fOptions.DeepMode, spx, spy);
            }

            fRenderer.SetTranslucent(0.0f);
            fModel.Draw(drawMode);

            if (hasDeep && fOptions.DeepMode == DeepMode.Foreground)
            {
                DrawDeep(fOptions.DeepMode, spx, spy);
            }
        }
示例#3
0
        public bool Build(byte maxDoors, byte minSize, byte maxSize, ExtRect area)
        {
            try {
                int hr = RandomHelper.GetBoundedRnd(minSize, maxSize);
                int wr = RandomHelper.GetBoundedRnd(minSize, maxSize);
                int tH = area.Height - hr;
                int tW = area.Width - wr;

                int tries = TryCount;
                while (tries > 0)
                {
                    int     x  = area.Left + RandomHelper.GetBoundedRnd(0, tW);
                    int     y  = area.Top + RandomHelper.GetBoundedRnd(0, tH);
                    ExtRect br = ExtRect.CreateBounds(x, y, wr, hr);

                    if (CanBuild(br, area))
                    {
                        Area = br;
                        if (maxDoors > 0)
                        {
                            BuildDoors(maxDoors, br);
                        }
                        Flush();

                        return(true);
                    }
                    tries--;
                }
            } catch (Exception ex) {
                Logger.Write("Building.build(): " + ex.Message);
            }

            return(false);
        }
示例#4
0
        private ExtRect GetDRect(int stepIndex)
        {
            int step     = fDestRect.Height / D_COUNT;
            int thumbTop = fDestRect.Top + stepIndex * step;

            return(ExtRect.CreateBounds(fDestRect.Left, thumbTop, fDestRect.Width, step));
        }
示例#5
0
        private void InternalDraw(ChartDrawMode drawMode, BackgroundMode background)
        {
            // drawing relative offset of tree on graphics
            int spx = 0;
            int spy = 0;

            if (drawMode == ChartDrawMode.dmInteractive)
            {
                var imageViewport = base.ImageViewport;
                spx = imageViewport.Left;
                spy = imageViewport.Top;
                fModel.VisibleArea = UIHelper.Rt2Rt(base.Viewport);
            }
            else
            {
                if (drawMode == ChartDrawMode.dmStaticCentered)
                {
                    Size clientSize = CanvasRectangle.Size;

                    if (fModel.ImageWidth < clientSize.Width)
                    {
                        spx += (clientSize.Width - fModel.ImageWidth) / 2;
                    }

                    if (fModel.ImageHeight < clientSize.Height)
                    {
                        spy += (clientSize.Height - fModel.ImageHeight) / 2;
                    }
                }

                fModel.VisibleArea = ExtRect.CreateBounds(0, 0, fModel.ImageWidth, fModel.ImageHeight);
            }

            fModel.SetOffsets(spx, spy);

            DrawBackground(background);

#if DEBUG_IMAGE
            using (Pen pen = new Pen(Color.Red)) {
                fRenderer.DrawRectangle(pen, Color.Transparent, fSPX, fSPY, fImageWidth, fImageHeight);
            }
#endif

            bool hasDeep = (fSelected != null && fSelected != fModel.Root && fSelected.Rec != null);

            if (hasDeep && fOptions.DeepMode == DeepMode.Background)
            {
                DrawDeep(fOptions.DeepMode, spx, spy);
            }

            fRenderer.SetTranslucent(0.0f);
            fModel.Draw(drawMode);

            if (hasDeep && fOptions.DeepMode == DeepMode.Foreground)
            {
                DrawDeep(fOptions.DeepMode, spx, spy);
            }
        }
示例#6
0
        private ExtRect GetDRect(int stepIndex)
        {
            int availableHeight = fDestRect.Height - (SCALE_Y1 + (Height - SCALE_Y2));
            int step            = availableHeight / fDCount;
            int thumpTop        = Math.Min(fDestRect.Top + SCALE_Y1 + stepIndex * step,
                                           fDestRect.Bottom - (Height - SCALE_Y2) - THUMB_RECT.Height);

            return(ExtRect.CreateBounds(fDestRect.Left, thumpTop, fDestRect.Width, THUMB_RECT.Height));
        }
示例#7
0
        public override void UpdateView()
        {
            ExtRect cr = fChart.GetClientRect();

            int height = Math.Min(cr.GetHeight() - (PADDING_Y << 1), RADIUS);
            int width  = (int)GetChordLength(height, (float)(SEGMENT_ANGLE * (Math.PI / 180.0f)));

            fDestRect = ExtRect.CreateBounds(cr.Left + PADDING_X,
                                             cr.Top + Math.Max(PADDING_Y, (cr.GetHeight() - height) >> 1),
                                             width, height);
        }
示例#8
0
        public void SetPerson(TreeChartPerson person)
        {
            if (person == null)
            {
                return;
            }
            fPerson = person;

            ExtPoint offsets = fChart.GetOffsets();
            ExtRect  rt      = fPerson.Rect.GetOffset(offsets.X, offsets.Y);

            rt        = ExtRect.CreateBounds(rt.Right, rt.Top, 40, rt.Height);
            fDestRect = rt;
        }
示例#9
0
        public void CalcBounds(int lines, ChartRenderer renderer)
        {
            try
            {
                InitInfo(lines);
                DefineExpands();

                int maxwid = 0;
                for (int k = 0; k < lines; k++)
                {
                    int wt = renderer.GetTextWidth(Lines[k], fModel.DrawFont);
                    if (maxwid < wt)
                    {
                        maxwid = wt;
                    }
                }

                int pad2side = (fModel.NodePadding * 2);

                fWidth  = pad2side + maxwid;
                fHeight = pad2side + renderer.GetTextHeight(fModel.DrawFont) * lines;

                if (fPortrait != null)
                {
                    ExtRect portRt = ExtRect.Create(0, 0, fHeight - 1, fHeight - 1);
                    portRt.Inflate(3, 3);

                    int   rtW   = portRt.GetWidth();
                    int   rtH   = portRt.GetHeight();
                    int   imgW  = fPortrait.Width;
                    int   imgH  = fPortrait.Height;
                    float ratio = SysUtils.ZoomToFit(imgW, imgH, rtW, rtH);
                    imgW = (int)Math.Round(imgW * ratio);
                    imgH = (int)Math.Round(imgH * ratio);

                    PortraitArea   = ExtRect.CreateBounds(portRt.Left, portRt.Top, imgW, imgH);
                    fPortraitWidth = imgW;

                    fWidth += imgW;
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("TreeChartPerson.CalcBounds(): " + ex.Message);
            }
        }
示例#10
0
        public override void UpdateView()
        {
            ExtRect cr = fChart.GetClientRect();

            if (fGrowOver)
            {
                int height = cr.GetHeight() - (PADDING_Y << 1);
                fDestRect = ExtRect.CreateBounds(cr.Right - (PADDING_X + Width), cr.Top + PADDING_Y, Width, height);
            }
            else
            {
                int height = Math.Min(cr.GetHeight() - (PADDING_Y << 1), Height);
                fDestRect = ExtRect.CreateBounds(cr.Right - (PADDING_X + Width),
                                                 cr.Top + Math.Max(PADDING_Y, (cr.GetHeight() - height) >> 1),
                                                 Width, height);
            }
        }
示例#11
0
        public void Test_ExtRectF()
        {
            ExtRectF rt = ExtRectF.Create(0, 0, 9, 9);

            Assert.AreEqual(0, rt.Left);
            Assert.AreEqual(0, rt.Top);
            Assert.AreEqual(9, rt.Right);
            Assert.AreEqual(9, rt.Bottom);
            Assert.AreEqual(10, rt.GetHeight());
            Assert.AreEqual(10, rt.GetWidth());

            rt = ExtRectF.CreateBounds(0, 0, 10, 10);

            Assert.AreEqual(0, rt.Left);
            Assert.AreEqual(0, rt.Top);
            Assert.AreEqual(9, rt.Right);
            Assert.AreEqual(9, rt.Bottom);
            Assert.AreEqual(10, rt.GetHeight());
            Assert.AreEqual(10, rt.GetWidth());

            Assert.AreEqual("{X=0,Y=0,Width=10,Height=10}", rt.ToString());

            Assert.IsTrue(rt.Contains(5, 5));

            rt.Inflate(3, -2);
            Assert.AreEqual("{X=3,Y=-2,Width=4,Height=14}", rt.ToString());

            rt.Offset(2, 5);
            Assert.AreEqual("{X=5,Y=3,Width=4,Height=14}", rt.ToString());

            rt = rt.GetOffset(10, 10);
            Assert.AreEqual("{X=15,Y=13,Width=4,Height=14}", rt.ToString());

            Assert.IsTrue(rt.IntersectsWith(ExtRect.Create(16, 14, 20, 20)));

            rt = ExtRectF.CreateEmpty();
            Assert.IsTrue(rt.IsEmpty());

            Assert.IsFalse(rt.Contains(5, 5));

            // implicit
            ExtRectF rtf = ExtRect.CreateBounds(11, 11, 20, 20);

            Assert.AreEqual("{X=11,Y=11,Width=20,Height=20}", rtf.ToString());
        }
示例#12
0
        private ExtRect GetSourceImageRegion()
        {
            ExtRect region;

            var imageSize = GetImageSize();

            if (!imageSize.IsEmpty)
            {
                Rectangle viewPort = GetImageViewPort();
                region = ExtRect.CreateBounds(-AutoScrollPosition.X, -AutoScrollPosition.Y, viewPort.Width, viewPort.Height);
            }
            else
            {
                region = ExtRect.Empty;
            }

            return(region);
        }
示例#13
0
        private void DrawDeep(DeepMode mode, int spx, int spy)
        {
            try {
                using (var deepModel = new TreeChartModel()) {
                    deepModel.Assign(fModel);
                    deepModel.SetRenderer(fRenderer);
                    deepModel.DepthLimitAncestors   = 2;
                    deepModel.DepthLimitDescendants = 2;
                    deepModel.GenChart(fSelected.Rec, TreeChartKind.ckBoth, true);
                    deepModel.RecalcChart(true);

                    var pers = deepModel.FindPersonByRec(fSelected.Rec);
                    if (pers == null)
                    {
                        Logger.WriteError("TreeChartBox.DrawDeep(): unexpected failure");
                        return;
                    }

                    int dmX = (spx + (fSelected.PtX - pers.PtX));
                    int dmY = (spy + (fSelected.PtY - pers.PtY));
                    deepModel.SetOffsets(dmX, dmY);
                    deepModel.VisibleArea = ExtRect.CreateBounds(0, 0, deepModel.ImageWidth, deepModel.ImageHeight);

                    switch (mode)
                    {
                    case DeepMode.Background:
                        fRenderer.SetTranslucent(0.75f);
                        break;

                    case DeepMode.Foreground:
                        fRenderer.SetTranslucent(0.25f);
                        IPen   xpen   = fRenderer.CreatePen(ChartRenderer.GetColor(BSDColors.Black), 2.0f);
                        IColor bColor = ChartRenderer.GetColor(BSDColors.White);
                        fRenderer.DrawRoundedRectangle(xpen, bColor, dmX, dmY, deepModel.ImageWidth, deepModel.ImageHeight, 6);
                        fRenderer.SetTranslucent(0.00f);
                        break;
                    }

                    deepModel.Draw(ChartDrawMode.dmStatic);
                }
            } catch (Exception ex) {
                Logger.WriteError("TreeChartBox.DrawDeep()", ex);
            }
        }
示例#14
0
        public ExtRect GetClientRect()
        {
            Rectangle rt = this.ClientRectangle;

            return(ExtRect.CreateBounds(rt.Left, rt.Top, rt.Width, rt.Height));
        }
示例#15
0
        private void InternalDraw(ChartDrawMode drawMode, BackgroundMode background)
        {
            // drawing relative offset of tree on graphics
            int spx = 0;
            int spy = 0;

            if (drawMode == ChartDrawMode.dmInteractive)
            {
                /*Rectangle viewPort = GetImageViewPort();
                 * fSPX = -viewPort.Left;
                 * fSPY = -viewPort.Top;*/

                spx += fBorderWidth - -AutoScrollPosition.X;
                spy += fBorderWidth - -AutoScrollPosition.Y;

                Size sz = ClientSize;

                if (fModel.ImageWidth < sz.Width)
                {
                    spx += (sz.Width - fModel.ImageWidth) / 2;
                }

                if (fModel.ImageHeight < sz.Height)
                {
                    spy += (sz.Height - fModel.ImageHeight) / 2;
                }

                fModel.VisibleArea = GetSourceImageRegion();
            }
            else
            {
                if (drawMode == ChartDrawMode.dmStaticCentered)
                {
                    Size sz = ClientSize;

                    if (fModel.ImageWidth < sz.Width)
                    {
                        spx += (sz.Width - fModel.ImageWidth) / 2;
                    }

                    if (fModel.ImageHeight < sz.Height)
                    {
                        spy += (sz.Height - fModel.ImageHeight) / 2;
                    }
                }

                fModel.VisibleArea = ExtRect.CreateBounds(0, 0, fModel.ImageWidth, fModel.ImageHeight);
            }

            fModel.SetOffsets(spx, spy);

            DrawBackground(background);

            #if DEBUG_IMAGE
            using (Pen pen = new Pen(Color.Red)) {
                fRenderer.DrawRectangle(pen, Color.Transparent, fSPX, fSPY, fImageWidth, fImageHeight);
            }
            #endif

            fModel.Draw(fModel.Root, fModel.Kind, drawMode);
        }
示例#16
0
        private void ArrangeText()
        {
            try {
                fAcceptFontChange = false;
                fHeights.Clear();

                Graphics gfx = CreateGraphics();
                //gfx.TextRenderingHint = TextRenderingHint.AntiAlias;
                try {
                    int xPos       = 0;
                    int yPos       = 0;
                    int xMax       = 0;
                    int lineHeight = 0;

                    string text    = fLines.Text;
                    Font   defFont = this.Font;
                    SizeF  csz     = this.ClientSize;
                    SizeF  zerosz  = new SizeF(0f, 0f);

                    var parser = new BBTextParser(AppHost.GfxProvider, defFont.SizeInPoints,
                                                  new ColorHandler(fLinkColor), new ColorHandler(ForeColor));

                    parser.ParseText(fChunks, text);

                    int line        = -1;
                    int chunksCount = fChunks.Count;
                    int k           = 0;
                    while (k < chunksCount)
                    {
                        BBTextChunk chunk       = fChunks[k];
                        bool        recalcChunk = false;

                        if (line != chunk.Line)
                        {
                            line = chunk.Line;

                            if (line > 0)
                            {
                                yPos += lineHeight;
                                fHeights.Add(lineHeight);
                            }

                            xPos       = 0;
                            lineHeight = 0;
                        }

                        int prevX = xPos;
                        int prevY = yPos;

                        string chunkStr = chunk.Text;
                        if (!string.IsNullOrEmpty(chunkStr))
                        {
                            using (var font = new Font(defFont.Name, chunk.Size, (sdFontStyle)chunk.Style, defFont.Unit)) {
                                SizeF strSize = gfx.MeasureString(chunkStr, font, zerosz, fStrFormat);

                                if (fWordWrap)
                                {
                                    int wBound = xPos + 2 * fBorderWidth;
                                    if (wBound + strSize.Width > csz.Width)
                                    {
                                        int lastIndex = chunkStr.Length - 1;
                                        while (true)
                                        {
                                            int spPos = chunkStr.LastIndexOf(' ', lastIndex);
                                            if (spPos <= 0)
                                            {
                                                // the beginning of the chunk is reached and there are no more words to carry
                                                chunk.Text = chunkStr.Substring(0, lastIndex + 1);
                                                strSize    = gfx.MeasureString(chunkStr, font, zerosz, fStrFormat);
                                                // the current chunk still does not fit into the area
                                                if (wBound + strSize.Width > csz.Width)
                                                {
                                                    // this is not the only chunk on this line
                                                    if (k > 0 && fChunks[k - 1].Line == chunk.Line)
                                                    {
                                                        // transfer the current chunk to the next line
                                                        // and recount it again at the next iteration
                                                        ShiftChunks(k, chunksCount);
                                                        recalcChunk = true;
                                                    }
                                                }
                                                break;
                                            }

                                            string newChunk = chunkStr.Substring(0, spPos);
                                            strSize = gfx.MeasureString(newChunk, font, zerosz, fStrFormat);
                                            if (wBound + strSize.Width < csz.Width)
                                            {
                                                var secondPart = chunk.Clone();
                                                secondPart.Text  = chunkStr.Substring(spPos + 1);
                                                secondPart.Line += 1;
                                                fChunks.Insert(k + 1, secondPart);
                                                chunksCount += 1;

                                                // shift next chunks
                                                ShiftChunks(k + 2, chunksCount);

                                                chunk.Text = newChunk;
                                                break;
                                            }
                                            else
                                            {
                                                lastIndex = spPos - 1;
                                            }
                                        }
                                    }
                                }

                                chunk.Width = (int)strSize.Width;

                                xPos += chunk.Width;
                                if (xMax < xPos)
                                {
                                    xMax = xPos;
                                }

                                int h = (int)strSize.Height;
                                if (lineHeight < h)
                                {
                                    lineHeight = h;
                                }
                            }

                            if (!string.IsNullOrEmpty(chunk.URL))
                            {
                                chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xPos - prevX, lineHeight);
                            }
                        }

                        if (!recalcChunk)
                        {
                            k++;
                        }
                    }

                    fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth);
                } finally {
                    gfx.Dispose();
                    fAcceptFontChange = true;
                    AdjustViewport(fTextSize);
                }
            } catch (Exception ex) {
                Logger.LogWrite("HyperView.ArrangeText(): " + ex.Message);
            }
        }
示例#17
0
 public static ExtRect Rt2Rt(Rectangle ert)
 {
     return(ExtRect.CreateBounds(ert.Left, ert.Top, ert.Width, ert.Height));
 }
示例#18
0
        private void ArrangeText()
        {
            try {
                SuspendLayout();

                fAcceptFontChange = false;
                fHeights.Clear();

                try {
                    int xPos       = 0;
                    int yPos       = 0;
                    int xMax       = 0;
                    int lineHeight = 0;

                    string text     = fLines.Text;
                    Font   defFont  = this.Font;
                    float  maxWidth = this.ClientSize.Width - (2 * fBorderWidth);

                    text = SysUtils.StripHTML(text);

                    var parser = new BBTextParser(AppHost.GfxProvider, defFont.Size,
                                                  new ColorHandler(fLinkColor), new ColorHandler(TextColor));

                    parser.ParseText(fChunks, text);

                    int line        = -1;
                    int chunksCount = fChunks.Count;
                    int k           = 0;
                    while (k < chunksCount)
                    {
                        BBTextChunk chunk       = fChunks[k];
                        bool        recalcChunk = false;

                        if (line != chunk.Line)
                        {
                            line = chunk.Line;

                            if (line > 0)
                            {
                                yPos += lineHeight;
                                fHeights.Add(lineHeight);
                            }

                            xPos       = 0;
                            lineHeight = 0;
                        }

                        int prevX = xPos;
                        int prevY = yPos;

                        string chunkStr = chunk.Text;
                        if (!string.IsNullOrEmpty(chunkStr))
                        {
                            using (var font = new Font(defFont.FamilyName, chunk.Size, (EDFontStyle)chunk.Style)) {
                                SizeF strSize = font.MeasureString(chunkStr);

                                if (fWordWrap && xPos + strSize.Width > maxWidth)
                                {
                                    int    lastPos = 0, prevPos = 0;
                                    string tempStr, prevStr = string.Empty;
                                    int    sliceType = -1;
                                    while (true)
                                    {
                                        tempStr = GetSlice(chunkStr, ref lastPos, ref sliceType);
                                        strSize = font.MeasureString(tempStr);
                                        if (xPos + strSize.Width <= maxWidth)
                                        {
                                            prevStr = tempStr;
                                            prevPos = lastPos;
                                        }
                                        else
                                        {
                                            if (sliceType == 0)
                                            {
                                                // first word
                                                if (xPos == 0)
                                                {
                                                    string tail = chunkStr.Substring(lastPos);
                                                    SplitChunk(chunk, k, tempStr, tail, ref chunksCount);
                                                }
                                                else
                                                {
                                                    ShiftChunks(k, chunksCount);
                                                    recalcChunk = true;
                                                }
                                                break;
                                            }
                                            else if (sliceType == 1 || sliceType == 2)
                                            {
                                                // middle or tail word
                                                string tail = chunkStr.Substring(prevPos);
                                                SplitChunk(chunk, k, prevStr, tail, ref chunksCount);
                                                break;
                                            }
                                            else if (sliceType == 3)
                                            {
                                                // one first and last word, nothing to do
                                                break;
                                            }
                                        }
                                    }
                                }

                                strSize     = font.MeasureString(chunk.Text);
                                chunk.Width = (int)strSize.Width;

                                xPos += chunk.Width;
                                if (xMax < xPos)
                                {
                                    xMax = xPos;
                                }

                                int h = (int)strSize.Height;
                                if (lineHeight < h)
                                {
                                    lineHeight = h;
                                }
                            }

                            if (!string.IsNullOrEmpty(chunk.URL))
                            {
                                chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xPos - prevX, lineHeight);
                            }
                        }

                        if (!recalcChunk)
                        {
                            k++;
                        }
                    }

                    fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth);
                } finally {
                    fAcceptFontChange = true;
                    SetImageSize(fTextSize);

                    ResumeLayout();
                }
            } catch (Exception ex) {
                Logger.WriteError("HyperView.ArrangeText()", ex);
            }
        }
示例#19
0
        private void ArrangeText()
        {
            try {
                fAcceptFontChange = false;
                fHeights.Clear();

                try {
                    int xPos       = 0;
                    int yPos       = 0;
                    int xMax       = 0;
                    int lineHeight = 0;

                    string text = fLines.Text.Trim();
                    if (!string.IsNullOrEmpty(text))
                    {
                        Font defFont = this.Font;
                        var  parser  = new BBTextParser(AppHost.GfxProvider, defFont.Size,
                                                        new ColorHandler(fLinkColor), new ColorHandler(TextColor));

                        parser.ParseText(fChunks, text);

                        int line        = -1;
                        int chunksCount = fChunks.Count;
                        for (int k = 0; k < chunksCount; k++)
                        {
                            BBTextChunk chunk = fChunks[k];

                            if (line != chunk.Line)
                            {
                                line = chunk.Line;

                                if (line > 0)
                                {
                                    yPos += lineHeight;
                                    fHeights.Add(lineHeight);
                                }

                                xPos       = 0;
                                lineHeight = 0;
                            }

                            int prevX = xPos;
                            int prevY = yPos;

                            if (!string.IsNullOrEmpty(chunk.Text))
                            {
                                using (var font = new Font(defFont.FamilyName, chunk.Size, (sdFontStyle)chunk.Style)) {
                                    SizeF strSize = font.MeasureString(chunk.Text);
                                    chunk.Width = (int)strSize.Width;

                                    xPos += chunk.Width;
                                    if (xMax < xPos)
                                    {
                                        xMax = xPos;
                                    }

                                    int h = (int)strSize.Height;
                                    if (lineHeight < h)
                                    {
                                        lineHeight = h;
                                    }
                                }

                                if (!string.IsNullOrEmpty(chunk.URL))
                                {
                                    chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xPos - prevX, lineHeight);
                                }
                            }
                        }
                    }

                    fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth);
                } finally {
                    fAcceptFontChange = true;
                    SetImageSize(fTextSize);
                }
            } catch (Exception ex) {
                Logger.LogWrite("HyperView.ArrangeText(): " + ex.Message);
            }
        }
示例#20
0
        private void DoPaint(Graphics gfx)
        {
            try
            {
                fAcceptFontChange = false;
                try
                {
                    Rectangle clientRect = ClientRectangle;
                    gfx.FillRectangle(new SolidBrush(BackColor), clientRect);
                    Font defFont = this.Font;

                    int xOffset    = fBorderWidth - -AutoScrollPosition.X;
                    int yOffset    = fBorderWidth - -AutoScrollPosition.Y;
                    int lineHeight = 0;

                    int line        = -1;
                    int chunksCount = fChunks.Count;
                    for (int k = 0; k < chunksCount; k++)
                    {
                        BBTextChunk chunk = fChunks[k];

                        if (line != chunk.Line)
                        {
                            line = chunk.Line;

                            xOffset  = fBorderWidth - -AutoScrollPosition.X;
                            yOffset += lineHeight;

                            // this condition is dirty hack
                            if (line >= 0 && line < fHeights.Count)
                            {
                                lineHeight = fHeights[line];
                            }
                        }

                        int prevX = xOffset;
                        int prevY = yOffset;

                        string ct = chunk.Text;
                        if (!string.IsNullOrEmpty(ct))
                        {
                            var chunkColor = ((ColorHandler)chunk.Color).Handle;
                            using (var brush = new SolidBrush(chunkColor)) {
                                using (var font = new Font(defFont.Name, chunk.Size, (sdFontStyle)chunk.Style, defFont.Unit)) {
                                    gfx.DrawString(ct, font, brush, xOffset, yOffset);
                                }
                            }

                            xOffset += chunk.Width;

                            if (!string.IsNullOrEmpty(chunk.URL))
                            {
                                chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xOffset - prevX, lineHeight);
                            }
                        }
                    }
                }
                finally
                {
                    fAcceptFontChange = true;
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("HyperView.DoPaint(): " + ex.Message);
            }
        }
示例#21
0
        public void CalcBounds(int lines, ChartRenderer renderer)
        {
            try {
                TreeChartOptions options = fModel.Options;

                InitInfo(lines);
                DefineExpands();

                int bh = renderer.GetTextHeight(fModel.BoldFont);
                int th = renderer.GetTextHeight(fModel.DrawFont);

                int maxwid = 0;
                int height = 0;
                for (int k = 0; k < lines; k++)
                {
                    IFont font;
                    if (options.BoldNames && k < NameLines)
                    {
                        height += bh;
                        font    = fModel.BoldFont;
                    }
                    else
                    {
                        height += th;
                        font    = fModel.DrawFont;
                    }

                    int wt = renderer.GetTextWidth(Lines[k], font);
                    if (maxwid < wt)
                    {
                        maxwid = wt;
                    }
                }

                int pad2side = (fModel.NodePadding * 2);

                fWidth  = pad2side + maxwid;
                fHeight = pad2side + height;

                if (fPortrait != null)
                {
                    ExtRect portRt = ExtRect.Create(0, 0, fHeight - 1, fHeight - 1);
                    portRt.Inflate(-3, -3);

                    int   rtW   = portRt.GetWidth();
                    int   rtH   = portRt.GetHeight();
                    int   imgW  = fPortrait.Width;
                    int   imgH  = fPortrait.Height;
                    float ratio = GfxHelper.ZoomToFit(imgW, imgH, rtW, rtH);
                    imgW = (int)Math.Round(imgW * ratio);
                    imgH = (int)Math.Round(imgH * ratio);

                    PortraitArea   = ExtRect.CreateBounds(portRt.Left, portRt.Top, imgW, imgH);
                    fPortraitWidth = imgW;

                    fWidth += imgW;
                }
            } catch (Exception ex) {
                Logger.WriteError("TreeChartPerson.CalcBounds()", ex);
            }
        }