Lua: fix crash of the new drawing primitives (drawcircle, drawdisk, drawfilledrect, drawline) when outside view area
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1756 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
		
							parent
							
								
									48c11e15a6
								
							
						
					
					
						commit
						64e39cda85
					
				@ -61,6 +61,9 @@ $(OBJDIR)/pages.o: pages.c global.h struct.h const.h pages.h errors.h loadsave.h
 | 
			
		||||
$(OBJDIR)/palette.o: palette.c const.h struct.h global.h misc.h engine.h readline.h \
 | 
			
		||||
 buttons.h pages.h help.h sdlscreen.h errors.h op_c.h windows.h input.h \
 | 
			
		||||
 palette.h shade.h
 | 
			
		||||
$(OBJDIR)/palette_test.o: palette_test.c const.h struct.h global.h misc.h engine.h \
 | 
			
		||||
 readline.h buttons.h pages.h help.h sdlscreen.h errors.h op_c.h \
 | 
			
		||||
 windows.h input.h palette.h shade.h
 | 
			
		||||
$(OBJDIR)/pversion.o: pversion.c
 | 
			
		||||
$(OBJDIR)/pxdouble.o: pxdouble.c global.h struct.h const.h sdlscreen.h misc.h \
 | 
			
		||||
 graph.h pxdouble.h pxwide.h
 | 
			
		||||
@ -81,7 +84,7 @@ $(OBJDIR)/pxwide2.o: pxwide2.c global.h struct.h const.h sdlscreen.h misc.h grap
 | 
			
		||||
$(OBJDIR)/readini.o: readini.c const.h errors.h global.h struct.h misc.h readini.h \
 | 
			
		||||
 setup.h
 | 
			
		||||
$(OBJDIR)/readline.o: readline.c const.h struct.h global.h misc.h errors.h \
 | 
			
		||||
 sdlscreen.h readline.h windows.h input.h
 | 
			
		||||
 sdlscreen.h readline.h windows.h input.h engine.h
 | 
			
		||||
$(OBJDIR)/realpath.o: realpath.c
 | 
			
		||||
$(OBJDIR)/saveini.o: saveini.c const.h global.h struct.h readini.h io.h errors.h \
 | 
			
		||||
 misc.h saveini.h setup.h
 | 
			
		||||
 | 
			
		||||
@ -42,6 +42,7 @@
 | 
			
		||||
#include "palette.h"
 | 
			
		||||
#include "input.h" // Is_shortcut()
 | 
			
		||||
#include "help.h" // Window_help()
 | 
			
		||||
#include "graph.h"
 | 
			
		||||
 | 
			
		||||
/// Lua scripts bound to shortcut keys.
 | 
			
		||||
char * Bound_script[10];
 | 
			
		||||
