package com.whoshuu.artbox.system;

import android.graphics.Bitmap;

import com.whoshuu.artbox.artemis.ComponentMapper;
import com.whoshuu.artbox.artemis.Entity;
import com.whoshuu.artbox.component.BitmapComponent;
import com.whoshuu.artbox.component.PositionComponent;

public class SpriteRenderSystem extends RenderSystem {

    @SuppressWarnings("unchecked")
    public SpriteRenderSystem() {
        super(PositionComponent.class, BitmapComponent.class);
    }

    @Override
    protected void initialize() {
        this.positions = new ComponentMapper<PositionComponent>(PositionComponent.class,
                this.world);
        this.bitmaps = new ComponentMapper<BitmapComponent>(BitmapComponent.class, this.world);
    }

    @Override
    protected void processEntity(Entity entity) {
        PositionComponent position = positions.get(entity);
        Bitmap bitmap = bitmaps.get(entity).getBitmap();

        float x = getRenderX(position.getX());
        float y = getRenderY(position.getY());
        Bitmap bm = Bitmap.createScaledBitmap(bitmap, 50, 50, false);

        canvas.drawBitmap(bm, x - (bm.getWidth() / 2), y - (bm.getHeight() / 2), null);
    }

    private ComponentMapper<PositionComponent> positions;
    private ComponentMapper<BitmapComponent> bitmaps;
}

@@ -60,16 +60,46 @@
 .Bitmap;
+%0Aimport android.graphics.Rect;
 %0A%0Aimport
@@ -221,22 +221,22 @@
 mponent.
-Bitmap
+Sprite
 Componen
@@ -292,16 +292,110 @@
 mponent;
+%0Aimport com.whoshuu.artbox.component.RenderComponent;%0Aimport com.whoshuu.artbox.util.SizeUtil;
 %0A%0Apublic
@@ -552,22 +552,45 @@
 .class, 
-Bitmap
+SpriteComponent.class, Render
 Componen
@@ -650,24 +650,51 @@
 tialize() %7B%0A
+        dest = new Rect();%0A
         this
@@ -770,24 +770,16 @@
 .class,%0A
-        
         
@@ -826,38 +826,38 @@
 ComponentMapper%3C
-Bitmap
+Sprite
 Component%3E(Bitma
@@ -851,22 +851,22 @@
 ponent%3E(
-Bitmap
+Sprite
 Componen
@@ -883,24 +883,52 @@
 his.world);%0A
+        super.initialize();%0A
     %7D%0A%0A    @
@@ -1058,53 +1058,163 @@
     
-Bitmap bitmap = bitmaps.get(entity).getBitmap
+SpriteComponent bitmapComponent = bitmaps.get(entity);%0A        Bitmap bitmap = bitmapComponent.getBitmap();%0A        Rect source = bitmapComponent.getSource
 ();%0A
@@ -1232,16 +1232,25 @@
 oat x = 
+SizeUtil.
 getRende
@@ -1288,16 +1288,25 @@
 oat y = 
+SizeUtil.
 getRende
@@ -1326,24 +1326,25 @@
 etY());%0A
+%0A
         
 Bitmap b
@@ -1339,71 +1339,273 @@
     
-Bitmap bm = Bitmap.createScaledBitmap(bitmap, 50, 50, false
+dest.set((int) x - (source.width() / 2),%0A                (int) y - (source.height() / 2),%0A                (int) x + (source.width() / 2),%0A                (int) y + (source.height() / 2));%0A%0A        canvas.rotate((float) - Math.toDegrees(position.getAngle()), x, y
 );%0A
-%0A
     
@@ -1631,75 +1631,140 @@
 ap(b
-m, x - (bm.getWidth() / 2), y - (bm.getHeight() / 2), null);%0A    %7D%0A
+itmap, source, dest, null); %0A        canvas.rotate((float) Math.toDegrees(position.getAngle()), x, y);%0A    %7D%0A%0A    private Rect dest;
 %0A   
@@ -1846,22 +1846,22 @@
 tMapper%3C
-Bitmap
+Sprite
 Componen

Support for animations and angles