Android Open Source - adventure.datetime Camera






From Project

Back to project page adventure.datetime.

License

The source code is released under:

MIT License

If you think the Android project adventure.datetime listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ca.cmput301f13t03.adventure_datetime.view.treeView;
/*w  w  w.java 2s.c  o  m*/
import android.graphics.*;

class Camera
{
  // these will be overwritten early on
  private static final float DEFAULT_WIDTH = 500;
  private static final float DEFAULT_HEIGHT = 1000;
  
  // x, y position of the top left of the screen in world coordinates
  private float x = 0;
  private float y = 0;
  
  // size of the view
  private float m_viewWidth = DEFAULT_WIDTH;
  private float m_viewHeight = DEFAULT_HEIGHT;
  
  // coords we want to keep centered
  private float m_xTarget = 0 - m_viewWidth / 2;
  private float m_yTarget = 0 - m_viewWidth / 2;
  
  private float m_zoomLevel = 1.0f;
  
  private Matrix m_transform = null;
  private Matrix m_inverse = null;
  
  private Object m_syncLock = new Object();
  
  public void DrawLocal(Canvas canvas, Paint paint, Path p)
  {
    synchronized (m_syncLock) 
    {
      p.transform(this.GetTransform());
      canvas.drawPath(p, paint);
      p.transform(this.GetInverseTransform());
    }
  }
  
  public void DrawLocal(Canvas canvas, Paint paint, Bitmap image, int x, int y)
  {
    synchronized (m_syncLock) 
    {
      Matrix trans = new Matrix(GetTransform());
      trans.setTranslate(x - this.x, y - this.y);
      canvas.drawBitmap(image, trans, paint);
    }
  }
  
  public void DrawLocal(Canvas canvas, Paint paint, String text, int centerX, int centerY)
  {
    synchronized (m_syncLock) 
    {
      float points[] = { centerX, centerY };
      this.GetTransform().mapPoints(points);
      canvas.drawText(text, points[0], points[1], paint);
    }
  }
  
  private Matrix GetTransform()
  {
    Matrix result = null;
    
    synchronized (m_syncLock) 
    {
      if(m_transform == null)
      {
        m_transform = new Matrix();
        m_transform.setScale(m_zoomLevel, m_zoomLevel);
        m_transform.setTranslate(-this.x, -this.y);
      }
      
      result = m_transform;
    }
    
    return result;
  }
  
  private Matrix GetInverseTransform()
  {
    Matrix result = null;
    
    synchronized (m_syncLock) 
    {
      if(m_inverse == null)
      {
        m_inverse = new Matrix();
        m_inverse.setScale(1.0f / m_zoomLevel, 1.0f / m_zoomLevel);
        m_inverse.setTranslate(this.x, this.y);
      }
      
      result = m_inverse;
    }
    
    return result;
  }
  
  public float GetXTarget()
  {
    return m_xTarget;
  }
  
  public float GetYTarget()
  {
    return m_yTarget;
  }
  
  public void ResizeView(float width, float height)
  {
    synchronized (m_syncLock) 
    {
      m_viewWidth = width;
      m_viewHeight = height;
      
      m_inverse = null;
      m_transform = null;
    }
    
    LookAt(m_xTarget, m_yTarget);
  }
  
  public void LookAt(float x, float y)
  {
    synchronized (m_syncLock) 
    {
      m_xTarget = x;
      m_yTarget = y;
      
      this.x = m_xTarget - m_viewWidth / 2;
      this.y = m_yTarget - m_viewHeight / 2;
      
      m_inverse = null;
      m_transform = null;
    }
  }
  
  public void ScreenCordsToWorldCords(float[] screenCords)
  {
    synchronized (m_syncLock) 
    {
      GetInverseTransform().mapPoints(screenCords);
    }
  }
}




Java Source Code List

