void LoadFonts(Fonts *f) { int ret; if (!f) { printf("Null-Pointer\n"); exit(EXITCODE_ERROR); } f->mSystem = FontCreate(); if (!f->mSystem) { printf("Out of memory\n"); exit(EXITCODE_ERROR); } ret = FontLoad(f->mSystem, "font7.mpf"); if (!ret) { printf("Font-Error\n"); exit(EXITCODE_ERROR); } switch (gConfig.mFontType) { case 1: f->mInternal = FontCreate(); if (!f->mInternal) { printf("Out of memory\n"); FontDestroy(f->mSystem); exit(EXITCODE_ERROR); } ret = FontLoad(f->mInternal, "font11.mpf"); if (!ret) { printf("Font-Error\n"); exit(EXITCODE_ERROR); } f->mText = f->mInternal; break; case 2: f->mInternal = FontCreate(); if (!f->mInternal) { printf("Out of memory\n"); FontDestroy(f->mSystem); exit(EXITCODE_ERROR); } ret = FontLoad(f->mInternal, "font23.mpf"); if (!ret) { printf("Font-Error\n"); exit(EXITCODE_ERROR); } f->mText = f->mInternal; break; default: f->mText = f->mSystem; break; } }
void FontLoadFromJSON(Font *f, const char *imgPath, const char *jsonPath) { yajl_val node = YAJLReadFile(jsonPath); if (node == NULL) { fprintf(stderr, "Error parsing font JSON '%s'\n", jsonPath); goto bail; } memset(f, 0, sizeof *f); // Load definitions from JSON data YAJLVec2i(&f->Size, node, "Size"); YAJLInt(&f->Stride, node, "Stride"); // Padding order is: left/top/right/bottom const yajl_val paddingNode = YAJLFindNode(node, "Padding"); f->Padding.Left = (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(paddingNode)->values[0]); f->Padding.Top = (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(paddingNode)->values[1]); f->Padding.Right = (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(paddingNode)->values[2]); f->Padding.Bottom = (int)YAJL_GET_INTEGER(YAJL_GET_ARRAY(paddingNode)->values[3]); YAJLVec2i(&f->Gap, node, "Gap"); bool proportional = false; YAJLBool(&proportional, node, "Proportional"); FontLoad(f, imgPath, proportional); bail: yajl_tree_free(node); }
int main(){ FrameworkInitialise("HelloWorld",1280,720,false); FrameworkBGColour(0.2f,0.4f,0.8f,1.0f); Sprite sprCarpet = SpriteLoad("./Images/Carpet.png",32,32,16,16); Font fntCourierNew = FontLoad("./Fonts/CourierNew.fnt"); //UPDATE while (FrameworkUpdate()){ //CLEAR AND DELTASET FrameworkClearScreen(); DeltaTimeSet(); count++; FPS = FPSGet(); for (int index = 1;index <= count; index++){ SpriteMove(sprCarpet,rand()%1280-640,rand()%720-360,rand()%99+1); SpriteDraw(sprCarpet); } if (FPS > 59.9f && FPS < 60.1f){ std::cout << "FPS :" << FPS << " sprite count :" << count << " triangle count : " << count*2 << std::endl; } if (FPS > 29.9f && FPS < 30.1f){ std::cout << "FPS :" << FPS << " sprite count :" << count << " triangle count : " << count*2 << std::endl; } DrawInt(fntCourierNew,GetInstanceCount(),0,360,0,true); } FrameworkShutdown(); return 1+1-1-1; }
//--------------------------- Fonts PyObject* LMF_FontLoad(PyObject *self, PyObject *args){ char* path; if (!PyArg_ParseTuple(args, "s", &path)) { ParsePyTupleError( __func__, __LINE__ ); return nullptr; } unsigned int FontID = FontLoad(path); return Py_BuildValue("i", FontID); }
bool GmgrInit(void) { params_vid_t params; handle_t device; LmuxInit(&gmgr_draw); LmuxInit(&gmgr_mux_gfxs); atexit(GmgrCleanup); device = FsOpen(SYS_DEVICES L"/Classes/video0", FILE_READ | FILE_WRITE); if (device == NULL) { _wdprintf(SYS_DEVICES L"/Classes/video0" L": %s\n", _wcserror(errno)); goto error0; } memset(¶ms.vid_setmode, 0, sizeof(params.vid_setmode)); if (!FsRequestSync(device, VID_SETMODE, ¶ms, sizeof(params), NULL)) { _wdprintf(L"VID_SETMODE: %s\n", _wcserror(errno)); goto error1; } gmgr_screen = GmgrCreateDeviceSurface(device, ¶ms.vid_setmode); if (gmgr_screen == NULL) { _wdprintf(L"GmgrCreateDeviceSurface: %s\n", _wcserror(errno)); goto error1; } gmgr_font = FontLoad(L"/Mobius/veramono.ttf", 12 * 64, gmgr_screen->mode.bitsPerPixel < 8 ? FB_FONT_MONO : FB_FONT_SMOOTH); if (gmgr_font == NULL) { _wdprintf(L"/Mobius/veramono.ttf: %s\n", _wcserror(errno)); goto error2; } if (!GmgrInitCursor()) goto error3; return true; error3: FontDelete(gmgr_font); gmgr_font = NULL; error2: GmgrCloseSurface(gmgr_screen); gmgr_screen = NULL; error1: HndClose(device); error0: return false; }
/****************************************************************************** * FontEditCommand(hBox, id) * * purpose: interprets menu id and calls appropriate function to do the task * * params: HWND hBox : handle to main window * WORD id : menu command id * returns: none * * side effects: plenty * *****************************************************************************/ VOID FontEditCommand( HWND hBox, WORD id ) { CHAR * szError; /* String for error messages */ LONG w; DWORD y, i, j; BOOL fRepaint = FALSE; HMENU hMenu; DLGPROC lpprocAboutDlg; MSG message; szError = ""; /* No Errors yet */ switch (id) { case FONT_EXIT: if (!CheckSave()) /* See if any files need saving */ break; /* Window's being destroyed. */ if (fLoaded) /* 4/8/87 Linsh added */ DeleteBitmap(); /* Get rid of memory DC */ PostQuitMessage(0); /* Cause application to be terminated */ break; case FONT_HELP_CONTENTS: WinHelp(hFont, gszHelpFile, HELP_CONTENTS, 0L); break; case FONT_HELP_SEARCH: /* * Tell winhelp to be sure this app's help file is current, * then invoke a search with an empty starting key. */ WinHelp(hFont, gszHelpFile, HELP_FORCEFILE, 0); WinHelp(hFont, gszHelpFile, HELP_PARTIALKEY, (DWORD)(LPSTR)""); break; case FONT_ABOUT: lpprocAboutDlg = (DLGPROC)AboutDlg; DialogBox (hInst, vszABOUT, hBox, lpprocAboutDlg); FreeProcInstance (lpprocAboutDlg); break; case FONT_LOAD: /* Check File Name */ case FONT_NEW : if (!CheckSave()) /* See if current font needs saving */ return; /* to prevent scrambling of Show window chars, Bring back Show ** window to parent window's client area before invoking the dialog */ if (CommDlgOpen(hBox,&ofstrFile,szNewFile,szExt,szFontFile,id) == FALSE) { InvalidateRect(hFont, (LPRECT)NULL, FALSE); UpdateWindow(hFont); return; } /* else drop thru */ case FONT_START: /* Here if file name passed as argument */ InvalidateRect(hFont, (LPRECT)NULL, FALSE); UpdateWindow(hFont); szError = FontLoad (szNewFile, &ofstrFile); /* Hack : needed to remove umwanted WM_MOUSEMOVE messages from the * queue. * Apparently, Windows needs to reposition the mouse after a dialog * is ended with a mouse double-click (releases mouse capture?) for * which a couple of WM_MOUSEMOVEs may get sent to parent app. * These mess with the edit box below the dialog if they happen to * overlap. */ PeekMessage((LPMSG) &message, hBox, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE); if (fLoaded) /* If loaded then do a few things */ { jChar = iChar = 65; /* Show an A */ if ((BYTE)iChar > (BYTE)font.LastChar) jChar = iChar = font.FirstChar; /* .. if we can */ swH = 15; /* Good bet to make A visible */ fEdited = fChanged = FALSE; ResizeShow(); /* Set Box to proper size */ ScrollFont(); /* Set thumb */ CharToBox(iChar); } FontRename(szError); SetFocus(hBox); return; case FONT_SAVE: if (!NewFile) { if (fLoaded && fChanged) { lstrcpy((LPSTR)szNewFile, (LPSTR)szFontFileFull); BoxToChar(iChar); /* Just in case */ szError = FontSave (szNewFile, &ofstrFile); FontRename(szError); /* Rename or Print Error */ return; } else return; } /* else file has been opened by selecting NEW... on menu. * Fall thro' and bring up SaveAs dialog minus default * filename in edit window */ case FONT_SAVEAS: BoxToChar(iChar); /* Just in case */ if (CommDlgSaveAs (hInst, hBox, &ofstrFile, szNewFile, szExt, szFontFile) == TRUE) { szError = FontSave (szNewFile, &ofstrFile); FontRename (szError); /* Rename or Print Error */ } /* to prevent scrambling of Show window chars, repaint show window after dialog is brought down */ InvalidateRect (hFont, (LPRECT)NULL, TRUE); UpdateWindow (hFont); return; case FONT_HEADER: /* to prevent scrambling of Show window chars, * repaint show window after dialog is invoked */ DialogBox(hInst, (LPSTR)vszDHeader, hBox, lpHeaderProc); InvalidateRect(hFont, (LPRECT)NULL, TRUE); UpdateWindow(hFont); return; case FONT_RESIZE: /* to prevent scrambling of Show window chars, repaint show window after dialog is brought down */ if (DialogBox(hInst, (LPSTR)vszDResize, hBox, lpReSizeProc)) { /* BoxToChar(iChar);*/ /* save current before resizing */ ResizeShow(); /* New Font Display Size */ CharToBox(iChar); /* New Box display */ } InvalidateRect(hFont, (LPRECT)NULL, TRUE); UpdateWindow(hFont); return; case FONT_COPY: /* Copy to Clipboard */ BoxToChar(iChar); /* Just in case */ ToClipboard(iChar, wBox, kBox); break; case FONT_PASTE: /* Paste in Character form Clipboard */ BoxBackup(); /* In case we change our minds */ ptA.x = ptA.y = 0; wBox = ClipboardToBox(ptA, wBox, kBox, TRUE); fRepaint = TRUE; break; case WIDER_LEFT: case WIDER_RIGHT: case WIDER_BOTH: case NARROWER_LEFT: case NARROWER_RIGHT: case NARROWER_BOTH: case WIDTH: w = newWidth = wBox; if (font.Family & 1) /* Variable width or else */ { switch (id) { case WIDER_BOTH: w++; case WIDER_LEFT: case WIDER_RIGHT: w++; break; case NARROWER_BOTH: w--; case NARROWER_LEFT: case NARROWER_RIGHT: w--; break; case WIDTH: if (DialogBox(hInst, (LPSTR)vszDWidth, hBox, lpWidthProc)) w = newWidth; break; } if (w < 0 || w >= wBoxLim) { MessageBox(hBox, (LPSTR)vszEdLimits0To64, (LPSTR)szAppName, MB_OK | MB_ICONASTERISK); break; /* Out of range! quit */ } if (w > (LONG) font.MaxWidth) { if (IDOK == MessageBox(hBox, (LPSTR)vszMaxWidthIncrease, (LPSTR)szAppName, MB_OKCANCEL | MB_ICONQUESTION)) font.MaxWidth = (WORD)w; else break; } BoxBackup(); /* In case we change our minds */ wBox = (WORD)w; /* Reset width */ fRepaint = TRUE; /* Signal redraw */ switch (id) { case WIDER_LEFT: #ifdef DBCS //DBCS_FIX DupCol(0, kBoxLim - 1); for (y = 0; y < kBoxLim; y++) matBox[0][y] = FALSE; /* Clear left column */ break; #endif case WIDER_BOTH: /* Shift character one right */ DupCol(0, kBoxLim - 1); for (y = 0; y < kBoxLim; y++) matBox[wBox -1][y] = FALSE; /* Clear right column */ for (y = 0; y < kBoxLim; y++) matBox[0][y] = FALSE; /* Clear left column */ break; case NARROWER_LEFT: case NARROWER_BOTH: /* Shift character one left */ if (wBox) { /* .. unless width is already 0 */ for (j = 0; j <= kBox - 1; j++) for (i = 0; i <= wBox - 1; i++) matBox[i][j] = matBox[i + 1][j]; break; } } } else { MessageBox(hBox, (LPSTR)vszCannotChangeWidth, (LPSTR)szAppName, MB_OK | MB_ICONASTERISK); } break; case ROW_ADD: case ROW_DEL: case COL_ADD: case COL_DEL: /* set cursor to "+" shaped cursor */ SetCapture (hBox); /* so that cursor doesn't get restored before we are done */ hOldCursor = SetCursor (LoadCursor (NULL, IDC_CROSS)); fCaptured = TRUE; cursor = id; break; case BOX_CLEAR: case BOX_FILL: case BOX_INV: case BOX_HATCH: case BOX_LEFTRIGHT: case BOX_TOPBOTTOM: case BOX_COPY: case BOX_PASTE: /* Get one o' da funky cursors */ SetCapture(hBox); hOldCursor = SetCursor(LoadCursor(hInst, MAKEINTRESOURCE(id))); fStartRubberBand = TRUE; CharRectDimensions((LPRECT)&FontRect); cursor = id; break; case BOX_REFRESH: /* Go get old version of character */ BoxBackup(); /* In case we change our minds */ CharToBox(iChar); hMenu = GetMenu(hBox); EnableMenuItem(hMenu, BOX_UNDO, MF_ENABLED); /* Can Unrefresh! */ break; case BOX_UNDO: BoxRestore(); hMenu = GetMenu(hBox); EnableMenuItem(hMenu, BOX_REFRESH, MF_ENABLED); fRepaint = TRUE; break; } if (fRepaint) { fEdited = fChanged = TRUE; InvalidateRect(hBox, (LPRECT)NULL, TRUE); } }
int mainCRTStartup(void) { handle_t server, client; unsigned i; params_vid_t params; font_t *font; vid = FsOpen(SYS_DEVICES L"/Classes/video0", FILE_READ | FILE_WRITE); if (vid == NULL) { _wdprintf(L"console: " SYS_DEVICES L"/Classes/video0: %s\n", _wcserror(errno)); return errno; } memset(&mode, 0, sizeof(mode)); params.vid_setmode = mode; if (!FsRequestSync(vid, VID_SETMODE, ¶ms, sizeof(params), NULL)) { _wdprintf(L"console: failed to set video mode: %s\n", _wcserror(errno)); HndClose(vid); return errno; } mode = params.vid_setmode; if (mode.flags & VIDEO_MODE_TEXT) { _wdprintf(L"console: text mode not supported\n"); return 0; } if (mode.bitsPerPixel == 4) { vidmem = NULL; if (!AccelCreateSurface(&mode, vid, &surf)) { _wdprintf(L"console: AccelCreateSurface failed\n"); return errno; } } else { handle_t handle_vidmem; handle_vidmem = HndOpen(mode.framebuffer); if (handle_vidmem == 0) { _wdprintf(L"console: unable to open framebuffer %s\n", mode.framebuffer); return errno; } vidmem = VmmMapSharedArea(handle_vidmem, 0, VM_MEM_USER | VM_MEM_READ | VM_MEM_WRITE); HndClose(handle_vidmem); if (!FramebufCreateSurface(&mode, vidmem, &surf)) { _wdprintf(L"console: video mode not supported: %u bits per pixel\n", mode.bitsPerPixel); return errno; } } FontInit(); font = FontLoad(font_name, 10 * 64, mode.bitsPerPixel < 8 ? FB_FONT_MONO : FB_FONT_SMOOTH); if (font == NULL) { _wdprintf(L"console: failed to load font %s\n", font_name); return errno; } cookies[0] = (void*) 0x12345678; num_buffers = 1; LmuxInit(&lmux_consoles); for (i = 0; i < _countof(consoles); i++) { LmuxInit(&consoles[i].lmux); consoles[i].width = consoles[i].height = 0; consoles[i].fg_colour = consoles[i].default_fg_colour = 0xc0c0c0; consoles[i].bg_colour = consoles[i].default_bg_colour = 0x000000; consoles[i].cookie = cookies[0]; consoles[i].buf_chars = NULL; consoles[i].font = font; FontGetMaxSize(consoles[i].font, &consoles[i].char_width, &consoles[i].char_height); } num_consoles = _countof(consoles); ConTileBuffer(0); num_consoles = 0; current = consoles; for (i = 0; i < _countof(consoles); i++) ConClear(consoles + i); server = FsCreate(server_name, 0); ThrCreateThread(ConKeyboardThread, NULL, 16, L"ConKeyboardThread"); ThrCreateThread(ConCursorThread, NULL, 16, L"ConCursorThread"); ConDisplaySignonMessage(); while ((client = PortAccept(server, FILE_READ | FILE_WRITE))) { if (num_consoles < _countof(consoles)) { consoles[num_consoles].client = client; ThrCreateThread(ConClientThread, consoles + num_consoles, 15, L"ConClientThread"); num_consoles++; } else HndClose(client); } for (i = 0; i < _countof(consoles); i++) { LmuxDelete(&consoles[i].lmux); free(consoles[i].buf_chars); } LmuxDelete(&lmux_consoles); FontDelete(font); HndClose(server); if (vidmem != NULL) VmmFree(vidmem); HndClose(vid); return EXIT_SUCCESS; }