mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
figure board dimensions in one place rather than two, then share.
This commit is contained in:
parent
51f3412567
commit
71e65433d3
3 changed files with 80 additions and 80 deletions
|
@ -0,0 +1,32 @@
|
|||
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
|
||||
/*
|
||||
* Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
|
||||
* rights reserved.
|
||||
*
|
||||
* 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 2 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, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
|
||||
// Why does this have to be its own class...
|
||||
public class BoardDims {
|
||||
public int width, height; // of the bitmap
|
||||
public int top;
|
||||
public int scoreHt;
|
||||
public int boardHt;
|
||||
public int trayTop, trayHt;
|
||||
public int cellSize;
|
||||
}
|
|
@ -113,12 +113,6 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
|
|||
private ZoomButtonsController m_zoomButtons;
|
||||
private boolean m_useZoomControl;
|
||||
|
||||
public BoardView( Context context )
|
||||
{
|
||||
super( context );
|
||||
init( context );
|
||||
}
|
||||
|
||||
// called when inflating xml
|
||||
public BoardView( Context context, AttributeSet attrs )
|
||||
{
|
||||
|
@ -126,11 +120,6 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
|
|||
init( context );
|
||||
}
|
||||
|
||||
// public boolean onClick( View view ) {
|
||||
// Utils.logf( "onClick called" );
|
||||
// return view == this;
|
||||
// }
|
||||
|
||||
public boolean onTouchEvent( MotionEvent event )
|
||||
{
|
||||
int action = event.getAction();
|
||||
|
@ -238,6 +227,33 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
|
|||
return m_useZoomControl ? 0 : m_top;
|
||||
}
|
||||
|
||||
private BoardDims figureBoardDims( int width, int height,
|
||||
CurGameInfo gi )
|
||||
{
|
||||
BoardDims result = new BoardDims();
|
||||
result.width = width;
|
||||
|
||||
int nCells = gi.boardSize;
|
||||
int cellSize = width / nCells;
|
||||
result.trayHt = cellSize * 3;
|
||||
result.scoreHt = cellSize; // scoreHt same as cells for proportion
|
||||
int wantHt = result.trayHt + result.scoreHt + (cellSize * nCells);
|
||||
int nToScroll = 0;
|
||||
if ( wantHt <= height ) {
|
||||
result.top = (height - wantHt) / 2;
|
||||
} else {
|
||||
nToScroll = nCells - ((height - (cellSize*3)) / cellSize);
|
||||
result.trayHt = height - (cellSize * (1 + (nCells-nToScroll)));
|
||||
result.top = 0;
|
||||
}
|
||||
|
||||
result.boardHt = cellSize * (nCells-nToScroll);
|
||||
result.trayTop = result.scoreHt + result.boardHt;
|
||||
result.height = result.scoreHt + result.boardHt + result.trayHt;
|
||||
result.cellSize = cellSize;
|
||||
return result;
|
||||
} // figureBoardDims
|
||||
|
||||
private boolean layoutBoardOnce()
|
||||
{
|
||||
final int width = getWidth();
|
||||
|
@ -252,39 +268,16 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
|
|||
m_layoutHeight = height;
|
||||
m_fontDims = null; // force recalc of font
|
||||
|
||||
int nCells = m_gi.boardSize;
|
||||
int cellSize = width / nCells;
|
||||
|
||||
// If we're vertical, we can likely fit all the board and
|
||||
// have a tall tray too. If horizontal, let's assume
|
||||
// that's so things will be big, and rather than make 'em
|
||||
// small assume some scrolling. So make the tray 1.5 to
|
||||
// 2.5x a cell width in height and then scroll however
|
||||
// many.
|
||||
|
||||
int trayHt = cellSize * 3;
|
||||
int scoreHt = cellSize; // scoreboard ht same as cells for
|
||||
// proportion
|
||||
int wantHt = trayHt + scoreHt + (cellSize * nCells);
|
||||
int nToScroll = 0;
|
||||
if ( wantHt <= height ) {
|
||||
m_top = (height - wantHt) / 2;
|
||||
} else {
|
||||
//
|
||||
nToScroll = nCells - ((height - (cellSize*3)) / cellSize);
|
||||
trayHt = height - (cellSize * (1 + (nCells-nToScroll)));
|
||||
m_top = 0;
|
||||
}
|
||||
|
||||
m_bitmap = Bitmap.createBitmap( 1 + width,
|
||||
1 + trayHt + scoreHt
|
||||
+ (cellSize *(nCells-nToScroll)),
|
||||
BoardDims dims = figureBoardDims( width, height, m_gi );
|
||||
m_top = dims.top;
|
||||
|
||||
m_bitmap = Bitmap.createBitmap( 1 + dims.width,
|
||||
1 + dims.height,
|
||||
Bitmap.Config.ARGB_8888 );
|
||||
m_canvas = new Canvas( m_bitmap );
|
||||
|
||||
// need to synchronize??
|
||||
m_jniThread.handle( JNIThread.JNICmd.CMD_LAYOUT, width,
|
||||
height, m_gi.boardSize );
|
||||
m_jniThread.handle( JNIThread.JNICmd.CMD_LAYOUT, dims );
|
||||
m_jniThread.handle( JNIThread.JNICmd.CMD_DRAW );
|
||||
layoutDone = true;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.graphics.Paint;
|
|||
import android.graphics.Rect;
|
||||
|
||||
import org.eehouse.android.xw4.R;
|
||||
import org.eehouse.android.xw4.BoardDims;
|
||||
import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
|
||||
|
||||
public class JNIThread extends Thread {
|
||||
|
@ -143,59 +144,35 @@ public class JNIThread extends Thread {
|
|||
Message.obtain( m_handler, DIALOG, titleArg, 0, text ).sendToTarget();
|
||||
}
|
||||
|
||||
private void doLayout( int width, int height, int nCells )
|
||||
private void doLayout( BoardDims dims )
|
||||
{
|
||||
int cellSize = width / nCells;
|
||||
|
||||
// If we're vertical, we can likely fit all the board and
|
||||
// have a tall tray too. If horizontal, let's assume
|
||||
// that's so things will be big, and rather than make 'em
|
||||
// small assume some scrolling. So make the tray 1.5 to
|
||||
// 2.5x a cell width in height and then scroll however
|
||||
// many.
|
||||
|
||||
int trayHt = cellSize * 3;
|
||||
int scoreHt = cellSize; // scoreboard ht same as cells for
|
||||
// proportion
|
||||
int wantHt = trayHt + scoreHt + (cellSize * nCells);
|
||||
int nToScroll = 0;
|
||||
if ( wantHt <= height ) {
|
||||
|
||||
} else {
|
||||
//
|
||||
nToScroll = nCells - ((height - (cellSize*3)) / cellSize);
|
||||
Utils.logf( "nToScroll: " + nToScroll );
|
||||
trayHt = height - (cellSize * (1 + (nCells-nToScroll)));
|
||||
}
|
||||
|
||||
int scoreWidth = width;
|
||||
int scoreWidth = dims.width;
|
||||
|
||||
if ( DeviceRole.SERVER_STANDALONE != m_gi.serverRole ) {
|
||||
scoreWidth -= cellSize;
|
||||
m_connsIconRect = new Rect( scoreWidth, 0,
|
||||
scoreWidth + cellSize, cellSize );
|
||||
scoreWidth -= dims.cellSize;
|
||||
m_connsIconRect =
|
||||
new Rect( scoreWidth, 0, scoreWidth + dims.cellSize,
|
||||
dims.cellSize );
|
||||
}
|
||||
|
||||
if ( m_gi.timerEnabled ) {
|
||||
Paint paint = new Paint();
|
||||
paint.setTextSize( scoreHt );
|
||||
paint.setTextSize( dims.scoreHt );
|
||||
Rect rect = new Rect();
|
||||
paint.getTextBounds( "-00:00", 0, 6, rect );
|
||||
int timerWidth = rect.right;
|
||||
scoreWidth -= timerWidth;
|
||||
XwJNI.board_setTimerLoc( m_jniGamePtr, scoreWidth, 0, timerWidth,
|
||||
scoreHt );
|
||||
dims.scoreHt );
|
||||
}
|
||||
XwJNI.board_setScoreboardLoc( m_jniGamePtr, 0, 0, scoreWidth,
|
||||
scoreHt, true );
|
||||
dims.scoreHt, true );
|
||||
|
||||
XwJNI.board_setPos( m_jniGamePtr, 0, scoreHt,
|
||||
width-1, ((nCells-nToScroll) * cellSize),
|
||||
false );
|
||||
XwJNI.board_setPos( m_jniGamePtr, 0, dims.scoreHt,
|
||||
dims.width-1, dims.boardHt, false );
|
||||
|
||||
XwJNI.board_setTrayLoc( m_jniGamePtr, 0,
|
||||
scoreHt + ((nCells-nToScroll) * cellSize),
|
||||
width, trayHt, kMinDivWidth );
|
||||
XwJNI.board_setTrayLoc( m_jniGamePtr, 0, dims.trayTop,
|
||||
dims.width-1, dims.trayHt, kMinDivWidth );
|
||||
|
||||
XwJNI.board_invalAll( m_jniGamePtr );
|
||||
}
|
||||
|
@ -285,9 +262,7 @@ public class JNIThread extends Thread {
|
|||
break;
|
||||
|
||||
case CMD_LAYOUT:
|
||||
doLayout( ((Integer)args[0]).intValue(),
|
||||
((Integer)args[1]).intValue(),
|
||||
((Integer)args[2]).intValue() );
|
||||
doLayout( (BoardDims)args[0] );
|
||||
draw = true;
|
||||
break;
|
||||
|
||||
|
|
Loading…
Reference in a new issue