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

📄 draw.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
	pNew->data.path.outline.value = 0x4d4d4d00;	/* Gray 70 percent */	pNew->data.path.width = (int)lMilliPoints2DrawUnits(500);	pNew->data.path.style.flags = 0;	pNew->data.path.style.reserved = 0;	pNew->data.path.style.cap_width = 0;	pNew->data.path.style.cap_length = 0;	piTmp = pNew->data.path.path;	*piTmp++ = drawfile_PATH_MOVE_TO;	*piTmp++ = pNew->data.path.bbox.min.x;	*piTmp++ = pNew->data.path.bbox.min.y;	*piTmp++ = drawfile_PATH_LINE_TO;	*piTmp++ = pNew->data.path.bbox.min.x;	*piTmp++ = pNew->data.path.bbox.max.y;	*piTmp++ = drawfile_PATH_LINE_TO;	*piTmp++ = pNew->data.path.bbox.max.x;	*piTmp++ = pNew->data.path.bbox.max.y;	*piTmp++ = drawfile_PATH_LINE_TO;	*piTmp++ = pNew->data.path.bbox.max.x;	*piTmp++ = pNew->data.path.bbox.min.y;	*piTmp++ = drawfile_PATH_CLOSE_LINE;	*piTmp++ = drawfile_PATH_END_PATH;	Error_CheckFatal(Drawfile_AppendObject(&pDiag->tInfo,					pDiag->tMemorySize, pNew, TRUE));	pNew = xfree(pNew);	pDiag->lXleft = 0;	return TRUE;} /* end of bAddDummyImage *//* * vMove2NextLine - move to the next line */voidvMove2NextLine(diagram_type *pDiag, drawfile_fontref tFontRef,	USHORT usFontSize){	long	l20;	TRACE_MSG("vMove2NextLine");	fail(pDiag == NULL);	fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);	if (tFontRef == 0) {		l20 = Drawfile_ScreenToDraw(32 + 3);	} else {		l20 = lWord2DrawUnits20(usFontSize);	}	pDiag->lYtop -= l20;} /* end of vMove2NextLine *//* * Create an start of paragraph (Phase 1) */voidvStartOfParagraph1(diagram_type *pDiag, long lBeforeIndentation){	TRACE_MSG("vStartOfParagraph1");	fail(pDiag == NULL);	fail(lBeforeIndentation < 0);	pDiag->lXleft = 0;	pDiag->lYtop -= lMilliPoints2DrawUnits(lBeforeIndentation);} /* end of vStartOfParagraph1 *//* * Create an start of paragraph (Phase 2) * DUMMY function */voidvStartOfParagraph2(diagram_type *pDiag){	TRACE_MSG("vStartOfParagraph2");} /* end of vStartOfParagraph2 *//* * Create an end of paragraph */voidvEndOfParagraph(diagram_type *pDiag,	drawfile_fontref tFontRef, USHORT usFontSize, long lAfterIndentation){	TRACE_MSG("vEndOfParagraph");	fail(pDiag == NULL);	fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE);	fail(lAfterIndentation < 0);	pDiag->lXleft = 0;	pDiag->lYtop -= lMilliPoints2DrawUnits(lAfterIndentation);} /* end of vEndOfParagraph *//* * Create an end of page */voidvEndOfPage(diagram_type *pDiag, long lAfterIndentation, BOOL bNewSection){	TRACE_MSG("vEndOfPage");	fail(pDiag == NULL);	fail(lAfterIndentation < 0);	pDiag->lXleft = 0;	pDiag->lYtop -= lMilliPoints2DrawUnits(lAfterIndentation);} /* end of vEndOfPage *//* * vSetHeaders - set the headers * DUMMY function */voidvSetHeaders(diagram_type *pDiag, USHORT usIstd){	TRACE_MSG("vSetHeaders");} /* end of vSetHeaders *//* * Create a start of list * DUMMY function */voidvStartOfList(diagram_type *pDiag, UCHAR ucNFC, BOOL bIsEndOfTable){	TRACE_MSG("vStartOfList");} /* end of vStartOfList *//* * Create an end of list * DUMMY function */voidvEndOfList(diagram_type *pDiag){	TRACE_MSG("vEndOfList");} /* end of vEndOfList *//* * Create a start of a list item * DUMMY function */voidvStartOfListItem(diagram_type *pDiag, BOOL bNoMarks){	TRACE_MSG("vStartOfListItem");} /* end of vStartOfListItem *//* * Create an end of a table * DUMMY function */voidvEndOfTable(diagram_type *pDiag){	TRACE_MSG("vEndOfTable");} /* end of vEndTable *//* * Add a table row * DUMMY function * * Returns TRUE when conversion type is XML */BOOLbAddTableRow(diagram_type *pDiag, char **aszColTxt,	int iNbrOfColumns, const short *asColumnWidth, UCHAR ucBorderInfo){	TRACE_MSG("bAddTableRow");	return FALSE;} /* end of bAddTableRow *//* * vForceRedraw - force a redraw of the main window */static voidvForceRedraw(diagram_type *pDiag){	window_state		tWindowState;	window_redrawblock	tRedraw;	int	x0, y0, x1, y1;	TRACE_MSG("vForceRedraw");	fail(pDiag == NULL);	DBG_DEC(pDiag->iScaleFactorCurr);	/* Read the size of the current diagram */	Drawfile_QueryBox(&pDiag->tInfo, &tRedraw.rect, TRUE);	/* Adjust the size of the work area */	x0 = tRedraw.rect.min.x * pDiag->iScaleFactorCurr / 100 - 1;	y0 = tRedraw.rect.min.y * pDiag->iScaleFactorCurr / 100 - 1;	x1 = tRedraw.rect.max.x * pDiag->iScaleFactorCurr / 100 + 1;	y1 = tRedraw.rect.max.y * pDiag->iScaleFactorCurr / 100 + 1;	/* Work area extension */	x0 -= WORKAREA_EXTENSION;	y0 -= WORKAREA_EXTENSION;	x1 += WORKAREA_EXTENSION;	y1 += WORKAREA_EXTENSION;	Window_SetExtent(pDiag->tMainWindow, x0, y0, x1, y1);	/* Widen the box slightly to be sure all the edges are drawn */	x0 -= 5;	y0 -= 5;	x1 += 5;	y1 += 5;	/* Force the redraw */	Window_ForceRedraw(pDiag->tMainWindow, x0, y0, x1, y1);	/* Reopen the window to show the correct size */	Error_CheckFatal(Wimp_GetWindowState(pDiag->tMainWindow, &tWindowState));	tWindowState.openblock.behind = -1;	Error_CheckFatal(Wimp_OpenWindow(&tWindowState.openblock));} /* end of vForceRedraw *//* * vShowDiagram - put the diagram on the screen */voidvShowDiagram(diagram_type *pDiag){	wimp_box	tRect;	int	x0, y0, x1, y1;	TRACE_MSG("vShowDiagram");	fail(pDiag == NULL);	Window_Show(pDiag->tMainWindow, open_NEARLAST);	Drawfile_QueryBox(&pDiag->tInfo, &tRect, TRUE);	/* Work area extension */	x0 = tRect.min.x - WORKAREA_EXTENSION;	y0 = tRect.min.y - WORKAREA_EXTENSION;	x1 = tRect.max.x + WORKAREA_EXTENSION;	y1 = tRect.max.y + WORKAREA_EXTENSION;	Window_SetExtent(pDiag->tMainWindow, x0, y0, x1, y1);	vForceRedraw(pDiag);} /* end of vShowDiagram *//* * vMainButtonClick - handle mouse buttons clicks for the main screen */voidvMainButtonClick(mouse_block *pMouse){	caret_block	tCaret;	window_state	ws;	TRACE_MSG("vMainButtonClick");	fail(pMouse == NULL);	DBG_DEC(pMouse->button.data.select);	DBG_DEC(pMouse->button.data.adjust);	DBG_DEC(pMouse->window);	DBG_DEC(pMouse->icon);	if (pMouse->window >= 0 &&	    pMouse->icon == -1 &&	    (pMouse->button.data.select || pMouse->button.data.adjust)) {		/* Get the input focus */		Error_CheckFatal(Wimp_GetWindowState(pMouse->window, &ws));		tCaret.window = pMouse->window;		tCaret.icon = -1;		tCaret.offset.x = pMouse->pos.x - ws.openblock.screenrect.min.x;		tCaret.offset.y = pMouse->pos.y - ws.openblock.screenrect.max.y;		tCaret.height = (int)BIT(25);		tCaret.index = 0;		Error_CheckFatal(Wimp_SetCaretPosition(&tCaret));	}} /* end of vMainButtonClick *//* * bMainKeyPressed - handle pressed keys for the main window */BOOLbMainKeyPressed(event_pollblock *pEvent, void *pvReference){	diagram_type 	*pDiag;	TRACE_MSG("bMainKeyPressed");	fail(pEvent == NULL);	fail(pEvent->type != event_KEY);	fail(pvReference == NULL);	pDiag = (diagram_type *)pvReference;	fail(pEvent->data.key.caret.window != pDiag->tMainWindow);	switch (pEvent->data.key.code) {	case keycode_CTRL_F2:		/* Ctrl F2 */		bDestroyDiagram(pEvent, pvReference);		break;	case keycode_F3:		/* F3 */		bSaveDrawfile(pEvent, pvReference);		break;	case keycode_SHIFT_F3:		/* Shift F3 */		bSaveTextfile(pEvent, pvReference);		break;	default:		DBG_DEC(pEvent->data.key.code);		Error_CheckFatal(Wimp_ProcessKey(pEvent->data.key.code));	}	return TRUE;} /* end of bMainKeyPressed *//* * bRedrawMainWindow - redraw the main window */BOOLbRedrawMainWindow(event_pollblock *pEvent, void *pvReference){	window_redrawblock	tBlock;	diagram_type	*pDiag;	drawfile_info	*pInfo;	double		dScaleFactor;	BOOL		bMore;	TRACE_MSG("bRedrawMainWindow");	fail(pEvent == NULL);	fail(pEvent->type != event_REDRAW);	fail(pvReference == NULL);	pDiag = (diagram_type *)pvReference;	fail(pDiag->tMainWindow != pEvent->data.openblock.window);	fail(pDiag->iScaleFactorCurr < MIN_SCALE_FACTOR);	fail(pDiag->iScaleFactorCurr > MAX_SCALE_FACTOR);	dScaleFactor = (double)pDiag->iScaleFactorCurr / 100.0;	pInfo = &pDiag->tInfo;	tBlock.window = pEvent->data.openblock.window;	Error_CheckFatal(Wimp_RedrawWindow(&tBlock, &bMore));	/* If there is no real diagram just go thru the motions */	while (bMore) {		if (pInfo->data != NULL && pInfo->length != 0) {			Error_CheckFatal(Drawfile_RenderDiagram(pInfo,						&tBlock, dScaleFactor));		}		Error_CheckFatal(Wimp_GetRectangle(&tBlock, &bMore));	}	return TRUE;} /* end of bRedrawMainWindow *//* * bScaleOpenAction - action to be taken when the Scale view window opens */BOOLbScaleOpenAction(event_pollblock *pEvent, void *pvReference){	window_state	tWindowState;	diagram_type	*pDiag;	TRACE_MSG("bScaleOpenAction");	fail(pEvent == NULL);	fail(pEvent->type != event_SEND);	fail(pEvent->data.message.header.action != message_MENUWARN);	fail(pvReference == NULL);	pDiag = (diagram_type *)pvReference;	if (menu_currentopen != pDiag->pSaveMenu ||	    pEvent->data.message.data.menuwarn.selection[0] != SAVEMENU_SCALEVIEW) {		return FALSE;	}	Error_CheckFatal(Wimp_GetWindowState(pDiag->tScaleWindow,						&tWindowState));	if (tWindowState.flags.data.open) {		/* The window is already open */		return TRUE;	}	DBG_MSG("vScaleOpenAction for real");	pDiag->iScaleFactorTemp = pDiag->iScaleFactorCurr;	vUpdateWriteableNumber(pDiag->tScaleWindow,			SCALE_SCALE_WRITEABLE, pDiag->iScaleFactorTemp);	Window_Show(pDiag->tScaleWindow, open_UNDERPOINTER);	return TRUE;} /* end of bScaleOpenAction *//* * vSetTitle - set the title of a window */voidvSetTitle(diagram_type *pDiag){	char	szTitle[WINDOW_TITLE_LEN];	TRACE_MSG("vSetTitle");	fail(pDiag == NULL);	fail(pDiag->szFilename[0] == '\0');	(void)sprintf(szTitle, "%.*s at %d%%",				FILENAME_TITLE_LEN,				pDiag->szFilename,				pDiag->iScaleFactorCurr % 1000);	if (strlen(pDiag->szFilename) > FILENAME_TITLE_LEN) {		szTitle[FILENAME_TITLE_LEN - 1] = OUR_ELLIPSIS;	}	Window_SetTitle(pDiag->tMainWindow, szTitle);} /* end of vSetTitle *//* * vScaleButtonClick - handle a mouse button click in the Scale view window */voidvScaleButtonClick(mouse_block *pMouse, diagram_type *pDiag){	BOOL	bCloseWindow, bRedraw;	TRACE_MSG("vScaleButtonClick");	fail(pMouse == NULL || pDiag == NULL);	fail(pMouse->window != pDiag->tScaleWindow);	bCloseWindow = FALSE;	bRedraw = FALSE;	switch (pMouse->icon) {	case SCALE_CANCEL_BUTTON:		bCloseWindow = TRUE;		pDiag->iScaleFactorTemp = pDiag->iScaleFactorCurr;		break;	case SCALE_SCALE_BUTTON:		bCloseWindow = TRUE;		bRedraw = pDiag->iScaleFactorCurr != pDiag->iScaleFactorTemp;		pDiag->iScaleFactorCurr = pDiag->iScaleFactorTemp;		break;	case SCALE_50_PCT:		pDiag->iScaleFactorTemp = 50;		break;	case SCALE_75_PCT:		pDiag->iScaleFactorTemp = 75;		break;	case SCALE_100_PCT:		pDiag->iScaleFactorTemp = 100;		break;	case SCALE_150_PCT:		pDiag->iScaleFactorTemp = 150;		break;	default:		DBG_DEC(pMouse->icon);		break;	}	if (bCloseWindow) {		/* Close the scale window */		Error_CheckFatal(Wimp_CloseWindow(pMouse->window));		if (bRedraw) {			/* Redraw the main window */			vSetTitle(pDiag);			vForceRedraw(pDiag);		}	} else {		vUpdateWriteableNumber(pMouse->window,				SCALE_SCALE_WRITEABLE,				pDiag->iScaleFactorTemp);	}} /* end of vScaleButtonClick *//* * bScaleKeyPressed - handle pressed keys for the scale window */BOOLbScaleKeyPressed(event_pollblock *pEvent, void *pvReference){	icon_block	tIcon;	diagram_type	*pDiag;	caret_block	*pCaret;	char		*pcChar;	int		iTmp;	TRACE_MSG("bScaleKeyPressed");        fail(pEvent == NULL);        fail(pEvent->type != event_KEY);        fail(pvReference == NULL);	pCaret = &pEvent->data.key.caret;	pDiag = (diagram_type *)pvReference;        fail(pEvent->data.key.caret.window != pDiag->tScaleWindow);	DBG_DEC_C(pCaret->icon != SCALE_SCALE_WRITEABLE, pCaret->icon);	DBG_DEC_C(pCaret->icon == SCALE_SCALE_WRITEABLE, pEvent->data.key.code);	if (pEvent->data.key.code != '\r' ||	    pCaret->icon != SCALE_SCALE_WRITEABLE) {		Error_CheckFatal(Wimp_ProcessKey(pEvent->data.key.code));		return TRUE;	}	Error_CheckFatal(Wimp_GetIconState(pCaret->window, pCaret->icon, &tIcon));	if (!tIcon.flags.data.text || !tIcon.flags.data.indirected) {		werr(1, "Icon %d must be indirected text", (int)pCaret->icon);	}	iTmp = (int)strtol(tIcon.data.indirecttext.buffer, &pcChar, 10);	if (*pcChar != '\0' && *pcChar != '\r') {		DBG_DEC(*pcChar);	} else if (iTmp < MIN_SCALE_FACTOR) {		pDiag->iScaleFactorTemp = MIN_SCALE_FACTOR;	} else if (iTmp > MAX_SCALE_FACTOR) {		pDiag->iScaleFactorTemp = MAX_SCALE_FACTOR;	} else {		pDiag->iScaleFactorTemp = iTmp;	}	pDiag->iScaleFactorCurr = pDiag->iScaleFactorTemp;	/* Close the scale window */	Error_CheckFatal(Wimp_CloseWindow(pCaret->window));	/* Redraw the main window */	vSetTitle(pDiag);	vForceRedraw(pDiag);	return TRUE;} /* end of bScaleKeyPressed */

⌨️ 快捷键说明

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