Project

General

Profile

« Previous | Next » 

Revision 352bd362

Added by Leszek Koltunski over 1 year ago

More support for configuring the stickers.

View differences:

src/main/java/org/distorted/objectlib/helpers/FactorySticker.java
184 184
    float quotient = radius/(float)Math.sqrt(vX*vX + vY*vY);
185 185
    float ret = computeAngle(vX,-vY)-computeQuotientOfCurvature(quotient,curvature);
186 186

  
187
    if( ret>=2*PI ) ret -= 2*PI;
188
    if( ret<0     ) ret += 2*PI;
187
    while( ret>=2*PI ) ret -= 2*PI;
188
    while( ret<0     ) ret += 2*PI;
189 189

  
190 190
    return ret;
191 191
    }
......
209 209

  
210 210
///////////////////////////////////////////////////////////////////////////////////////////////////
211 211

  
212
  private void drawRoundCorner(Canvas canvas, Paint paint,int color, int left, int bottom, float stroke,
213
                              float radius, float cX, float cY, float pA, float cA)
212
  private void drawRoundCorner(Canvas canvas, Paint paint, int color, int left, int bottom,
213
                               float stroke, float radius, float cX, float cY, float pA, float cA)
214 214
    {
215
    final float A = 4.0f;
216

  
215 217
    cX = (0.5f+cX)*mTexHeight;
216 218
    cY = (0.5f-cY)*mTexHeight;
217
    float R = radius*mTexHeight + stroke/2;
219
    float r = radius*mTexHeight + stroke/2;    // distance from the center of the circle arc of
220
                                               // which we are drawing to the center of the edge line
221
    float R = radius*mTexHeight + A*stroke/2;  // distance from the center of the circle to the center
222
                                               // of the arc being drawn; the arc is A times thicker.
218 223

  
219 224
    boolean isConvex = ((pA<cA && cA<pA+PI) || (pA<cA+2*PI && cA+2*PI<pA+PI));
220 225
    float startA, stopA, centerA, alpha, D;
......
230 235
      float diff = cA-centerA;
231 236
      if( diff<0 ) diff += 2*PI;
232 237
      alpha = diff> PI/2 ? PI-diff : diff;
233
      D = (float)(R/Math.sin(alpha));
238
      D = (float)(r/Math.sin(alpha));
234 239
      }
235 240
    else
236 241
      {
......
241 246
      float diff = centerA-cA;
242 247
      if( diff<0 ) diff += 2*PI;
243 248
      alpha = diff> PI/2 ? PI-diff : diff;
244
      D = (float)((R-stroke)/Math.sin(alpha));
249
      D = (float)((r-stroke)/Math.sin(alpha));
245 250
      }
246 251

  
247 252
    float sweepA = startA-stopA;
......
257 262
    sweepA *= 180/PI;
258 263

  
259 264
    if( !isConvex ) paint.setColor(color);
265
    paint.setStrokeWidth(A*stroke);
260 266
    canvas.drawArc( left+oX-R, bottom-oY-R, left+oX+R, bottom-oY+R, startA, sweepA, false, paint);
261 267
    if( !isConvex ) paint.setColor(COLOR_STROKE);
262 268
    }
......
265 271
// TODO: this doesn't really support proper drawing of rounded corners in case two neighbouring
266 272
// strokes are not equal to each other.
267 273

  
268
  private void drawEdge(Canvas canvas, Paint paint, int left, int bottom, int color,
269
                        float[] strokes, float[][] vertices, float[] angles, float[] radii )
274
  private void drawEdge(Canvas canvas, Paint paint, int left, int bottom, int color, float[] strokes,
275
                        float[][] vertices, float[] angles, float[] radii, float borders, float corners )
