// Lua: ucg.print( self, str ) static int lucg_print( lua_State *L ) { lucg_userdata_t *lud; if ((lud = get_lud( L )) == NULL) return 0; const char *s = luaL_checkstring( L, 2 ); if (s == NULL) return 0; while (*s) { ucg_int_t delta; delta = ucg_DrawGlyph(LUCG, lud->tx, lud->ty, lud->tdir, *(s++)); switch(lud->tdir) { case 0: lud->tx += delta; break; case 1: lud->ty += delta; break; case 2: lud->tx -= delta; break; default: case 3: lud->ty -= delta; break; } } return 0; }
ucg_int_t ucg_DrawString(ucg_t *ucg, ucg_int_t x, ucg_int_t y, uint8_t dir, const char *str) { ucg_int_t delta, sum; sum = 0; while( *str != '\0' ) { delta = ucg_DrawGlyph(ucg, x, y, dir, (uint8_t)*str); switch(dir) { case 0: x += delta; break; case 1: y += delta; break; case 2: x -= delta; break; case 3: y -= delta; break; } sum += delta; str++; } return sum; }
void set_clip_range(ucg_t *ucg) { prepare_picture(ucg); ucg_SetFontPosBaseline(ucg); ucg_SetFont(ucg, ucg_font_ncenB18_tf); ucg_SetColor(ucg, 0, 255, 255, 255); /* draw white A */ ucg_DrawGlyph(ucg, 50, 40, 0, 'A'); ucg_SetClipRange(ucg, 57, 20, 30, 15); /* restrict area */ ucg_SetColor(ucg, 0, 0, 0, 127); ucg_DrawBox(ucg, 0, 0, 128, 64); /* fill the restricted area with dark blue */ ucg_SetColor(ucg, 0, 0, 0, 255); ucg_DrawGlyph(ucg, 50, 40, 0, 'A'); /* draw light blue A */ hrule(ucg, ox+57, 20, 30, 0); vrule(ucg, ox+57+30, 20, 15, 1); pos(ucg, ox+50, 40, 0); save_picture(ucg, "set_clip_range"); }
// Lua: width = ucg.drawGlyph( self, x, y, dir, encoding ) static int lucg_drawGlyph( lua_State *L ) { lucg_userdata_t *lud; if ((lud = get_lud( L )) == NULL) return 0; ucg_int_t args[3]; lucg_get_int_args( L, 2, 3, args ); const char *c = luaL_checkstring( L, (1+3) + 1 ); if (c == NULL) return 0; lua_pushinteger( L, ucg_DrawGlyph( LUCG, args[0], args[1], args[2], *c ) ); return 1; }
int main(void) { ucg_int_t a,b; ucg_Init(&ucg, ucg_sdl_dev_cb, ucg_ext_none, (ucg_com_fnptr)0); ucg_SetFontMode(&ucg, UCG_FONT_MODE_TRANSPARENT); ucg_SetFont(&ucg, ucg_font_ncenB24); //ucg_SetRotate90(&ucg); //ucg_SetRotate270(&ucg); //ucg_SetClipRange(&ucg, 10,5,40,20); a = 2; b = 3; ucg_SetColor(&ucg, 0, 135*a/b,206*a/b,250*a/b); ucg_SetColor(&ucg, 1, 176*a/b,226*a/b,255*a/b); ucg_SetColor(&ucg, 2, 25*a/b,25*a/b,112*a/b); ucg_SetColor(&ucg, 3, 85*a/b,26*a/b,139*a/b); ucg_DrawGradientBox(&ucg, 0, 0, ucg_GetWidth(&ucg)/4, ucg_GetHeight(&ucg)); ucg_SetColor(&ucg, 1, 135*a/b,206*a/b,250*a/b); ucg_SetColor(&ucg, 0, 176*a/b,226*a/b,255*a/b); ucg_SetColor(&ucg, 3, 25*a/b,25*a/b,112*a/b); ucg_SetColor(&ucg, 2, 85*a/b,26*a/b,139*a/b); ucg_DrawGradientBox(&ucg, ucg_GetWidth(&ucg)/4, 0, ucg_GetWidth(&ucg)/4, ucg_GetHeight(&ucg)); ucg_SetColor(&ucg, 0, 135*a/b,206*a/b,250*a/b); ucg_SetColor(&ucg, 1, 176*a/b,226*a/b,255*a/b); ucg_SetColor(&ucg, 2, 25*a/b,25*a/b,112*a/b); ucg_SetColor(&ucg, 3, 85*a/b,26*a/b,139*a/b); ucg_DrawGradientBox(&ucg, ucg_GetWidth(&ucg)*2/4, 0, ucg_GetWidth(&ucg)/4, ucg_GetHeight(&ucg)); ucg_SetColor(&ucg, 1, 135*a/b,206*a/b,250*a/b); ucg_SetColor(&ucg, 0, 176*a/b,226*a/b,255*a/b); ucg_SetColor(&ucg, 3, 25*a/b,25*a/b,112*a/b); ucg_SetColor(&ucg, 2, 85*a/b,26*a/b,139*a/b); ucg_DrawGradientBox(&ucg, ucg_GetWidth(&ucg)*3/4, 0, ucg_GetWidth(&ucg)/4, ucg_GetHeight(&ucg)); upper_pin(&ucg, 7+0*14, 4); upper_pin(&ucg, 7+1*14, 4); upper_pin(&ucg, 7+2*14, 4); upper_pin(&ucg, 7+3*14, 4); ic_body(&ucg, 2, 10); lower_pin(&ucg, 7+0*14, 41); lower_pin(&ucg, 7+1*14, 41); lower_pin(&ucg, 7+2*14, 41); lower_pin(&ucg, 7+3*14, 41); ucg_SetColor(&ucg, 0, 135*a/b, 206*a/b, 250*a/b); ucg_DrawString(&ucg, 63+1, 33+1, 0, "glib"); ucg_SetColor(&ucg, 0, 255, 168, 0); ucg_DrawGlyph(&ucg, 26, 38, 0, 'U'); ucg_DrawString(&ucg, 63, 33, 0, "glib"); ucg_SetColor(&ucg, 0, 135*a/b, 206*a/b, 250*a/b); ucg_SetColor(&ucg, 1, 135*a/b, 206*a/b, 250*a/b); ucg_SetColor(&ucg, 2, 135*a/b, 206*a/b, 250*a/b); ucg_SetColor(&ucg, 3, 135*a/b, 206*a/b, 250*a/b); ucg_DrawGradientBox(&ucg, 84+1, 42+1-6, 42, 4); ucg_SetColor(&ucg, 0, 255, 180, 40); ucg_SetColor(&ucg, 1, 235, 148, 0); //ucg_DrawGradientLine(&ucg, 79, 42, 20, 0); ucg_SetColor(&ucg, 2, 245, 158, 0); ucg_SetColor(&ucg, 3, 220, 138, 0); ucg_DrawGradientBox(&ucg, 84, 42-6, 42, 4); ucg_SetColor(&ucg, 0, 255, 168, 0); ucg_SetFont(&ucg, ucg_font_5x8); //ucg_SetFont(&ucg, ucg_font_courB08); ucg_DrawString(&ucg, 2, 54, 0, "http://"); ucg_DrawString(&ucg, 1, 61, 0, "code.google.com/p/ucglib/"); while( ucg_sdl_get_key() < 0 ) ; return 0; }