@ -148,6 +149,13 @@ void Update_colors_during_script(void)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Paint a pixel in image without updating the screen
 | 
			
		||||
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)
 | 
			
		||||
    Pixel_in_current_screen(x_pos,y_pos,color,0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// Wrapper functions to call C from Lua
 | 
			
		||||
 | 
			
		||||
@ -362,7 +370,7 @@ int L_DrawLine(lua_State* L)
 | 
			
		||||
  LUA_ARG_NUMBER(4, "drawline", y2, INT_MIN, INT_MAX);
 | 
			
		||||
  LUA_ARG_NUMBER(5, "drawline", c,  INT_MIN, INT_MAX);
 | 
			
		||||
 | 
			
		||||
  Pixel_figure = Display_pixel;
 | 
			
		||||
  Pixel_figure = (void (*) (word,word,byte))Pixel_figure_no_screen;
 | 
			
		||||
  Draw_line_general(x1, y1, x2, y2, c);
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
@ -372,6 +380,7 @@ int L_DrawLine(lua_State* L)
 | 
			
		||||
int L_DrawFilledRect(lua_State* L)
 | 
			
		||||
{
 | 
			
		||||
  int x1, y1, x2, y2, c;
 | 
			
		||||
  int min_x,min_y,max_x,max_y, x_pos, y_pos;
 | 
			
		||||
 | 
			
		||||
  int nb_args = lua_gettop(L);
 | 
			
		||||
 | 
			
		||||
@ -382,9 +391,44 @@ int L_DrawFilledRect(lua_State* L)
 | 
			
		||||
  LUA_ARG_NUMBER(4, "drawfilledrect", y2, INT_MIN, INT_MAX);
 | 
			
		||||
  LUA_ARG_NUMBER(5, "drawfilledrect", c,  INT_MIN, INT_MAX);
 | 
			
		||||
 | 
			
		||||
  Draw_filled_rectangle(x1, y1, x2, y2, c);
 | 
			
		||||
  // Put bounds in ascending order
 | 
			
		||||
  if (x2>x1)
 | 
			
		||||
  {
 | 
			
		||||
    min_x=x1;
 | 
			
		||||
    max_x=x2;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    min_x=x2;
 | 
			
		||||
    max_x=x1;
 | 
			
		||||
  }
 | 
			
		||||
  if (y2>y1)
 | 
			
		||||
  {
 | 
			
		||||
    min_y=y1;
 | 
			
		||||
    max_y=y2;
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    min_y=y2;
 | 
			
		||||
    max_y=y1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Clipping limits
 | 
			
		||||
  if (max_x>Main_image_width)
 | 
			
		||||
    max_x=Main_image_width-1;
 | 
			
		||||
  if (max_y>Main_image_height)
 | 
			
		||||
    max_y=Main_image_height-1;
 | 
			
		||||
  if (min_x<0)
 | 
			
		||||
    min_x=0;
 | 
			
		||||
  if (min_y<0)
 | 
			
		||||
    min_y=0;
 | 
			
		||||
 | 
			
		||||
  // Perform drawing
 | 
			
		||||
  for (y_pos=min_y; y_pos<=max_y;y_pos++)
 | 
			
		||||
    for (x_pos=min_x; x_pos<=max_x;x_pos++)
 | 
			
		||||
      Pixel_in_current_screen(x_pos,y_pos,c,0);
 | 
			
		||||
  return 0;
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -400,7 +444,7 @@ int L_DrawCircle(lua_State* L)
 | 
			
		||||
  LUA_ARG_NUMBER(3, "drawcircle", r, INT_MIN, INT_MAX);
 | 
			
		||||
  LUA_ARG_NUMBER(4, "drawcircle", c, INT_MIN, INT_MAX);
 | 
			
		||||
 | 
			
		||||
  Pixel_figure = Display_pixel;
 | 
			
		||||
  Pixel_figure = (void (*) (word,word,byte))Pixel_figure_no_screen;
 | 
			
		||||
  Circle_limit = r*r;
 | 
			
		||||
  Draw_empty_circle_general(x1, y1, r, c);
 | 
			
		||||
 | 
			
		||||
@ -410,18 +454,30 @@ int L_DrawCircle(lua_State* L)
 | 
			
		||||
 | 
			
		||||
int L_DrawDisk(lua_State* L)
 | 
			
		||||
{
 | 
			
		||||
  int x1, y1, r, c;
 | 
			
		||||
  int center_x, center_y, r, c;
 | 
			
		||||
  long circle_limit;
 | 
			
		||||
  short x_pos,y_pos;
 | 
			
		||||
  short min_x,max_x,min_y,max_y;
 | 
			
		||||
 | 
			
		||||
  int nb_args = lua_gettop(L);
 | 
			
		||||
 | 
			
		||||
  LUA_ARG_LIMIT(4, "drawdisk");
 | 
			
		||||
  LUA_ARG_NUMBER(1, "drawdisk", x1, INT_MIN, INT_MAX);
 | 
			
		||||
  LUA_ARG_NUMBER(2, "drawdisk", y1, INT_MIN, INT_MAX);
 | 
			
		||||
  LUA_ARG_NUMBER(1, "drawdisk", center_x, INT_MIN, INT_MAX);
 | 
			
		||||
  LUA_ARG_NUMBER(2, "drawdisk", center_y, INT_MIN, INT_MAX);
 | 
			
		||||
  LUA_ARG_NUMBER(3, "drawdisk", r, INT_MIN, INT_MAX);
 | 
			
		||||
  LUA_ARG_NUMBER(4, "drawdisk", c, INT_MIN, INT_MAX);
 | 
			
		||||
 | 
			
		||||
  Circle_limit = r*r;
 | 
			
		||||
  Draw_filled_circle(x1, y1, r, c);
 | 
			
		||||
  circle_limit = r*r;
 | 
			
		||||
  
 | 
			
		||||
  // Compute clipping limits
 | 
			
		||||
  min_x=center_x-r<0 ? 0 : center_x-r;
 | 
			
		||||
  max_x=center_x+r>=Main_image_width? Main_image_width-1 : center_x+r;
 | 
			
		||||
  min_y=center_y-r<0 ? 0 : center_y-r;
 | 
			
		||||
  max_y=center_y+r>=Main_image_height? Main_image_height-1 : center_y+r;
 | 
			
		||||
 | 
			
		||||
  for (y_pos=min_y;y_pos<=max_y;y_pos++)
 | 
			
		||||
    for (x_pos=min_x;x_pos<=max_x;x_pos++)
 | 
			
		||||
      Pixel_in_current_screen(x_pos,y_pos,c,0);
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1275,7 +1275,6 @@ void Draw_empty_circle_general(short center_x,short center_y,short radius,byte c
 | 
			
		||||
  Pixel_figure(center_x+radius,center_y,color); // Droite
 | 
			
		||||
  Pixel_figure(center_x,center_y+radius,color); // Bas
 | 
			
		||||
 | 
			
		||||
  if(Main_magnifier_mode) Update_part_of_screen(center_x-radius,center_y-radius,2*radius+1,2*radius+1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
  // -- Tracé définitif d'un cercle vide --
 | 
			
		||||
 | 
			
		||||
@ -63,6 +63,7 @@ void Draw_empty_circle_general(short center_x,short center_y,short radius,byte c
 | 
			
		||||
void Draw_empty_circle_permanent(short center_x,short center_y,short radius,byte color);
 | 
			
		||||
void Draw_empty_circle_preview  (short center_x,short center_y,short radius,byte color);
 | 
			
		||||
void Hide_empty_circle_preview (short center_x,short center_y,short radius);
 | 
			
		||||
void Draw_empty_circle_general(short center_x,short center_y,short radius,byte color);
 | 
			
		||||
void Draw_filled_circle         (short center_x,short center_y,short radius,byte color);
 | 
			
		||||
 | 
			
		||||
void Draw_empty_ellipse_permanent(short center_x,short center_y,short horizontal_radius,short vertical_radius,byte color);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user