Beispiel #1
0
Layer * Layer_testdraw(Layer * self, SDL_Surface * target, int camera_x, int camera_y, int view_w, int view_h) {
    int tx;
    int ty;
    int xx;
    int yy;
    int tilehigh = self->tile_h;
    int tilewide = self->tile_w;
    Element     tile= Qnil;
    SDL_Surface *aid= NULL;
    tile            = self->tiles[0][0];
    if (tile == Qnil) { return NULL; }
    aid             = Element_surface(tile);
    if (!aid) { return NULL; }
    xx         = -32 ;
    yy         = -32 ;
    for (ty = 0 ; ty < 3 ; ty ++) {  
     yy   += tilehigh;
     for (tx = 0 ; tx < 3 ; tx ++) { 
        xx += tilewide;
        printf("draw %p:  (%hd,%hd) %hdx%hd %p\n", aid, xx, yy, aid->w, aid->h, aid->pixels); 
        surface_blit(aid, target, xx, yy);
      }
      xx    = -32;
    }
  return self;
} 
Beispiel #2
0
Layer * Layer_draw(Layer * self, SDL_Surface * target, int camera_x, int camera_y, int view_w, int view_h) {
    Sint16 tilewide   = self->tile_w;
    Sint16 tilehigh   = self->tile_h;
    Sint16 camx       = camera_x;
    Sint16 camy       = camera_y;
    Sint16 txstart    = (camx / self->tile_w);
    Sint16 tystart    = (camy / self->tile_h);
    Sint16 xtilestop  = (view_w   / self->tile_w) + 1;
    Sint16 ytilestop  = (view_h   / self->tile_h) + 1;
    Sint16 txstop     = xtilestop + txstart;
    Sint16 tystop     = ytilestop + tystart;
    Sint16 drawx      = 0;
    Sint16 drawy      = 0;
    Sint16 tydex      = 0;
    Sint16 txdex      = 0;
    SDL_Rect   drect  = {0,0,0,0};
    SDL_Rect   srect= { 0, 0, 32, 32}; 
    Element     *row= NULL;
    Element     tile= Qnil;
    SDL_Surface *aid= NULL;
    srect.w         = tilewide;
    srect.h         = tilehigh;
        
    if (txstart >= self->w || tystart >= self->h) { return self; }
    if (txstart < 0) { txstart = 0; }
    if (tystart < 0) { tystart = 0; }
    if (txstop > self->w) { txstop = self->w ; }
    if (tystop > self->h) { tystop = self->h ; }
    /* drect.w = tilewide;
    drect.h = tilehigh; */
    drawy   = -camy + ( (tystart-1) * tilehigh );
    tydex   = tystart;
    /*printf("tx: %d -> %d by %d ty: %d -> %d by %d (drawy: %d) view %d x %d \n", txstart, txstop, tilewide, tystart, tystop, tilehigh, drawy, view_w, view_h); 
    */   
    while (tydex < tystop) { 
      drawy   += tilehigh;
      drawx   =  -camx + ( (txstart-1) * tilewide );
      row     = self->tiles[tydex];
      txdex   = txstart;
      while (txdex < txstop) { 
        drawx   += tilewide; 
        tile     = self->tiles[tydex][txdex];
        if (tile != Qnil) {
          aid      = Element_surface(tile);
          if (aid) { 
            int res;
            /* drawy; */
            /* printf("draw %p -> %p tx: %hd@%hd , ty: %hd@%hd\n", aid, target, txdex, drawx, tydex, drawy); */
            res = surface_blit(aid, target, drawx, drawy);
            /* res = SDL_BlitSurface(aid, NULL, target, &drect); */
            /* printf("blit result: %d ", res);
            printf("blit area:  (%hd,%hu)  %hu x %hu\n", drect.x, drect.y, drect.w, drect.h);*/
          }
        }        
        txdex += 1;
      }
      tydex  += 1;
    }
  return self;
} 
Beispiel #3
0
bool_t fb_blit(struct fb * fb, struct surface_t * surface, u32_t x, u32_t y, u32_t w, u32_t h, u32_t ox, u32_t oy)
{
	struct rect_t dst_rect, src_rect;

	dst_rect.x = x;
	dst_rect.y = y;
	dst_rect.w = w;
	dst_rect.h = h;

	src_rect.x = ox;
	src_rect.y = oy;
	src_rect.w = w;
	src_rect.h = h;

	surface_set_clip_rect(&(fb->info->surface), NULL);
	return surface_blit(&(fb->info->surface), &dst_rect, surface, &src_rect, BLEND_MODE_REPLACE);
}
Beispiel #4
0
int
main(int argc, char *argv[])
{
    long dt;
    long started;
    XWindow xw;
    struct demo_gui gui;

    /* Platform */
    UNUSED(argc); UNUSED(argv);
    memset(&xw, 0, sizeof xw);
    xw.dpy = XOpenDisplay(NULL);
    xw.root = DefaultRootWindow(xw.dpy);
    xw.screen = XDefaultScreen(xw.dpy);
    xw.vis = XDefaultVisual(xw.dpy, xw.screen);
    xw.cmap = XCreateColormap(xw.dpy,xw.root,xw.vis,AllocNone);
    xw.swa.colormap = xw.cmap;
    xw.swa.event_mask =
        ExposureMask | KeyPressMask | KeyReleaseMask |
        ButtonPress | ButtonReleaseMask| ButtonMotionMask |
        Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask|
        PointerMotionMask;
    xw.win = XCreateWindow(xw.dpy, xw.root, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0,
        XDefaultDepth(xw.dpy, xw.screen), InputOutput,
        xw.vis, CWEventMask | CWColormap, &xw.swa);
    XStoreName(xw.dpy, xw.win, "X11");
    XMapWindow(xw.dpy, xw.win);
    XGetWindowAttributes(xw.dpy, xw.win, &xw.attr);
    xw.width = (unsigned int)xw.attr.width;
    xw.height = (unsigned int)xw.attr.height;
    xw.surf = surface_create(xw.dpy, xw.screen, xw.win, xw.width, xw.height);
    xw.font = font_create(xw.dpy, "fixed");

    /* GUI */
    memset(&gui, 0, sizeof gui);
    zr_command_queue_init_fixed(&gui.queue, calloc(MAX_MEMORY, 1), MAX_MEMORY);
    gui.font.userdata = zr_handle_ptr(xw.font);
    gui.font.height = (zr_float)xw.font->height;
    gui.font.width = font_get_text_width;
    init_demo(&gui);

    while (gui.running) {
        /* Input */
        XEvent evt;
        started = timestamp();
        zr_input_begin(&gui.input);
        while (XCheckWindowEvent(xw.dpy, xw.win, xw.swa.event_mask, &evt)) {
            if (evt.type == KeyPress)
                key(&xw, &gui.input, &evt, zr_true);
            else if (evt.type == KeyRelease) key(&xw, &gui.input, &evt, zr_false);
            else if (evt.type == ButtonPress) btn(&gui.input, &evt, zr_true);
            else if (evt.type == ButtonRelease) btn(&gui.input, &evt, zr_false);
            else if (evt.type == MotionNotify) motion(&gui.input, &evt);
            else if (evt.type == Expose || evt.type == ConfigureNotify)
                resize(&xw, xw.surf);
        }
        zr_input_end(&gui.input);

        /* GUI */
        run_demo(&gui);

        /* Draw */
        XClearWindow(xw.dpy, xw.win);
        surface_clear(xw.surf, 0x00646464);
        draw(xw.surf, &gui.queue);
        surface_blit(xw.win, xw.surf, xw.width, xw.height);
        XFlush(xw.dpy);

        /* Timing */
        dt = timestamp() - started;
        if (dt < DTIME)
            sleep_for(DTIME - dt);
    }

    free(zr_buffer_memory(&gui.queue.buffer));
    font_del(xw.dpy, xw.font);
    surface_del(xw.surf);
    XUnmapWindow(xw.dpy, xw.win);
    XFreeColormap(xw.dpy, xw.cmap);
    XDestroyWindow(xw.dpy, xw.win);
    XCloseDisplay(xw.dpy);
    return 0;
}