Beispiel #1
0
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            // do nothing
            if (BackgroundImage != null)              // guess we can let it paint the image...
            {
                e.Graphics.DrawImage(this.BackgroundImage, this.ClientRectangle
                                     , new RectangleF(0, 0, this.BackgroundImage.Size.Width, this.BackgroundImage.Size.Height), GraphicsUnit.Pixel
                                     );

                base.OnPaintBackground(e);
            }

            if (current_page == null)
            {
                current_page = new page(this);
            }

            if (current_page.Count == 0)
            {
                font_tracker ft = Xperdex.GetFontTracker("Default");
                ft.DrawString(e.Graphics, "No Objects\nALT-V to Configure\nLeft click drag region\nRight click in region to add control"
                              , new SolidBrush(Color.Azure)
                              , new Point(0, 0)
                              , font_scale_x, font_scale_y
                              //, StringFormat.GenericTypographic
                              );
            }

            if (flags.editing)
            {
                // hazy green edit...
                Brush b  = new SolidBrush(Color.FromArgb(32, 0, 84, 84));
                Pen   p  = new Pen(Color.FromArgb(43, 255, 255, 255));
                Pen   p2 = new Pen(Color.FromArgb(43, 0, 0, 0));
                // r is a global variable that determines scaling for parts.
                current_page.rect = this.ClientRectangle;

                e.Graphics.FillRectangle(b, this.ClientRectangle);


                {
                    int x, y;

                    for (x = 0; x <= current_page.partsX; x++)
                    {
                        e.Graphics.DrawLine(p
                                            , current_page.PARTX(x), 0
                                            , current_page.PARTX(x), current_page.PARTY(current_page.partsY));
                        e.Graphics.DrawLine(p2, current_page.PARTX(x) + 1, 0
                                            , current_page.PARTX(x) + 1, current_page.PARTY(current_page.partsY));
                    }

                    for (y = 0; y <= current_page.partsY; y++)
                    {
                        e.Graphics.DrawLine(p, 0, current_page.PARTY(y)
                                            , current_page.PARTX(current_page.partsX), current_page.PARTY(y));
                        e.Graphics.DrawLine(p2, 0, current_page.PARTY(y) + 1
                                            , current_page.PARTX(current_page.partsX), current_page.PARTY(y) + 1);
                    }

                    Font c_label = Xperdex.GetFontTracker("Default Fixed(Fixed)", "Lucida Console", 10);
                    foreach (ControlTracker c in current_page)
                    {
                        Brush selected_brush = new SolidBrush(Color.FromArgb(80, 0, 128, 0));
                        //lprintf( WIDE("Our fancy coords could be %d,%d %d,%d"), PARTX( selection.x ), PARTY( selection.y )
                        //		 , PARTW( selection.x, selection.w )
                        //		 , PARTH( selection.y, selection.h ));
                        // and to look really pretty select the outer edge on the bottom, also

                        //e.Graphics.FillRectangle(selected_brush, rect);
                        e.Graphics.FillRectangle(selected_brush, current_page.PARTX(c.grid_rect.X), current_page.PARTY(c.grid_rect.Y)
                                                 , current_page.PARTW(c.grid_rect.X, c.grid_rect.Width) + 1
                                                 , current_page.PARTH(c.grid_rect.Y, c.grid_rect.Height) + 1
                                                 );
                        {
                            selected_brush = new SolidBrush(Color.FromArgb(84, 128, 0, 0));
                            e.Graphics.FillRectangle(selected_brush
                                                     , current_page.PARTX(c.grid_rect.X)
                                                     , current_page.PARTY(c.grid_rect.Y)
                                                     , current_page.PARTW(c.grid_rect.X, 1) + 1
                                                     , current_page.PARTH(c.grid_rect.Y, 1) + 1
                                                     );
                            e.Graphics.FillRectangle(selected_brush
                                                     , current_page.PARTX(c.grid_rect.Right - 1)
                                                     , current_page.PARTY(c.grid_rect.Top)
                                                     , current_page.PARTW(c.grid_rect.Right - 1, 1) + 1
                                                     , current_page.PARTH(c.grid_rect.Top, 1) + 1
                                                     );
                            e.Graphics.FillRectangle(selected_brush
                                                     , current_page.PARTX(c.grid_rect.X)
                                                     , current_page.PARTY(c.grid_rect.Bottom - 1)
                                                     , current_page.PARTW(c.grid_rect.X, 1) + 1
                                                     , current_page.PARTH(c.grid_rect.Bottom - 1, 1) + 1
                                                     );
                            e.Graphics.FillRectangle(selected_brush
                                                     , current_page.PARTX(c.grid_rect.Right - 1)
                                                     , current_page.PARTY(c.grid_rect.Bottom - 1)
                                                     , current_page.PARTW(c.grid_rect.Right - 1, 1) + 1
                                                     , current_page.PARTH(c.grid_rect.Bottom - 1, 1) + 1
                                                     );
                            e.Graphics.DrawString(c.o.ToString(), c_label, Brushes.White, new PointF(c.c.Location.X, c.c.Location.Y));
                        }
                    }
                    if (flags.selecting)
                    {
                        Brush selected_brush = new SolidBrush(Color.FromArgb(170, 0, 0, Color.Blue.B));
                        //lprintf( WIDE("Our fancy coords could be %d,%d %d,%d"), PARTX( selection.x ), PARTY( selection.y )
                        //		 , PARTW( selection.x, selection.w )
                        //		 , PARTH( selection.y, selection.h ));
                        // and to look really pretty select the outer edge on the bottom, also
                        e.Graphics.FillRectangle(selected_brush, current_page.PARTX(selection.X), current_page.PARTY(selection.Y)
                                                 , current_page.PARTW(selection.X, selection.Width) + 1
                                                 , current_page.PARTH(selection.Y, selection.Height) + 1
                                                 );
                    }
                }
            }
        }
