diff options
Diffstat (limited to 'src/ui/listwidget.c')
-rw-r--r-- | src/ui/listwidget.c | 51 |
1 files changed, 5 insertions, 46 deletions
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c index b10bf8c3..fb328c2f 100644 --- a/src/ui/listwidget.c +++ b/src/ui/listwidget.c | |||
@@ -302,31 +302,6 @@ static iBool processEvent_ListWidget_(iListWidget *d, const SDL_Event *ev) { | |||
302 | return processEvent_Widget(w, ev); | 302 | return processEvent_Widget(w, ev); |
303 | } | 303 | } |
304 | 304 | ||
305 | #if 0 | ||
306 | static void allocVisBuffer_ListWidget_(iListWidget *d) { | ||
307 | /* Make sure two buffers cover the entire visible area. */ | ||
308 | // const iRect inner = innerBounds_Widget(as_Widget(d)); | ||
309 | const iInt2 size = init_I2(inner.size.x, (inner.size.y / 2 / d->itemHeight + 1) * d->itemHeight); | ||
310 | if (!d->visBuffers[0].texture || !isEqual_I2(size, d->visBufSize)) { | ||
311 | d->visBufSize = size; | ||
312 | iForIndices(i, d->visBuffers) { | ||
313 | if (d->visBuffers[i].texture) { | ||
314 | SDL_DestroyTexture(d->visBuffers[i].texture); | ||
315 | } | ||
316 | d->visBuffers[i].texture = | ||
317 | SDL_CreateTexture(renderer_Window(get_Window()), | ||
318 | SDL_PIXELFORMAT_RGBA8888, | ||
319 | SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, | ||
320 | size.x, | ||
321 | size.y); | ||
322 | SDL_SetTextureBlendMode(d->visBuffers[i].texture, SDL_BLENDMODE_NONE); | ||
323 | d->visBuffers[i].origin = i * size.y; | ||
324 | iZap(d->visBuffers[i].validRange); | ||
325 | } | ||
326 | } | ||
327 | } | ||
328 | #endif | ||
329 | |||
330 | static void drawItem_ListWidget_(const iListWidget *d, iPaint *p, size_t index, iInt2 pos) { | 305 | static void drawItem_ListWidget_(const iListWidget *d, iPaint *p, size_t index, iInt2 pos) { |
331 | const iWidget * w = constAs_Widget(d); | 306 | const iWidget * w = constAs_Widget(d); |
332 | const iRect bounds = innerBounds_Widget(w); | 307 | const iRect bounds = innerBounds_Widget(w); |
@@ -340,15 +315,14 @@ static const iListItem *item_ListWidget_(const iListWidget *d, size_t pos) { | |||
340 | } | 315 | } |
341 | 316 | ||
342 | static void draw_ListWidget_(const iListWidget *d) { | 317 | static void draw_ListWidget_(const iListWidget *d) { |
343 | const iWidget *w = constAs_Widget(d); | 318 | const iWidget *w = constAs_Widget(d); |
344 | const iRect bounds = innerBounds_Widget(w); | 319 | const iRect bounds = innerBounds_Widget(w); |
345 | if (!bounds.size.y || !bounds.size.x || !d->itemHeight) { | 320 | if (!bounds.size.y || !bounds.size.x || !d->itemHeight) { |
346 | return; | 321 | return; |
347 | } | 322 | } |
348 | iPaint p; | 323 | iPaint p; |
349 | init_Paint(&p); | 324 | init_Paint(&p); |
350 | drawBackground_Widget(w); | 325 | drawBackground_Widget(w); |
351 | // iListWidget *m = iConstCast(iListWidget *, d); | ||
352 | alloc_VisBuf(d->visBuf, bounds.size, d->itemHeight); | 326 | alloc_VisBuf(d->visBuf, bounds.size, d->itemHeight); |
353 | /* Update invalid regions/items. */ { | 327 | /* Update invalid regions/items. */ { |
354 | /* TODO: This seems to draw two items per each shift of the visible region, even though | 328 | /* TODO: This seems to draw two items per each shift of the visible region, even though |
@@ -362,19 +336,15 @@ static void draw_ListWidget_(const iListWidget *d) { | |||
362 | const int bottom = numItems_ListWidget(d) * d->itemHeight; | 336 | const int bottom = numItems_ListWidget(d) * d->itemHeight; |
363 | const iRangei vis = { d->scrollY / d->itemHeight * d->itemHeight, | 337 | const iRangei vis = { d->scrollY / d->itemHeight * d->itemHeight, |
364 | ((d->scrollY + bounds.size.y) / d->itemHeight + 1) * d->itemHeight }; | 338 | ((d->scrollY + bounds.size.y) / d->itemHeight + 1) * d->itemHeight }; |
365 | // printf("visBufSize.y = %d\n", d->visBufSize.y); | ||
366 | reposition_VisBuf(d->visBuf, vis); | 339 | reposition_VisBuf(d->visBuf, vis); |
367 | /* Check which parts are invalid. */ | 340 | /* Check which parts are invalid. */ |
368 | iRangei invalidRange[3]; | 341 | iRangei invalidRange[3]; |
369 | invalidRanges_VisBuf(d->visBuf, (iRangei){ 0, bottom }, invalidRange); | 342 | invalidRanges_VisBuf(d->visBuf, (iRangei){ 0, bottom }, invalidRange); |
370 | iForIndices(i, d->visBuf->buffers) { | 343 | iForIndices(i, d->visBuf->buffers) { |
371 | iVisBufTexture *buf = &d->visBuf->buffers[i]; | 344 | iVisBufTexture *buf = &d->visBuf->buffers[i]; |
372 | // printf("%zu: orig %d, invalid %d ... %d\n", i, buf->origin, invalidRange[i].start, invalidRange[i].end); | ||
373 | iRanges drawItems = { iMax(0, buf->origin) / d->itemHeight, | 345 | iRanges drawItems = { iMax(0, buf->origin) / d->itemHeight, |
374 | iMax(0, buf->origin + d->visBuf->texSize.y) / d->itemHeight }; | 346 | iMax(0, buf->origin + d->visBuf->texSize.y) / d->itemHeight }; |
375 | iBool isTargetSet = iFalse; | ||
376 | if (isEmpty_Rangei(buf->validRange)) { | 347 | if (isEmpty_Rangei(buf->validRange)) { |
377 | isTargetSet = iTrue; | ||
378 | beginTarget_Paint(&p, buf->texture); | 348 | beginTarget_Paint(&p, buf->texture); |
379 | fillRect_Paint(&p, (iRect){ zero_I2(), d->visBuf->texSize }, bg[i]); | 349 | fillRect_Paint(&p, (iRect){ zero_I2(), d->visBuf->texSize }, bg[i]); |
380 | } | 350 | } |
@@ -384,21 +354,14 @@ static void draw_ListWidget_(const iListWidget *d) { | |||
384 | const iListItem *item = constAt_PtrArray(&d->items, index); | 354 | const iListItem *item = constAt_PtrArray(&d->items, index); |
385 | const iRect itemRect = { init_I2(0, index * d->itemHeight - buf->origin), | 355 | const iRect itemRect = { init_I2(0, index * d->itemHeight - buf->origin), |
386 | init_I2(d->visBuf->texSize.x, d->itemHeight) }; | 356 | init_I2(d->visBuf->texSize.x, d->itemHeight) }; |
387 | if (!isTargetSet) { | 357 | beginTarget_Paint(&p, buf->texture); |
388 | beginTarget_Paint(&p, buf->texture); | ||
389 | isTargetSet = iTrue; | ||
390 | } | ||
391 | fillRect_Paint(&p, itemRect, bg[i]); | 358 | fillRect_Paint(&p, itemRect, bg[i]); |
392 | class_ListItem(item)->draw(item, &p, itemRect, d); | 359 | class_ListItem(item)->draw(item, &p, itemRect, d); |
393 | // printf("- drawing invalid item %zu\n", index); | ||
394 | } | 360 | } |
395 | } | 361 | } |
396 | /* Visible range is not fully covered. Fill in the new items. */ | 362 | /* Visible range is not fully covered. Fill in the new items. */ |
397 | if (!isEmpty_Rangei(invalidRange[i])) { | 363 | if (!isEmpty_Rangei(invalidRange[i])) { |
398 | if (!isTargetSet) { | 364 | beginTarget_Paint(&p, buf->texture); |
399 | beginTarget_Paint(&p, buf->texture); | ||
400 | isTargetSet = iTrue; | ||
401 | } | ||
402 | drawItems.start = invalidRange[i].start / d->itemHeight; | 365 | drawItems.start = invalidRange[i].start / d->itemHeight; |
403 | drawItems.end = invalidRange[i].end / d->itemHeight + 1; | 366 | drawItems.end = invalidRange[i].end / d->itemHeight + 1; |
404 | for (size_t j = drawItems.start; j < drawItems.end && j < size_PtrArray(&d->items); j++) { | 367 | for (size_t j = drawItems.start; j < drawItems.end && j < size_PtrArray(&d->items); j++) { |
@@ -407,13 +370,9 @@ static void draw_ListWidget_(const iListWidget *d) { | |||
407 | init_I2(d->visBuf->texSize.x, d->itemHeight) }; | 370 | init_I2(d->visBuf->texSize.x, d->itemHeight) }; |
408 | fillRect_Paint(&p, itemRect, bg[i]); | 371 | fillRect_Paint(&p, itemRect, bg[i]); |
409 | class_ListItem(item)->draw(item, &p, itemRect, d); | 372 | class_ListItem(item)->draw(item, &p, itemRect, d); |
410 | // printf("- drawing item %zu\n", j); | ||
411 | } | 373 | } |
412 | } | 374 | } |
413 | if (isTargetSet) { | 375 | endTarget_Paint(&p); |
414 | endTarget_Paint(&p); | ||
415 | } | ||
416 | // fflush(stdout); | ||
417 | } | 376 | } |
418 | validate_VisBuf(d->visBuf); | 377 | validate_VisBuf(d->visBuf); |
419 | clear_IntSet(&iConstCast(iListWidget *, d)->invalidItems); | 378 | clear_IntSet(&iConstCast(iListWidget *, d)->invalidItems); |