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

📄 cal_ui.c

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 C
📖 第 1 页 / 共 2 页
字号:
/*                                                                        * Copyright (c) 2003 Century Software, Inc.   All Rights Reserved.      *                                                                        * This file is part of the PIXIL Operating Environment                  *                                                                        * The use, copying and distribution of this file is governed by one     * of two licenses, the PIXIL Commercial License, or the GNU General     * Public License, version 2.                                            *                                                                        * Licensees holding a valid PIXIL Commercial License may use this file  * in accordance with the PIXIL Commercial License Agreement provided    * with the Software. Others are governed under the terms of the GNU    * General Public License version 2.                                     *                                                                        * This file may be distributed and/or modified under the terms of the   * GNU General Public License version 2 as published by the Free         * Software Foundation and appearing in the file LICENSE.GPL included    * in the packaging of this file.                                       *                                                                        * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING   * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A             * PARTICULAR PURPOSE.                                                   *                                                                        * RESTRICTED RIGHTS LEGEND                                              *                                                                      * Use, duplication, or disclosure by the government is subject to       * restriction as set forth in paragraph (b)(3)(b) of the Rights in      * Technical Data and Computer Software clause in DAR 7-104.9(a).        *                                                                       * See http://www.pixil.org/gpl/ for GPL licensing        * information.                                                          *                                                                       * See http://www.pixil.org/license.html or               * email cetsales@centurysoftware.com for information about the PIXIL    * Commercial License Agreement, or if any conditions of this licensing  * are not clear to you.                                                 *//* System header files */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <ctype.h>/* Local header files */#include <nano-X.h>#include <pixlib/pixlib.h>#include "cal_ui.h"/* Typedef, macro, enum/struct/union defnitions *//* Global scope variables *//* File scope variables */static GR_WINDOW_ID cal_win;	/* Calibration window */static GR_SCREEN_INFO si;	/* Screen info */static int g_text_x = START_TEXT_Y;	/* Default value, taken from nxcal.c */static CalPt_t last = { -1, -1 };	/* Previous coordinates *//* Static function prototypes */static void nxcal_drawCH(CalPt_t * pt, int flags);static void nxcal_drawPt(CalPt_t * pt, int flags);static void nxcal_drawText(char *text);static void nxcal_getCtrlPts(int size, CalPt_t * pts);/*static void nxcal_normalizePts(int npts, CalPt_t *ctrlpts, CalPt_t *newpts);*/static int nxcal_getStoredPts(int *npts, CalPt_t ** cpts, CalPt_t ** dpts,			      char *calfile);static int nxcal_grInit(int flags);static int nxcal_setStoredPts(int npts, CalPt_t * cpts, CalPt_t * dpts,			      char *calfile);static int nxcal_ValidatePt(int npts, CalPt_t * dpts);/*-----------------------------------------------------------------------------*\****	Static function definitions**\*-----------------------------------------------------------------------------*//*******************************************************************************\****	Function:	void nxcal_drawCH()**	Desc:		Handles the actual raw nanox calls to draw the cross hair at the**				specified location**	Accepts:	CalPt_t *pt = Point (x,y) to draw the center of the cross**				int flag = How to draw**	Returns:	Nothing (void)**\*******************************************************************************/static voidnxcal_drawCH(CalPt_t * pt, int flag){    GR_EVENT event;    int hx_coord1,	hx_coord2,	hy_coord1, hy_coord2, vx_coord1, vx_coord2, vy_coord1, vy_coord2;    GR_GC_ID gc = GrNewGC();    /* Get the horizontal and vertical lines */    hx_coord1 = pt->x - (SZ_XHAIR / 2);    hx_coord2 = pt->x + (SZ_XHAIR / 2);    hy_coord1 = hy_coord2 = pt->y;    vy_coord1 = pt->y - (SZ_XHAIR / 2);    vy_coord2 = pt->y + (SZ_XHAIR / 2);    vx_coord1 = vx_coord2 = pt->x;    GrSetGCBackground(gc, NXCAL_BACKGROUND);    GrSetGCForeground(gc, NXCAL_FOREGROUND);    if (!flag) {	GrSetGCMode(gc, GR_MODE_XOR);	GrSetGCForeground(gc, NXCAL_FOREGROUND);    } /* end of if */    else {	GrSetGCMode(gc, GR_MODE_SET);	GrSetGCForeground(gc, NXCAL_BACKGROUND);    }				/* end of else */    GrLine(cal_win, gc, hx_coord1, hy_coord1, hx_coord2, hy_coord2);    GrLine(cal_win, gc, vx_coord1, vy_coord1, vx_coord2, vy_coord2);    GrDestroyGC(gc);    while (GrPeekEvent(&event))	GrGetNextEvent(&event);}				/* end of nxcal_drawCH() *//*******************************************************************************\****	Function:	void nxcal_drawPt()**	Desc:		Draws the cross hair at the specified point,actually, sets things**				things up and leaves the actual drawing of the cross hair to**				nxcal_drawCH().**	Accepts:	CalPt_t *pt = The point to draw at**				int flags = Value to determine if drawing or erasing, etc**	Returns:	Nothing (void)**\*******************************************************************************/static voidnxcal_drawPt(CalPt_t * pt, int flags){    int ani_frames = 20,	/* Number of CH to draw */      i;			/* Loop iterator */    CalPt_t cur_pt;		/* Current point */    if (flags) {	if (last.x != -1)	    nxcal_drawCH(&last, flags);	return;    }    /* end of if */    if (last.x == -1) {	last.x = pt->x;	last.y = pt->y;    }    /* end of if if */    if (last.x != pt->x || last.y != pt->y) {	/* Erase the previous plus */	nxcal_drawCH(&last, 1);	for (i = 0; i < ani_frames; i++) {	    cur_pt.x = last.x + ((pt->x - last.x) * i / ani_frames);	    cur_pt.y = last.y + ((pt->y - last.y) * i / ani_frames);	    nxcal_drawCH(&cur_pt, 0);	    usleep(60);	    nxcal_drawCH(&cur_pt, 0);	}			/* end of for */	last.x = pt->x;	last.y = pt->y;    }    /* end of if */    nxcal_drawCH(&last, 0);}				/* end of nxcal_drawPt() *//*******************************************************************************\****	Function:	void nxcal_drawText()**	Desc:		Displays the text message to the screen**	Accepts:	char *text = Ptr to the text message**	Returns:	Nothing (void)**\*******************************************************************************/static voidnxcal_drawText(char *text){    GR_GC_ID gc = GrNewGC();    GR_SIZE tw, th, tb;    /* Set up the GC */    GrSetGCBackground(gc, NXCAL_BACKGROUND);    GrSetGCForeground(gc, NXCAL_FOREGROUND);    GrSetGCMode(gc, GR_MODE_SET);    /* Determine the position of the text and draw it */    GrGetGCTextSize(gc, text, -1, 0, &tw, &th, &tb);    GrText(cal_win, gc, (si.vs_width - tw) / 2, g_text_x, text, -1, 0);    g_text_x += th + 3;    /* Destroy resources and return */    GrDestroyGC(gc);    return;}				/* end of nxcal_drawText() *//*******************************************************************************\****	Function:	void nxcal_getCtrlPts()**	Desc:		Gets the CONTROL points to process against**	Accepts:	int npts = Number of points t`o accept**				CalPt_t *pts = array to store points into (has size of npts elements)**	Returns:	Nothing (void)**\*******************************************************************************/static voidnxcal_getCtrlPts(int npts, CalPt_t * pts){    pts[0].x = pts[0].y = CAL_OFFSET1;    pts[1].x = si.vs_width - CAL_OFFSET2 - 1;    pts[1].y = CAL_OFFSET2;    pts[2].x = CAL_OFFSET2;    pts[2].y = si.vs_height - CAL_OFFSET2 - 1;    pts[3].x = si.vs_width - CAL_OFFSET1 - 1;    pts[3].y = si.vs_height - CAL_OFFSET1 - 1;    pts[4].x = si.vs_width / 2;    pts[4].y = si.vs_height / 2;    return;}				/* end of nxcal_getCtrlPts() *//*******************************************************************************\****	Function:	int nxcal_getStoredPts()**	Desc:		Function used to retreive the stored calibration points from the**				file**	Accepts:	int *npts = Number of pts read from file **				CalPt_t **cpts = Storage for control points to be dynamically created**				CalPt_t **dpts = Storage for data points to be dynamically created**				char *calfile = Path of the file**	Returns:	int; 0 on success, -1 on error**\*******************************************************************************/static intnxcal_getStoredPts(int *npts, CalPt_t ** cpts, CalPt_t ** dpts, char *calfile){    char *cp,			/* Generic pointer */     *dp,			/* Pointer to data points */      filebuf[255];		/* File buffer */    int alc_cnt = 3,		/* Initial number of entries to expect */      ncnt = 0;			/* Number of points read in */    FILE *infp;			/* In file pointer */    CalPt_t *tmp;		/* Use in reallocs */    if (calfile == NULL || (infp = fopen(calfile, "r")) == NULL) {	return (-1);    }    /* end of if */    /* Initially allocate alc_cnt elements */    if ((*cpts = calloc(alc_cnt, sizeof(CalPt_t))) == NULL ||	(*dpts = calloc(alc_cnt, sizeof(CalPt_t))) == NULL) {	return (-1);    }    /* end of if */    /*       ** Expected format of the file:       ** x,y\n       ** ...     */    while (fgets(filebuf, sizeof(filebuf), infp) != NULL) {	/* Determine if filebuf contains valid point data */	if (toupper(filebuf[0]) != 'C')	    continue;	/* See if more memory needs to be allocated */	if (ncnt >= alc_cnt) {	    tmp = realloc(*cpts, (alc_cnt + 1) * sizeof(CalPt_t));	    if (tmp == NULL)		break;	    *cpts = tmp;	    tmp = realloc(*dpts, (alc_cnt + 1) * sizeof(CalPt_t));	    if (tmp == NULL)		break;	    *dpts = tmp;	    alc_cnt++;	}	/* end of if */	/* Parse the string */	if ((dp = strchr(filebuf, 'D')) != NULL	    || (dp = strchr(filebuf, 'd')) != NULL) {	    *dp = '\0';	    dp++;	}	/* end of if */	/* Get the control points */	if ((cp = strchr(filebuf, ',')) == NULL)	    continue;	*cp = '\0';	cp++;	(*cpts)[ncnt].x = atoi(&filebuf[1]);	(*cpts)[ncnt].y = atoi(cp);	/* Get the data points */	if ((cp = strchr(dp, ',')) == NULL)	    continue;	*cp = '\0';	cp++;	(*dpts)[ncnt].x = atoi(dp);	(*dpts)[ncnt].y = atoi(cp);	ncnt++;    }				/* end of while */    if (*npts)	*npts = ncnt;    fclose(infp);    return ((ncnt == 0) ? -1 : 0);}				/* end of nxcal_getStoredPts() *//*******************************************************************************\****	Function:	int nxcal_grInit()**	Desc:		Initializes the underlying graphics engine (in this particular**				case, microwindows) and setups up the main window for this**	Accepts:	int flags = flags for nanox initialization; where:**					NXCAL_NONINT_MODE = Initialize the graphics engine**	Retruns:	int; 0 on success, -1 otherwise**\*******************************************************************************/static intnxcal_grInit(int flags){    GR_WM_PROPERTIES win_props;	/* Window properties */    GR_GC_ID gc;    /* Make connection to the Nano-X server */#if 0    if (flags & NXCAL_NONINT_MODE) {	if (GrOpen() < 0)	    return (-1);    }				/* end of if  */#endif    /* Get the screen sizes */    GrGetScreenInfo(&si);    /* Create a new window, to cover the entire width of the screen */    cal_win = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, si.vs_width, si.vs_height,			  1, NXCAL_BACKGROUND, NXCAL_BACKGROUND);    memset(&win_props, 0, sizeof(win_props));    GrGetWMProperties(cal_win, &win_props);    win_props.props |= GR_WM_PROPS_NODECORATE;    win_props.flags |= GR_WM_FLAGS_PROPS;    GrSetWMProperties(cal_win, &win_props);    /* Map the window */    GrMapWindow(cal_win);    /* Force the window to be blank */    gc = GrNewGC();    GrSetGCBackground(gc, NXCAL_BACKGROUND);    GrSetGCForeground(gc, NXCAL_FOREGROUND);    GrSetGCMode(gc, GR_MODE_SET);    GrRect(cal_win, gc, 0, 0, si.vs_width, si.vs_height);    GrDestroyGC(gc);    return 0;}				/* end of nxcal_grInit(void) */#if 0/*******************************************************************************\****	Function:	void nxcal_normalizePts()**	Desc:		Determines if any of the X/Y axis are flipped, and if they are**				it will rearrange the order of the newpts array to feed into**				the calibrate function properly.**	Accepts:	int npts = Number of points to deal with**				CalPt_t *ctrlpts = Array of "control" points

⌨️ 快捷键说明

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