📄 gxapi_graphics_kni.c
字号:
/* * * * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * 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 version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */#include <midpError.h>#include <midpEventUtil.h>#include <gx_graphics.h>#include <gxapi_constants.h>#include <gxapi_graphics.h>#include "gxapi_intern_graphics.h"#ifdef UNDER_CE#include "gxj_intern_graphics.h"#include "gxj_intern_putpixel.h"#include "gxj_intern_image.h"extern void fast_rect_8x8(void*first_pixel, int ypitch, int pixel);#endif/** * Get a C structure representing the given <tt>ImageData</tt> class. */#define GET_IMAGEDATA_PTR_FROM_GRAPHICS(handle) \ GXAPI_GET_GRAPHICS_PTR(handle)->img != NULL ? \ GXAPI_GET_GRAPHICS_PTR(handle)->img->imageData : \ (java_imagedata*)NULL/** * Gets the clipping region of the given graphics object. * * @param G handle to the <tt>Graphics</tt> object * @param ARRAY native <tt>jshort</tt> array to save the clip data */#define GET_CLIP(G, ARRAY) \ ARRAY[0] = GXAPI_GET_GRAPHICS_PTR(G)->clipX1, \ ARRAY[1] = GXAPI_GET_GRAPHICS_PTR(G)->clipY1, \ ARRAY[2] = GXAPI_GET_GRAPHICS_PTR(G)->clipX2, \ ARRAY[3] = GXAPI_GET_GRAPHICS_PTR(G)->clipY2/** * Translate the pixel location according to the translation of * the given graphics object. * * @param G handle to the <tt>Graphics</tt> object * @param X variable representing the <tt>x</tt> coordinate to be translated; * this macro sets the value of X * @param Y variable representing the <tt>y</tt> coordinate to be translated; * this macro sets the value of Y */#define TRANSLATE(G, X, Y) \ (X) += GXAPI_GET_GRAPHICS_PTR((G))->transX, \ (Y) += GXAPI_GET_GRAPHICS_PTR((G))->transY/** * @file * Implementation of Java native methods for the <tt>Graphics</tt> class. *//** * Draws a straight line between the given coordinates using the * current color, stroke style, and clipping data. * <p> * Java declaration: * <pre> * drawLine(IIII)V * </pre> * * @param x1 The x coordinate of the start of the line * @param y1 The y coordinate of the start of the line * @param x2 The x coordinate of the end of the line * @param y2 The y coordinate of the end of the line */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(javax_microedition_lcdui_Graphics_drawLine) { int y2 = KNI_GetParameterAsInt(4); int x2 = KNI_GetParameterAsInt(3); int y1 = KNI_GetParameterAsInt(2); int x1 = KNI_GetParameterAsInt(1); KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); if (GRAPHICS_OP_IS_ALLOWED(thisObject)) { jshort clip[4]; /* Defined in Graphics.java as 4 shorts */ TRANSLATE(thisObject, x1, y1); TRANSLATE(thisObject, x2, y2); GET_CLIP(thisObject, clip); gx_draw_line(GET_PIXEL(thisObject), clip, GET_IMAGEDATA_PTR_FROM_GRAPHICS(thisObject), GET_LINESTYLE(thisObject), x1, y1, x2, y2); } KNI_EndHandles(); KNI_ReturnVoid();}/** * Draws the outline of the specified rectangle using the current * color and stroke style. According to the MIDP specification, * if either the <tt>width</tt> or <tt>height</tt> are negative, * no rectangle is drawn. * <p> * Java declaration: * <pre> * drawRect(IIII)V * </pre> * * @param x The x coordinate of the rectangle to be drawn * @param y The y coordinate of the rectangle to be drawn * @param width The width of the rectangle to be drawn * @param height The height of the rectangle to be drawn */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(javax_microedition_lcdui_Graphics_drawRect) { int h = KNI_GetParameterAsInt(4); int w = KNI_GetParameterAsInt(3); int y = KNI_GetParameterAsInt(2); int x = KNI_GetParameterAsInt(1); /* * @note { Spec verify step: "If either width or height * is less than zero, nothing is drawn." } */ if ((w >= 0) && (h >= 0)) { KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); if (GRAPHICS_OP_IS_ALLOWED(thisObject)) { jshort clip[4]; /* Defined in Graphics.java as 4 shorts */ TRANSLATE(thisObject, x, y); GET_CLIP(thisObject, clip); gx_draw_rect(GET_PIXEL(thisObject), clip, GET_IMAGEDATA_PTR_FROM_GRAPHICS(thisObject), GET_LINESTYLE(thisObject), x, y, w, h); } KNI_EndHandles(); } KNI_ReturnVoid();}/** * Fills the specified rectangle using the current color and * stroke style. According to the MIDP specification, if either * the <tt>width</tt> or <tt>height</tt> are negative, no * rectangle is drawn. * <p> * Java declaration: * <pre> * fillRect(IIII)V * </pre> * * @param x The x coordinate of the rectangle to be drawn * @param y The y coordinate of the rectangle to be drawn * @param width The width of the rectangle to be drawn * @param height The height of the rectangle to be drawn */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(javax_microedition_lcdui_Graphics_fillRect) { int h = KNI_GetParameterAsInt(4); int w = KNI_GetParameterAsInt(3); int y = KNI_GetParameterAsInt(2); int x = KNI_GetParameterAsInt(1); /* * @note { Spec verify step: "If either width or height * is zero or less, nothing is drawn." } */ if ((w >= 0) && (h >= 0)) { KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); if (GRAPHICS_OP_IS_ALLOWED(thisObject)) { jshort clip[4]; /* Defined in Graphics.java as 4 shorts */ TRANSLATE(thisObject, x, y); GET_CLIP(thisObject, clip); gx_fill_rect(GET_PIXEL(thisObject), clip, GET_IMAGEDATA_PTR_FROM_GRAPHICS(thisObject), GET_LINESTYLE(thisObject), x, y, w, h); } KNI_EndHandles(); } KNI_ReturnVoid();}/** * Draws the outline of the specified rectangle, with rounded corners, * using the current color and stroke style. According to the MIDP * specification, if either the <tt>width</tt> or <tt>height</tt> * are negative, no rectangle is drawn. * <p> * Java declaration: * <pre> * drawRoundRect(IIIIII)V * </pre> * * @param x The x coordinate of the rectangle to be drawn * @param y The y coordinate of the rectangle to be drawn * @param width The width of the rectangle to be drawn * @param height The height of the rectangle to be drawn * @param arcWidth The horizontal diameter of the arc at the four corners * @param arcHeight The vertical diameter of the arc at the four corners */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(javax_microedition_lcdui_Graphics_drawRoundRect) { int arcHeight = KNI_GetParameterAsInt(6); int arcWidth = KNI_GetParameterAsInt(5); int h = KNI_GetParameterAsInt(4); int w = KNI_GetParameterAsInt(3); int y = KNI_GetParameterAsInt(2); int x = KNI_GetParameterAsInt(1); /* * @note { Spec verify step: "If either width or height * is less than zero, nothing is drawn." } */ if ((w >= 0) && (h >= 0)) { KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); if (GRAPHICS_OP_IS_ALLOWED(thisObject)) { jshort clip[4]; /* Defined in Graphics.java as 4 shorts */ TRANSLATE(thisObject, x, y); GET_CLIP(thisObject, clip); gx_draw_roundrect(GET_PIXEL(thisObject), clip, GET_IMAGEDATA_PTR_FROM_GRAPHICS(thisObject), GET_LINESTYLE(thisObject), x, y, w, h, arcWidth, arcHeight); } KNI_EndHandles(); } KNI_ReturnVoid();}/** * Fills the specified rectangle, with rounded corners, using * the current color and stroke style. According to the MIDP * specification, if either the <tt>width</tt> or <tt>height</tt> * are negative, no rectangle is drawn. * <p> * Java declaration: * <pre> * fillRoundRect(IIIIII)V * </pre> * * @param x The x coordinate of the rectangle to be drawn * @param y The y coordinate of the rectangle to be drawn * @param width The width of the rectangle to be drawn * @param height The height of the rectangle to be drawn * @param arcWidth The horizontal diameter of the arc at the four corners * @param arcHeight The vertical diameter of the arc at the four corners */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(javax_microedition_lcdui_Graphics_fillRoundRect) { int arcHeight = KNI_GetParameterAsInt(6); int arcWidth = KNI_GetParameterAsInt(5); int h = KNI_GetParameterAsInt(4); int w = KNI_GetParameterAsInt(3); int y = KNI_GetParameterAsInt(2); int x = KNI_GetParameterAsInt(1); /* * @note { Spec verify step: "If either width or height * is zero or less, nothing is drawn." } */ if ((w >= 0) && (h >= 0)) { KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); if (GRAPHICS_OP_IS_ALLOWED(thisObject)) { jshort clip[4]; /* Defined in Graphics.java as 4 shorts */ TRANSLATE(thisObject, x, y); GET_CLIP(thisObject, clip); gx_fill_roundrect(GET_PIXEL(thisObject), clip, GET_IMAGEDATA_PTR_FROM_GRAPHICS(thisObject), GET_LINESTYLE(thisObject), x, y, w, h, arcWidth, arcHeight); } KNI_EndHandles(); } KNI_ReturnVoid();}/** * Draws the outline of the specified circular or elliptical arc * segment using the current color and stroke style. According * to the MIDP specification, if either the <tt>width</tt> or * <tt>height</tt> are negative, no arc is drawn. * <p> * Java declaration: * <pre> * drawArc(IIIIII)V * </pre> * * @param x The x coordinate of the upper-left corner of the arc * to be drawn * @param y The y coordinate of the upper-left corner of the arc * to be drawn * @param width The width of the arc to be drawn * @param height The height of the arc to be drawn * @param startAngle The beginning angle * @param arcAngle The angular extent of the arc, relative to * <tt>startAngle</tt> */KNIEXPORT KNI_RETURNTYPE_VOIDKNIDECL(javax_microedition_lcdui_Graphics_drawArc) { int arcAngle = KNI_GetParameterAsInt(6); int startAngle = KNI_GetParameterAsInt(5); int h = KNI_GetParameterAsInt(4); int w = KNI_GetParameterAsInt(3); int y = KNI_GetParameterAsInt(2); int x = KNI_GetParameterAsInt(1); /* * @note { Spec verify step: "If either width or height * is less than zero, nothing is drawn." } */ if ((w >= 0) && (h >= 0)) { KNI_StartHandles(1); KNI_DeclareHandle(thisObject); KNI_GetThisPointer(thisObject); if (GRAPHICS_OP_IS_ALLOWED(thisObject)) { jshort clip[4]; /* Defined in Graphics.java as 4 shorts */ TRANSLATE(thisObject, x, y); #ifdef PLATFORM_SUPPORT_CCW_ARC_ONLY /* this block transfer any negative number of * start angle or arc angle to positive and * always counter-clockwise. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -