Esempio n. 1
0
        void PaintSprite(DateTime now)
        {
            if (sprite_surface == null)
            {
                return;
            }

            /* make sure the sprite is on screen before doing the rectangle intersection/blit stuff */
            if (sprite_surface != null)
            {
                if ((x > SpriteManager.X - sprite_surface.Width / 2) && (x - sprite_surface.Width / 2 <= SpriteManager.X + Painter.SCREEN_RES_X) &&
                    (y > SpriteManager.Y - sprite_surface.Height / 2) && (y - sprite_surface.Height / 2 <= SpriteManager.Y + 375))
                {
                    Painter.Blit(sprite_surface,
                                 new Point(x - SpriteManager.X - sprite_surface.Width / 2,
                                           y - SpriteManager.Y - sprite_surface.Height / 2));

                    if (show_sprite_borders)
                    {
                        Painter.DrawBox(new Rectangle(new Point(x - SpriteManager.X - sprite_surface.Width / 2,
                                                                y - SpriteManager.Y - sprite_surface.Height / 2),
                                                      new Size(sprite_surface.Width - 1,
                                                               sprite_surface.Height - 1)),
                                        Color.Green);
                    }
                }
            }
        }
Esempio n. 2
0
    public static void Main(string[] args)
    {
        MpqContainer mpq = new MpqContainer();

        mpq.Add(new MpqArchive("/home/toshok/src/starcraft/sc-cd/install.exe"));
        mpq.Add(new MpqArchive("/home/toshok/src/starcraft/starcraft/StarDat.mpq"));

        Fnt fnt = (Fnt)mpq.GetResource("files\\font\\font16.fnt");

        Console.WriteLine("loading font palette");
        Stream palStream = (Stream)mpq.GetResource("glue\\Palmm\\tFont.pcx");
        Pcx    pcx1      = new Pcx();

        pcx1.ReadFromStream(palStream, -1, -1);

        Painter.InitializePainter(false, 300);

        Surface textSurf1 = GuiUtil.ComposeText(str1, fnt, pcx1.Palette);
        Surface textSurf2 = GuiUtil.ComposeText(str2, fnt, pcx1.Palette);
        Surface textSurf3 = GuiUtil.ComposeText(str3, fnt, pcx1.Palette);
        Surface textSurf4 = GuiUtil.ComposeText(str4, fnt, pcx1.Palette);

        Surface backgroundSurface = new Surface(Painter.SCREEN_RES_X, Painter.SCREEN_RES_Y);

        backgroundSurface.Fill(new Rectangle(new Point(0, 0), backgroundSurface.Size), Color.Red);

        Painter.Add(Layer.UI,
                    delegate(DateTime now) {
            int y = 0;
            Painter.Blit(textSurf1, new Point(0, y)); y += textSurf1.Height;
            Painter.Blit(textSurf2, new Point(0, y)); y += textSurf2.Height;
            Painter.Blit(textSurf3, new Point(0, y)); y += textSurf3.Height;
            Painter.Blit(textSurf4, new Point(0, y)); y += textSurf4.Height;
        });

        Painter.Add(Layer.Background,
                    delegate(DateTime now) {
            Painter.Blit(backgroundSurface);
        });

        Events.KeyboardUp += delegate(object o, KeyboardEventArgs keyargs) {
            if (keyargs.Key == Key.Escape)
            {
                Events.QuitApplication();
            }
        };

        Events.Run();
    }
