//----------------------------------------------------------------------------
// This is the guts of the FormPaint procedure.
//
// It calculates and optionally draws the visible thumbnail images in their
// proper positions.
//
// Various class variables are updated:
// f_index_of_current_image
// f_index_of_image_on_right
// f_index_of_image_on_left
//
// f_image_regions
//
procedure tMainForm.PaintThumbnails( isPaint: boolean );
var
percent: extended;
offset: extended;
image_index: integer;
image_offset: extended;
x, xc, w, h, i: integer; // x, x center, width, height, index
dest: tBitmap32;
cri: integer; // click region index
//..........................................................................
procedure inner_loop_paint;
begin
with f_image_list[ i ] do
if offset < 0.300001
then begin
if tinymap = nil then begin
tinymap := tBitmap32.create;
tinymap.setSize( w, h );
StretchTransfer(
tinymap,
tinymap.clipRect,
tinymap.clipRect,
bitmap,
bitmap.boundsRect,
f_resampler,
dmOpaque
)
end;
tinymap.drawTo(
canvas.handle,
f_image_regions[ cri ].area.left,
f_image_regions[ cri ].area.top
)
end
else begin
dest := tBitmap32.create;
try
dest.setSize( w, h );
StretchTransfer(
dest,
dest.clipRect,
dest.clipRect,
bitmap,
bitmap.boundsRect,
f_resampler,
dmOpaque
);
dest.drawTo(
canvas.handle,
f_image_regions[ cri ].area.left,
f_image_regions[ cri ].area.top
)
finally dest.free end
end
end;
//..........................................................................
begin
// Calculate the current percentage across the scrollbar and images
percent := scroll_grip_position;
offset := (f_image_list.count -1) *percent;
image_index := round( offset );
image_offset := (frac( offset +0.5 ) -0.5); // --> -0.5 .. +0.5
// Draw the active image full-size . . . . . . . . . . . . . . . . . . . . .
xc := img_scroll_grip.left +(img_scroll_grip.width div 2)
-round( IMAGE_WIDTH_MAXIMUM *image_offset )
-(IMAGE_WIDTH_MAXIMUM div 2);
f_index_of_current_image := image_index;
if f_image_list.count < f_index_of_current_image then exit;
with f_image_regions[ 0 ] do begin
is_used := TRUE;
image_index := f_index_of_current_image;
area := rect(
xc,
IMAGE_BOTTOM_EDGE_OFFSET -IMAGE_HEIGHT_MAXIMUM,
xc +IMAGE_WIDTH_MAXIMUM +DISTANCE_BETWEEN_IMAGES +1,
IMAGE_BOTTOM_EDGE_OFFSET +1
)
end;
cri := 1;
if isPaint then
with f_image_list[ f_index_of_current_image ] do
bitmap.drawTo(
canvas.handle,
xc,
IMAGE_BOTTOM_EDGE_OFFSET -IMAGE_HEIGHT_MAXIMUM
);
// Draw all images to the right . . . . . . . . . . . . . . . . . . . . . .
f_index_of_image_on_right := image_index;
i := image_index +1;
x := xc +IMAGE_WIDTH_MAXIMUM +DISTANCE_BETWEEN_IMAGES;
offset := ((image_offset +0.5) *0.4) +0.6;
while x < self.width do begin
if i >= f_image_list.count then break;
f_index_of_image_on_right := i;
w := round( IMAGE_WIDTH_MAXIMUM *offset );
h := round( IMAGE_HEIGHT_MAXIMUM *offset );
with f_image_regions[ cri ] do begin
is_used := true;
image_index := i;
area.left := x;
area.right := x +w +DISTANCE_BETWEEN_IMAGES +1;
area.bottom := IMAGE_BOTTOM_EDGE_OFFSET -30 +round( offset *30 ) +1;
area.top := area.bottom -h
end;
if isPaint then inner_loop_paint;
inc( cri );
inc( i );
inc( x, w +DISTANCE_BETWEEN_IMAGES );
offset := max( offset *0.6, 0.3 )
end;
// Draw all images to the left . . . . . . . . . . . . . . . . . . . . . . .
f_index_of_image_on_left := image_index;
i := image_index -1;
x := xc -DISTANCE_BETWEEN_IMAGES;
offset := ((1.0 -(image_offset +0.5)) *0.4) +0.6;
while x > 0 do begin
if i < 0 then break;
f_index_of_image_on_left := i;
w := round( IMAGE_WIDTH_MAXIMUM *offset );
h := round( IMAGE_HEIGHT_MAXIMUM *offset );
with f_image_regions[ cri ] do begin
is_used := true;
image_index := i;
area.left := x -w;
area.right := x +DISTANCE_BETWEEN_IMAGES +1;
area.bottom := IMAGE_BOTTOM_EDGE_OFFSET -30 +round( offset *30 ) +1;
area.top := area.bottom -h
end;
if isPaint then inner_loop_paint;
inc( cri );
dec( i );
dec( x, w +DISTANCE_BETWEEN_IMAGES );
offset := max( offset *0.6, 0.3 )
end;
// End of image regions
f_number_of_visible_images := cri; //mtg del
with f_image_regions[ cri ] do begin
is_used := false;
image_index := i +1
end
end;