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

📄 draw1.cpp

📁 这是一个在vxWorks操作系统下的原创电子地图代码
💻 CPP
字号:
//  Copyright (c) 1990-1998 Zinc Software, Inc.//  Copyright (c) 1999-2000 Wind River Systems, Inc.// May be freely copied, used and distributed.// This example derives an object from ZafWindwoObject and implements // a Draw() function that uses many of the drawing primitives available// in ZAF. When drawing on an object it is important to do the drawing// in a Draw() function to insure that the object is refreshed at the // neccessary times by the OS.#include <zinc/zaf.hpp>#include <zinc/z_keymap.hpp>#include <zinc/z_device.hpp>#include "taskLib.h"#include "ioLib.h"#include "iosLib.h"#include "vxWorks.h"#include"stdio.h"#include <ugl/ugl.h>#include "string.h"#include "ntPassFsLib.h"#include "draw1.hpp"//#include "ftugldrawText.h"bool isdraw = true;int pMapLayernum = 0, xOld = 0,yOld = 0;//extern ZafMap pDrawMap; //extern struct MapLayer  *MapLayerNum[6];extern "C"{extern void EmapZoomIn();extern void EmapZoomOut();extern void EmapMoveUp();extern void EmapMoveDown();extern void EmapMoveLeft();extern void EmapMoveRight();extern void EmapMouseSpan(int dx,int dy);extern void SetCurrentMapLayer(int layernum);extern void InitializeEmapLib(char *filePath);extern void RedrawEmap(ZafDisplay * display, ZafRegionStruct windRec);extern void winHello(int x, int y);}// ----- Draw Object -------------------------------------------------------DrawObject::DrawObject(void) ://	ZafWindowObject(1, 1, 40, 13)	ZafWindowObject(1, 1, 120, 39){	// Turn off the OSDraw so Draw() function will be called.	SetOSDraw(false);	//SetOSDraw(true);	SetParentPalette(true);}#if defined(ZAF_DEFAULT_DRAW)ZafEventType DrawObject::Draw(const ZafEventStruct &event, ZafEventType ccode){	ZafDisplay *display = Display();	ZafRegionStruct drawRegion = BeginDraw();//	if (ccode == S_REDISPLAY_REGION)//		display->SetClipRegion(event.region);	// Draw a border around the object.//	DrawBorder(drawRegion, ccode);//	DrawBackground(drawRegion, ccode);	// Draw a rectangle with a wide border.	// Set the foreground color to green to draw the border.	//display->SetForeground(ZAF_CLR_GREEN);	// Set the background color to yellow to fill the rectangle.	//display->SetBackground(ZAF_CLR_YELLOW);		//display->Rectangle(drawRegion.left + display->cellWidth, 		//drawRegion.top + (display->cellHeight / 2), drawRegion.right - display->cellWidth,		//drawRegion.bottom - (display->cellHeight / 2), 4, true);	// Set the lineStyle to dotted to draw dashed lines or borders.	display->SetLineStyle(ZAF_LINE_DOTTED);	// Draw a filled arc.	// Set the foreground to black to draw the border.	//display->SetForeground(ZAF_CLR_BLACK);	// Set the background to light green to fill the arc.	display->SetBackground(ZAF_CLR_LIGHTGREEN);	//display->Ellipse(drawRegion.right - (20 * display->cellWidth),		//drawRegion.bottom - (6 * display->cellHeight),		//drawRegion.right - (10 * display->cellWidth), drawRegion.bottom -		//(3 * display->cellWidth), 25, 249, 1, true);	// Draw a line and change the color to draw with.	display->SetForeground(ZAF_CLR_LIGHTBLUE);	//display->Line(drawRegion.right, drawRegion.top, drawRegion.left,		//drawRegion.bottom, 1);	// Draw a filled polygon.	// Create a list of points.		/*if(isdraw == true)	pDrawMap.MDL_drawMapLayer(display, MapLayerNum[pMapLayernum]);*/	RedrawEmap(display, drawRegion);	//ZafCoordinate polyPoints [6];	//polyPoints[0] = drawRegion.left + (4 * display->cellWidth);	//polyPoints[1] = drawRegion.bottom - (7 * display->cellHeight);	//polyPoints[2] = drawRegion.left + (5 * display->cellWidth);	//polyPoints[3] = drawRegion.bottom - (3 * display->cellHeight);	//polyPoints[4] = drawRegion.left + (10 * display->cellWidth);	//polyPoints[5] = drawRegion.bottom - (2 * display->cellHeight);	// Set the background and foreground colors.	//display->SetForeground(ZAF_CLR_RED);	//display->SetBackground(ZAF_CLR_MAGENTA);		// Set the line style to solid lines	display->SetLineStyle(ZAF_LINE_SOLID);	//display->Polygon(3, polyPoints, 1, true, true);	// Draw some text.	// Set the color to draw the text in.	//display->SetForeground(ZAF_CLR_RED);	// Set the font to use.	//display->SetFont(ZAF_FNT_SYSTEM);	//display->Text(drawRegion.left + (6 * display->cellWidth),		//drawRegion.top + ((12 * display->cellHeight) / 5) , ZAF_ITEXT("This is text."));	EndDraw();	return (ccode);}#endifZafEventType DrawObject::Event(const ZafEventStruct &event){    int dx = 0,dy = 0;    ZafEventType ccode = LogicalEvent(event);	switch(ccode)	{		case L_UP:			EmapMoveUp();			Draw(event, ccode);			break;		case L_DOWN:			EmapMoveDown();			Draw(event, ccode);			break;		case L_LEFT:			EmapMoveLeft();			Draw(event, ccode);			break;		case L_RIGHT:			EmapMoveRight();			Draw(event, ccode);			break;		case L_MOUSE1_UP :			dx = event.position.column - xOld;			dy = event.position.line - yOld;			/*taskSpawn("twinhello", 100, 0, 10240,                                       (FUNCPTR)winHello,                                      ix + tx, iy + ty,                                      2, 3, 4, 5, 6, 7, 8, 9);*/			EmapMouseSpan(dx,dy);			Draw(event, ccode);			break;		case L_MOUSE1_DOWN:			xOld = event.position.column ;			yOld = event.position.line ;			break;	}	if (event.type==E_KEY&&event.key.value=='=' )	{					EmapZoomIn();			Draw(event, ccode);			return 0;	}	else if (event.type==E_KEY&&event.key.value=='-' )	{					EmapZoomOut();			Draw(event, ccode);			return 0;	}	else if (event.type==E_KEY&&event.key.value=='0' )	{					pMapLayernum = 0;			SetCurrentMapLayer(pMapLayernum);			Draw(event, ccode);			return 0;	}		else if (event.type==E_KEY&&event.key.value=='1' )	{					pMapLayernum = 1;			SetCurrentMapLayer(pMapLayernum);			Draw(event, ccode);			return 0;	}		else if (event.type==E_KEY&&event.key.value=='2' )	{					pMapLayernum = 2;			SetCurrentMapLayer(pMapLayernum);			Draw(event, ccode);			return 0;	}		else if (event.type==E_KEY&&event.key.value=='3' )	{					pMapLayernum = 3;			SetCurrentMapLayer(pMapLayernum);			Draw(event, ccode);			return 0;	}		else if (event.type==E_KEY&&event.key.value=='4' )	{					pMapLayernum = 4;			Draw(event, ccode);			return 0;	}	else if (event.type==E_KEY&&event.key.value=='5' )	{					pMapLayernum = 5;			SetCurrentMapLayer(pMapLayernum);			Draw(event, ccode);			return 0;	}	else if (event.type==E_KEY&&event.key.value=='6' )	{					pMapLayernum = 6;			SetCurrentMapLayer(pMapLayernum);			Draw(event, ccode);			return 0;	}	else if (event.type==E_KEY&&event.key.value=='7' )	{					pMapLayernum = 7;			SetCurrentMapLayer(pMapLayernum);			Draw(event, ccode);			return 0;	}	return (ZafWindowObject::Event(event));}/*ZafEventType DrawObject::Event(const ZafEventStruct &event){	ZafEventType ccode = LogicalEvent(event);	switch (ccode)	{	case '=':		isdraw = true;		draw(event, ccode);		break;	case '-':		isdraw = false;		draw(event, ccode);		break;	case RED_BACKGROUND:		SetBackgroundColor(ZAF_CLR_RED);		break;	case GREEN_BACKGROUND:		SetBackgroundColor(ZAF_CLR_GREEN);		break;	case BLUE_BACKGROUND:		SetBackgroundColor(ZAF_CLR_BLUE);		break;	case DRAW_MAPALL_EVENT:		Draw(event, ccode);		break;	default:		 Pass the event to the base class for processing.		draw(event, ccode);		ccode = ZafWindowObject::Event(event);		break;	}	return (ccode);}*/// ----- Main() -------------------------------------------------------------int ZafApplication::Main(void){	// Ensure main() is linked properly.	ntPassFsInit (1);    	ntPassFsDevInit ("host:");/*	pDrawMap.DDL_initMapGlobal();	pDrawMap.DDL_readMapFiles("host:e:\\default");*/	InitializeEmapLib("host:e:\\default\\mapdata\\");	//init_lib_face_xx("host:e:\\default\\mapdata\\simkai.ttf","host:e:\\default\\mapdata\\table.txt");	LinkMain();	// Create a window with a DrawObject.	ZafWindow *window = new ZafWindow(0, 0, 42, 15);	ZafPullDownMenu *menuBar = new ZafPullDownMenu;	ZafPullDownItem *fileMenu = new ZafPullDownItem("File");	fileMenu->Add(new ZafPopUpItem("Open",ZAF_NORMAL_ITEM));	fileMenu->Add(new ZafPopUpItem("", ZAF_EXIT_OPTION));	menuBar->Add(fileMenu);	ZafPullDownItem *controlMenu = new ZafPullDownItem("Controller");	controlMenu->Add(new ZafPopUpItem("Zoom in",ZAF_NORMAL_ITEM));	controlMenu->Add(new ZafPopUpItem("Zoom out",ZAF_NORMAL_ITEM));	menuBar->Add(controlMenu);	window->Add(menuBar); /*	ZafButton *sysButton = new ZafSystemButton(ZAF_EMPTY_SYSTEM_BUTTON);	sysButton->Add(new ZafPopUpItem(ZAF_ITEXT("Item 1")));	sysButton->Add(new ZafPopUpItem(ZAF_ITEXT("Item 2")));	sysButton->Add(new ZafPopUpItem(ZAF_ITEXT("Item 3")));	sysButton->Add(new ZafPopUpItem(ZAF_ITEXT("Item 4")));	sysButton->Add(new ZafPopUpItem(ZAF_ITEXT("Item 5")));	sysButton->Add(new ZafPopUpItem(ZAF_NULLP(ZafIChar), ZAF_SEPARATOR));	sysButton->Add(new ZafPopUpItem(ZAF_ITEXT(""), ZAF_EXIT_OPTION));	window->Add(sysButton);*/	window->AddGenericObjects(new ZafStringData("Map Window"));	window->Add(new DrawObject());		// Center the window.	WindowManager()->Center(window);	// Add the window to the window manager.	WindowManager()->Add(window);	// Get the user input.	Control();	// Return success.	return (0);}

⌨️ 快捷键说明

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