⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drawable.java

📁 国外人写的操作感挺好的一款滑雪游戏.结构也比较清楚
💻 JAVA
字号:
// Copyright (c) 2004 Venan Entertainment, Inc. All rights reserved.
//
// Venan Entertainment, Inc.,  Middletown, Connecticut 06457
// http://www.venan.com
//

import javax.microedition.lcdui.Graphics;

public class Drawable
{
	public static final int ALIGNH_NONE = 0;
	public static final int ALIGNH_LEFT = 1;
	public static final int ALIGNH_CENTER = 2;
	public static final int ALIGNH_RIGHT = 3;
	private static final int	ALIGN_HORZ = 0x3;

	public static final int ALIGNV_NONE = 0;
	public static final int ALIGNV_TOP = 1<<2;
	public static final int ALIGNV_MIDDLE = 2<<2;
	public static final int ALIGNV_BOTTOM = 3<<2;
	private static final int	ALIGN_VERT = 0xc;

	public int 				m_iX, m_iY;
	public int 				m_iWidth, m_iHeight;
	public boolean 			m_bVisible = true;
	private int 			m_iAlign = 0;
	Window	 				m_parent;
	public Drawable			m_next;
	public Drawable			m_prev;

	public Drawable()
	{
	}

	public void setPosition( int x, int y )
	{
		m_iX = x;
		m_iY = y;
	}

	public void setDimensions( int width, int height )
	{
		m_iWidth = width;
		m_iHeight = height;
		calculateAlignment();
		if (m_parent != null)
			m_parent.adjustSpacing();
	}

	public void setParent( Window parent )
	{
	    m_parent = parent;
		calculateAlignment();
	}

	public void setAlignment( int iAlign )
	{
	    m_iAlign = iAlign;
		calculateAlignment();
	}

	void calculateAlignment()
	{
		if (m_parent == null || (m_iAlign == 0))
			return;

		int iAlignH = ALIGN_HORZ & m_iAlign;
		if (iAlignH != ALIGNH_NONE)
		{
			switch( iAlignH )
			{
				case ALIGNH_LEFT:
					m_iX = 0; break;
				case ALIGNH_CENTER:
					m_iX = (m_parent.m_iWidth - m_iWidth) >> 1; break;
				case ALIGNH_RIGHT:
					m_iX = (m_parent.m_iWidth - m_iWidth); break;
			}
		}

		int iAlignV = ALIGN_VERT & m_iAlign;
		if (iAlignV != ALIGNV_NONE)
		{
			switch( iAlignV )
			{
				case ALIGNV_TOP:
					m_iY = 0; break;
				case ALIGNV_MIDDLE:
					m_iY = (m_parent.m_iHeight - m_iHeight) >> 1; break;
				case ALIGNV_BOTTOM:
					m_iY = (m_parent.m_iHeight - m_iHeight); break;
			}
		}
	}

	public final int getAbsoluteX()
	{
		if ( m_parent != null )
		{
			return m_parent.getAbsoluteX() + m_iX;
		}
		else
		{
			return m_iX;
		}
	}

	public final int getAbsoluteY()
	{
		if ( m_parent != null )
		{
			return m_parent.getAbsoluteY() + m_iY;
		}
		else
		{
			return m_iY;
		}
	}

	public void paint( Graphics g ) {}

	public void translatePaint( Graphics g, int iX, int iY )
	{
		m_iX += iX;
		m_iY += iY;
		paint(g);
		m_iX -= iX;
		m_iY -= iY;
	}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -