Пример #1
0
        private void RedrawBuffer()
        {
            if (_bufferSurface != null)
            {
                _bufferSurface.Dispose();
            }

            _bufferSurface = new GDISurface(this.Width, this.Height, this, true);

            using (Graphics gfx = Graphics.FromHdc(_bufferSurface.hDC))
            {
                //try
                //{
                _bufferSurface.FontTransparent = true;

                if (this.BackgroundImage != null)
                {
                    gfx.DrawImage(this.BackgroundImage, 0, 0, this.Width, this.Height);
                }
                else
                {
                    _bufferSurface.Clear(this.BackColor);
                }
                int x = LabelMargin;
                int y = LabelMargin;
                for (int i = vScroll.Value; i < _Rows.Count; i++)
                {
                    FormatLabelRow r = (FormatLabelRow)_Rows[i];
                    x         = LabelMargin;
                    r.Visible = true;
                    r.Top     = y;
                    if (r.RenderSeparator)
                    {
                        Color c1 = Color.FromArgb(120, 0, 0, 0);
                        Brush b1 = new SolidBrush(c1);
                        gfx.FillRectangle(b1, 0, y, this.Width, 1);

                        Color c2 = Color.FromArgb(120, 255, 255, 255);
                        Brush b2 = new SolidBrush(c2);
                        gfx.FillRectangle(b2, 0, y + 1, this.Width, 1);

                        b1.Dispose();
                        b2.Dispose();


                        //bbuff.DrawLine (this.ForeColor,new Point (0,y),new Point (this.Width,y));
                    }

                    foreach (FormatLabelWord w in r.Words)
                    {
                        int ypos = r.Height - w.Height + y;

                        if (w.Image != null)
                        {
                            gfx.DrawImage(w.Image, x, y);
                            //bbuff.FillRect (Color.Red ,x,ypos,w.Width ,w.Height);
                        }
                        else
                        {
                            GDIFont gf = null;
                            if (w.Element.Link != null)
                            {
                                Font f = null;

                                FontStyle fs = w.Element.Font.Style;
                                if (w.Element.Link == _ActiveElement)
                                {
                                    if (_Link_UnderLine_Hover)
                                    {
                                        fs |= FontStyle.Underline;
                                    }

                                    f = new Font(w.Element.Font, fs);
                                }
                                else
                                {
                                    if (_Link_UnderLine)
                                    {
                                        fs |= FontStyle.Underline;
                                    }

                                    f = new Font(w.Element.Font, fs);
                                }

                                gf = GetFont(f);
                            }
                            else
                            {
                                gf = GetFont(w.Element.Font);
                            }

                            _bufferSurface.Font = gf;
                            if (w.Element.Effect != TextEffect.None)
                            {
                                _bufferSurface.TextForeColor = w.Element.EffectColor;

                                if (w.Element.Effect == TextEffect.Outline)
                                {
                                    for (int xx = -1; xx <= 1; xx++)
                                    {
                                        for (int yy = -1; yy <= 1; yy++)
                                        {
                                            _bufferSurface.DrawTabbedString(w.Text, x + xx, ypos + yy, 0, 0);
                                        }
                                    }
                                }
                                else if (w.Element.Effect != TextEffect.None)
                                {
                                    _bufferSurface.DrawTabbedString(w.Text, x + 1, ypos + 1, 0, 0);
                                }
                            }


                            if (w.Element.Link != null)
                            {
                                if (w.Element.Link == _ActiveElement)
                                {
                                    _bufferSurface.TextForeColor = Link_Color_Hover;
                                }
                                else
                                {
                                    _bufferSurface.TextForeColor = Link_Color;
                                }
                            }
                            else
                            {
                                _bufferSurface.TextForeColor = w.Element.ForeColor;
                            }

                            _bufferSurface.TextBackColor = w.Element.BackColor;
                            _bufferSurface.DrawTabbedString(w.Text, x, ypos, 0, 0);
                        }

                        w.ScreenArea = new Rectangle(new Point(x, ypos), w.ScreenArea.Size);
                        //w.ScreenArea.Y = ypos;
                        x += w.Width;
                    }

                    y += r.Height + r.BottomPadd;
                    if (y > this.Height)
                    {
                        break;
                    }
                }

                //}
                //catch (Exception x)
                //{
                //    Console.WriteLine(x.Message);
                //}
            }
        }