270 276
    {
271 277
    int length = vertices.length;
272 278

  
......
281 287

  
282 288
    for(int vert=0; vert<length; vert++)
283 289
      {
284
      float stroke = strokes[vert]*mTexHeight;
290
      float stroke = borders*strokes[vert]*mTexHeight;
285 291

  
286 292
      if( stroke>0 )
287 293
        {
......
312 318

  
313 319
    for(int vert=0; vert<length; vert++)
314 320
      {
315
      float stroke = strokes[vert]*mTexHeight;
316
      paint.setStrokeWidth(stroke);
317

  
321
      float stroke = borders*strokes[vert]*mTexHeight;
318 322
      int prev = vert==0 ? length-1 : vert-1;
319
      float prevAngle = computeSideAngle(currX-prevX,currY-prevY,radii[prev],-prevA);
320
      float currAngle = computeSideAngle(nextX-currX,nextY-currY,radii[vert],+currA);
323
      float rp = radii[prev]*corners;
324
      float rv = radii[vert]*corners;
325
      float prevAngle = computeSideAngle(currX-prevX,currY-prevY,rp,-prevA);
326
      float currAngle = computeSideAngle(nextX-currX,nextY-currY,rv,+currA);
321 327

  
322
      if( radii[vert]>0 && stroke>0 )
323
        drawRoundCorner(canvas,paint,color,left,bottom,stroke,radii[vert],currX,currY,prevAngle,currAngle);
328
      if( rv>0 && stroke>0 )
329
        drawRoundCorner(canvas,paint,color,left,bottom,stroke,rv,currX,currY,prevAngle,currAngle);
324 330

  
325 331
      prevX = currX;
326 332
      prevY = currY;
......
337 343
///////////////////////////////////////////////////////////////////////////////////////////////////
338 344
// PUBLIC
339 345

  
340
  public void drawRoundedPolygons(Canvas canvas, Paint paint, int left, int bottom, int color, int height, ObjectSticker sticker)
346
  public void drawRoundedPolygons(Canvas canvas, Paint paint, int left, int bottom, int color,
347
                                  int height, ObjectSticker sticker, float borders, float corners)
341 348
    {
342 349
    mTexHeight = height;
343 350

  
......
362 369
    for(int l=0; l<numLoops; l++)
363 370
      {
364 371
      float[] ang = (angles==null? null : angles[l]);
365
      drawEdge(canvas, paint, left, bottom, color, strokes[l], vertices[l], ang, radii[l]);
372
      drawEdge(canvas, paint, left, bottom, color, strokes[l], vertices[l], ang, radii[l], borders, corners);
366 373
      }
367 374

  
368 375
    canvas.restore();
src/main/java/org/distorted/objectlib/main/ObjectControl.java
816 816
      mPreRender.resetAllTextureMaps();
817 817
      }
818 818

  
819
///////////////////////////////////////////////////////////////////////////////////////////////////
820

  
821
    public void recreateSticker(float borders, float corners)
822
      {
823
      TwistyObject object = mPreRender.getObject();
824
      object.createTexture(borders,corners);
825
      object.setTexture();
826
      }
827

  
819 828
///////////////////////////////////////////////////////////////////////////////////////////////////
820 829

  
821 830
    public TwistyObject getObject()
src/main/java/org/distorted/objectlib/main/ObjectPreRender.java
37 37
  private TwistyObject mOldObject, mNewObject;
38 38
  private OperatingSystemInterface mOS;
39 39
  private MovesFinished mAddActionListener;
40
//  private final BlockController mBlockController;
41 40
  private final ObjectLibInterface mInterface;
42 41
  private String mDebug;
43 42
  private float mMoveX, mMoveY;
src/main/java/org/distorted/objectlib/main/TwistyObject.java
1614 1614
///////////////////////////////////////////////////////////////////////////////////////////////////
1615 1615
// the getFaceColors + final INTERNAL_COLOR in a grid (so that we do not exceed the maximum texture size)
1616 1616

  
1617
  private void createTexture()
1617
  void createTexture(float borders, float corners)
1618 1618
    {
1619 1619
    Paint paint = new Paint();
1620
    mBitmap = Bitmap.createBitmap( mNumTexCols*mTexHeight, mNumTexRows*mTexHeight, Bitmap.Config.ARGB_4444);
1621 1620
    Canvas canvas = new Canvas(mBitmap);
1622 1621

  
1623 1622
    paint.setAntiAlias(true);
......
1636 1635
          {
1637 1636
          ObjectSticker sticker = retSticker(texture/mNumFaceColors);
1638 1637
          int color = getColor(texture%mNumFaceColors);
1639
          factory.drawRoundedPolygons(canvas, paint, col*mTexHeight, (mNumTexRows-row)*mTexHeight, color, mTexHeight, sticker);
1638
          factory.drawRoundedPolygons(canvas, paint, col*mTexHeight, (mNumTexRows-row)*mTexHeight, color, mTexHeight, sticker,borders,corners);
1640 1639
          }
1641 1640
        else if( texture>mNumTextures-mNumOverrides && texture<=mNumTextures )
1642 1641
          {
......
1652 1651

  
1653 1652
  void setTexture()
1654 1653
    {
1655
    if( mBitmap==null ) createTexture();
1654
    if( mBitmap==null )
1655
      {
1656
      mBitmap = Bitmap.createBitmap( mNumTexCols*mTexHeight, mNumTexRows*mTexHeight, Bitmap.Config.ARGB_4444);
1657
      createTexture(1.0f,1.0f);
1658
      }
1656 1659

  
1657 1660
    if( !mTexture.setTextureAlreadyInverted(mBitmap) )
1658 1661
      {

Also available in: Unified diff