- 论坛徽章:
- 0
|
graphics是这样改的,看看MIDP文档,注意边界和宽度的定义.
/*
* @(#)graphics.c 1.18 02/11/06 @(#)
*
* Copyright (c) 1999-2002 Sun Microsystems, Inc. All rights reserved.
* PROPRIETARY/CONFIDENTIAL
* Use is subject to license terms.
*/
#include
#include
#include
#ifndef LINUX
#error "----------------------------"
#endif
#if 0
#include "Qimage.h"
typedef struct _mbs {
QImage image;
unsigned char *imageMask; /* this serves as a bit mask and as an alpha
* channel array depending on what kind of
* information is in the image. these two
* properties are mutually exclusive so this
* is ok
*/
jint width;
jint height;
jint mutable;
jbyte prop;
} myBitmapStruct;
#define GRAPHICS_SETUP(filled) \
int left,right,top,bottom; \
QPen oldPen = painter->pen(); \
QBrush oldBrush = painter->brush(); \
myBitmapStruct *b = (myBitmapStruct*) dst; \
left = top = 0; \
right = b ? b->width : DISPLAY_WIDTH; \
bottom = b ? b->height : DISPLAY_HEIGHT; \
if (clip) { \
if (left clip[0] + clip[2]) \
right = clip[0] + clip[2]; \
if (bottom > clip[1] + clip[3]) \
bottom = clip[1] + clip[3]; \
painter->setClipRect(left, top, right, bottom); \
} \
if (filled) { \
painter->setPen(Qt::NoPen); \
painter->setBrush(QColor((pixel & 0xff), ((pixel >> 8) & 0xff), ((pixel >> 16) & 0xff)); \
} else { \
painter->setPen(QColor((pixel & 0xff), ((pixel >> 8) & 0xff), ((pixel >> 16) & 0xff)); \
if(dotted) { \
painter->setPen(Qt::DotLine) \
} \
painter->setBrush(Qt::NoBrush); \
}
#define GRAPHICS_CLEANUP() \
painter->setPen(oldPen); \
painter->setBrush(oldBrush);
#endif
#define GRAPHICS_SETUP(filled)
#define GRAPHICS_CLEANUP()
/*
* Draw a line between two points (x1,y1) and (x2,y2).
*/
void LCDUIdrawLine(int pixel, short *clip, void* dst, int dotted,
int x1, int y1, int x2, int y2)
{
GRAPHICS_SETUP(FALSE);
painter->drawLine(x1,y1,x2+1,y2+1);
GRAPHICS_CLEANUP();
if(!doubleBuffer && (dst==NULL)) {
refreshPaintWindow(x1, y1, x2+1, y2+1);
}
}
/*
* Draw a rectangle at (x,y) with the given width and height.
*/
void LCDUIdrawRect(int pixel, short *clip, void* dst, int dotted,
int x, int y, int width, int height)
{
if ((width = 0) && (height >= 0)) {
LCDUIdrawLine(pixel, clip, dst, dotted,
x, y, x + width, y + height);
}
return;
} else {
width++;
height++;
GRAPHICS_SETUP(FALSE);
painter->drawRect(x, y, width, height);
if(!doubleBuffer && (dst==NULL)) {
refreshPaintWindow(x, y, x + width, y + height);
}
GRAPHICS_CLEANUP();
}
}
/*
* Fill a rectangle at (x,y) with the given width and height.
*/
void LCDUIfillRect(int pixel, short *clip, void* dst, int dotted,
int x, int y, int width, int height)
{
if ((width 0) && (height > 0)) {
LCDUIdrawLine(pixel, clip, dst, dotted,
x, y, x + width - 1, y + height - 1);
}
return;
} else {
GRAPHICS_SETUP(FALSE);
painter->fillRect(x,y,width,height,QColor((pixel & 0xff), ((pixel >> 8) & 0xff), ((pixel >> 16) & 0xff)));
GRAPHICS_CLEANUP();
if (!doubleBuffer && (dst == NULL)) {
refreshPaintWindow(x, y, x + width, y + height);
}
}
}
/*
* Draw a rectangle at (x,y) with the given width and height. arcWidth and
* arcHeight, if nonzero, indicate how much of the corners to round off.
*/
void
LCDUIdrawRoundRect(int pixel, short *clip, void* dst, int dotted,
int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
if ((width = 0 && height >= 0) {
LCDUIdrawLine(pixel, clip, dst, dotted,
x, y, x + width, y + height);
}
return;
} else {
if(arcWidth>width) {
arcWidth=width;
}
if(arcHeight>height) {
arcHeight=height;
}
width++;
height++;
GRAPHICS_SETUP(FALSE);
painter->drawRoundRect(x,y,width,height,arcWidth*100/width,arcHeight*100/height);
GRAPHICS_CLEANUP();
}
if (!doubleBuffer && (dst == NULL)) {
refreshPaintWindow(x, y, x + width, y + height);
}
}
/*
* Fill a rectangle at (x,y) with the given width and height. arcWidth and
* arcHeight, if nonzero, indicate how much of the corners to round off.
*/
void LCDUIfillRoundRect(int pixel,short *clip, void* dst, int dotted,
int x, int y, int width, int height,
int arcWidth, int arcHeight)
{
if (width =0 && height >= 0) {
LCDUIdrawLine(pixel, clip, dst, dotted,x, y, x + width-1, y + height-1);
}
return;
} else {
width++;
height++;
GRAPHICS_SETUP(TRUE);
painter->drawRoundRect(x, y, width, height);
GRAPHICS_CLEANUP();
}
if (!doubleBuffer && (dst == NULL)) {
refreshPaintWindow(x, y, x + width, y + height);
}
}
/*
* Draw an elliptical arc centered in the given rectangle. The
* portion of the arc to be drawn starts at startAngle (with 0 at the
* 3 o'clock position) and proceeds counterclockwise by
* degrees. arcAngle may not be negative.
*/
void LCDUIdrawArc(int pixel, short *clip, void* dst, int dotted,
int x, int y, int width, int height,
int startAngle, int arcAngle)
{
if ((width = 0 && height >= 0) {
LCDUIdrawLine(pixel, clip, dst, dotted,x, y, x + width, y + height);
}
return;
} else {
GRAPHICS_SETUP(FALSE);
width++;
height++;
if(startAngle==arcAngle) {
painter->drawEllipse(x, y, x+width, y+height);
}else{
painter->drawArc(x, y, width, height,startAngle
* degrees. arcAngle may not be negative.
*/
void
LCDUIfillArc(int pixel, short *clip, void* dst, int dotted,
int x, int y, int width, int height,
int startAngle, int arcAngle)
{
if ((width = 0 || height >= 0) {
LCDUIdrawLine(pixel, clip, dst, dotted,x, y, x + width, y + height);
}
return;
} else {
GRAPHICS_SETUP(TRUE);
width++;
height++;
if(startAngle==arcAngle) {
painter->drawEllipse(x, y, x+width, y+height);
} else {
painter->drawPie(x,y,width,height,startAngledrawPolygon(pts);
GRAPHICS_CLEANUP();
if (!doubleBuffer && (dst == NULL)) {
/* determine the bounding rectangle for this triangle */
if (x1 >= x2) {
xmax = x1;
xmin = x2;
} else {
xmax = x2;
xmin = x1;
}
if (x3 > xmax) {
xmax = x3;
} else if (x3 = y2) {
ymax = y1;
ymin = y2;
} else {
ymax = y2;
ymin = y1;
}
if (y3 > ymax) {
ymax = y3;
} else if (y3
#include "virtualXlib.h"
#include
#include
class MidpWidget : public QWidget
{
public:
MidpWidget( QWidget *parent=0, const char *name=0 );
~MidpWidget();
protected:
void paintEvent( QPaintEvent * );
void mousePressEvent( QMouseEvent *);
void mouseReleaseEvent( QMouseEvent *);
void mouseMoveEvent( QMouseEvent *);
public:
QPainter *painer;
};
/*
* Defines screen size
*/
#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 320
/*
* This (x,y) coordinate pair refers to the offset of the upper
* left corner of the display screen within the MIDP phone handset
* graphic window
*/
#define X_SCREEN_OFFSET 30
#define Y_SCREEN_OFFSET 131
/* The max number of characters in a command menu item */
#define MAX_MENU_COMMAND_LENGTH 127
/* The max number of characters in a soft button command label */
#define MAX_SOFTBUTTON_COMMAND_LENGTH 12
extern MidpWidget *display;
extern jboolean doubleBuffer;
extern int visualDepth;
extern int numColors;
#define FONTPARAMS face, style, size
#define FONTPARAMS_PROTO int face, int style, int size
extern void setupFont(FONTPARAMS_PROTO);
extern void refreshPaintWindow(int x1, int y1, int x2, int y2);
/*added by lijiqun*/
extern QPainter *painter;
extern QPixmap *pixmap;
#endif
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/25111/showart_215154.html |
|