Change rendering system to use function pointers, see Issue 31 c38 : preliminary work to make the same executable handle Layers or Anims. Fixed an old issue where Lasso-ing a brush with right mouse button wouldn't erase cleanly (visual). Fixed an old issue where picking colors in layer 5 would not 'see' through layers.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1906 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2012-02-22 23:47:53 +00:00
parent 8ea1ab7fc8
commit 55d0889bc8
10 changed files with 189 additions and 89 deletions

View File

@ -350,7 +350,7 @@ void Draw_paintbrush(short x,short y,byte color)
for (yy=min_y; yy<min_y+height; yy++) for (yy=min_y; yy<min_y+height; yy++)
for (xx=min_x; xx<min_x+width; xx++) for (xx=min_x; xx<min_x+width; xx++)
{ {
Pixel_in_current_screen(xx,yy,color,0); Pixel_in_current_screen(xx,yy,color);
} }
// Feedback // Feedback
// This part is greatly taken from Hide_paintbrush() // This part is greatly taken from Hide_paintbrush()
@ -895,7 +895,7 @@ void Capture_brush(short start_x,short start_y,short end_x,short end_y,short cle
for (y_pos=start_y;y_pos<start_y+Brush_height;y_pos++) for (y_pos=start_y;y_pos<start_y+Brush_height;y_pos++)
for (x_pos=start_x;x_pos<start_x+Brush_width;x_pos++) for (x_pos=start_x;x_pos<start_x+Brush_width;x_pos++)
{ {
Pixel_in_current_screen(x_pos,y_pos,Back_color,1); Pixel_in_current_screen_with_preview(x_pos,y_pos,Back_color);
} }
Update_part_of_screen(start_x,start_y,Brush_width,Brush_height); Update_part_of_screen(start_x,start_y,Brush_width,Brush_height);
} }
@ -1295,7 +1295,7 @@ void Capture_brush_with_lasso(int vertices, short * points,short clear)
} }
else else
{ {
Pixel_in_current_screen(x_pos,y_pos,Back_color,0); Pixel_in_current_screen_with_preview(x_pos,y_pos,Back_color);
} }
} }
} }

View File

@ -159,7 +159,7 @@ void Update_colors_during_script(void)
void Pixel_figure_no_screen(short x_pos,short y_pos,byte color) void Pixel_figure_no_screen(short x_pos,short y_pos,byte color)
{ {
if (x_pos>0 && y_pos >0 && x_pos<Main_image_width && y_pos<Main_image_height) if (x_pos>0 && y_pos >0 && x_pos<Main_image_width && y_pos<Main_image_height)
Pixel_in_current_screen(x_pos,y_pos,color,0); Pixel_in_current_screen(x_pos,y_pos,color);
} }
@ -379,7 +379,7 @@ int L_PutPicturePixel(lua_State* L)
// Silently ignored // Silently ignored
return 0; return 0;
} }
Pixel_in_current_screen(x, y, c, 0); Pixel_in_current_screen(x, y, c);
return 0; // no values returned for lua return 0; // no values returned for lua
} }
@ -476,7 +476,7 @@ int L_DrawFilledRect(lua_State* L)
// Perform drawing // Perform drawing
for (y_pos=min_y; y_pos<=max_y;y_pos++) for (y_pos=min_y; y_pos<=max_y;y_pos++)
for (x_pos=min_x; x_pos<=max_x;x_pos++) for (x_pos=min_x; x_pos<=max_x;x_pos++)
Pixel_in_current_screen(x_pos,y_pos,c,0); Pixel_in_current_screen(x_pos,y_pos,c);
return 0; return 0;
} }
@ -539,7 +539,7 @@ int L_DrawDisk(lua_State* L)
{ {
short x=(x_pos-center_x)*2-even; short x=(x_pos-center_x)*2-even;
if (x*x+y*y <= circle_limit) if (x*x+y*y <= circle_limit)
Pixel_in_current_screen(x_pos,y_pos,c,0); Pixel_in_current_screen(x_pos,y_pos,c);
} }
} }

