Project

General

Profile

Download (3.83 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / main / DistortedSurface.java @ c41d046c

1 c5369f1b leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 fe82a979 Leszek Koltunski
package org.distorted.library.main;
21 c5369f1b leszek
22 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
23
24 226144d0 leszek
abstract class DistortedSurface extends DistortedObject
25
{
26 c7da4e65 leszek
  int mColorCreated;
27 9ed80185 Leszek Koltunski
  int mNumColors;
28
  int[] mColorH;
29 6e7c8721 Leszek Koltunski
  int mWidth, mHeight;
30 af4cc5db Leszek Koltunski
31 af27df87 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
32
33 9ed80185 Leszek Koltunski
  DistortedSurface(int width, int height, int create, int numcolors, int type)
34 af4cc5db Leszek Koltunski
    {
35 226144d0 leszek
    super(create,type);
36
37 9ed80185 Leszek Koltunski
    mNumColors    = numcolors;
38 6e7c8721 Leszek Koltunski
    mWidth        = width ;
39
    mHeight       = height;
40 c7da4e65 leszek
    mColorCreated = create;
41 9ed80185 Leszek Koltunski
42
    if( mNumColors>0 )
43
      {
44
      mColorH = new int[mNumColors];
45
      for( int i=0; i<mNumColors; i++ )  mColorH[i] = 0;
46
      }
47 af4cc5db Leszek Koltunski
    }
48
49 f28fffc2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
50 226144d0 leszek
// debugging only
51 f28fffc2 Leszek Koltunski
52 226144d0 leszek
  String printDetails()
53 f28fffc2 Leszek Koltunski
    {
54 226144d0 leszek
    return getClass().getSimpleName()+" "+mWidth+"x"+mHeight;
55 f28fffc2 Leszek Koltunski
    }
56
57 af4cc5db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
58
// PUBLIC API
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60 c5369f1b leszek
/**
61 3a70bd6d leszek
 * Return the width of this Surface.
62 af4cc5db Leszek Koltunski
 *
63 3a70bd6d leszek
 * @return width of the Object, in pixels.
64 c5369f1b leszek
 */
65 af4cc5db Leszek Koltunski
  public int getWidth()
66
    {
67 6e7c8721 Leszek Koltunski
    return mWidth;
68 af4cc5db Leszek Koltunski
    }
69
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71 c5369f1b leszek
/**
72 3a70bd6d leszek
 * Return the height of this Surface.
73 af4cc5db Leszek Koltunski
 *
74 3a70bd6d leszek
 * @return height of the Object, in pixels.
75 c5369f1b leszek
 */
76 af4cc5db Leszek Koltunski
  public int getHeight()
77
    {
78 6e7c8721 Leszek Koltunski
    return mHeight;
79 af4cc5db Leszek Koltunski
    }
80
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82 c5369f1b leszek
/**
83 8d52a49c Leszek Koltunski
 * Return the depth of this Surface.
84 af4cc5db Leszek Koltunski
 * <p>
85
 * Admittedly quite a strange method. Why do we need to pass a Mesh to it? Because one cannot determine
86
 * 'depth' of a Surface (bitmap really!) when rendered based only on the texture itself, that depends
87
 * on the Mesh it is rendered with.
88
 *
89
 * @return depth of the Object, in pixels.
90 c5369f1b leszek
 */
91 af4cc5db Leszek Koltunski
  public int getDepth(MeshObject mesh)
92
    {
93 6e7c8721 Leszek Koltunski
    return mesh==null ? 0 : (int)(mWidth*mesh.zFactor);
94 af4cc5db Leszek Koltunski
    }
95 226144d0 leszek
}