static void create_aux_windows (_THIS) { GR_WM_PROPERTIES props ; Dprintf ("enter create_aux_windows\n") ; // Don't create any extra windows if we are being managed if (SDL_windowid) { FSwindow = 0 ; return ; } if (FSwindow && FSwindow != GR_ROOT_WINDOW_ID) { GrDestroyWindow (FSwindow) ; } FSwindow = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, BLACK, BLACK) ; props.flags = GR_WM_FLAGS_PROPS ; props.props = GR_WM_PROPS_NODECORATE ; GrSetWMProperties (FSwindow, & props) ; GrSelectEvents (FSwindow, (GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_CLOSE_REQ)) ; Dprintf ("leave create_aux_windows\n") ; }
/* * Initialize graphics and open a window for the viewer */ Bool CreateXWindow(void) { int fd; GR_SIZE w, h; GR_SCREEN_INFO si; if ((fd = GrOpen()) < 0) return(False); nx_dpy.fd = fd; dpy = &nx_dpy; GrGetScreenInfo(&si); /* pass screen details to RFB handler */ myFormat.bitsPerPixel = si.bpp; myFormat.depth = si.bpp; /* is this right? */ myFormat.bigEndian = 0; /* how do I find this out? */ myFormat.trueColour = (myFormat.depth == 8 && !useBGR233) ? 0 : 1; if (myFormat.trueColour) { myFormat.redMax = myFormat.greenMax = 7; myFormat.blueMax = 3; myFormat.redShift = 0; myFormat.greenShift = 3; myFormat.blueShift = 6; } pixtype = si.pixtype; /* get the initial server palette */ GrGetSystemPalette(&srv_pal); #if 0 /* DEBUG */ for (i = 0; i < srv_pal.count; i++) { printf("0x%02x %03d %03d %03d\n", i, \ srv_pal.palette[i].r, srv_pal.palette[i].g, \ srv_pal.palette[i].b ); } #endif /* create the top-level window */ w = (VW_WIDTH > (si.cols - VW_X)) ? (si.cols - VW_X) : VW_WIDTH; h = (VW_HEIGHT > (si.rows - VW_Y)) ? (si.rows - VW_Y) : VW_HEIGHT; if ((wid = GrNewWindow(GR_ROOT_WINDOW_ID, VW_X, VW_Y, w, h, 2, LTGRAY, BLACK)) == 0) { fprintf(stderr, "Unable to create top-level window\n"); GrClose(); return False; } /* select events to receive */ GrSelectEvents(wid, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_MOUSE_POSITION); /* make thw window visible */ GrMapWindow(wid); canvas = wid; /* create the graphics contexts */ gc = GrNewGC(); srcGC = GrNewGC(); dstGC = GrNewGC(); return True; }
static void do_update(GR_EVENT_UPDATE *ep) { mwin * mwp; mwin * tmwp; GR_WINDOW_INFO winfo; if (IsDecoration(ep->wid)) return; if ((mwp = FindWindow(ep->wid)) == NULL) { /* We have a new window */ if (ep->utype != GR_UPDATE_MAP) return; if ((mwp = NewWindow(ep->wid)) == NULL) { GrError("malloc failed\n"); return; } GrGetWindowInfo(ep->wid, &winfo); mwp->x = ep->x - winfo.bordersize; mwp->y = ep->y - winfo.bordersize; mwp->width = ep->width + 2 * winfo.bordersize; GrMoveWindow(mwp->wid, mwp->x + winfo.bordersize, mwp->y + DEC_HEIGHT + 2 * winfo.bordersize); mwp->fid = GrNewWindow(GR_ROOT_WINDOW_ID, mwp->x + 1, mwp->y + 1, mwp->width - 2, DEC_HEIGHT - 2, 1, BLUE, BLACK); GrSelectEvents(mwp->fid, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION); GrMapWindow(mwp->fid); } else { switch (ep->utype) { case GR_UPDATE_UNMAP: GrUnmapWindow(mwp->fid); GrDestroyWindow(mwp->fid); if (mwins == mwp) { mwins = mwp->next; } else for(tmwp = mwins; tmwp; tmwp = tmwp->next) { if (tmwp->next == mwp) { tmwp->next = mwp->next; } } free(mwp); break; case GR_UPDATE_MOVE: GrGetWindowInfo(ep->wid, &winfo); if ((ep->x == (mwp->x + winfo.bordersize)) && (ep->y == (mwp->y + winfo.bordersize + DEC_HEIGHT))) { return; } mwp->x = ep->x - winfo.bordersize; mwp->y = ep->y - winfo.bordersize - DEC_HEIGHT; GrMoveWindow(mwp->fid, mwp->x + 1, mwp->y + 1); default: break; } } }
/* Cover root window to erase roaches. */ void CoverRoot(void) { GR_WINDOW_ID roachWin; roachWin = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, display_width, display_height, 0, CYAN, BLACK); GrLowerWindow(roachWin); GrMapWindow(roachWin); GrFlush(); }
nxeyes_state *init(void) { nxeyes_state *state; GR_REGION_ID rid1, rid2; GR_SCREEN_INFO si; GR_WM_PROPERTIES props; if(!(state = malloc(sizeof(nxeyes_state)))) return NULL; state->oldx = state->oldy = state->x = state->y = 0; state->button_down = state->eyes_closed = state->quit = 0; state->olx = state->orx = EYEMASK_WIDTH / 2; state->oly = state->ory = EYEMASK_HEIGHT / 2; GrGetScreenInfo(&si); state->mousex = si.xpos; state->mousey = si.ypos; state->mouse_moved = 1; state->gc = GrNewGC(); GrSetGCForeground(state->gc, GR_COLOR_WHITE); GrSetGCBackground(state->gc, GR_COLOR_BLACK); state->wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, (EYEFG_HEIGHT * 2) + EYE_SPACING, EYEFG_HEIGHT, 0, GR_COLOR_WHITE, 0); rid1 = GrNewBitmapRegion(eyemask_bits, EYEMASK_WIDTH, EYEMASK_HEIGHT); rid2 = GrNewBitmapRegion(eyemask_bits, EYEMASK_WIDTH, EYEMASK_HEIGHT); GrOffsetRegion(rid2, EYEMASK_WIDTH + EYE_SPACING, 0); GrUnionRegion(rid1, rid1, rid2); GrSetWindowRegion(state->wid, rid1, GR_WINDOW_BOUNDING_MASK); GrDestroyRegion(rid1); GrDestroyRegion(rid2); props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_NODECORATE; GrSetWMProperties(state->wid, &props); GrSelectEvents(state->wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_MOUSE_POSITION | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_TIMER); GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_MOUSE_POSITION); GrMapWindow(state->wid); srand(123); #if MW_FEATURE_TIMERS start_blink_timer(state); #endif return state; }
static void GrNewWindowWrapper(void *r) { nxNewWindowReq *req = r; GR_WINDOW_ID wid; wid = GrNewWindow(req->parentid, req->x, req->y, req->width, req->height, req->bordersize, req->backgroundcolor, req->bordercolor); GsWriteType(current_fd,GrNumNewWindow); GsWrite(current_fd, &wid, sizeof(wid)); }
mvp_widget_t* mvpw_create(mvp_widget_t *parent, GR_COORD x, GR_COORD y, unsigned int width, unsigned int height, GR_COLOR bg, GR_COLOR border_color, int border_size) { mvp_widget_t *widget; GR_WINDOW_ID wid, pwid; if (parent) pwid = parent->wid; else pwid = GR_ROOT_WINDOW_ID; wid = GrNewWindow(pwid, x, y, width, height, border_size, bg, border_color); if (wid == 0) return NULL; if ((widget=(mvp_widget_t*)malloc(sizeof(*widget))) == NULL) return NULL; memset(widget, 0, sizeof(*widget)); widget->wid = wid; widget->parent = parent; widget->x = x; widget->y = y; widget->width = width; widget->height = height; widget->bg = bg; widget->border_color = border_color; widget->border_size = border_size; widget->user_data = NULL; if (add_widget(widget) < 0) goto err; widget->event_mask = GR_EVENT_MASK_EXPOSURE; GrSelectEvents(wid, widget->event_mask); return widget; err: if (widget) mvpw_destroy(widget); return NULL; }
//------------------------------------------------------------------------------ // Function Name : init_ui_manager() // Description : //------------------------------------------------------------------------------ BOOL init_ui_manager(void) { CObject* pObject; UINT id; PRINT_FUNC_CO(); // start nano-x service if (GrOpen() < 0) { // DBGMSG(DBG_MAIN, "[Failure]\r\n--> %s: GrOpen Failed!!\r\n", __func__); return FALSE; } GrSetErrorHandler(error_handler); GrGetScreenInfo(&g_scr_info); // prepare g_font g_font = GrCreateFontEx((GR_CHAR *)FONT_PATH, 18, 18, NULL); GrSetFontAttr(g_font, (GR_TFKERNING | GR_TFANTIALIAS), 0); g_wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, g_scr_info.cols, g_scr_info.rows, 0, BLACK, 0); if (g_wid == 0) { // DBGMSG(DBG_MAIN, "[Failure]\r\n--> %s: GrNewWindow failure\r\n", __func__); GrClose(); return FALSE; } g_gc = GrNewGC(); GrRaiseWindow(g_wid); GrMapWindow(g_wid); GrSelectEvents(g_wid, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_EXPOSURE); GrSetGCUseBackground(g_gc, FALSE); // GrSetGCUseBackground(g_gc, TRUE); GrSetGCFont(g_gc, g_font); // GrSetGCBackground(g_gc, BLACK); GrSetGCForeground(g_gc, WHITE); // BuildObject(); return TRUE; }
int main() { GR_WINDOW_ID window; GR_EVENT event; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } window = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, 100, 60, 4, WHITE, BLUE); GrMapWindow(window); while(1) GrCheckNextEvent(&event); GrClose(); }
CRJinkeScreen( int width, int height ) : CRGUIScreenBase( width, height, true ) { if( GrOpen() < 0 ) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); return; } GR_WM_PROPERTIES props; //GR_SCREEN_INFO si; //GrGetScreenInfo(&si); _wid = GrNewWindow(GR_ROOT_WINDOW_ID,VIEWER_WINDOW_X,VIEWER_WINDOW_Y, VIEWER_WINDOW_WIDTH,VIEWER_WINDOW_HEIGHT, 0, GR_COLOR_WHITE, 0); _gc = GrNewGC(); GrSetGCForeground(_gc, GR_COLOR_BLACK); GrSetGCBackground(_gc, GR_COLOR_WHITE); GrSelectEvents(_wid, GR_EVENT_MASK_BUTTON_DOWN | \ GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION |\ GR_EVENT_MASK_EXPOSURE |GR_EVENT_MASK_KEY_UP|\ GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_CLOSE_REQ); //Set Windows style props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_NODECORATE; GrSetWMProperties(_wid, &props); //#ifndef USE_OLD_NANOX GrMapWindow(_wid); GrSetFocus(_wid); //#endif _canvas = LVRef<LVDrawBuf>( new LVGrayDrawBuf( _width, _height, GRAY_BACKBUFFER_BITS ) ); _front = LVRef<LVDrawBuf>( new LVGrayDrawBuf( _width, _height, GRAY_BACKBUFFER_BITS ) ); _canvas->Clear(0xFFFFFF); //_front->Clear(0xFFFFFF); _front->Clear(0x000000); instance = this; }
int main(void) { GR_WINDOW_ID wid; GR_GC_ID gc; GR_EVENT event; if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to the Nano-X server\n"); return 1; } wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, BITMAPWIDTH, BITMAPHEIGHT, 0, GR_COLOR_WHITE, 0); GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE); gc = GrNewGC(); GrSetGCForeground(gc, GR_COLOR_BLACK); GrSetGCBackground(gc, GR_COLOR_WHITE); GrMapWindow(wid); while(1) { GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_EXPOSURE: redraw(wid, gc); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); return 0; default: break; } } }
// // Member Function // void CContextWeather::Init() { CObject* pObject; CObjectIcon* pObjectIcon; UINT id; CContext::Init(); // 배경 이미지 pObject = new CObjectImage(m_wid_parent, m_gc, 0, 0, g_scr_info.cols, g_scr_info.rows); if(pObject) { pObject->LoadImage(IMG_BACKGROUND, "/app/img/main_bg_blank.png"); id = m_ObjectList.AddObject(pObject); } // 왼쪽 날씨 이미지 pObject = new CObjectIcon(m_wid_parent, m_gc, 1, 169, 300, 246); if(pObject) { pObjectIcon = (CObjectIcon*)pObject; pObjectIcon->AllocImageCount(IMG_ENUM_WEATHER_COUNT); pObject->LoadImage(IMG_ENUM_WEATHER_SERENITY, "/app/img/weather/serenity.png"); pObject->LoadImage(IMG_ENUM_WEATHER_PARTLY_CLOUDY, "/app/img/weather/partly_cloudy.png"); pObject->LoadImage(IMG_ENUM_WEATHER_CLOUDY, "/app/img/weather/cloudy.png"); pObject->LoadImage(IMG_ENUM_WEATHER_SHOWER, "/app/img/weather/shower.png"); pObject->LoadImage(IMG_ENUM_WEATHER_RAINNY, "/app/img/weather/rainny.png"); pObject->LoadImage(IMG_ENUM_WEATHER_THUNDERSTORM, "/app/img/weather/thunderstorm.png"); pObject->LoadImage(IMG_ENUM_WEATHER_SNOW, "/app/img/weather/snow.png"); id = m_ObjectList.AddObject(pObject); } // 오른쪽 날씨 이미지 pObject = new CObjectIcon(m_wid_parent, m_gc, 499, 169, 300, 246); if(pObject) { pObjectIcon = (CObjectIcon*)pObject; pObjectIcon->AllocImageCount(IMG_ENUM_WEATHER_COUNT); pObject->LoadImage(IMG_ENUM_WEATHER_SERENITY, "/app/img/weather/serenity.png"); pObject->LoadImage(IMG_ENUM_WEATHER_PARTLY_CLOUDY, "/app/img/weather/partly_cloudy.png"); pObject->LoadImage(IMG_ENUM_WEATHER_CLOUDY, "/app/img/weather/cloudy.png"); pObject->LoadImage(IMG_ENUM_WEATHER_SHOWER, "/app/img/weather/shower.png"); pObject->LoadImage(IMG_ENUM_WEATHER_RAINNY, "/app/img/weather/rainny.png"); pObject->LoadImage(IMG_ENUM_WEATHER_THUNDERSTORM, "/app/img/weather/thunderstorm.png"); pObject->LoadImage(IMG_ENUM_WEATHER_SNOW, "/app/img/weather/snow.png"); id = m_ObjectList.AddObject(pObject); } // 가스On/Off 이미지 pObject = new CObjectIcon(m_wid_parent, m_gc, 325, 245, 137, 137); //좌측여백 13 if(pObject) { pObjectIcon = (CObjectIcon*)pObject; pObjectIcon->AllocImageCount(IMG_ENUM_GAS_COUNT); pObject->LoadImage(IMG_ENUM_GAS_ON, "/app/img/main_icon/main_gas_on.png"); //적색 가스사용 pObject->LoadImage(IMG_ENUM_GAS_OFF, "/app/img/main_icon/main_gas_off.png"); //녹색 가스차단 id = m_ObjectList.AddObject(pObject); } // 주차아이콘 pObject = new CObjectImage(m_wid_parent, m_gc, 0, 419, 261, 61); if(pObject) { pObject->LoadImage(IMG_BACKGROUND, "/app/img/main_bar_back.png"); id = m_ObjectList.AddObject(pObject); } //g_setup_data.m_SetupData.gas_stat: 0=사용중, 1=사용차단 m_isGasOff = (g_setup_data.m_SetupData.gas_stat) ? TRUE : FALSE; //멘트가 표시될 서브 윈도 m_wid_ment = GrNewWindow(g_wid, MENT_AREA_X, MENT_AREA_Y, MENT_AREA_WIDTH, MENT_AREA_HEIGHT, 0, 0, 0); if(m_wid_ment) { // GrMapWindow(m_wid_ment); //이미지 버퍼링을 처리할 Pixel Map // m_pixmap_ment = GrNewPixmap(MENT_AREA_WIDTH, MENT_AREA_HEIGHT, NULL); m_pixmap_ment = GrNewPixmap(MENT_PIXEL_MAP_WIDTH, MENT_AREA_HEIGHT, NULL); #if 0 RedrawImage(m_wid_ment, g_gc, 0, 0, MENT_AREA_WIDTH, MENT_AREA_HEIGHT, MENT_AREA_X, MENT_AREA_Y, MENT_AREA_WIDTH, MENT_AREA_HEIGHT, WEATHER_OBJ_BG); RedrawImage(m_pixmap_ment, g_gc, 0, 0, MENT_AREA_WIDTH, MENT_AREA_HEIGHT, MENT_AREA_X, MENT_AREA_Y, MENT_AREA_WIDTH, MENT_AREA_HEIGHT, WEATHER_OBJ_BG); DrawText(g_szWeatherMent[g_setup_data.m_SetupData.today_weather], m_pixmap_ment, g_gc, 0, 0, m_width_ment, MENT_AREA_HEIGHT, g_font, 24, WHITE, TXT_HALIGN_LEFT|TXT_VALIGN_MIDDLE); GrRaiseWindow(m_wid_ment); #endif } else { DBGMSGC(DBG_WEATHER, "%s: GrNewWindow failure\r\n", __func__); } }
void show_jpeg(int client, char *file, int show_time) { GR_EVENT event; /* current event */ GR_IMAGE_ID id = 0; GR_SIZE w = -1; GR_SIZE h = -1; GR_IMAGE_INFO info; GR_WINDOW_ID w1; /* id for large window */ GR_GC_ID gc1; /* graphics context for text */ GR_SCREEN_INFO si; int time_left; bool ever_exposed = false; #if !defined(HAVE_JPEG_SUPPORT) && !defined(HAVE_BMP_SUPPORT) && !defined(HAVE_GIF_SUPPORT) printf("Sorry, no image support compiled in\n"); exit(1); #endif GrGetScreenInfo(&si); printf("Loading image: %s\n", file); if (access(file, F_OK) < 0) { fdprintf(client, "Can't access \"%s\": %s\n", file, strerror(errno)); return; } id = GrLoadImageFromFile(file, 0); if (id) { GrGetImageInfo(id, &info); } else { // File exists, so why the error? int fd, len; char buf[64]; fdprintf(client, "Can't load %s\n", file); if ((fd = open(file, O_RDONLY)) >= 0) { len = read(fd, buf, 64); if (len != 64) { diag_printf("Short read? len = %d\n", len); } else { diag_dump_buf(buf, len); } close(fd); } else { diag_printf("Can't oopen \"%s\": %s\n", file, strerror(errno)); } return; } w = info.width; h = info.height; if ((si.rows < info.height) || (si.cols < info.width)) { // Preserve aspect ratio if (si.cols < info.width) { w = si.cols; h = (si.cols * info.height) / info.width; } if (si.rows < h) { w = (si.rows * w) / h; h = si.rows; } } printf("Create window - orig %dx%d => %dx%d\n", info.width, info.height, w, h); fdprintf(client, "<INFO> Display \"%s\" - orig %dx%d => %dx%d\n", file, info.width, info.height, w, h); w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, w, h, 4, BLACK, WHITE); GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE); GrMapWindow(w1); gc1 = GrNewGC(); GrSetGCForeground(gc1, WHITE); #define TO_MS 50 time_left = show_time * 1000; while (time_left > 0) { GrGetNextEventTimeout(&event, TO_MS); // milliseconds switch(event.type) { case GR_EVENT_TYPE_CLOSE_REQ: GrDestroyWindow(w1); GrFreeImage(id); return; /* no return*/ case GR_EVENT_TYPE_EXPOSURE: /*GrDrawImageFromFile(w1, gc1, 0, 0, w, h, argv[1],0);*/ GrDrawImageToFit(w1, gc1, 0, 0, w, h, id); ever_exposed = true; break; default: case GR_EVENT_TYPE_NONE: case GR_EVENT_TYPE_TIMEOUT: time_left -= TO_MS; if ((time_left < 0) && !ever_exposed) { // Things get real cranky if we delete the window too fast! time_left = TO_MS; } break; } } GrUnmapWindow(w1); GrDestroyWindow(w1); GrDestroyGC(gc1); GrFreeImage(id); }
int main(int argc, char **argv) { GR_SCREEN_INFO si; GR_WM_PROPERTIES props; if (GrOpen() < 0) { fprintf(stderr, "Cannot open graphics\n"); exit(1); } GrReqShmCmds(65536); /* Test by Morten Rolland for shm support */ GrGetScreenInfo(&si); #ifdef __ECOS /* 240x320 screen*/ COLS = si.cols - 10; ROWS = si.rows - 40; #else COLS = si.cols - 40; ROWS = si.rows - 80; #endif mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, COLS, ROWS, 0, BLACK, BLACK); /* set title */ props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION; props.title = "NanoX World Map"; GrSetWMProperties(mainwid, &props); mapwidth = COLS - 2; mapheight = ROWS - 2; mapxorig = mapwidth / 2; mapyorig = mapheight / 2; selectxscale = 4; selectyscale = 3; coordx = 0; coordy = ROWS - 1; mapwid = GrNewWindow(mainwid, 1, 1, mapwidth, mapheight, #if 0 1, BLACK, WHITE); #else 1, LTGRAY, BLACK); #endif GrSelectEvents(mainwid, GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(mapwid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_MOUSE_POSITION | GR_EVENT_MASK_KEY_DOWN); GrMapWindow(mainwid); GrMapWindow(mapwid); mapgc = GrNewGC(); xorgc = GrNewGC(); GrSetGCMode(xorgc, GR_MODE_XOR); Longitude = ITOF(0); Latitude = ITOF(0); setzoom(ITOF(1)); while (1) checkevent(); }
int main(int argc, char ** argv) { GR_BITMAP bitmap1fg[7]; /* mouse cursor */ GR_BITMAP bitmap1bg[7]; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } GrGetScreenInfo(&si); w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 30, si.cols - 120, si.rows - 60, 1, WHITE, LTBLUE); GrSelectEvents(w1, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | GR_EVENT_MASK_CLOSE_REQ); GrMapWindow(w1); gc1 = GrNewGC(); gc3 = GrNewGC(); GrSetGCForeground(gc1, GRAY); GrSetGCBackground(gc1, LTBLUE); GrSetGCFont(gc1, GrCreateFont(GR_FONT_SYSTEM_FIXED, 0, NULL)); /*GrSetGCFont(gc1, GrCreateFont(GR_FONT_OEM_FIXED, 0, NULL));*/ GrSetGCForeground(gc3, WHITE); GrSetGCBackground(gc3, BLACK); bitmap1fg[0] = MASK(_,_,X,_,X,_,_); bitmap1fg[1] = MASK(_,_,_,X,_,_,_); bitmap1fg[2] = MASK(_,_,_,X,_,_,_); bitmap1fg[3] = MASK(_,_,_,X,_,_,_); bitmap1fg[4] = MASK(_,_,_,X,_,_,_); bitmap1fg[5] = MASK(_,_,_,X,_,_,_); bitmap1fg[6] = MASK(_,_,X,_,X,_,_); bitmap1bg[0] = MASK(_,X,X,X,X,X,_); bitmap1bg[1] = MASK(_,_,X,X,X,_,_); bitmap1bg[2] = MASK(_,_,X,X,X,_,_); bitmap1bg[3] = MASK(_,_,X,X,X,_,_); bitmap1bg[4] = MASK(_,_,X,X,X,_,_); bitmap1bg[5] = MASK(_,_,X,X,X,_,_); bitmap1bg[6] = MASK(_,X,X,X,X,X,_); GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg); /*GrFillRect(GR_ROOT_WINDOW_ID, gc1, 0, 0, si.cols, si.rows);*/ GrSetGCForeground(gc1, BLACK); GrSetGCBackground(gc1, WHITE); text_init(); if (term_init() < 0) { GrClose(); exit(1); } /* we want tfd events also*/ GrRegisterInput(tfd); #if 1 GrMainLoop(HandleEvent); #else while(1) { GR_EVENT ev; GrGetNextEvent(&ev); HandleEvent(&ev); } #endif /* notreached*/ return 0; }
void initialise(lstate *state) { GR_SCREEN_INFO si; GR_IMAGE_ID back_image; GR_IMAGE_INFO imageinfo; int rows = 1, columns = 1, width, height, x = 0, y = 0; GR_WM_PROPERTIES props; litem *i; if(GrOpen() < 0) { GrError("Couldn't connect to Nano-X server\n"); exit(4); } state->window_background_mode = 0; state->window_background_image = NULL; sspid = -1; read_config(state); GrGetScreenInfo(&si); if(si.rows > si.cols) { rows = state->numlitems; while((((rows / columns) + rows % columns) * ITEM_HEIGHT) > si.rows) { columns++; } if((columns * ITEM_WIDTH) > si.cols) goto toomany; rows = (rows / columns) + (rows % columns); width = columns * ITEM_WIDTH + 1 + columns; height = rows * ITEM_HEIGHT + 1 + rows; } else { columns = state->numlitems; while((((columns / rows) + (columns % rows)) * ITEM_WIDTH) > si.cols) { rows++; } if((rows * ITEM_HEIGHT) > si.rows) goto toomany; columns = (columns / rows) + (columns % rows); width = columns * ITEM_WIDTH + 1 + columns; height = (rows * ITEM_HEIGHT) + 1 + rows; y = si.rows - (rows * ITEM_HEIGHT) - 1 - rows; } state->gc = GrNewGC(); GrSetGCForeground(state->gc, ITEM_TEXT_COLOUR); GrSetGCBackground(state->gc, ITEM_BACKGROUND_COLOUR); if(state->window_background_image) { if(!(back_image = GrLoadImageFromFile( state->window_background_image, 0))) { GrError("Couldn't load background image\n"); } else { GrGetImageInfo(back_image, &imageinfo); if(!(state->background_pixmap = GrNewPixmap( imageinfo.width, imageinfo.height, NULL))) { GrError("Couldn't allocate pixmap " "for background image\n"); } else { GrDrawImageToFit(state->background_pixmap, state->gc, 0, 0, imageinfo.width, imageinfo.height, back_image); GrFreeImage(back_image); GrSetBackgroundPixmap(GR_ROOT_WINDOW_ID, state->background_pixmap, state->window_background_mode); GrClearWindow(GR_ROOT_WINDOW_ID, GR_TRUE); } } } if(state->ssitems) GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_SCREENSAVER); state->main_window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, y, width, height, 0, ITEM_BACKGROUND_COLOUR, 0); GrSelectEvents(state->main_window, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_TIMER); props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_NOMOVE | GR_WM_PROPS_NODECORATE | GR_WM_PROPS_NOAUTOMOVE | GR_WM_PROPS_NOAUTORESIZE; GrSetWMProperties(state->main_window, &props); i = state->lastlitem; y = 0; while(i) { i->wid = GrNewWindow(state->main_window, (x * ITEM_WIDTH) + x + 1, (y * ITEM_HEIGHT) + y + 1, ITEM_WIDTH, ITEM_HEIGHT, 1, ITEM_BACKGROUND_COLOUR, ITEM_BORDER_COLOUR); GrSelectEvents(i->wid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrMapWindow(i->wid); i = i->prev; if(++x == columns) { x = 0; y++; } } GrMapWindow(state->main_window); signal(SIGCHLD, &reaper); do_startups(state); return; toomany: GrError("Too many items to fit on screen\n"); exit(6); }
int main(int argc, char *argv[]) { GR_EVENT event; GR_PROP *data; GR_SERIALNO count = 0; GR_WINDOW_ID wid, serverid; if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); return 1; } wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, 1, 1, 0, 0, 0); if(!wid) { fprintf(stderr, "Couldn't get a window\n"); GrClose(); return 1; } GrSelectEvents(wid, GR_EVENT_MASK_CLIENT_DATA | GR_EVENT_MASK_TIMER); if(GrGetWindowProperty(GR_ROOT_WINDOW_ID, "demo_ipc_server", &data) != sizeof(serverid)) { if(!data) { fprintf(stderr, "Couldn't find server ID\n"); GrClose(); return 1; } else { fprintf(stderr, "Server ID property is wrong size\n"); free(data); GrClose(); return 1; } } memcpy(&serverid, data, sizeof(serverid)); free(data); printf("Found server at window %d\n", serverid); GrCreateTimer(wid, 1000, GR_TRUE); while(1) { GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_TIMER: send_ping(wid, serverid, count++); break; case GR_EVENT_TYPE_CLIENT_DATA: handle_packet(&event); break; default: fprintf(stderr, "Got unknown event %d\n", event.type); break; } } GrClose(); return 0; }
int main(int argc,char **argv) { char *imagefile = "bin/slidebmp.bmp"; if (GrOpen() < 0) { GrError("cannot open graphics\n"); exit(1); } gc1 = GrNewGC(); #if USE_IMAGE image = GrNewWindow(GR_ROOT_WINDOW_ID, 300, 0, (WIDTH_IN_TILES * tile_width), (HEIGHT_IN_TILES * tile_height), 4, BLACK, WHITE); if (argc > 1) imagefile = argv[1]; /* need to find out image size.... */ image_addr = malloc(4 * (WIDTH_IN_TILES * tile_width) * (HEIGHT_IN_TILES * tile_height)); image = GrNewPixmap((WIDTH_IN_TILES * tile_width), (HEIGHT_IN_TILES * tile_height), image_addr); GrDrawImageFromFile(image, gc1, 0, 0, GR_IMAGE_MAX_SIZE, GR_IMAGE_MAX_SIZE, imagefile, 0); #endif /* calculate size of tile area */ calc_width = 10 + (WIDTH_IN_TILES * tile_width); calc_height = 15 + 35 + (HEIGHT_IN_TILES * tile_height); #if 0 /* enforce minimum size */ if (calc_width < 240) calc_width=240; if (calc_height < 320) calc_height=320; #endif master = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, calc_width, calc_height, 1, RED, WHITE); buttons = GrNewWindow((GR_WINDOW_ID) master, 5, 5, (calc_width - 5), 35, 1, RED, RED); tiles = GrNewWindow((GR_WINDOW_ID) master, (calc_width/2) - (WIDTH_IN_TILES * tile_width /2), 45 + ((calc_height - 50)/2) - (HEIGHT_IN_TILES * tile_height /2), (WIDTH_IN_TILES * tile_width), (HEIGHT_IN_TILES * tile_height), 1, RED, RED); GrMapWindow(master); GrMapWindow(buttons); GrMapWindow(tiles); /* set random seed */ srandom((int) getpid()); RandomiseTiles(); GrSelectEvents(master, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ| GR_EVENT_MASK_KEY_DOWN); GrSelectEvents(buttons, GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(tiles, GR_EVENT_MASK_BUTTON_DOWN); RefreshWindow(); while (GR_TRUE) { GR_EVENT event; GrGetNextEvent(&event); HandleEvents(&event); } }
/* ***********************************************************/ int main(int argc, char* argv[]) { GR_EVENT event; GR_WM_PROPERTIES props; int computer_side; char s[256]; int i; BOOL found; char temp[50]; if (GrOpen() < 0) { fprintf(stderr, "tuxchess: cannot open graphics\n"); exit(1); } load_images(); master = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, BM_WIDTH, BM_HEIGHT, 0, WHITE, WHITE); board = GrNewWindow((GR_WINDOW_ID) master, 0, 0, 394, 394, 0, WHITE, WHITE); text = GrNewWindow((GR_WINDOW_ID) master, 0, 393, 394, 20, 0, BLACK, BLACK); GrSelectEvents(master, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE; props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION | GR_WM_PROPS_CLOSEBOX; props.title = TITLE; GrSetWMProperties(master, &props); /* eliminate white background*/ props.flags = GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_NOBACKGROUND; GrSetWMProperties(board, &props); GrMapWindow(master); GrMapWindow(board); GrMapWindow(text); gc = GrNewGC(); text_gc = GrNewGC(); init(); gen(); max_time = 1 << 25; max_depth = 4; if (argc > 1) computer_side = side; /* computer plays white */ else { computer_side = EMPTY; /* human plays white */ gprintf("Make a move..."); } for (;;) { if (side == computer_side) { /* think about the move and make it */ think(0); if (!pv[0][0].u) { gprintf("No legal moves"); computer_side = EMPTY; continue; } sprintf(temp,"Computer's move: %s\n", move_str(pv[0][0].b)); gprintf(temp); makemove(pv[0][0].b); ply = 0; gen(); print_board(); print_result(); continue; } GrGetNextEvent(&event); switch(event.type) { case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); /* no return*/ case GR_EVENT_TYPE_EXPOSURE: print_board(); gprintf(NULL); break; case GR_EVENT_TYPE_BUTTON_DOWN: mouse_hit(event.button.x, event.button.y); break; } if (to != 999) { /* loop through the moves to see if it's legal */ found = FALSE; for (i = 0; i < first_move[1]; ++i) if (gen_dat[i].m.b.from == from && gen_dat[i].m.b.to == to) { found = TRUE; /* get the promotion piece right */ if (gen_dat[i].m.b.bits & 32) switch (s[4]) { case 'N': break; case 'B': i += 1; break; case 'R': i += 2; break; default: i += 3; break; } break; } /* if */ if (!found || !makemove(gen_dat[i].m.b)) gprintf("Illegal move.\n"); else { ply = 0; gen(); print_board(); print_result(); computer_side = side; to = 999; } } /* if to != 999 */ } /* for (;;) */ return(0); /* never reached */ }
int main(int argc, char **argv) { int t = 1; GR_EVENT event; /* current event */ while (t < argc) { if (!strcmp("-t", argv[t])) { bTextwin = GR_TRUE; ++t; continue; } } if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } if (bTextwin) { /* create text output window for debugging*/ wt = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 20, TEXTWIN_WIDTH, TEXTWIN_HEIGHT, 5, BLACK, GREEN); GrSelectEvents(wt, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_EXPOSURE); GrMapWindow(wt); gct = GrNewGC(); GrSetGCForeground(gct, GREEN); GrGetGCTextSize(gct, "A",1, GR_TFASCII, &width, &height, &base); GrSetGCFont(gct, GrCreateFont(GR_FONT_SYSTEM_FIXED, 0, NULL)); gctb = GrNewGC(); GrSetGCForeground(gctb, BLACK); } /* create scribble input window*/ w = create_scribble(); while (1) { GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_BUTTON_DOWN: do_buttondown(&event.button); break; case GR_EVENT_TYPE_BUTTON_UP: do_buttonup(&event.button); break; case GR_EVENT_TYPE_MOUSE_POSITION: case GR_EVENT_TYPE_MOUSE_MOTION: do_motion(&event.mouse); break; case GR_EVENT_TYPE_FOCUS_IN: do_focusin(&event.general); break; case GR_EVENT_TYPE_KEY_DOWN: do_keystroke(&event.keystroke); break; case GR_EVENT_TYPE_EXPOSURE: do_exposure(&event.exposure); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); } } }
void init_game(nstate *state) { GR_WM_PROPERTIES props; if(GrOpen() < 0) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); exit(1); } state->main_window = GrNewWindow(GR_ROOT_WINDOW_ID, MAIN_WINDOW_X_POSITION, MAIN_WINDOW_Y_POSITION, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT, 0, MAIN_WINDOW_BACKGROUND_COLOUR, 0); /* set title */ props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION; props.title = "Nano-Tetris"; GrSetWMProperties(state->main_window, &props); GrSelectEvents(state->main_window, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_TIMEOUT); state->score_window = GrNewWindow(state->main_window, SCORE_WINDOW_X_POSITION, SCORE_WINDOW_Y_POSITION, SCORE_WINDOW_WIDTH, SCORE_WINDOW_HEIGHT, 0, SCORE_WINDOW_BACKGROUND_COLOUR, 0); GrSelectEvents(state->score_window, GR_EVENT_MASK_EXPOSURE); GrMapWindow(state->score_window); state->scoregcf = GrNewGC(); GrSetGCForeground(state->scoregcf, SCORE_WINDOW_FOREGROUND_COLOUR); GrSetGCBackground(state->scoregcf, SCORE_WINDOW_BACKGROUND_COLOUR); state->scoregcb = GrNewGC(); GrSetGCForeground(state->scoregcb, SCORE_WINDOW_BACKGROUND_COLOUR); state->next_shape_window = GrNewWindow(state->main_window, NEXT_SHAPE_WINDOW_X_POSITION, NEXT_SHAPE_WINDOW_Y_POSITION, NEXT_SHAPE_WINDOW_WIDTH, NEXT_SHAPE_WINDOW_HEIGHT, 0, NEXT_SHAPE_WINDOW_BACKGROUND_COLOUR, 0); GrSelectEvents(state->next_shape_window, GR_EVENT_MASK_EXPOSURE); GrMapWindow(state->next_shape_window); state->nextshapegcf = GrNewGC(); state->nextshapegcb = GrNewGC(); GrSetGCForeground(state->nextshapegcb, NEXT_SHAPE_WINDOW_BACKGROUND_COLOUR); state->new_game_button = GrNewWindow(state->main_window, NEW_GAME_BUTTON_X_POSITION, NEW_GAME_BUTTON_Y_POSITION, NEW_GAME_BUTTON_WIDTH, NEW_GAME_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->new_game_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrMapWindow(state->new_game_button); state->buttongcf = GrNewGC(); GrSetGCForeground(state->buttongcf, BUTTON_FOREGROUND_COLOUR); GrSetGCBackground(state->buttongcf, BUTTON_BACKGROUND_COLOUR); state->buttongcb = GrNewGC(); GrSetGCForeground(state->buttongcb, BUTTON_BACKGROUND_COLOUR); state->pause_continue_button = GrNewWindow(state->main_window, PAUSE_CONTINUE_BUTTON_X_POSITION, PAUSE_CONTINUE_BUTTON_Y_POSITION, PAUSE_CONTINUE_BUTTON_WIDTH, PAUSE_CONTINUE_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->pause_continue_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->anticlockwise_button = GrNewWindow(state->main_window, ANTICLOCKWISE_BUTTON_X_POSITION, ANTICLOCKWISE_BUTTON_Y_POSITION, ANTICLOCKWISE_BUTTON_WIDTH, ANTICLOCKWISE_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->anticlockwise_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->clockwise_button = GrNewWindow(state->main_window, CLOCKWISE_BUTTON_X_POSITION, CLOCKWISE_BUTTON_Y_POSITION, CLOCKWISE_BUTTON_WIDTH, CLOCKWISE_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->clockwise_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->left_button = GrNewWindow(state->main_window, LEFT_BUTTON_X_POSITION, LEFT_BUTTON_Y_POSITION, LEFT_BUTTON_WIDTH, LEFT_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->left_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->right_button = GrNewWindow(state->main_window, RIGHT_BUTTON_X_POSITION, RIGHT_BUTTON_Y_POSITION, RIGHT_BUTTON_WIDTH, RIGHT_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->right_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->drop_button = GrNewWindow(state->main_window, DROP_BUTTON_X_POSITION, DROP_BUTTON_Y_POSITION, DROP_BUTTON_WIDTH, DROP_BUTTON_HEIGHT, 0, BUTTON_BACKGROUND_COLOUR, 0); GrSelectEvents(state->drop_button, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); state->well_window = GrNewWindow(state->main_window, WELL_WINDOW_X_POSITION, WELL_WINDOW_Y_POSITION, WELL_WINDOW_WIDTH, WELL_WINDOW_HEIGHT, 0, WELL_WINDOW_BACKGROUND_COLOUR, 0); GrSelectEvents(state->well_window, GR_EVENT_MASK_EXPOSURE); GrMapWindow(state->well_window); state->wellgc = GrNewGC(); GrMapWindow(state->main_window); state->state = STATE_STOPPED; state->score = 0; read_hiscore(state); state->level = 0; state->running_buttons_mapped = 0; srandom(time(0)); choose_new_shape(state); new_game(state); }
int main(int ac,char **av) { GR_WINDOW_ID w, w2; GR_GC_ID gc; GR_EVENT event; GR_WM_PROPERTIES props; if (GrOpen() < 0) { printf("Can't open graphics\n"); exit(1); } /* pass errors through main loop*/ GrSetErrorHandler(NULL); #define WIDTH 320 #define HEIGHT 240 w = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, WIDTH, HEIGHT, 0, GREEN, BLACK); w2 = GrNewWindow(w, 20, 20, 40, 40, 0, WHITE, BLACK); props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE; props.props = GR_WM_PROPS_NOBACKGROUND; props.title = "Nano-X Demo2"; GrSetWMProperties(w, &props); gc = GrNewGC(); GrSelectEvents(w, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP); GrMapWindow(w); GrSetFocus(w); /* serious bug here: when wm running, w2 is mapped anyway!!*/ /*GrMapWindow(w2);*/ for (;;) { /*GR_EVENT_KEYSTROKE *kev;*/ GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_EXPOSURE: GrSetGCForeground(gc,GrGetSysColor(GR_COLOR_APPWINDOW)); GrFillRect(w, gc, event.exposure.x, event.exposure.y, event.exposure.width, event.exposure.height); GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPTEXT)); GrSetGCUseBackground(gc, GR_FALSE); GrText(w, gc, 10, 30, "Hello World", -1, GR_TFASCII); GrRect(w, gc, 5, 5, 300, 60); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); exit(0); break; case GR_EVENT_TYPE_ERROR: printf("\7demo2: Error (%s) ", event.error.name); printf(nxErrorStrings[event.error.code],event.error.id); break; #if 0 case GR_EVENT_TYPE_BUTTON_DOWN: /* test server error on bad syscall*/ GrMapWindow(w2); GrMoveWindow(GR_ROOT_WINDOW_ID, 0, 0); { GR_SCREEN_INFO sinfo; GrGetScreenInfo(&sinfo); } break; #endif #if 0 case GR_EVENT_TYPE_KEY_DOWN: kev = (GR_EVENT_KEYSTROKE *)&event; printf("DOWN %d (%04x) %04x\n", kev->ch, kev->ch, kev->modifiers); break; case GR_EVENT_TYPE_KEY_UP: kev = (GR_EVENT_KEYSTROKE *)&event; printf("UP %d (%04x) %04x\n", kev->ch, kev->ch, kev->modifiers); break; #endif } } GrClose(); return 0; }
int main(int argc,char **argv) { GR_EVENT event; /* current event */ struct app_info * act; int width, height; #ifdef USE_WEIRD_POINTER GR_BITMAP bitmap1fg[7]; /* bitmaps for first cursor */ GR_BITMAP bitmap1bg[7]; #endif for(act = Apps; act->app_id[0] != '\0'; act++, num_apps++); if (GrOpen() < 0) { GrError("cannot open graphics\n"); return 1; } GrGetScreenInfo(&si); signal(SIGCHLD, &reaper); gc = GrNewGC(); bgc = GrNewGC(); GrSetGCForeground(bgc, GRAY); GrSetGCFont(gc, GrCreateFontEx(GR_FONT_SYSTEM_FIXED, 0, 0, NULL)); GrGetGCTextSize(gc, "A", 1, GR_TFASCII, &fwidth, &fheight, &fbase); width = fwidth * 8 + 4; height = (fheight) * num_apps + 4; w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 5, 5, width, height, 1, WHITE, BLACK); GrSelectEvents(w1, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CHLD_UPDATE); GrMapWindow(w1); #ifdef USE_WEIRD_POINTER bitmap1bg[0] = MASK(_,_,X,X,X,_,_); bitmap1bg[1] = MASK(_,X,X,X,X,X,_); bitmap1bg[2] = MASK(_,X,X,X,X,X,_); bitmap1bg[3] = MASK(_,X,X,X,X,X,_); bitmap1bg[4] = MASK(_,X,X,X,X,X,_); bitmap1bg[5] = MASK(_,X,X,X,X,X,_); bitmap1bg[6] = MASK(X,X,X,X,X,X,X); bitmap1fg[0] = MASK(_,_,_,_,_,_,_); bitmap1fg[1] = MASK(_,_,_,X,_,_,_); bitmap1fg[2] = MASK(_,_,X,X,X,_,_); bitmap1fg[3] = MASK(_,_,X,X,X,_,_); bitmap1fg[4] = MASK(_,_,X,X,X,_,_); bitmap1fg[5] = MASK(_,_,X,X,X,_,_); bitmap1fg[6] = MASK(_,X,X,X,X,X,_); GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg); #endif GrFillRect(GR_ROOT_WINDOW_ID, bgc, 0, 0, si.cols, si.rows); GrSetGCForeground(gc, BLACK); GrSetGCBackground(gc, WHITE); while (1) { GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_EXPOSURE: do_exposure(&event.exposure); break; case GR_EVENT_TYPE_BUTTON_DOWN: do_buttondown(&event.button); break; case GR_EVENT_TYPE_BUTTON_UP: do_buttonup(&event.button); break; case GR_EVENT_TYPE_UPDATE: do_update(&event.update); break; case GR_EVENT_TYPE_MOUSE_POSITION: do_mouse(&event.mouse); break; case GR_EVENT_TYPE_CLOSE_REQ: GrClose(); return 0; } } }
int main(int argc, char **argv) { int serialFd; int outFd; GR_SCREEN_INFO info; GR_WINDOW_ID calWindow; GR_EVENT event; /* Open up the graphics */ if (GrOpen() == -1) { fprintf(stderr, "Error! Unable to open the graphics engine\n"); return(-1); } /* Now open the serial port */ serialFd = calInitSerial("/dev/ttyS1"); if (serialFd == -1) { fprintf(stderr, "Error! Unable to open the touchscreen device\n"); return(-1); } GrGetScreenInfo(&info); /* Decide which points we are going to touch */ dataPoints[0].scrX = 10; dataPoints[0].scrY = 10; dataPoints[1].scrX = 10; dataPoints[1].scrY = info.rows - 10; dataPoints[2].scrX = info.cols - 10; dataPoints[2].scrY = info.rows - 10; dataPoints[3].scrX = info.cols - 10; dataPoints[3].scrY = 10; /* Now, create a window that spans the entire size of the screen */ calWindow = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, info.cols, info.rows, 0, BGCOLOR, FGCOLOR); GrSelectEvents(calWindow, GR_EVENT_MASK_EXPOSURE); GrMapWindow(calWindow); /* Wait for exposure */ while(GrPeekEvent(&event) != GR_EVENT_TYPE_EXPOSURE); /* Ok, now that we have been exposed, draw the instructions */ drawText(calWindow, instructions, 4); if (!doPoints(calWindow, serialFd)) { double scrXDelta, rawXDelta; double scrYDelta, rawYDelta; double deltaX, deltaY; scrXDelta = (double) dataPoints[2].scrX - dataPoints[0].scrX; rawXDelta = (double) dataPoints[2].rawX - dataPoints[0].rawX; scrYDelta = (double) dataPoints[1].scrY - dataPoints[0].scrY; rawYDelta = (double) dataPoints[1].rawY - dataPoints[0].rawY; /* We can now extrapolate and discover the extreme edges of the screen */ /* First, the low values */ deltaX = abs( (rawXDelta / scrXDelta) * ((double) dataPoints[0].scrX)); deltaY = abs( (rawYDelta / scrYDelta) * ((double) dataPoints[0].scrY)); /* deltaX = abs((double) dataPoints[0].scrX * rawXDelta) / scrXDelta); deltaY = abs((double) (dataPoints[0].scrY * rawYDelta) / scrYDelta); */ /* Print out the raw values, accounting for possible inversion */ if (dataPoints[0].rawX > dataPoints[2].rawX) { printf("%d ", (int) (dataPoints[0].rawX + deltaX)); printf("%d ", (int) (dataPoints[2].rawX - deltaX)); } else { printf("%d ", (int) (dataPoints[0].rawX - deltaX)); printf("%d ", (int) (dataPoints[2].rawX + deltaX)); } if (dataPoints[0].rawY >dataPoints[1].rawY) { printf("%d ", (int) (dataPoints[0].rawY + deltaY)); printf("%d\n", (int) (dataPoints[1].rawY - deltaY)); } else { printf("%d ", (int) (dataPoints[0].rawY - deltaY)); printf("%d\n", (int) (dataPoints[1].rawY + deltaY)); } } else { fprintf(stderr, "Error - Unable to read the touchscreen\n"); } /* Close everything down */ calCloseSerial(serialFd); GrClose(); /* Byebye! */ return(0); }
static int NX_CreateWindow (_THIS, SDL_Surface * screen, int w, int h, int bpp, Uint32 flags) { Dprintf ("enter NX_CreateWindow\n") ; // If a window is already present, destroy it and start fresh if (SDL_Window && SDL_Window != GR_ROOT_WINDOW_ID) { NX_DestroyWindow (this, screen) ; } // See if we have been given a window id if (SDL_windowid) { SDL_Window = strtol (SDL_windowid, NULL, 0) ; } else { SDL_Window = 0 ; } if ( ! SDL_ReallocFormat (screen, bpp, SDL_Visual.red_mask, SDL_Visual.green_mask, SDL_Visual.blue_mask, 0)) return -1; // Create (or use) the nanox display window if (! SDL_windowid) { SDL_Window = GrNewWindow (GR_ROOT_WINDOW_ID, 0, 0, w, h, 0, BLACK, WHITE) ; GrSelectEvents (SDL_Window, (GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_FOCUS_IN | GR_EVENT_MASK_FOCUS_OUT | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_MOUSE_ENTER | GR_EVENT_MASK_MOUSE_EXIT | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_CLOSE_REQ)) ; } /* Create the graphics context here, once we have a window */ SDL_GC = GrNewGC () ; if (SDL_GC == 0) { SDL_SetError("Couldn't create graphics context"); return(-1); } // Map them both and go fullscreen, if requested if (! SDL_windowid) { GrMapWindow (SDL_Window) ; if (flags & SDL_FULLSCREEN) { screen -> flags |= SDL_FULLSCREEN ; NX_EnterFullScreen (this) ; } else { screen -> flags &= ~ SDL_FULLSCREEN ; } } #ifdef ENABLE_NANOX_DIRECT_FB /* attempt allocating the client side framebuffer */ Clientfb = GrOpenClientFramebuffer(); /* NULL return will default to using GrArea()*/ #endif Dprintf ("leave NX_CreateWindow\n") ; return 0 ; }
int main() { int fd = open(bri_name, O_WRONLY); if ( fd < 0) { perror(bri_name); return 1; } char buff[10]; int notquit = 1, val= read_val(bri_name), max = read_val("/sys/class/backlight/s3c/max_brightness"); if ( max <= 0) return 1; GR_WINDOW_ID wid; /* window id */ GR_GC_ID gc; /* graphics context id */ GR_EVENT event; /* current event */ GR_SCREEN_INFO si; /* screen information */ if (GrOpen() < 0) { fprintf(stderr, "Cannot open graphics\n"); return 1; } GrGetScreenInfo(&si); printf("R=%d C=%d\n", si.rows, si.cols); wid = GrNewWindow(GR_ROOT_WINDOW_ID, 50, 50, max, HEIGHT, 1, BLACK, WHITE); GR_WM_PROPERTIES props; props.title = "Nx Light"; props.flags = GR_WM_FLAGS_TITLE; GrSetWMProperties( wid, &props); GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_MOUSE_MOTION | GR_EVENT_MASK_BUTTON_UP | GR_EVENT_MASK_BUTTON_DOWN ); GrMapWindow(wid); gc = GrNewGC(); while (notquit) { GrGetNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_MOUSE_MOTION: if ( !((GR_EVENT_MOUSE *)&event)->buttons ) break; if ( (event.mouse.x > 0) && (event.mouse.x < max)) { snprintf(buff, 9, "%d\n", val = event.mouse.x); write( fd, buff, strlen(buff)); } GrSetGCForeground(gc, WHITE); GrFillRect(wid, gc, 0, 0, val, HEIGHT); GrSetGCForeground(gc, BLACK); GrFillRect(wid, gc, val, 0, max+1, HEIGHT); break; case GR_EVENT_TYPE_EXPOSURE: if (event.exposure.wid == wid) GrSetGCForeground(gc, WHITE); GrFillRect(wid, gc, 0, 0, val, HEIGHT); GrSetGCForeground(gc, BLACK); GrFillRect(wid, gc, val, 0, max+1, HEIGHT); break; case GR_EVENT_TYPE_CLOSE_REQ: notquit = 0; } } close(fd); return 0; }
int ui_loop(int argc, char **argv, const char *name) { GR_EVENT event; /* current event */ GR_IMAGE_ID id = 0; NGLXContext cx; int width, height, k; if (GrOpen() < 0) { fprintf(stderr, "cannot open graphics\n"); exit(1); } width = 400; height = 300; GrSetErrorHandler(errorcatcher); w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, width, height, 4, BLACK, WHITE); GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_KEY_DOWN); GrMapWindow(w1); gc1 = GrNewGC(); GrSetGCForeground(gc1, WHITE); cx = nglXCreateContext(NULL, 0); nglXMakeCurrent(w1, cx); init(); reshape(width, height); while (1) { GrCheckNextEvent(&event); switch (event.type) { case GR_EVENT_TYPE_CLOSE_REQ: GrFreeImage(id); GrClose(); exit(0); case GR_EVENT_TYPE_EXPOSURE: break; case GR_EVENT_TYPE_KEY_DOWN: { GR_EVENT_KEYSTROKE *kp = &event.keystroke; /* XXX: nanoX special keys are totally bugged ! */ switch (kp->ch) { case 81: k = KEY_LEFT; break; case 83: k = KEY_RIGHT; break; case 82: k = KEY_UP; break; case 84: k = KEY_DOWN; break; default: k = kp->ch; break; } key(k, 0); } break; default: idle(); break; } } return 0; }
/* Initialise the game and return the state structure or NULL on failure: */ nbstate *init(int argc, char *argv[]) { GR_PROP *prop; nbstate *state; GR_SCREEN_INFO si; GR_BITMAP cursor = 0; GR_WM_PROPERTIES props; /* Try to connect to the Nano-X server: */ if(GrOpen() < 1) { fprintf(stderr, "Couldn't connect to Nano-X server\n"); return NULL; } /* Check that the server was built with alpha blending support * (necessary for the alpha blended sprites and special effects): */ GrGetScreenInfo(&si); if(!si.alphablend) { fprintf(stderr, "Error: Nano-X server was built without alpha " "blending support\nSet ALPHABLENDING = 1 in " "include/device.h, rebuild, and try again.\n"); return NULL; } /* Allocate the state structure and initialise it with defaults: */ if(!(state = malloc(sizeof(nbstate)))) return NULL; setup_default_state(state); /* Try to parse the command line arguments: */ if(parse_cmd_args(state, argc, argv)) { free(state); return NULL; } /* Try to load the game file: */ if(load_game_file(state)) { free(state); return NULL; } /* Load the high score file: */ load_hiscore(state); /* Calculate the canvas size: */ state->canvaswidth = state->width * state->brickwidth; state->canvasheight = state->scores.h + state->ball.s->h + (2 * BALLS_BORDER) + (state->height * state->brickheight) + 3 * state->brickheight + state->batheight; /* Place the bat in the centre of the window: */ state->batx = state->canvaswidth / 2; /* Create various pixmaps and alpha channels: */ state->scores.p = GrNewPixmap(state->canvaswidth, state->scores.h, NULL); state->scores.a = GrNewAlpha(state->canvaswidth, state->scores.h); state->canvas = GrNewPixmap(state->canvaswidth, state->canvasheight, NULL); /* The new and old canvasses are only used when screen fading is * enabled: */ if(state->faderate) { state->newcanvas = GrNewPixmap(state->canvaswidth, state->canvasheight, NULL); state->oldcanvas = GrNewPixmap(state->canvaswidth, state->canvasheight, NULL); } state->brickalpha = GrNewAlpha(state->brickwidth, state->brickheight); /* Start off with the canvas completely black: */ GrSetGCForeground(state->gc, GR_COLOR_BLACK); GrFillRect(state->canvas, state->gc, 0, 0, state->canvaswidth, state->canvasheight); /* If there is a window manager running, place the window off the * screen and let the window manager move it where it wants (avoids * flicker if we were to draw the window on screen before the window * manager moved it somewhere else): */ if(GrGetWindowProperty(GR_ROOT_WINDOW_ID, "WINDOW_MANAGER", &prop)) { free(prop); state->winx = GR_OFF_SCREEN; } /* Create the output window: */ state->wid = GrNewWindow(GR_ROOT_WINDOW_ID, state->winx, 0, state->canvaswidth, state->canvasheight, 0, 0, 0); /* Set the window title: */ props.flags = GR_WM_FLAGS_TITLE; props.title = "NanoBreaker"; GrSetWMProperties(state->wid, &props); /* Make the cursor over the output window be invisible: */ GrSetCursor(state->wid, 1, 1, 1, 1, 0, 0, &cursor, &cursor); /* Select the events we want to receive for the output window: */ GrSelectEvents(state->wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP | GR_EVENT_MASK_UPDATE | GR_EVENT_MASK_TIMER); /* Select for mouse position events on the root window so we can move * the bat even when the pointer strays outside the window (which it * often does because the cursor is invisible you don't know exactly * where it is): */ GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_MOUSE_POSITION); /* Map the output window (make it visible): */ GrMapWindow(state->wid); /* Create the one second periodic timer that is used to decrement the * power-up and power-down timers: */ state->tid = GrCreateTimer(state->wid, 1000, GR_TRUE); /* Reset the game: */ reset_game(state); return state; /* Return the newly allocated state structure. */ }
int main(int argc,char **argv) { GR_COORD x; GR_COORD y; GR_SIZE width; GR_SIZE height; GR_COORD rightx; /* x coordinate for right half stuff */ GR_BOOL setsize; /* TRUE if size of board is set */ GR_BOOL setmines; /* TRUE if number of mines is set */ GR_SIZE newsize = 10; /* desired size of board */ GR_COUNT newmines = 25; /* desired number of mines */ GR_WM_PROPERTIES props; setmines = GR_FALSE; setsize = GR_FALSE; argc--; argv++; while ((argc > 0) && (**argv == '-')) { switch (argv[0][1]) { case 'm': if (argc <= 0) { fprintf(stderr, "Missing mine count\n"); exit(1); } argc--; argv++; newmines = atoi(*argv); setmines = GR_TRUE; break; case 's': if (argc <= 0) { fprintf(stderr, "Missing size\n"); exit(1); } argc--; argv++; newsize = atoi(*argv); setsize = GR_TRUE; break; default: fprintf(stderr, "Unknown option \"-%c\"\n", argv[0][1]); exit(1); } argc--; argv++; } if (argc > 0) savefile = *argv; srand(time(0)); readgame(savefile); if (setsize) { if ((newsize < MINSIZE) || (newsize > MAXSIZE)) { fprintf(stderr, "Illegal board size\n"); exit(1); } if (newsize != size) { if (steps && playing) { fprintf(stderr, "Cannot change size while game is in progress\n"); exit(1); } playing = GR_FALSE; size = newsize; if (!playing) mines = (size * size * MINEPERCENT) / 100; } } if (setmines) { if ((newmines <= 0) || ((newmines > (size * size) / 2))) { fprintf(stderr, "Illegal number of mines\n"); exit(1); } if (newmines != mines) { if (steps && playing) { fprintf(stderr, "Cannot change mines while game is in progress\n"); exit(1); } playing = GR_FALSE; mines = newmines; } } findindex(); /* * Parameters of the game have been verified. * Now open the graphics and play the game. */ if (GrOpen() < 0) { fprintf(stderr, "Cannot open graphics\n"); exit(1); } GrReqShmCmds(655360); /* Test by Morten Rolland for shm support */ GrGetScreenInfo(&si); GrGetFontInfo(0, &fi); charheight = fi.height; /* * Create the main window which will contain all the others. */ #if 0 COLS = si.cols - 40; #else COLS = si.cols; #endif ROWS = si.rows - 80; mainwid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, COLS, ROWS, 0, BLACK, WHITE); /* set title */ props.flags = GR_WM_FLAGS_TITLE | GR_WM_FLAGS_PROPS; props.props = GR_WM_PROPS_APPFRAME | GR_WM_PROPS_CAPTION; props.title = "Land Mine"; GrSetWMProperties(mainwid, &props); /* * Create the board window which lies at the left side. * Make the board square, and as large as possible while still * leaving room to the right side for statistics and buttons. */ width = COLS - RIGHTSIDE - (si.xdpcm * RIGHTGAP / 10) - BOARDBORDER * 2; height = (((long) width) * si.ydpcm) / si.xdpcm; if (height > ROWS /* - y * 2*/) { height = ROWS - BOARDBORDER * 2; width = (((long) height) * si.xdpcm) / si.ydpcm; } xp = width / size; yp = height / size; width = xp * size - 1; height = yp * size - 1; x = BOARDBORDER; y = (ROWS - height) / 2; rightx = x + width + (si.xdpcm * RIGHTGAP / 10); boardwid = GrNewWindow(mainwid, x, y, width, height, BOARDBORDER, BLUE, WHITE); /* * Create the buttons. */ x = rightx; y = (si.ydpcm * BOARDGAP / 10); quitwid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT, 1, RED, WHITE); y += (si.ydpcm * BUTTONGAP / 10); savewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT, 1, GREEN, WHITE); y += (si.ydpcm * BUTTONGAP / 10); newgamewid = GrNewWindow(mainwid, x, y, BUTTONWIDTH, BUTTONHEIGHT, 1, GREEN, WHITE); /* * Create the statistics window. */ x = rightx; y += (si.ydpcm * STATUSGAP / 10); width = COLS - x; height = ROWS - y; statwid = GrNewWindow(mainwid, x, y, width, height, 0, 0, 0); statwidth = width; statheight = height; /* * Create the GC for drawing the board. */ boardgc = GrNewGC(); cleargc = GrNewGC(); delaygc = GrNewGC(); redgc = GrNewGC(); greengc = GrNewGC(); statgc = GrNewGC(); blackgc = GrNewGC(); buttongc = GrNewGC(); xorgc = GrNewGC(); GrSetGCBackground(boardgc, BLUE); GrSetGCForeground(cleargc, BLUE); GrSetGCForeground(redgc, RED); GrSetGCForeground(greengc, GREEN); GrSetGCForeground(statgc, GRAY); GrSetGCForeground(delaygc, BLACK); GrSetGCForeground(blackgc, BLACK); GrSetGCMode(delaygc, GR_MODE_XOR); GrSetGCMode(xorgc, GR_MODE_XOR); GrSetGCUseBackground(boardgc, GR_FALSE); GrSetGCUseBackground(buttongc, GR_FALSE); GrSelectEvents(mainwid, GR_EVENT_MASK_CLOSE_REQ); GrSelectEvents(boardwid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN); GrSelectEvents(statwid, GR_EVENT_MASK_EXPOSURE); GrSelectEvents(quitwid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(newgamewid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); GrSelectEvents(savewid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN); setcursor(); GrMapWindow(mainwid); GrMapWindow(boardwid); GrMapWindow(statwid); GrMapWindow(quitwid); GrMapWindow(savewid); GrMapWindow(newgamewid); if (!playing) newgame(); while (GR_TRUE) { GR_EVENT event; GrGetNextEvent(&event); handleevent(&event); } }
int main(int argc, char **argv) { GR_WINDOW_ID window; GR_EVENT event; GR_GC_ID gc; GR_FONT_ID fontid; int x, y, rnd = 0; MWLOGFONT lf; char description[128]; srand(time(0)); GrOpen(); window = GrNewWindow(GR_ROOT_WINDOW_ID, 5, 5, MAXW, MAXH, 4, BLACK, BLUE); GrMapWindow(window); gc = GrNewGC(); GrSelectEvents(window,GR_EVENT_MASK_ALL); GrSetGCUseBackground(gc,GR_FALSE); GrSetGCBackground(gc, GR_RGB(0, 0, 0)); y = 30; x = 0; while(1) { GrCheckNextEvent(&event); if(event.type == GR_EVENT_TYPE_CLOSE_REQ) { GrClose(); exit(0); } sleep(1); MWLF_Clear(&lf); description[0] = '\0'; // lf.lfSerif = 1; if ( rnd & 1 ) { lf.lfWeight = MWLF_WEIGHT_BOLD; strcat(description,"Bold "); } if ( rnd & 2 ) { lf.lfItalic = 1; strcat(description,"Italics "); } if ( rnd & 4 ) { lf.lfOblique = 1; strcat(description,"Oblique "); } if ( rnd & 8 ) { lf.lfMonospace = 1; strcat(description,"°íÁ¤Æø Monospace "); } else { lf.lfProportional = 1; strcat(description,"Proportional "); } if ( argc > 1 ) strcpy(lf.lfFaceName,argv[1]); else strcpy(lf.lfFaceName,"fantasy"); fontid = GrCreateFont(0, 0, &lf); /* GrSetFontSize(fontid, 1+(int)(80.0 * rand() / (RAND_MAX+1.0))); */ GrSetFontSize(fontid,26); GrSetFontRotation(fontid, 330); /* 33 degrees*/ GrSetFontAttr(fontid, GR_TFKERNING | GR_TFANTIALIAS, 0); GrSetGCFont(gc, fontid); /*GrSetGCBackground(gc, rand() & 0xffffff);*/ GrSetGCForeground(gc, 0xffffff); /* x = (int) ((MAXW * 1.0) *rand()/(RAND_MAX+1.0)); y = (int) ((MAXH * 1.0) *rand()/(RAND_MAX+1.0)); */ GrText(window, gc,x,y, description, -1, GR_TFASCII); GrDestroyFont(fontid); rnd++; y += 30; if ( y > 460 ) y = 0; } GrClose(); }