<commit_before>/*
Copyright (C) 2013 <NAME>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package info.meoblast001.thugaim.engine;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.SurfaceView;
import android.view.SurfaceHolder;

import java.util.concurrent.LinkedBlockingQueue;

public class Graphics extends SurfaceView implements SurfaceHolder.Callback
{
  private class BitmapRenderOperation
  {
    public Bitmap bitmap;
    public int x, y;
    public float angle;
  }

  private Context context = null;
  private int focus_x = 0, focus_y = 0;
  private float focus_angle = 0.0f;
  private LinkedBlockingQueue<BitmapRenderOperation> render_operations =
    new LinkedBlockingQueue<BitmapRenderOperation>();

  public Graphics(Context context, AttributeSet attr)
  {
    super(context, attr);
    this.context = context;

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
  }

  public void surfaceChanged(SurfaceHolder holder, int format, int width,
                             int height)
  {
  }

  public void surfaceCreated(SurfaceHolder holder)
  {
  }

  public void surfaceDestroyed(SurfaceHolder holder)
  {
  }

  public void draw(Bitmap bitmap, int x, int y, float angle)
  {
    BitmapRenderOperation operation = new BitmapRenderOperation();
    operation.bitmap = bitmap;
    operation.x = x;
    operation.y = y;
    operation.angle = angle;
    render_operations.add(operation);
  }

  public void focusOn(int x, int y, float angle)
  {
    focus_x = x;
    focus_y = y;
    focus_angle = angle;
  }

  public void finishDraw()
  {
    SurfaceHolder holder = getHolder();

    if (!holder.getSurface().isValid())
      return;

    Canvas canvas = holder.lockCanvas();
    canvas.drawColor(Color.BLACK);

    canvas.translate((float) -focus_x, (float) -focus_y);
    canvas.rotate(-focus_angle);
    canvas.save();
    while (render_operations.size() > 0)
    {
      BitmapRenderOperation operation = render_operations.poll();

      canvas.save();
      canvas.translate((float) operation.x, (float) operation.y);
      canvas.rotate(operation.angle);
      canvas.drawBitmap(operation.bitmap, 0, 0, null);<commit_msg>Origin of bitmap rotations is the centre of the bitmap<commit_after>/*
Copyright (C) 2013 <NAME>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package info.meoblast001.thugaim.engine;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.SurfaceView;
import android.view.SurfaceHolder;

import java.util.concurrent.LinkedBlockingQueue;

public class Graphics extends SurfaceView implements SurfaceHolder.Callback
{
  private class BitmapRenderOperation
  {
    public Bitmap bitmap;
    public int x, y;
    public float angle;
  }

  private Context context = null;
  private int focus_x = 0, focus_y = 0;
  private float focus_angle = 0.0f;
  private LinkedBlockingQueue<BitmapRenderOperation> render_operations =
    new LinkedBlockingQueue<BitmapRenderOperation>();

  public Graphics(Context context, AttributeSet attr)
  {
    super(context, attr);
    this.context = context;

    SurfaceHolder holder = getHolder();
    holder.addCallback(this);
  }

  public void surfaceChanged(SurfaceHolder holder, int format, int width,
                             int height)
  {
  }

  public void surfaceCreated(SurfaceHolder holder)
  {
  }

  public void surfaceDestroyed(SurfaceHolder holder)
  {
  }

  public void draw(Bitmap bitmap, int x, int y, float angle)
  {
    BitmapRenderOperation operation = new BitmapRenderOperation();
    operation.bitmap = bitmap;
    operation.x = x;
    operation.y = y;
    operation.angle = angle;
    render_operations.add(operation);
  }

  public void focusOn(int x, int y, float angle)
  {
    focus_x = x;
    focus_y = y;
    focus_angle = angle;
  }

  public void finishDraw()
  {
    SurfaceHolder holder = getHolder();

    if (!holder.getSurface().isValid())
      return;

    Canvas canvas = holder.lockCanvas();
    canvas.drawColor(Color.BLACK);

    canvas.translate((float) -focus_x, (float) -focus_y);
    canvas.rotate(-focus_angle);
    canvas.save();
    while (render_operations.size() > 0)
    {
      BitmapRenderOperation operation = render_operations.poll();

      canvas.save();
      canvas.translate((float) operation.x, (float) operation.y);
      canvas.rotate(operation.angle);
      canvas.drawBitmap(operation.bitmap,
                        (int) (-operation.bitmap.getWidth() / 2),
                        (int) (-operation.bitmap.getHeight() / 2), null);
{'fraction_non_alphanumeric': 0.0878561736770692, 'fraction_numerical': 0.00508819538670285, 'mean_word_length': 3.571317829457364, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2884393', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1595, 'n_words': 540}