Пример #2
0
        private void CreateRows()
        {
            if (_Elements != null)
            {
                int x = 0;
                _Rows = new ArrayList();

                //build rows---------------------------------------------
                FormatLabelRow row = new FormatLabelRow();
                _Rows.Add(row);
                bool WhiteSpace = false;
                foreach (FormatLabelElement Element in _Elements)
                {
                    if (Element.words == null)
                    {
                        return;
                    }

                    if (Element.NewLine)
                    {
                        //tag forces a new line
                        x   = 0;
                        row = new FormatLabelRow();
                        _Rows.Add(row);
                        WhiteSpace = true;
                    }
                    if (Element.TagName == "hr")
                    {
                        row.RenderSeparator = true;
                    }

                    //else
                    //{


                    foreach (FormatLabelWord word in Element.words)
                    {
                        if (WordWrap)
                        {
                            int scrollwdh = 0;
                            if (ScrollBars == ScrollBars.Both || ScrollBars == ScrollBars.Vertical)
                            {
                                scrollwdh = vScroll.Width;
                            }

                            if ((word.Width + x) > this.ClientWidth - LabelMargin - scrollwdh)
                            {
                                //new line due to wordwrap
                                x   = 0;
                                row = new FormatLabelRow();
                                _Rows.Add(row);
                                WhiteSpace = true;
                            }
                        }

                        if (word.Text.Replace(" ", "") != "" || word.Image != null)
                        {
                            WhiteSpace = false;
                        }

                        if (!WhiteSpace)
                        {
                            row.Words.Add(word);

                            x += word.Width;
                        }
                    }
                    //}
                }

                //apply width and height to all rows
                int index = 0;
                foreach (FormatLabelRow r in this._Rows)
                {
                    int width  = 0;
                    int height = 0;
                    int padd   = 0;

                    if (index > 0)
                    {
                        int            previndex = index - 1;
                        FormatLabelRow prev      = (FormatLabelRow)_Rows[previndex];
                        while (previndex >= 0 && prev.Words.Count == 0)
                        {
                            prev = (FormatLabelRow)_Rows[previndex];
                            previndex--;
                        }

                        if (previndex >= 0)
                        {
                            prev = (FormatLabelRow)_Rows[previndex];
                            if (prev.Words.Count > 0)
                            {
                                FormatLabelWord w = (FormatLabelWord)prev.Words[prev.Words.Count - 1];
                                height = w.Height;
                            }
                        }
                    }


                    foreach (FormatLabelWord w in r.Words)
                    {
                        if (w.Height > height && (w.Text != ""))
                        {
                            height = w.Height;
                        }

                        width += w.Width;
                    }
                    r.Height = height;

                    int MaxImageH = 0;
                    foreach (FormatLabelWord w in r.Words)
                    {
                        if (w.Image != null)
                        {
                            if (w.Height > height)
                            {
                                MaxImageH = w.Height;
                            }
                        }
                    }

                    foreach (FormatLabelWord w in r.Words)
                    {
                        int imgH    = 0;
                        int imgPadd = 0;
                        if (w.Image != null)
                        {
                            string valign = GetAttrib("valign", w.Element.Tag);
                            switch (valign)
                            {
                            case "top":
                            {
                                imgH    = r.Height;
                                imgPadd = w.Height - imgH;
                                break;
                            }

                            case "middle":
                            case "center":
                            {
                                int tmp = 0;
                                imgH    = r.Height;
                                tmp     = (w.Height - imgH) / 2;
                                imgH   += tmp;
                                imgPadd = tmp;

                                break;
                            }

                            case "bottom":
                            {
                                imgH    = w.Height;
                                imgPadd = 0;
                                break;
                            }

                            default:
                            {
                                imgH    = w.Height;
                                imgPadd = 0;
                                break;
                            }
                            }

                            if (imgH > height)
                            {
                                height = imgH;
                            }

                            if (imgPadd > padd)
                            {
                                padd = imgPadd;
                            }


                            width += w.Width;
                        }
                    }
                    r.Width      = width;
                    r.Height     = height;
                    r.BottomPadd = padd;
                    index++;
                }

                this.vScroll.Maximum = this._Rows.Count;
            }
        }
		private void CreateRows()
		{
			if (_Elements != null)
			{
				int x = 0;
				_Rows = new ArrayList();

				//build rows---------------------------------------------
				FormatLabelRow row = new FormatLabelRow();
				_Rows.Add(row);
				bool WhiteSpace = false;
				foreach (FormatLabelElement Element in _Elements)
				{
					if (Element.words == null)
						return;

					if (Element.NewLine)
					{
						//tag forces a new line
						x = 0;
						row = new FormatLabelRow();
						_Rows.Add(row);
						WhiteSpace = true;
					}
					if (Element.TagName == "hr")
					{
						row.RenderSeparator = true;
					}

					//else
					//{


					foreach (FormatLabelWord word in Element.words)
					{
						if (WordWrap)
						{
							int scrollwdh = 0;
							if (ScrollBars == ScrollBars.Both || ScrollBars == ScrollBars.Vertical)
								scrollwdh = vScroll.Width;

							if ((word.Width + x) > this.ClientWidth - LabelMargin - scrollwdh)
							{
								//new line due to wordwrap
								x = 0;
								row = new FormatLabelRow();
								_Rows.Add(row);
								WhiteSpace = true;
							}
						}

						if (word.Text.Replace(" ", "") != "" || word.Image != null)
							WhiteSpace = false;

						if (!WhiteSpace)
						{
							row.Words.Add(word);

							x += word.Width;
						}
					}
					//}
				}

				//apply width and height to all rows
				int index = 0;
				foreach (FormatLabelRow r in this._Rows)
				{
					int width = 0;
					int height = 0;
					int padd = 0;

					if (index > 0)
					{
						int previndex = index - 1;
						FormatLabelRow prev = (FormatLabelRow) _Rows[previndex];
						while (previndex >= 0 && prev.Words.Count == 0)
						{
							prev = (FormatLabelRow) _Rows[previndex];
							previndex--;
						}

						if (previndex >= 0)
						{
							prev = (FormatLabelRow) _Rows[previndex];
							if (prev.Words.Count > 0)
							{
								FormatLabelWord w = (FormatLabelWord) prev.Words[prev.Words.Count - 1];
								height = w.Height;
							}
						}

					}


					foreach (FormatLabelWord w in r.Words)
					{
						if (w.Height > height && (w.Text != ""))
							height = w.Height;

						width += w.Width;

					}
					r.Height = height;

					int MaxImageH = 0;
					foreach (FormatLabelWord w in r.Words)
					{
						if (w.Image != null)
						{
							if (w.Height > height)
								MaxImageH = w.Height;
						}
					}

					foreach (FormatLabelWord w in r.Words)
					{
						int imgH = 0;
						int imgPadd = 0;
						if (w.Image != null)
						{
							string valign = GetAttrib("valign", w.Element.Tag);
							switch (valign)
							{
								case "top":
									{
										imgH = r.Height;
										imgPadd = w.Height - imgH;
										break;
									}
								case "middle":
								case "center":
									{
										int tmp = 0;
										imgH = r.Height;
										tmp = (w.Height - imgH)/2;
										imgH += tmp;
										imgPadd = tmp;

										break;
									}
								case "bottom":
									{
										imgH = w.Height;
										imgPadd = 0;
										break;
									}
								default:
									{
										imgH = w.Height;
										imgPadd = 0;
										break;
									}

							}

							if (imgH > height)
								height = imgH;

							if (imgPadd > padd)
								padd = imgPadd;


							width += w.Width;
						}
					}
					r.Width = width;
					r.Height = height;
					r.BottomPadd = padd;
					index++;
				}

				this.vScroll.Maximum = this._Rows.Count;
			}
		}