Beispiel #2
0
        internal void Render(Control c, Graphics g, bool fill_back, Color fill_color, String _text, Fraction _scaleX, Fraction _scaleY)
        {
            //this.scaleX = scaleX;
            //this.scaleY = scaleY;
            if (updated)
            {
                //SizeF size = g.MeasureString( "M", font.f );
                //scaleX = new Fraction( size.Width, 10 );
                //scaleY = new Fraction( size.Height, 10 );
                this.scaleX = new Fraction(c.Width, 250);
                this.scaleY = new Fraction(c.Height, 250);
                updated     = false;
            }
            {
                switch (_anchor)
                {
                case AnchorPoint.TopLeft:
                    x = scaleX * _orig_x;
                    y = scaleY * _orig_y;
                    break;

                case AnchorPoint.TopRight:
                    x = c.Width - scaleX * _orig_x;
                    y = scaleY * _orig_y;
                    break;

                case AnchorPoint.BottomLeft:
                    x = scaleX * _orig_x;
                    y = c.Height - scaleY * _orig_y;
                    break;

                case AnchorPoint.BottomRight:
                    x = c.Width - scaleX * _orig_x;
                    y = c.Height - scaleY * _orig_y;
                    break;
                }
            }


            float xofs = 0;
            float yofs = 0;

            // right anchored labels are deault behavior  right justified
            // Let anchored labels are deault behavior left justified

            // this is mode normal....
            // center should set text against the offset point middle
            // Right should set text against this point as the right point
            // normal (left) justify is exactly what this is now...
            {
                SizeF size = g.MeasureString((_text == null) ? Name : _text, font.font);
                size.Width  = _scaleX.ToFloat() * size.Width;
                size.Height = _scaleY.ToFloat() * size.Height;
                switch (anchor)
                {
                case AnchorPoint.TopLeft:
                    xofs = size.Width / 2;
                    yofs = size.Height / 2;
                    break;

                case AnchorPoint.TopRight:
                    xofs = -size.Width / 2;
                    yofs = size.Height / 2;
                    break;

                case AnchorPoint.BottomLeft:
                    xofs = size.Width / 2;
                    yofs = -size.Height / 2;
                    break;

                case AnchorPoint.BottomRight:
                    xofs = -size.Width / 2;
                    yofs = -size.Height / 2;
                    break;
                }
                if (bHorizCenter)
                {
                    x    = c.Width / 2;
                    xofs = 0;

                    /*
                     * if( size.Width >= c.Width )
                     * {
                     *      // string too wide... just drop it to the left...
                     *      // ( x + (-x ) = 0 ) draw at 0
                     *      xofs = -x;
                     * }
                     * else
                     * {
                     *      xofs = ( ( c.Width - size.Width ) / 2 );
                     *      xofs -= x; // then rebiasing later corrects this ...
                     * }
                     */
                    effective_space = new Rectangle((int)(x + xofs - (size.Width / 2)), (int)(y + yofs - (size.Height / 2)), (int)size.Width, (int)size.Height);
                }
                else
                {
                    effective_space = new Rectangle((int)(x + xofs - (size.Width / 2)), (int)(y + yofs - (size.Height / 2)), (int)size.Width, (int)size.Height);
                }
            }

            if (bHorizCenter || bDrawRightJustified)
            {
                if (fill_back)
                {
                    g.FillRectangle(new SolidBrush(fill_color), effective_space);
                }
#if asdfsadf
                SizeF size = g.MeasureString((_text == null) ? Name : _text, font.f);
                if (bDrawRightJustified)
                {
                    xofs = -size.Width;
                }
                if (bHorizCenter)
                {
                    if (size.Width >= c.Width)
                    {
                        // string too wide... just drop it to the left...
                        // ( x + (-x ) = 0 ) draw at 0
                        xofs = -x;
                    }
                    else
                    {
                        xofs  = ((c.Width - size.Width) / 2);
                        xofs -= x;                         // then rebiasing later corrects this ...
                    }
                }
#endif
            }
            else
            {
                //SizeF size = g.MeasureString( ( _text == null ) ? Name : _text, font.f );
                //effective_space = new Rectangle( (int)x, (int)y, (int)size.Width, (int)size.Height );
                if (fill_back)
                {
                    g.FillRectangle(new SolidBrush(fill_color), effective_space);
                }
            }
            //lprintf( WIDE("output %s at %ld"), layout->content, layout->y );

            if (greyed)
            {
                //, key->flags.bGreyed ? BASE_COLOR_WHITE : layout->text
            }
            else
            {
                if (brush != null)
                {
                    font.DrawString(g, (_text == null) ? Name : _text
                                    , brush, new Point((int)(x + xofs), (int)(y + yofs)), _scaleX, _scaleY);
                }
            }
        }