Esempio n. 3
0
        void PaintStarfield(DateTime dt)
        {
            float scroll_factor = 1.0f;

            float[] factors = new float[starfield_layers.Length];

            for (int i = 0; i < starfield_layers.Length; i++)
            {
                factors[i]     = scroll_factor;
                scroll_factor *= 0.75f;
            }

            Rectangle dest;
            Rectangle source;

            for (int i = starfield_layers.Length - 1; i >= 0; i--)
            {
                int scroll_x = (int)(topleft_x * factors[i]);
                int scroll_y = (int)(topleft_y * factors[i]);

                if (scroll_x > Painter.SCREEN_RES_X)
                {
                    scroll_x %= Painter.SCREEN_RES_X;
                }
                if (scroll_y > 375)
                {
                    scroll_y %= 375;
                }


                dest = new Rectangle(new Point(0, 0),
                                     new Size(Painter.SCREEN_RES_X - scroll_x,
                                              375 - scroll_y));
                source    = dest;
                source.X += scroll_x;
                source.Y += scroll_y;

                Painter.Blit(starfield_layers[i],
                             dest, source);

                if (scroll_x != 0)
                {
                    dest = new Rectangle(new Point(Painter.SCREEN_RES_X - scroll_x, 0),
                                         new Size(scroll_x, 375 - scroll_y));
                    source    = dest;
                    source.X -= Painter.SCREEN_RES_X - scroll_x;
                    source.Y += scroll_y;

                    Painter.Blit(starfield_layers[i],
                                 dest, source);
                }

                if (scroll_y != 0)
                {
                    dest = new Rectangle(new Point(0, 375 - scroll_y),
                                         new Size(Painter.SCREEN_RES_X - scroll_x, scroll_y));
                    source    = dest;
                    source.X += scroll_x;
                    source.Y -= 375 - scroll_y;

                    Painter.Blit(starfield_layers[i],
                                 dest, source);
                }

                if (scroll_x != 0 || scroll_y != 0)
                {
                    dest = new Rectangle(new Point(Painter.SCREEN_RES_X - scroll_x, 375 - scroll_y),
                                         new Size(scroll_x, scroll_y));
                    source    = dest;
                    source.X -= Painter.SCREEN_RES_X - scroll_x;
                    source.Y -= 375 - scroll_y;

                    Painter.Blit(starfield_layers[i],
                                 dest, source);
                }
            }
        }
Esempio n. 4
0
        void RedrawOverlay()
        {
            Drawing drw = CurrentDrawing;

            if (drw == null || backbuffer == null)
            {
                return; //no overlay if no drawing
            }
            //Point2i dcs = cursorpixel;
            Point2d cursor_wcs = CursorWorldPos;

            //make sure overlay area is as big as backbuffer
            if (overlay == null || overlay.Width < backbuffer.Width || overlay.Height < backbuffer.Height)
            {
                if (overlay != null)
                {
                    overlay.Dispose();
                }
                overlay = Guppy.CreatePicture(backbuffer.Width, backbuffer.Height, PictureMode.Software);
            }


            using (PainterExtentsRecorder exrec = new PainterExtentsRecorder()) //to remember area drawn to
            {
                using (Painter overlaypainter = overlay.CreatePainter())
                {
                    if (overlay_needs_background)
                    {
                        overlaypainter.Blit(backbuffer, 0, 0, backbuffer.Width, backbuffer.Height, 0, 0, backbuffer.Width, backbuffer.Height);
                        overlay_needs_background = false;
                    }


                    using (PainterAggregate painter = new PainterAggregate(overlaypainter, exrec))
                    {
                        //let the current sink do its job
                        painter.Transform = CurrentDrawing.ViewTransform;
                        CurrentSink.OnTracking(cursorpixel, cursor_wcs, painter);
                    }


                    Rectangle2i fliprect     = Rectangle2i.Empty; //the part of screen to flip
                    Rectangle2i newdirtyrect = fliprect;          //the new dirty screen rectangle

                    //compute slightly grown extents of area to show
                    var er = exrec.RecordedExtents;
                    if (!er.Empty)
                    {
                        newdirtyrect = new Rectangle2i((int)(er.XMin - 5), (int)(er.YMin - 5), (int)(er.XMax + 5), (int)(er.YMax + 5));
                        fliprect     = newdirtyrect;
                    }

                    //include old dirty area in flipping rectangle
                    if (!screen_dirty.IsEmpty)
                    {
                        fliprect = fliprect.Append(screen_dirty.XMin, screen_dirty.YMin);
                        fliprect = fliprect.Append(screen_dirty.XMax, screen_dirty.YMax);
                    }

                    //flip if fliprect not empty.
                    if (!fliprect.IsEmpty)
                    {
                        using (Painter frontpainter = drawarea.CreatePainter())
                        {
                            int x = fliprect.XMin, y = fliprect.YMin, w = fliprect.Width, h = fliprect.Height;
                            frontpainter.Blit(overlay, x, y, w, h, x, y, w, h);
                            overlaypainter.Blit(backbuffer, x, y, w, h, x, y, w, h);
                        }
                    }


                    //remove the temp graphics from the overlay buffer
                    if (!screen_dirty.IsEmpty)
                    {
                        int x = screen_dirty.XMin, y = screen_dirty.YMin, w = screen_dirty.Width, h = screen_dirty.Height;

                        overlaypainter.Color = RGB.Green;
                    }

                    screen_dirty = newdirtyrect;
                }
            }
        }