From 88995a591020f02c495547b00abde98b0df14051 Mon Sep 17 00:00:00 2001 From: Cracker64 Date: Sat, 23 Apr 2011 18:44:18 -0400 Subject: line/box tool for decorations, some other things. diff --git a/src/graphics.c b/src/graphics.c index 0b9ffe7..c0fce81 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -3068,6 +3068,86 @@ void draw_decorations(pixel *vid_buf,pixel *decorations) vid_buf[i] = PIXRGB(r,g,b); } } +void create_decorations(pixel *decorations,int x, int y, int rx, int ry, int r, int g, int b) +{ + int i,j; + for (j=-ry; j<=ry; j++) + for (i=-rx; i<=rx; i++) + if(y+j>=0 && x+i>=0 && x+iabs(x2-x1), x, y, dx, dy, sy; + float e, de; + if (cp) + { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) + { + y += sy; + if (!(rx+ry)) + { + if (cp) + create_decorations(decorations,y, x, rx, ry, r, g, b); + else + create_decorations(decorations,x, y, rx, ry, r, g, b); + } + e -= 1.0f; + } + } +} +void box_decorations(pixel *decorations,int x1, int y1, int x2, int y2, int r, int g, int b) +{ + int i, j; + if (x1>x2) + { + i = x2; + x2 = x1; + x1 = i; + } + if (y1>y2) + { + j = y2; + y2 = y1; + y1 = j; + } + for (j=y1; j<=y2; j++) + for (i=x1; i<=x2; i++) + create_decorations(decorations,i, j, 0, 0, r, g, b); +} //draws the photon colors in the HUD void draw_wavelengths(pixel *vid, int x, int y, int h, int wl) diff --git a/src/interface.c b/src/interface.c index 312e338..748d313 100644 --- a/src/interface.c +++ b/src/interface.c @@ -4278,7 +4278,7 @@ int console_parse_partref(char *txt, int *which, char *err) void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) { - int i,cr=127,cg=0,cb=0,b = 0,mx,my,bq = 0,j; + int i,cr=127,cg=0,cb=0,b = 0,mx,my,bq = 0,j, lb=0,lx=0,ly=0,lm=0; int window_offset_x_left = 2; int window_offset_x_right = XRES - 279; int window_offset_y = 2; @@ -4341,9 +4341,6 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); draw_decorations(vid_buf,decorations); - ui_edit_draw(vid_buf, &box_R); - ui_edit_draw(vid_buf, &box_G); - ui_edit_draw(vid_buf, &box_B); ui_edit_process(mx, my, b, &box_R); ui_edit_process(mx, my, b, &box_G); ui_edit_process(mx, my, b, &box_B); @@ -4368,10 +4365,14 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) box_G.x = XRES - 254 + 40; box_B.x = XRES - 254 + 75; } + clearrect(vid_buf, window_offset_x, window_offset_y, 2+255+4+10+5, 2+255+20); drawrect(vid_buf, window_offset_x, window_offset_y, 2+255+4+10+5, 2+255+20, 255, 255, 255, 255);//window around whole thing drawrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, 255, 255, 255, 255); - HSV_to_RGB(h,s,v,&cr,&cg,&cb); - fillrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, cr, cg, cb, 255); + ui_edit_draw(vid_buf, &box_R); + ui_edit_draw(vid_buf, &box_G); + ui_edit_draw(vid_buf, &box_B); + + render_cursor(vid_buf, mx, my, PT_DUST, *bsx, *bsy); for(int ss=0; ss<=255; ss++) for(int hh=0;hh<=255;hh++) { @@ -4390,7 +4391,13 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) HSV_to_RGB(0,0,vv,&cr,&cg,&cb); vid_buf[(vv+grid_offset_y)*(XRES+BARSIZE)+(i+grid_offset_x+255+4)] = PIXRGB(cr, cg, cb); } - if(mx >= window_offset_x && my >= window_offset_y && mx <= window_offset_x+255+4+10+5 && my <= window_offset_y+255+20)//in the main window + HSV_to_RGB(h,s,v,&cr,&cg,&cb); + fillrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, cr, cg, cb, 255); + sprintf(box_R.str,"%d",cr); + sprintf(box_G.str,"%d",cg); + sprintf(box_B.str,"%d",cb); + + if(!lb && mx >= window_offset_x && my >= window_offset_y && mx <= window_offset_x+255+4+10+5 && my <= window_offset_y+255+20)//in the main window { if(mx >= grid_offset_x +255+4 && my >= grid_offset_y && mx <= grid_offset_x+255+4+10 && my <= grid_offset_y+255) { @@ -4423,24 +4430,71 @@ void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy) sprintf(box_G.str,"%d",cg); sprintf(box_B.str,"%d",cb); } + if(b && mx >= window_offset_x + onleft_button_offset_x && my >= window_offset_y +255+4 && mx <= window_offset_x + onleft_button_offset_x +13 && my <= window_offset_y +255+4 +13) + on_left = !on_left; } - else + else if (b)//there is a click, outside window { - render_cursor(vid_buf, mx, my, PT_DUST, *bsx, *bsy); - HSV_to_RGB(h,s,v,&cr,&cg,&cb); - if (b) + if (lb)//mouse is held down + { + if (lm == 1)//line tool + { + xor_line(lx, ly, mx, my, vid_buf); + } + else if (lm == 2)//box tool + { + xor_line(lx, ly, lx, my, vid_buf); + xor_line(lx, my, mx, my, vid_buf); + xor_line(mx, my, mx, ly, vid_buf); + xor_line(mx, ly, lx, ly, vid_buf); + } + else//while mouse is held down, it draws lines between previous and current positions + { + line_decorations(decorations,lx, ly, mx, my, *bsx, *bsy, cr, cg, cb); + lx = mx; + ly = my; + } + } + else //first click { - for (j=-*bsy; j<=*bsy; j++) - for (i=-*bsx; i<=*bsx; i++) - if(my+j>=0 && mx+i>=0 && mx+i= window_offset_x + onleft_button_offset_x && my >= window_offset_y +255+4 && mx <= window_offset_x + onleft_button_offset_x +13 && my <= window_offset_y +255+4 +13) - on_left = !on_left; + if (sdl_wheel) { //change brush size -- cgit v0.9.2-21-gd62e