ca.cmput301f13t03.adventure_datetime.controller.AuthorControllerTest.java
ca.cmput301f13t03.adventure_datetime.controller.AuthorController.java
ca.cmput301f13t03.adventure_datetime.controller.UserControllerTest.java
ca.cmput301f13t03.adventure_datetime.controller.UserController.java
ca.cmput301f13t03.adventure_datetime.model.AccountServiceTests.java
ca.cmput301f13t03.adventure_datetime.model.AccountService.java
ca.cmput301f13t03.adventure_datetime.model.BookmarkTest.java
ca.cmput301f13t03.adventure_datetime.model.Bookmark.java
ca.cmput301f13t03.adventure_datetime.model.ChoiceTest.java
ca.cmput301f13t03.adventure_datetime.model.Choice.java
ca.cmput301f13t03.adventure_datetime.model.CommentTest.java
ca.cmput301f13t03.adventure_datetime.model.Comment.java
ca.cmput301f13t03.adventure_datetime.model.ES.java
ca.cmput301f13t03.adventure_datetime.model.ImageTest.java
ca.cmput301f13t03.adventure_datetime.model.Image.java
ca.cmput301f13t03.adventure_datetime.model.StoryDBTest.java
ca.cmput301f13t03.adventure_datetime.model.StoryDB.java
ca.cmput301f13t03.adventure_datetime.model.StoryFragmentTest.java
ca.cmput301f13t03.adventure_datetime.model.StoryFragment.java
ca.cmput301f13t03.adventure_datetime.model.StoryManager.java
ca.cmput301f13t03.adventure_datetime.model.StoryTest.java
ca.cmput301f13t03.adventure_datetime.model.Story.java
ca.cmput301f13t03.adventure_datetime.model.ThreadPool.java
ca.cmput301f13t03.adventure_datetime.model.WebStorageCleaner.java
ca.cmput301f13t03.adventure_datetime.model.WebStorageTest.java
ca.cmput301f13t03.adventure_datetime.model.WebStorage.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IAllFragmentsListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IBookmarkListListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ICommentsListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ICurrentFragmentListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ICurrentStoryListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ILocalStorage.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.ILocalStoriesListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IOnlineStoriesListener.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IStoryModelDirector.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IStoryModelPresenter.java
ca.cmput301f13t03.adventure_datetime.model.Interfaces.IWebStorage.java
ca.cmput301f13t03.adventure_datetime.serviceLocator.Locator.java
ca.cmput301f13t03.adventure_datetime.view.AuthorEdit_Edit.java
ca.cmput301f13t03.adventure_datetime.view.AuthorEdit_Overview.java
ca.cmput301f13t03.adventure_datetime.view.AuthorEdit.java
ca.cmput301f13t03.adventure_datetime.view.AuthorStories.java
ca.cmput301f13t03.adventure_datetime.view.AuthorStoryDescription.java
ca.cmput301f13t03.adventure_datetime.view.AuthorViewPager.java
ca.cmput301f13t03.adventure_datetime.view.BrowseFragment.java
ca.cmput301f13t03.adventure_datetime.view.BrowseView.java
ca.cmput301f13t03.adventure_datetime.view.CommentsView.java
ca.cmput301f13t03.adventure_datetime.view.ContinueView.java
ca.cmput301f13t03.adventure_datetime.view.FragmentViewActivity.java
ca.cmput301f13t03.adventure_datetime.view.FragmentView.java
ca.cmput301f13t03.adventure_datetime.view.FullScreen_Image.java
ca.cmput301f13t03.adventure_datetime.view.IFragmentSelected.java
ca.cmput301f13t03.adventure_datetime.view.MainViewTest.java
ca.cmput301f13t03.adventure_datetime.view.MainView.java
ca.cmput301f13t03.adventure_datetime.view.StoryDescription.java
ca.cmput301f13t03.adventure_datetime.view.treeView.Camera.java
ca.cmput301f13t03.adventure_datetime.view.treeView.ConnectionPlacer.java
ca.cmput301f13t03.adventure_datetime.view.treeView.FragmentConnection.java
ca.cmput301f13t03.adventure_datetime.view.treeView.FragmentNode.java
ca.cmput301f13t03.adventure_datetime.view.treeView.GridSegment.java
ca.cmput301f13t03.adventure_datetime.view.treeView.InputHandler.java
ca.cmput301f13t03.adventure_datetime.view.treeView.NodeGrid.java
ca.cmput301f13t03.adventure_datetime.view.treeView.NodePlacer.java
ca.cmput301f13t03.adventure_datetime.view.treeView.Region.java
ca.cmput301f13t03.adventure_datetime.view.treeView.TreeView.java