Beispiel #3
0
        void Label_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        //protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
        {
            if (font == null)
            {
                return;
            }
            {
                Canvas canvas   = this.Parent as Canvas;
                int    offset   = 0;
                String realtext = variables.Variables.ResolveVariables(this, text);

                List <SizeF>  output_size;
                List <string> output;
                output      = new List <string>();
                output_size = new List <SizeF>();
                int idx;
                if (realtext != null)
                {
                    do
                    {
                        idx = realtext.IndexOf('_', offset);

                        if (idx >= 0)
                        {
                            output.Add(realtext.Substring(offset, idx - offset));
                            offset = idx + 1;
                        }
                        else
                        {
                            output.Add(realtext.Substring(offset, realtext.Length - offset));
                        }
                    } while(idx >= 0);
                }
                int height = 0;
                foreach (string s in output)
                {
                    SizeF size;
                    output_size.Add(size = font.MeasureString(e.Graphics, s, canvas.font_scale_x, canvas.font_scale_y));
                    //output_size.Add( size = e.Graphics.MeasureString( s, font ) );
                    height += (int)(size.Height + (height > 0 ? 2 : 0));
                }

                Point _point = new Point(Size);
                Point point  = new Point();
                if (centered)
                {
                    //SizeF size = new SizeF(gout.MeasureString(realtext, c.Font));
                    _point.X /= 2;
                    _point.Y /= 2;
                    //_point.Y -= (int)( height / 2 );

                    point.Y = _point.Y;
                    point.X = _point.X;
                    int n = 0;
                    foreach (string s in output)
                    {
                        //point.X = _point.X - (int)( output_size[n].Width / 2 );
                        if (canvas != null)
                        {
                            font.DrawString(e.Graphics, s, textbrush, point, canvas.font_scale_x, canvas.font_scale_y);
                        }
                        else
                        {
                            font.DrawString(e.Graphics, s, textbrush, point, new Fraction(1, 1), new Fraction(1, 1));
                        }
                        point.Y += (int)(output_size[n].Height) + ((n > 0) ? 2 : 0);
                        n++;
                    }
                }
                else if (right_just)
                {
                    //SizeF size = new SizeF(gout.MeasureString(realtext, c.Font));
                    _point.X /= 2;
                    _point.Y /= 2;
                    //_point.Y -= (int)( height / 2 );

                    point.Y = _point.Y;
                    int n = 0;
                    foreach (string s in output)
                    {
                        point.X = Width - (5 + (int)(output_size[n].Width / 2));

                        /*
                         * e.Graphics.DrawString( s
                         *       , font
                         *       , textbrush
                         *       , point );
                         * */
                        font.DrawString(e.Graphics, s, textbrush, point, canvas.font_scale_x, canvas.font_scale_y);
                        point.Y += (int)(output_size[n].Height) + ((n > 0) ? 2 : 0);
                        n++;
                    }
                }
                else
                {
                    //SizeF size = new SizeF(gout.MeasureString(realtext, c.Font));
                    _point.X /= 2;
                    _point.Y /= 2;
                    //_point.Y -= (int)( height / 2 );

                    point.Y = _point.Y;
                    int n = 0;
                    foreach (string s in output)
                    {
                        point.X = 5 + (int)(output_size[n].Width / 2);

                        /*
                         * e.Graphics.DrawString( s
                         *       , font
                         *       , textbrush
                         *       , point );
                         * */
                        font.DrawString(e.Graphics, s, textbrush, point, canvas.font_scale_x, canvas.font_scale_y);
                        point.Y += (int)(output_size[n].Height) + ((n > 0) ? 2 : 0);
                        n++;
                    }
                }
            }
            //base.OnPaint( e );
        }