Example #1
0
static void GmgrCleanup(void)
{
    FontDelete(gmgr_font);
    gmgr_font = NULL;
    LmuxDelete(&gmgr_draw);
    LmuxDelete(&gmgr_mux_gfxs);
    GmgrCloseSurface(gmgr_screen);
    gmgr_screen = NULL;
}
Example #2
0
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(&params.vid_setmode, 0, sizeof(params.vid_setmode));
    if (!FsRequestSync(device, VID_SETMODE, &params, sizeof(params), NULL))
    {
        _wdprintf(L"VID_SETMODE: %s\n", _wcserror(errno));
        goto error1;
    }

    gmgr_screen = GmgrCreateDeviceSurface(device, &params.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;
}
Example #3
0
void GmgrDrawText(gfx_h hgfx, const rect_t *rect, const wchar_t *str, size_t length)
{
    point_t size;
    videomode_t mode;
    gmgr_surface_t *surface;
    gfx_t *gfx;
    rect_t clip;
    int ax1, ay1, ax2, ay2;
    unsigned i;

    gfx = GmgrLockGraphics(hgfx);
    if (gfx == NULL)
        return;

    FontGetTextSize(gmgr_font, str, length, &size);
    if (size.x < rect->right - rect->left)
        size.x = rect->right - rect->left;
    if (size.y < rect->bottom - rect->top)
        size.y = rect->bottom - rect->top;

    mode = gmgr_screen->mode;
    mode.width = size.x;
    mode.height = size.y;
    mode.bytesPerLine = (mode.bitsPerPixel * size.x) / 8;
    surface = GmgrCreateMemorySurface(&mode, GMGR_SURFACE_SHARED);
    if (surface == NULL)
    {
        GmgrUnlockGraphics(gfx);
        return;
    }

    FontDrawText(gmgr_font, &surface->surf, 0, 0, str, length, 
        gfx->colour_pen, gfx->colour_fill);

    for (i = 0; i < gfx->clip.num_rects; i++)
    {
        clip = gfx->clip.rects[i];
        ay1 = max(rect->top, clip.top);
        ay2 = min(rect->bottom, clip.bottom);

        if (ay2 > ay1)
        {
            ax1 = max(clip.left, rect->left);
            ax2 = min(clip.right, rect->right);

            if (ax2 > ax1)
            {
                rect_t dest;
                int src_x, src_y;

                dest.left = ax1;
                dest.top = ay1;
                dest.right = ax2;
                dest.bottom = ay2;
                src_x = dest.left - rect->left;
                src_y = dest.top - rect->top;

                gfx->surface->surf.vtbl->SurfBltMemoryToScreen(&gfx->surface->surf,
                    &dest,
                    (uint8_t*) surface->base 
                        + src_y * surface->mode.bytesPerLine
                        + (src_x * surface->mode.bitsPerPixel) / 8,
                    surface->mode.bytesPerLine);
            }
        }
    }

    GmgrCloseSurface(surface);
    GmgrUnlockGraphics(gfx);
}