View File

@ -1106,7 +1106,7 @@ void Fill_general(byte fill_color)
byte filled = Read_pixel_from_current_layer(x_pos,y_pos); byte filled = Read_pixel_from_current_layer(x_pos,y_pos);
// First, restore the color. // First, restore the color.
Pixel_in_current_screen(x_pos,y_pos,Read_pixel_from_backup_layer(x_pos,y_pos),0); Pixel_in_current_screen(x_pos,y_pos,Read_pixel_from_backup_layer(x_pos,y_pos));
if (filled==2) if (filled==2)
{ {
@ -2782,7 +2782,7 @@ void Display_pixel(word x,word y,byte color)
Tilemap_draw(x,y, color); Tilemap_draw(x,y, color);
} }
else else
Pixel_in_current_screen(x,y,color,1); Pixel_in_current_screen_with_preview(x,y,color);
} }
} }
@ -3008,9 +3008,10 @@ byte Read_pixel_from_current_screen (word x,word y)
#ifndef NOLAYERS #ifndef NOLAYERS
byte depth; byte depth;
byte color; byte color;
if (Main_current_layer==4) if (Constraint_mode)
return *(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width); if (Main_current_layer==4)
return *(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width);
color = *(Main_screen+y*Main_image_width+x); color = *(Main_screen+y*Main_image_width+x);
if (color != Main_backups->Pages->Transparent_color) // transparent color if (color != Main_backups->Pages->Transparent_color) // transparent color
@ -3023,85 +3024,127 @@ byte Read_pixel_from_current_screen (word x,word y)
#endif #endif
} }
void Pixel_in_current_screen (word x,word y,byte color,int with_preview) /// Paint a a single pixel in image only : as-is.
void Pixel_in_screen_direct(word x,word y,byte color)
{ {
#ifndef NOLAYERS *((y)*Main_image_width+(x)+/*Main_backups->Pages->Image[Main_current_layer].Pixels*/Main_screen)=color;
if (!Constraint_mode) }
/// Paint a a single pixel in image and on screen: as-is.
void Pixel_in_screen_direct_with_preview(word x,word y,byte color)
{
*((y)*Main_image_width+(x)+/*Main_backups->Pages->Image[Main_current_layer].Pixels*/Main_screen)=color;
Pixel_preview(x,y,color);
}
#ifndef NOLAYERS
/// Paint a a single pixel in image only : using layered display.
void Pixel_in_screen_layered(word x,word y,byte color)
{
byte depth = *(Main_visible_image_depth_buffer.Image+x+y*Main_image_width);
*(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color;
if ( depth <= Main_current_layer)
{ {
byte depth = *(Main_visible_image_depth_buffer.Image+x+y*Main_image_width); if (color == Main_backups->Pages->Transparent_color) // transparent color
*(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color; // fetch pixel color from the topmost visible layer
if ( depth <= Main_current_layer) color=*(Main_backups->Pages->Image[depth].Pixels + x+y*Main_image_width);
{
if (color == Main_backups->Pages->Transparent_color) // transparent color
// fetch pixel color from the topmost visible layer
color=*(Main_backups->Pages->Image[depth].Pixels + x+y*Main_image_width);
*(x+y*Main_image_width+Main_screen)=color;
if (with_preview)
Pixel_preview(x,y,color);
}
}
else if ( Main_current_layer == 4)
{
if (color<4)
{
// Paste in layer
*(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color;
// Paste in depth buffer
*(Main_visible_image_depth_buffer.Image+x+y*Main_image_width)=color;
// Fetch pixel color from the target raster layer
color=*(Main_backups->Pages->Image[color].Pixels + x+y*Main_image_width);
// Draw that color on the visible image buffer
*(x+y*Main_image_width+Main_screen)=color;
if (with_preview)
Pixel_preview(x,y,color);
}
}
else if (Main_current_layer<4 && (Main_layers_visible & (1<<4)))
{
byte depth;
*(x+y*Main_image_width+Main_screen)=color;
}
}
/// Paint a a single pixel in image and on screen : using layered display.
void Pixel_in_screen_layered_with_preview(word x,word y,byte color)
{
byte depth = *(Main_visible_image_depth_buffer.Image+x+y*Main_image_width);
*(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color;
if ( depth <= Main_current_layer)
{
if (color == Main_backups->Pages->Transparent_color) // transparent color
// fetch pixel color from the topmost visible layer
color=*(Main_backups->Pages->Image[depth].Pixels + x+y*Main_image_width);
*(x+y*Main_image_width+Main_screen)=color;
Pixel_preview(x,y,color);
}
}
/// Paint a a single pixel in image only : in a layer under one that acts as a layer-selector (mode 5).
void Pixel_in_screen_underlay(word x,word y,byte color)
{
byte depth;
// Paste in layer
*(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color;
// Search depth
depth = *(Main_backups->Pages->Image[4].Pixels + x+y*Main_image_width);
if ( depth == Main_current_layer)
{
// Draw that color on the visible image buffer
*(x+y*Main_image_width+Main_screen)=color;
}
}
/// Paint a a single pixel in image and on screen : in a layer under one that acts as a layer-selector (mode 5).
void Pixel_in_screen_underlay_with_preview(word x,word y,byte color)
{
byte depth;
// Paste in layer
*(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color;
// Search depth
depth = *(Main_backups->Pages->Image[4].Pixels + x+y*Main_image_width);
if ( depth == Main_current_layer)
{
// Draw that color on the visible image buffer
*(x+y*Main_image_width+Main_screen)=color;
Pixel_preview(x,y,color);
}
}
/// Paint a a single pixel in image only : in a layer that acts as a layer-selector (mode 5).
void Pixel_in_screen_overlay(word x,word y,byte color)
{
if (color<4)
{
// Paste in layer // Paste in layer
*(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color; *(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color;
// Search depth // Paste in depth buffer
depth = *(Main_backups->Pages->Image[4].Pixels + x+y*Main_image_width); *(Main_visible_image_depth_buffer.Image+x+y*Main_image_width)=color;
// Fetch pixel color from the target raster layer
if ( depth == Main_current_layer) color=*(Main_backups->Pages->Image[color].Pixels + x+y*Main_image_width);
{ // Draw that color on the visible image buffer
// Draw that color on the visible image buffer *(x+y*Main_image_width+Main_screen)=color;
*(x+y*Main_image_width+Main_screen)=color;
if (with_preview)
Pixel_preview(x,y,color);
}
}
else
{
byte depth;
*(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color;
depth = *(Main_visible_image_depth_buffer.Image+x+y*Main_image_width);
if ( depth <= Main_current_layer)
{
if (color == Main_backups->Pages->Transparent_color) // transparent color
// fetch pixel color from the topmost visible layer
color=*(Main_backups->Pages->Image[depth].Pixels + x+y*Main_image_width);
*(x+y*Main_image_width+Main_screen)=color;
if (with_preview)
Pixel_preview(x,y,color);
}
} }
#else
*((y)*Main_image_width+(x)+Main_backups->Pages->Image[Main_current_layer].Pixels)=color;
if (with_preview)
Pixel_preview(x,y,color);
#endif
} }
/// Paint a a single pixel in image and on screen : in a layer that acts as a layer-selector (mode 5).
void Pixel_in_screen_overlay_with_preview(word x,word y,byte color)
{
if (color<4)
{
// Paste in layer
*(Main_backups->Pages->Image[Main_current_layer].Pixels + x+y*Main_image_width)=color;
// Paste in depth buffer
*(Main_visible_image_depth_buffer.Image+x+y*Main_image_width)=color;
// Fetch pixel color from the target raster layer
color=*(Main_backups->Pages->Image[color].Pixels + x+y*Main_image_width);
// Draw that color on the visible image buffer
*(x+y*Main_image_width+Main_screen)=color;
Pixel_preview(x,y,color);
}
}
#endif
Func_pixel Pixel_in_current_screen=Pixel_in_screen_direct;
Func_pixel Pixel_in_current_screen_with_preview=Pixel_in_screen_direct_with_preview;
void Pixel_in_spare(word x,word y, byte color) void Pixel_in_spare(word x,word y, byte color)
{ {
*((y)*Spare_image_width+(x)+Spare_backups->Pages->Image[Spare_current_layer].Pixels)=color; *((y)*Spare_image_width+(x)+Spare_backups->Pages->Image[Spare_current_layer].Pixels)=color;
@ -3116,3 +3159,37 @@ byte Read_pixel_from_current_layer(word x,word y)
{ {
return *((y)*Main_image_width+(x)+Main_backups->Pages->Image[Main_current_layer].Pixels); return *((y)*Main_image_width+(x)+Main_backups->Pages->Image[Main_current_layer].Pixels);
} }
void Update_pixel_renderer(void)
{
#ifndef NOLAYERS
if (!Constraint_mode)
{
// layered
Pixel_in_current_screen = Pixel_in_screen_layered;
Pixel_in_current_screen_with_preview = Pixel_in_screen_layered_with_preview;
}
else if ( Main_current_layer == 4)
{
// overlay
Pixel_in_current_screen = Pixel_in_screen_overlay;
Pixel_in_current_screen_with_preview = Pixel_in_screen_overlay_with_preview;
}
else if (Main_current_layer<4 && (Main_layers_visible & (1<<4)))
{
// underlay
Pixel_in_current_screen = Pixel_in_screen_underlay;
Pixel_in_current_screen_with_preview = Pixel_in_screen_underlay_with_preview;
}
else
{
// layered (again)
Pixel_in_current_screen = Pixel_in_screen_layered;
Pixel_in_current_screen_with_preview = Pixel_in_screen_layered_with_preview;
}
#else
// direct
Pixel_in_current_screen = Pixel_in_screen_direct;
Pixel_in_current_screen_with_preview = Pixel_in_screen_direct_with_preview;
#endif
}

View File

@ -121,8 +121,17 @@ void Update_part_of_screen(short x, short y, short width, short height);
void Redraw_grid(short x, short y, unsigned short w, unsigned short h); void Redraw_grid(short x, short y, unsigned short w, unsigned short h);
void Pixel_in_current_screen (word x,word y,byte color,int with_preview);
void Pixel_in_spare(word x,word y, byte color); void Pixel_in_spare(word x,word y, byte color);
void Pixel_in_current_layer(word x,word y, byte color); void Pixel_in_current_layer(word x,word y, byte color);
byte Read_pixel_from_current_screen (word x,word y); byte Read_pixel_from_current_screen (word x,word y);
byte Read_pixel_from_current_layer(word x,word y); byte Read_pixel_from_current_layer(word x,word y);
/// Paint a single pixel in image only.
extern Func_pixel Pixel_in_current_screen;
/// Paint a single pixel in image AND on screen.
extern Func_pixel Pixel_in_current_screen_with_preview;
/// Sets ::Pixel_in_current_screen and ::Pixel_in_current_screen_with_preview
void Update_pixel_renderer(void);

View File

@ -89,6 +89,7 @@ void Layer_activate(int layer, short side)
Update_depth_buffer(); // Only need the depth buffer Update_depth_buffer(); // Only need the depth buffer
//Download_infos_page_main(Main_backups->Pages); //Download_infos_page_main(Main_backups->Pages);
//Update_FX_feedback(Config.FX_Feedback); //Update_FX_feedback(Config.FX_Feedback);
Update_pixel_renderer();
Display_all_screen(); Display_all_screen();
Display_layerbar(); Display_layerbar();
Display_cursor(); Display_cursor();

View File

@ -189,7 +189,7 @@ void Set_pixel(T_IO_Context *context, short x_pos, short y_pos, byte color)
{ {
// Chargement des pixels dans l'écran principal // Chargement des pixels dans l'écran principal
case CONTEXT_MAIN_IMAGE: case CONTEXT_MAIN_IMAGE:
Pixel_in_current_screen(x_pos,y_pos,color,0); Pixel_in_current_screen(x_pos,y_pos,color);
break; break;
// Chargement des pixels dans la brosse // Chargement des pixels dans la brosse
@ -1335,6 +1335,8 @@ void Set_loading_layer(T_IO_Context *context, int layer)
} }
Main_current_layer = layer; Main_current_layer = layer;
context->Target_address=Main_backups->Pages->Image[layer].Pixels; context->Target_address=Main_backups->Pages->Image[layer].Pixels;
Update_pixel_renderer();
} }
} }

View File

@ -238,7 +238,7 @@ void Replace_a_color(byte old_color, byte new_color)
for (y=0; y<Main_image_height; y++) for (y=0; y<Main_image_height; y++)
for (x=0; x<Main_image_width; x++) for (x=0; x<Main_image_width; x++)
if (Read_pixel_from_current_layer(x,y) == old_color) if (Read_pixel_from_current_layer(x,y) == old_color)
Pixel_in_current_screen(x,y,new_color,0); Pixel_in_current_screen(x,y,new_color);
Update_rect(0,0,0,0); // On peut TOUT a jour Update_rect(0,0,0,0); // On peut TOUT a jour
// C'est pas un problème car il n'y a pas de preview // C'est pas un problème car il n'y a pas de preview
} }

View File

@ -3011,13 +3011,19 @@ void Load_CM5(T_IO_Context* context)
Palette_loaded(context); Palette_loaded(context);
if (Constraint_mode != 1)
Constraint_mode = 1;
if (Read_byte(file, &value)!=1) if (Read_byte(file, &value)!=1)
File_error = 2; File_error = 2;
// This forces the creation of 5 layers total :
// Needed because the "pixel" functions will seek layer 4
Set_loading_layer(context, 4);
// Now select layer 0 again
Set_loading_layer(context, 0); Set_loading_layer(context, 0);
if (Constraint_mode != 1)
Constraint_mode = 1;
for(ty=0; ty<context->Height; ty++) for(ty=0; ty<context->Height; ty++)
for(tx=0; tx<context->Width; tx++) for(tx=0; tx<context->Width; tx++)
{ {

View File

@ -678,6 +678,7 @@ void Update_screen_targets(void)
Main_screen=Main_backups->Pages->Image[Main_current_layer].Pixels; Main_screen=Main_backups->Pages->Image[Main_current_layer].Pixels;
Screen_backup=Main_backups->Pages->Next->Image[Main_current_layer].Pixels; Screen_backup=Main_backups->Pages->Next->Image[Main_current_layer].Pixels;
#endif #endif
Update_pixel_renderer();
} }
/// Update all the special image buffers, if necessary. /// Update all the special image buffers, if necessary.

View File

@ -192,7 +192,11 @@ void Tilemap_draw(word x, word y, byte color)
yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + Snap_height - rel_y - 1; yy = (tile / Main_tilemap_width)*Snap_height+Snap_offset_Y + Snap_height - rel_y - 1;
break; break;
} }
Pixel_in_current_screen(xx,yy,color,yy>=Limit_top&&yy<=Limit_bottom&&xx>=Limit_left&&xx<=Limit_right); if (yy>=Limit_top&&yy<=Limit_bottom&&xx>=Limit_left&&xx<=Limit_right)
Pixel_in_current_screen_with_preview(xx,yy,color);
else
Pixel_in_current_screen(xx,yy,color);
tile = Main_tilemap[tile].Next; tile = Main_tilemap[tile].Next;
} while (tile != first_tile); } while (tile != first_tile);