📄 wexbasic.c
字号:
*/ UGL_MDIB patternDib; UGL_MDDB_ID patternBitmap; /* * Initialize UGL. Must do this before trying to do anything * else within UGL/WindML. */ uglInitialize(); /* Obtain the device identifier for the display */ pRegistryData = uglRegistryFind (UGL_DISPLAY_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { uglDeinitialize(); return (UGL_STATUS_ERROR); } devId = (UGL_DEVICE_ID)pRegistryData->id; /* Obtain the input service */ pRegistryData = uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { uglDeinitialize(); return (UGL_STATUS_ERROR); } inputServiceId = (UGL_INPUT_SERVICE_ID)pRegistryData->id; /* * Obtain the dimensions of the display. We will use these * to center some of our objects. */ uglInfo(devId, UGL_MODE_INFO_REQ, &modeInfo); displayWidth = modeInfo.width; displayHeight = modeInfo.height; /* * Create a graphics context. Default values are set during * the creation. */ gc = uglGcCreate(devId); /* * Initialize colors. UGL maintains a Color Look-Up Table (CLUT) * for devices that do not represent colors directly. Essentially * some hardware is only able to represent a subset of colors at * any given time. To manage which colors will be available for * rendering, UGL uses color allocation. If the hardware is able * to represent colors directly, then the uglColorAlloc() function * still works, but it is then essentially a no-op. * * We have set up for 16 colors, so here we will "allocate" them * within UGL's CLUT (sometimes referred to as a "palette"). Colors * can also be de-allocated, or freed, with uglColorFree. * * Since the ARGB's are intermingled with the UGL_COLORs in * the colorTable, we must allocate each color individually. * If the ARGB's had a contiguous array of ARGBs, and likewise for * the UGL_COLORs, a single uglColorAlloc call could be made. * (see the windows example). */ uglColorAlloc (devId, &colorTable[BLACK].rgbColor, UGL_NULL, &colorTable[BLACK].uglColor, 1); uglColorAlloc(devId, &colorTable[BLUE].rgbColor, UGL_NULL, &colorTable[BLUE].uglColor, 1); uglColorAlloc(devId, &colorTable[GREEN].rgbColor, UGL_NULL, &colorTable[GREEN].uglColor, 1); uglColorAlloc(devId, &colorTable[CYAN].rgbColor, UGL_NULL, &colorTable[CYAN].uglColor, 1); uglColorAlloc(devId, &colorTable[RED].rgbColor, UGL_NULL, &colorTable[RED].uglColor, 1); uglColorAlloc(devId, &colorTable[MAGENTA].rgbColor, UGL_NULL, &colorTable[MAGENTA].uglColor, 1); uglColorAlloc(devId, &colorTable[BROWN].rgbColor, UGL_NULL, &colorTable[BROWN].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTGRAY].rgbColor, UGL_NULL, &colorTable[LIGHTGRAY].uglColor, 1); uglColorAlloc(devId, &colorTable[DARKGRAY].rgbColor, UGL_NULL, &colorTable[DARKGRAY].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTBLUE].rgbColor, UGL_NULL, &colorTable[LIGHTBLUE].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTGREEN].rgbColor, UGL_NULL, &colorTable[LIGHTGREEN].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTCYAN].rgbColor, UGL_NULL, &colorTable[LIGHTCYAN].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTRED].rgbColor, UGL_NULL, &colorTable[LIGHTRED].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTMAGENTA].rgbColor, UGL_NULL, &colorTable[LIGHTMAGENTA].uglColor, 1); uglColorAlloc(devId, &colorTable[YELLOW].rgbColor, UGL_NULL, &colorTable[YELLOW].uglColor, 1); uglColorAlloc(devId, &colorTable[WHITE].rgbColor, UGL_NULL, &colorTable[WHITE].uglColor, 1); /* * Here is where we actually create the bitmap for the fill * pattern. We are not going to do much with bitmaps here, just * use one for a fill pattern. Bitmaps are a huge topic, so for * more information about bitmaps and associated operations, look * at the bitmap example and WindML documentation. */ patternDib.width = patternDib.stride = patternData.width; patternDib.height = patternData.height; patternDib.pImage = patternData.data; patternBitmap = uglMonoBitmapCreate(devId, &patternDib, UGL_DIB_INIT_DATA, 0, UGL_NULL); /* Get the screen ready for some drawing. */ ClearScreen(gc); /* ----------------------- Draw a line. --------------------------- */ /* * The batch commands are bracketing each of the different drawing * areas. Since we are really just drawing everything and then * pausing, only one batch start at the beginning and then a * batch stop at the end is needed. We'll keep them around each * section as a reminder. The batch commands are optional; they * can enhance performance by locking resources for the UGL * functions called within their scope. Otherwise each UGL function * will do its own resource locking and un-locking which adds over- * head. */ uglBatchStart(gc); /* * The foreground color is the color of the object being drawn. * There is a background color that is used to define the color * of solid fills (no pattern is defined). Both of these values * are part of the Graphics Context (GC). So here we are changing * the GC. If the GC didn't contain the color, we would have to * pass them to the line drawing function as parameters (since the * GC does contain the colors, passing them as parameters is not * an option in UGL). */ uglForegroundColorSet(gc, colorTable[WHITE].uglColor); /* Draw the line! Diagonal from upper left to lower right. */ uglLine(gc, 0, 0, displayWidth - 1, displayHeight - 1); uglBatchEnd(gc); /* ------------------- Draw a dashed line. ------------------------ */ uglBatchStart(gc); /* * This is another change to the a GC value. Change the style of * line; there are two options from which to choose: solid and dashed. */ uglLineStyleSet(gc, UGL_LINE_STYLE_DASHED); uglForegroundColorSet(gc, colorTable[WHITE].uglColor); /* Diagonal from upper right to lower left */ uglLine(gc, displayWidth - 1, 0, 0, displayHeight -1); uglBatchEnd(gc); /* ------------------- Draw a thick line. ----------------------- */ uglBatchStart(gc); uglForegroundColorSet(gc, colorTable[WHITE].uglColor); uglLineStyleSet(gc, UGL_LINE_STYLE_SOLID); uglLineWidthSet(gc, 7); uglLine(gc, displayWidth / 2, 0, displayWidth / 2, displayHeight -1); uglBatchEnd(gc); /* --------------- Draw a thick dashed line. ---------------------- */ uglBatchStart(gc); uglLineStyleSet(gc, UGL_LINE_STYLE_DASHED); uglForegroundColorSet(gc, colorTable[WHITE].uglColor); uglLineWidthSet(gc, 7); uglLine(gc, 0, displayHeight / 2, displayWidth - 1, displayHeight / 2); uglBatchEnd(gc); /* -------------------- Draw a rectangle. ------------------------- */ uglBatchStart(gc); /* * Here we are setting the pattern bitmap in the GC. Since it is in * the GC all subsequent drawing that does a fill will use this * pattern. */ uglFillPatternSet(gc, patternBitmap); uglForegroundColorSet(gc, colorTable[WHITE].uglColor); uglBackgroundColorSet(gc, colorTable[GREEN].uglColor); uglLineStyleSet(gc, UGL_LINE_STYLE_SOLID); uglLineWidthSet(gc, 7); uglRectangle(gc, displayWidth / 8, displayHeight / 8, displayWidth / 4, displayHeight / 4); uglBatchEnd(gc); /* -------------------- Draw polygons. ---------------------------- */ uglBatchStart(gc); { int j; /* * poly[] is and array of points. The uglPolygon() function actually * is looking for a list of position values and assumes they are * organized as alternating x and y coordinates (x, y, x, y, x, ...). * I am using a list of points since it creates a compatible list * of positions and I can then manipulate the coordinates a little * more conveniently. It does require a cast in uglPolygon's parms * though. The polygon definition must be a closed path; the first * point and the last point are equal. Polygon lines may cross * without a problem. */ UGL_POINT poly[] = {{0,17},{30,0},{30,10},{70,0},{66,6},{90,3},{60,10},{64,5},{24,17},{24,10},{0,17}}; /* * Since the fill pattern from before is still in the GC, these * polygons will have the same pattern. These polygons are rather * flat, so the pattern doesn't show as more than a few pixels inside. * Also note that the colors are set differently and that the colors * are applied to the fill pattern as well. */ uglForegroundColorSet(gc, colorTable[LIGHTCYAN].uglColor); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglLineWidthSet(gc, 1); uglLineStyleSet(gc, UGL_LINE_STYLE_SOLID); /* * Adjust the position of the entire polygon. Add the same x * coordinate adjustment to all of the x-coordinates. The same * is done for all of the y coordinates. */ for (j=0;j<11;j++) { poly[j].x += displayWidth / 2 - 60; poly[j].y += displayHeight / 2 - 40; } /* * Just to make it interesting, draw five of these * polygons, spaced 15 pixels apart vertically. */ for (i = 0; i < 5;i++) { int j; uglPolygon(gc, 11, (UGL_POS *)poly); for (j=0;j<11;j++) { poly[j].x += 10; poly[j].y += 15; } } } uglBatchEnd(gc); /* ---------------- Draw solid filled polygons. ------------------- */ uglBatchStart(gc); { UGL_POINT poly[] = {{0,17},{30,0},{30,10},{70,0},{66,6},{90,3},{60,10},{64,5},{24,17},{24,10},{0,17}}; int j, k; for (j=0;j<11;j++) { poly[j].x += displayWidth / 2 - 200; poly[j].y += displayHeight / 2 + 45; } /* * By setting the GC's fill pattern to UGL_NULL uglPolygon() will * assume a solid pattern for its fill. This would be the default, * but since we used a different fill for the rectangle, we need to * set it back again now. */ uglFillPatternSet(gc, UGL_NULL); uglForegroundColorSet(gc, colorTable[LIGHTCYAN].uglColor); uglBackgroundColorSet(gc, colorTable[CYAN].uglColor); uglLineWidthSet(gc, 1); uglLineStyleSet(gc, UGL_LINE_STYLE_SOLID); /* To make it even more interesting, draw three sets of 5 polygons. */ for (k = 0; k < 3;k++) { for (i = 0; i < 5;i++) { uglPolygon(gc, 11, (UGL_POS *)poly); for (j=0;j<11;j++) { poly[j].x += 10; poly[j].y += 15; } } /* Move each of the 3, five polygon, sets to a different position. */ for (j=0;j<11;j++) { poly[j].x += 100; poly[j].y -= 60; } } } uglBatchEnd(gc); /* --------------------- Draw an ellipse. ------------------------- */ /* * With the drivers that ship with WindML, the ellipse only draws * single pixel width borders. */ uglBatchStart(gc); { uglForegroundColorSet(gc, colorTable[BLUE].uglColor); uglBackgroundColorSet(gc, colorTable[RED].uglColor); uglEllipse(gc, 5 * displayWidth / 8, displayHeight / 6, 15 * displayWidth / 16, displayHeight / 3, 0, 0, 0, 0); } uglBatchEnd(gc); /* ---------------- Draw a pie sliced ellipse. -------------------- */ /* * The coordinates chosen here put this pie slice on top of the * previous ellipse. */ uglBatchStart(gc); { uglForegroundColorSet(gc, colorTable[YELLOW].uglColor); uglBackgroundColorSet(gc, colorTable[GREEN].uglColor); uglEllipse(gc, 5 * displayWidth / 8, displayHeight / 6, 15 * displayWidth / 16, displayHeight / 3, 5 * displayWidth / 8, displayHeight / 6, 5 * displayWidth / 8, displayHeight / 3); } uglBatchEnd(gc); /* -------- Wait for the signal to quit from basicStop. ------------- */ wexPause(); /* ---------------- Clean everything up and exit. ----------------- */ uglMonoBitmapDestroy(devId, patternBitmap); uglGcDestroy (gc); uglDeinitialize(); return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -