static void background_init( Background* back, SkinBackground* sback, SkinLocation* loc, SkinRect* frame ) { SkinRect r; back->image = skin_image_rotate( sback->image, loc->rotation ); skin_rect_rotate( &r, &sback->rect, loc->rotation ); r.pos.x += loc->anchor.x; r.pos.y += loc->anchor.y; back->origin = r.pos; skin_rect_intersect( &back->rect, &r, frame ); }
static int display_init( ADisplay* disp, SkinDisplay* sdisp, SkinLocation* loc, SkinRect* frame ) { skin_rect_rotate( &disp->rect, &sdisp->rect, loc->rotation ); disp->rect.pos.x += loc->anchor.x; disp->rect.pos.y += loc->anchor.y; disp->rotation = (loc->rotation + sdisp->rotation) & 3; switch (disp->rotation) { case SKIN_ROTATION_0: disp->origin = disp->rect.pos; break; case SKIN_ROTATION_90: disp->origin.x = disp->rect.pos.x + disp->rect.size.w; disp->origin.y = disp->rect.pos.y; break; case SKIN_ROTATION_180: disp->origin.x = disp->rect.pos.x + disp->rect.size.w; disp->origin.y = disp->rect.pos.y + disp->rect.size.h; break; default: disp->origin.x = disp->rect.pos.x; disp->origin.y = disp->rect.pos.y + disp->rect.size.h; break; } skin_size_rotate( &disp->datasize, &sdisp->rect.size, sdisp->rotation ); skin_rect_intersect( &disp->rect, &disp->rect, frame ); #if 0 fprintf(stderr, "... display_init rect.pos(%d,%d) rect.size(%d,%d) datasize(%d,%d)\n", disp->rect.pos.x, disp->rect.pos.y, disp->rect.size.w, disp->rect.size.h, disp->datasize.w, disp->datasize.h); #endif disp->qfbuff = sdisp->qfbuff; disp->data = sdisp->qfbuff->pixels; disp->onion = NULL; disp->brightness = LCD_BRIGHTNESS_DEFAULT; return (disp->data == NULL) ? -1 : 0; }
static void background_redraw( Background* back, SkinRect* rect, SDL_Surface* surface ) { SkinRect r; if (skin_rect_intersect( &r, rect, &back->rect ) ) { SDL_Rect rd, rs; rd.x = r.pos.x; rd.y = r.pos.y; rd.w = r.size.w; rd.h = r.size.h; rs.x = r.pos.x - back->origin.x; rs.y = r.pos.y - back->origin.y; rs.w = r.size.w; rs.h = r.size.h; SDL_BlitSurface( skin_image_surface(back->image), &rs, surface, &rd ); } }
SkinOverlap skin_region_test_intersect( SkinRegion* r1, SkinRegion* r2 ) { Run *runs1, *runs2; Run run2_tmp[ RUNS_RECT_COUNT ]; SkinRect r; if (region_isEmpty(r1) || region_isEmpty(r2)) return SKIN_OUTSIDE; if ( !skin_rect_intersect( &r, &r1->bounds, &r2->bounds) ) return SKIN_OUTSIDE; if (region_isRect(r1)) { if (region_isRect(r2)) { return skin_rect_contains_rect(&r1->bounds, &r2->bounds); } else { SkinRegion* tmp = r1; r1 = r2; r2 = tmp; } } /* here r1 is guaranteed to be complex, r2 is either rect of complex */ runs1 = r1->runs; if (region_isRect(r2)) { runs2 = run2_tmp; runs_set_rect(runs2, &r2->bounds); } else { runs2 = r2->runs; } { int flags = 0; while (runs1[0] != YSENTINEL && runs2[0] != YSENTINEL) { int ytop1 = runs1[0]; int ybot1 = runs1[1]; int ytop2 = runs2[0]; int ybot2 = runs2[1]; if (ybot1 <= ytop2) { /* band1 over band2 */ flags |= FLAG_REGION_1; runs1 = runs_next_scanline( runs1 ); } else if (ybot2 <= ytop1) { /* band2 over band1 */ flags |= FLAG_REGION_2; runs2 = runs_next_scanline( runs2 ); } else /* band1 and band2 overlap */ { Run* span1; Run* span2; int ybot; if (ytop1 < ytop2) { flags |= FLAG_REGION_1; ytop1 = ytop2; } else if (ytop2 < ytop1) { flags |= FLAG_REGION_2; ytop2 = ytop1; } ybot = (ybot1 < ybot2) ? ybot1 : ybot2; span1 = runs1 + 2; span2 = runs2 + 2; while (span1[0] != XSENTINEL && span2[0] != XSENTINEL) { int xleft1 = span1[0]; int xright1 = span1[1]; int xleft2 = span2[0]; int xright2 = span2[1]; RASSERT(xright1 != XSENTINEL); RASSERT(xright2 != XSENTINEL); if (xright1 <= xleft2) { flags |= FLAG_REGION_1; span1 += 2; } else if (xright2 <= xleft1) { flags |= FLAG_REGION_2; span2 += 2; } else { int xright; if (xleft1 < xleft2) { flags |= FLAG_REGION_1; xleft1 = xleft2; } else if (xleft2 < xleft1) { flags |= FLAG_REGION_2; xleft2 = xleft1; } xright = (xright1 < xright2) ? xright1 : xright2; flags |= FLAG_REGION_BOTH; if (xright == xright1) span1 += 2; if (xright == xright2) span2 += 2; } } if (span1[0] != XSENTINEL) { flags |= FLAG_REGION_1; } if (span2[0] != XSENTINEL) { flags |= FLAG_REGION_2; } if (ybot == ybot1) runs1 = runs_next_scanline( runs1 ); if (ybot == ybot2) runs2 = runs_next_scanline( runs2 ); } } if (runs1[0] != YSENTINEL) { flags |= FLAG_REGION_1; } if (runs2[0] != YSENTINEL) { flags |= FLAG_REGION_2; } if ( !(flags & FLAG_REGION_BOTH) ) { /* no intersection at all */ return SKIN_OUTSIDE; } if ( (flags & FLAG_REGION_2) != 0 ) { /* intersection + overlap */ return SKIN_OVERLAP; } return SKIN_INSIDE; } }