@@ -462,44 +462,41 @@ function pd.Class:canvas_realizedollar(s)
462462end
463463
464464function pd .Class :repaint (layer )
465- if layer == nil or layer <= 1 then
466- if type (self .paint ) == " function" then
467- local g = _gfx_internal .start_paint (self ._object , 1 );
468- if type (self .paint ) == " function" and g ~= nil then
469- self :paint (g );
470- _gfx_internal .end_paint (g , 1 );
465+ local paint_funcs = {}
466+ if type (self .paint ) == " function" then
467+ table.insert (paint_funcs , self .paint )
468+ -- Check for layer paint functions
469+ local i = 2
470+ while true do
471+ local paint_layer_method = " paint_layer_" .. tostring (i )
472+ if type (self [paint_layer_method ]) == " function" then
473+ table.insert (paint_funcs , self [paint_layer_method ])
474+ i = i + 1 ;
475+ else
476+ break -- Exit the loop when no more paint_layer_X methods are found
477+ end
471478 end
472- end
473479 end
474- if layer == nil or layer == 0 then
475- local i = 2
476- while true do
477- local paint_layer_method = " paint_layer_" .. tostring (i )
478- if type (self [paint_layer_method ]) == " function" then
479- local g = _gfx_internal .start_paint (self ._object , i )
480- if g ~= nil then
481- self [paint_layer_method ](self , g )
482- _gfx_internal .end_paint (g , i )
483- i = i + 1
484- else
485- break ;
486- end
487-
480+ -- repaint all
481+ if layer == nil or layer == 0 then
482+ for i , paint_fn in ipairs (paint_funcs ) do
483+ local g = _gfx_internal .start_paint (self ._object , i );
484+ if type (paint_fn ) == " function" and g ~= nil then
485+ paint_fn (self , g );
486+ _gfx_internal .end_paint (g , i );
488487 else
489- break -- Exit the loop when no more paint_layer_X methods are found
488+ break ;
490489 end
491490 end
492- end
493- if layer ~= nil and layer >= 2 then
494- local paint_layer_method = " paint_layer_" .. tostring (layer )
495- if type (self [paint_layer_method ]) == " function" then
496- local g = _gfx_internal .start_paint (self ._object , layer )
497- if g ~= nil then
498- self [paint_layer_method ](self , g )
499- _gfx_internal .end_paint (g , layer )
500- end
491+ -- repaint only chosen index
492+ elseif layer <= # paint_funcs then
493+ local g = _gfx_internal .start_paint (self ._object , layer );
494+ local paint_fn = paint_funcs [layer ]
495+ if type (paint_fn ) == " function" and g ~= nil then
496+ paint_fn (self , g );
497+ _gfx_internal .end_paint (g , layer );
501498 end
502- end
499+ end
503500end
504501
505502function pd .Class :get_size ()
0 commit comments