¶Ô±ÈÐÂÎļþ |
| | |
| | | /* |
| | | * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. |
| | | * |
| | | * Redistribution and use in source and binary forms, with or without |
| | | * modification, are permitted provided that the following conditions are met: |
| | | * |
| | | * Redistributions of source code must retain the above copyright notice, |
| | | * this list of conditions and the following disclaimer. |
| | | * Redistributions in binary form must reproduce the above copyright |
| | | * notice, this list of conditions and the following disclaimer in the |
| | | * documentation and/or other materials provided with the distribution. |
| | | * Neither the name of the dreamlu.net developer nor the names of its |
| | | * contributors may be used to endorse or promote products derived from |
| | | * this software without specific prior written permission. |
| | | * Author: Chill åºéª (smallchill@163.com) |
| | | */ |
| | | package org.springblade.core.tool.support; |
| | | |
| | | /** |
| | | * å¾çæä½ç±» |
| | | * |
| | | * @author Chill |
| | | */ |
| | | public class ImagePosition { |
| | | |
| | | /** |
| | | * å¾çé¡¶é¨. |
| | | */ |
| | | public static final int TOP = 32; |
| | | |
| | | /** |
| | | * å¾çä¸é¨. |
| | | */ |
| | | public static final int MIDDLE = 16; |
| | | |
| | | /** |
| | | * å¾çåºé¨. |
| | | */ |
| | | public static final int BOTTOM = 8; |
| | | |
| | | /** |
| | | * å¾ç左侧. |
| | | */ |
| | | public static final int LEFT = 4; |
| | | |
| | | /** |
| | | * å¾çå±
ä¸. |
| | | */ |
| | | public static final int CENTER = 2; |
| | | |
| | | /** |
| | | * å¾çå³ä¾§. |
| | | */ |
| | | public static final int RIGHT = 1; |
| | | |
| | | /** |
| | | * 横åè¾¹è·ï¼é å·¦æé 峿¶åè¾¹ççè·ç¦». |
| | | */ |
| | | private static final int PADDING_HORI = 6; |
| | | |
| | | /** |
| | | * 纵åè¾¹è·ï¼é 䏿é åºæ¶åè¾¹ççè·ç¦». |
| | | */ |
| | | private static final int PADDING_VERT = 6; |
| | | |
| | | |
| | | /** |
| | | * å¾çä¸ç[å·¦ä¸è§]çxåæ . |
| | | */ |
| | | private int boxPosX; |
| | | |
| | | /** |
| | | * å¾çä¸ç[å·¦ä¸è§]çyåæ . |
| | | */ |
| | | private int boxPosY; |
| | | |
| | | /** |
| | | * Instantiates a new image position. |
| | | * |
| | | * @param width the width |
| | | * @param height the height |
| | | * @param boxWidth the box width |
| | | * @param boxHeight the box height |
| | | * @param style the style |
| | | */ |
| | | public ImagePosition(int width, int height, int boxWidth, int boxHeight, int style) { |
| | | switch (style & 7) { |
| | | case LEFT: |
| | | boxPosX = PADDING_HORI; |
| | | break; |
| | | case RIGHT: |
| | | boxPosX = width - boxWidth - PADDING_HORI; |
| | | break; |
| | | case CENTER: |
| | | default: |
| | | boxPosX = (width - boxWidth) / 2; |
| | | } |
| | | switch (style >> 3 << 3) { |
| | | case TOP: |
| | | boxPosY = PADDING_VERT; |
| | | break; |
| | | case MIDDLE: |
| | | boxPosY = (height - boxHeight) / 2; |
| | | break; |
| | | case BOTTOM: |
| | | default: |
| | | boxPosY = height - boxHeight - PADDING_VERT; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Gets the x. |
| | | * |
| | | * @return the x |
| | | */ |
| | | public int getX() { |
| | | return getX(0); |
| | | } |
| | | |
| | | /** |
| | | * Gets the x. |
| | | * |
| | | * @param x 横ååç§» |
| | | * @return the x |
| | | */ |
| | | public int getX(int x) { |
| | | return this.boxPosX + x; |
| | | } |
| | | |
| | | /** |
| | | * Gets the y. |
| | | * |
| | | * @return the y |
| | | */ |
| | | public int getY() { |
| | | return getY(0); |
| | | } |
| | | |
| | | /** |
| | | * Gets the y. |
| | | * |
| | | * @param y 纵ååç§» |
| | | * @return the y |
| | | */ |
| | | public int getY(int y) { |
| | | return this.boxPosY + y; |
| | | } |
| | | |
| | | } |