void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color) { int i; int l; l = strlen16(s); for (i=0; (i<l); i++) { gdImageChar(im, f, x, y, s[i], color); x += f->w; } }
void Gd::drawChar(int x, int y, char ch, int color, FontStyle style) { gdFontPtr font = style == FontTiny ? gdFontGetTiny() : style == FontSmall ? gdFontGetSmall() : style == FontMedium ? gdFontGetMediumBold() : style == FontLarge ? gdFontGetLarge() : style == FontGiant ? gdFontGetGiant() : gdFontGetMediumBold(); gdImageChar(_imagePtr, font, x, y, ch, color); }
void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color) /* void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, char *s, int color) this avoids gcc4 warning */ { int i; int l; l = strlen(s); for (i=0; (i<l); i++) { gdImageChar(im, f, x, y, s[i], color); x += f->w; } }
void gdDrawImage(HDC hdc, RECT *rc) { HDC mem_dc; BITMAPINFO bmp_info; void* bits; HBITMAP bmp, temp; gdImagePtr im; int width, height, stride; int white, black, blue, red; char *s = "Hello world!"; gdFontPtr lfont, gfont; width = rc->right - rc->left; height = rc->bottom - rc->top; bmp_info = gdCreateBmp(width, height); // Create memory device context mem_dc = CreateCompatibleDC(hdc); if (!mem_dc) { MessageBox(NULL, "Can't create a compatible DC!", "Error!", MB_ICONEXCLAMATION | MB_OK); return; } // bits points to a shared buffer of pixels bits = NULL; bmp = CreateDIBSection(mem_dc, &bmp_info, DIB_RGB_COLORS, (void**)&bits, 0, 0); // Selecting the object before doing anything allows you to use libgd // together with native Windows GDI. temp = (HBITMAP)SelectObject(mem_dc, bmp); /*stride = ((width * 1 + 3) >> 2) << 2;*/ // always uses 32bit in BMPINFO stride = width; im = NULL; // Attach shared buffer of pixels to GD image // Negative stride places 0,0 in upper-left corner im = gdImageTrueColorAttachBuffer((int*)bits, width, height, -stride); if (!im) { MessageBox(NULL, "GD image creation failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return; } // Start of GD drawing white = gdImageColorAllocate(im, 255, 255, 255); black = gdImageColorAllocate(im, 0, 0, 0); blue = gdImageColorAllocate(im, 0, 0, 255); // Allocate the color red, 50% transparent. red = gdImageColorAllocateAlpha(im, 255, 0, 0, 64); // Erase background with white color gdImageFilledRectangle(im, 0, 0, width, height, 0xFF0000); lfont = gdFontGetLarge(); gfont = gdFontGetGiant(); // Draw a dashed line from the upper left corner to the lower right corner. gdImageFilledRectangle(im, 25, 25, 100, 100, blue); gdImageChar(im, gfont, 35, 35, 'Q', white); gdImageFilledRectangle(im, 50, 50, 75, 175, red); gdImageLine(im, 0, 0, 150, 150, black); gdImageString(im, gdFontGetLarge(), im->sx / 2 - (strlen(s) * lfont->w / 2), im->sy / 2 - lfont->h / 2, (unsigned char*)s, black); // Copy drawing from memory context (shared bitmap buffer) to screen DC. BitBlt(hdc, rc->left, rc->top, width, height, mem_dc, 0, 0, SRCCOPY); // Free gdImageDetachBuffer(im); SelectObject(mem_dc, temp); DeleteObject(bmp); DeleteObject(mem_dc); }
void JBDungeonPainterGD::m_char( int x, int y, char c, long color, void* font ) { gdImageChar( m_image, (gdFontPtr)font, x, y, c, color ); }