Ejemplo n.º 1
0
        public virtual void PaintObjects(GLEx g, int minX, int minY, int maxX, int maxY)
        {
            lock (objects)
            {
                IIterator it = objects.Iterator();
                for (; it.HasNext();)
                {
                    thing = (Actor)it.Next();
                    if (!thing.visible)
                    {
                        continue;
                    }
                    isListener = (thing.actorListener != null);

                    if (isVSync)
                    {
                        if (isListener)
                        {
                            thing.actorListener.Update(elapsedTime);
                        }
                        thing.Update(elapsedTime);
                    }

                    RectBox rect = thing.GetRectBox();
                    actorX      = minX + thing.GetX();
                    actorY      = minY + thing.GetY();
                    actorWidth  = rect.width;
                    actorHeight = rect.height;
                    if (actorX + actorWidth < minX || actorX > maxX ||
                        actorY + actorHeight < minY || actorY > maxY)
                    {
                        continue;
                    }
                    LTexture actorImage = thing.GetImage();
                    if (actorImage != null)
                    {
                        width          = (actorImage.GetWidth() * thing.scaleX);
                        height         = (actorImage.GetHeight() * thing.scaleY);
                        isBitmapFilter = (thing.filterColor != null);
                        thing.SetLastPaintSeqNum(paintSeq++);
                        angle      = thing.GetRotation();
                        colorAlpha = thing.alpha;

                        if (thing.isAnimation)
                        {
                            if (isBitmapFilter)
                            {
                                g.DrawTexture(actorImage, actorX, actorY, width,
                                              height, angle, thing.filterColor);
                            }
                            else
                            {
                                if (colorAlpha != 1f)
                                {
                                    g.SetAlpha(colorAlpha);
                                }
                                g.DrawTexture(actorImage, actorX, actorY, width,
                                              height, angle);
                                if (colorAlpha != 1f)
                                {
                                    g.SetAlpha(1f);
                                }
                            }
                        }
                        else
                        {
                            int texId = actorImage.GetTextureID();

                            LTextureBatch batch = (LTextureBatch)textures
                                                  .GetValue(texId);

                            if (batch == null)
                            {
                                LTextureBatch pBatch = LTextureBatch
                                                       .BindBatchCache(this, texId,
                                                                       actorImage);
                                batch = pBatch;
                                batch.GLBegin();

                                textures.Put(texId, batch);
                            }

                            batch.SetTexture(actorImage);

                            if (isBitmapFilter)
                            {
                                batch.Draw(actorX, actorY, width, height, angle,
                                           thing.filterColor);
                            }
                            else
                            {
                                if (colorAlpha != 1f)
                                {
                                    alphaColor.a = colorAlpha;
                                }
                                batch.Draw(actorX, actorY, width, height, angle,
                                           alphaColor);
                                if (colorAlpha != 1f)
                                {
                                    alphaColor.a = 1;
                                }
                            }
                        }
                    }
                    if (thing.isConsumerDrawing)
                    {
                        if (actorX == 0 && actorY == 0)
                        {
                            thing.Draw(g);
                            if (isListener)
                            {
                                thing.actorListener.Draw(g);
                            }
                        }
                        else
                        {
                            g.Translate(actorX, actorY);
                            thing.Draw(g);
                            if (isListener)
                            {
                                thing.actorListener.Draw(g);
                            }
                            g.Translate(-actorX, -actorY);
                        }
                    }
                }

                int size = textures.Size();
                if (size > 0)
                {
                    for (int i = 0; i < size; i++)
                    {
                        LTextureBatch batch = (LTextureBatch)textures.Get(i);
                        batch.GLEnd();
                    }
                    textures.Clear();
                }
            }
        }