Decorations! ,still messing with it. It does not save currently. TODO: fix typing in boxes to update the color. Line/box tools. Some basic color selections like an element menu.
This commit is contained in:
parent
aa3f475edc
commit
bd8de4c842
@ -114,6 +114,8 @@ void xor_rect(pixel *vid, int x, int y, int w, int h);
|
||||
|
||||
void draw_parts(pixel *vid);
|
||||
|
||||
void draw_decorations(pixel *vid_buf,pixel *decorations);
|
||||
|
||||
void draw_wavelengths(pixel *vid, int x, int y, int h, int wl);
|
||||
|
||||
void render_signs(pixel *vid_buf);
|
||||
|
@ -244,5 +244,6 @@ int console_parse_coords(char *txt, int *x, int *y, char *err);
|
||||
int console_parse_type(char *txt, int *element, char *err);
|
||||
int console_parse_partref(char *txt, int *which, char *err);
|
||||
|
||||
void decorations_ui(pixel *vid_buf,pixel *decorations,int *bsx,int *bsy);
|
||||
#endif
|
||||
|
||||
|
@ -66,6 +66,9 @@ int register_extension();
|
||||
|
||||
int cpu_check(void);
|
||||
|
||||
void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b);
|
||||
|
||||
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v);
|
||||
// a b
|
||||
// c d
|
||||
struct matrix2d {
|
||||
|
@ -3056,6 +3056,18 @@ void draw_parts(pixel *vid)
|
||||
#endif
|
||||
|
||||
}
|
||||
void draw_decorations(pixel *vid_buf,pixel *decorations)
|
||||
{
|
||||
int i,r,g,b;
|
||||
for (i=0; i<(XRES+BARSIZE)*YRES; i++)
|
||||
{
|
||||
r = PIXR(decorations[i]);
|
||||
g = PIXG(decorations[i]);
|
||||
b = PIXB(decorations[i]);
|
||||
if (r>0 || g>0 || b>0)
|
||||
vid_buf[i] = PIXRGB(r,g,b);
|
||||
}
|
||||
}
|
||||
|
||||
//draws the photon colors in the HUD
|
||||
void draw_wavelengths(pixel *vid, int x, int y, int h, int wl)
|
||||
|
220
src/interface.c
220
src/interface.c
@ -4275,3 +4275,223 @@ int console_parse_partref(char *txt, int *which, char *err)
|
||||
if (strcmp(err,"")==0) strcpy(err,"Particle does not exist");
|
||||
return 0;
|
||||
}
|
||||
|
||||
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 window_offset_x_left = 2;
|
||||
int window_offset_x_right = XRES - 279;
|
||||
int window_offset_y = 2;
|
||||
int grid_offset_x_left = 5;
|
||||
int grid_offset_x_right = XRES - 274;
|
||||
int grid_offset_y = 5;
|
||||
int onleft_button_offset_x_left = 259;
|
||||
int onleft_button_offset_x_right = 4;
|
||||
int on_left = 1;
|
||||
int grid_offset_x;
|
||||
int window_offset_x;
|
||||
int onleft_button_offset_x;
|
||||
int h = 0, s = 255, v = 127;
|
||||
int th = 0, ts =255, tv=127;
|
||||
ui_edit box_R;
|
||||
ui_edit box_G;
|
||||
ui_edit box_B;
|
||||
|
||||
box_R.x = 5;
|
||||
box_R.y = 5+255+4;
|
||||
box_R.w = 30;
|
||||
box_R.nx = 1;
|
||||
box_R.def = "";
|
||||
strcpy(box_R.str, "127");
|
||||
box_R.focus = 0;
|
||||
box_R.hide = 0;
|
||||
box_R.multiline = 0;
|
||||
box_R.cursor = 0;
|
||||
|
||||
box_G.x = 40;
|
||||
box_G.y = 5+255+4;
|
||||
box_G.w = 30;
|
||||
box_G.nx = 1;
|
||||
box_G.def = "";
|
||||
strcpy(box_G.str, "");
|
||||
box_G.focus = 0;
|
||||
box_G.hide = 0;
|
||||
box_G.multiline = 0;
|
||||
box_G.cursor = 0;
|
||||
|
||||
box_B.x = 75;
|
||||
box_B.y = 5+255+4;
|
||||
box_B.w = 30;
|
||||
box_B.nx = 1;
|
||||
box_B.def = "";
|
||||
strcpy(box_B.str, "");
|
||||
box_B.focus = 0;
|
||||
box_B.hide = 0;
|
||||
box_B.multiline = 0;
|
||||
box_B.cursor = 0;
|
||||
|
||||
pixel *old_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
|
||||
memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
|
||||
while (!sdl_poll())
|
||||
{
|
||||
bq = b;
|
||||
b = SDL_GetMouseState(&mx, &my);
|
||||
mx /= sdl_scale;
|
||||
my /= sdl_scale;
|
||||
|
||||
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);
|
||||
//HSV_to_RGB(h,s,v,&cr,&cg,&cb);
|
||||
//if(cr != atoi(box_R.str))
|
||||
//RGB_to_HSV(atoi(box_R.str),cg,cb,&h,&s,&v);
|
||||
if(on_left==1)
|
||||
{
|
||||
grid_offset_x = grid_offset_x_left;
|
||||
window_offset_x = window_offset_x_left;
|
||||
onleft_button_offset_x = onleft_button_offset_x_left;
|
||||
box_R.x = 5;
|
||||
box_G.x = 40;
|
||||
box_B.x = 75;
|
||||
}
|
||||
else
|
||||
{
|
||||
grid_offset_x = grid_offset_x_right;
|
||||
window_offset_x = window_offset_x_right;
|
||||
onleft_button_offset_x = onleft_button_offset_x_right;
|
||||
box_R.x = XRES - 254 + 5;
|
||||
box_G.x = XRES - 254 + 40;
|
||||
box_B.x = XRES - 254 + 75;
|
||||
}
|
||||
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);
|
||||
for(int ss=0; ss<=255; ss++)
|
||||
for(int hh=0;hh<=255;hh++)
|
||||
{
|
||||
cr = 0;
|
||||
cg = 0;
|
||||
cb = 0;
|
||||
HSV_to_RGB(hh,255-ss,255,&cr,&cg,&cb);
|
||||
vid_buf[(ss+grid_offset_y)*(XRES+BARSIZE)+(hh+grid_offset_x)] = PIXRGB(cr, cg, cb);
|
||||
}
|
||||
for(int vv=0; vv<=255; vv++)
|
||||
for( i=0; i<10; i++)
|
||||
{
|
||||
cr = 0;
|
||||
cg = 0;
|
||||
cb = 0;
|
||||
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
|
||||
{
|
||||
if(mx >= grid_offset_x +255+4 && my >= grid_offset_y && mx <= grid_offset_x+255+4+10 && my <= grid_offset_y+255)
|
||||
{
|
||||
tv = my - grid_offset_y;
|
||||
if(b)
|
||||
{
|
||||
v =my - grid_offset_y;
|
||||
}
|
||||
HSV_to_RGB(h,s,tv,&cr,&cg,&cb);
|
||||
//clearrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6,12,12);
|
||||
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(mx >= grid_offset_x && my >= grid_offset_y && mx <= grid_offset_x+255 && my <= grid_offset_y+255)
|
||||
{
|
||||
th = mx - grid_offset_x;
|
||||
ts = 255 - (my - grid_offset_y);
|
||||
if(b)
|
||||
{
|
||||
h = mx - grid_offset_x;
|
||||
s = 255 - (my - grid_offset_y);
|
||||
}
|
||||
HSV_to_RGB(th,ts,v,&cr,&cg,&cb);
|
||||
//clearrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6,12,12);
|
||||
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.def,"%d",cr);
|
||||
sprintf(box_R.str,"%d",cr);
|
||||
sprintf(box_G.str,"%d",cg);
|
||||
sprintf(box_B.str,"%d",cb);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
render_cursor(vid_buf, mx, my, PT_DUST, *bsx, *bsy);
|
||||
HSV_to_RGB(h,s,v,&cr,&cg,&cb);
|
||||
if (b)
|
||||
{
|
||||
for (j=-*bsy; j<=*bsy; j++)
|
||||
for (i=-*bsx; i<=*bsx; i++)
|
||||
if(my+j>=0 && mx+i>=0 && mx+i<XRES && my+j<YRES)
|
||||
if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(*bsx,2))+(pow(j,2))/(pow(*bsy,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=(*bsy)*(*bsx)))
|
||||
decorations[(my+j)*(XRES+BARSIZE)+(mx+i)] = PIXRGB(cr, cg, cb);
|
||||
}
|
||||
sprintf(box_R.str,"%d",cr);
|
||||
sprintf(box_G.str,"%d",cg);
|
||||
sprintf(box_B.str,"%d",cb);
|
||||
}
|
||||
|
||||
addpixel(vid_buf,grid_offset_x + h,grid_offset_y-1,255,255,255,255);
|
||||
addpixel(vid_buf,grid_offset_x -1,grid_offset_y+(255-s),255,255,255,255);
|
||||
|
||||
addpixel(vid_buf,grid_offset_x + th,grid_offset_y-1,100,100,100,255);
|
||||
addpixel(vid_buf,grid_offset_x -1,grid_offset_y+(255-ts),100,100,100,255);
|
||||
|
||||
addpixel(vid_buf,grid_offset_x + 255 +3,grid_offset_y+tv,100,100,100,255);
|
||||
addpixel(vid_buf,grid_offset_x + 255 +3,grid_offset_y +v,255,255,255,255);
|
||||
|
||||
sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
|
||||
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;
|
||||
if (sdl_wheel)
|
||||
{
|
||||
//change brush size
|
||||
{
|
||||
if (!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
|
||||
{
|
||||
*bsx += sdl_wheel;
|
||||
*bsy += sdl_wheel;
|
||||
}
|
||||
else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL)))
|
||||
{
|
||||
*bsx += sdl_wheel;
|
||||
}
|
||||
else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT)))
|
||||
{
|
||||
*bsy += sdl_wheel;
|
||||
}
|
||||
if (*bsx>1180)
|
||||
*bsx = 1180;
|
||||
if (*bsx<0)
|
||||
*bsx = 0;
|
||||
if (*bsy>1180)
|
||||
*bsy = 1180;
|
||||
if (*bsy<0)
|
||||
*bsy = 0;
|
||||
sdl_wheel = 0;
|
||||
/*if(su >= PT_NUM) {
|
||||
if(sl < PT_NUM)
|
||||
su = sl;
|
||||
if(sr < PT_NUM)
|
||||
su = sr;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
if(sdl_key=='b')
|
||||
{
|
||||
free(old_buf);
|
||||
return;
|
||||
}
|
||||
}
|
||||
free(old_buf);
|
||||
}
|
||||
|
@ -2658,6 +2658,7 @@ int main(int argc, char *argv[])
|
||||
PyObject *pname,*pmodule,*pfunc,*pvalue,*pargs,*pstep,*pkey;
|
||||
PyObject *tpt_console_obj;
|
||||
#endif
|
||||
pixel *decorations = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
|
||||
vid_buf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
|
||||
pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
|
||||
GSPEED = 1;
|
||||
@ -3243,6 +3244,8 @@ int main(int argc, char *argv[])
|
||||
console_mode = !console_mode;
|
||||
//hud_enable = !console_mode;
|
||||
}
|
||||
if (sdl_key=='b')
|
||||
decorations_ui(vid_buf,decorations,&bsx,&bsy);//decoration_mode = !decoration_mode;
|
||||
if (sdl_key=='g')
|
||||
{
|
||||
if (sdl_mod & (KMOD_SHIFT))
|
||||
@ -3535,7 +3538,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
menu_ui_v3(vid_buf, active_menu, &sl, &sr, &dae, b, bq, x, y); //draw the elements in the current menu
|
||||
|
||||
draw_decorations(vid_buf,decorations);
|
||||
if (zoom_en && x>=sdl_scale*zoom_wx && y>=sdl_scale*zoom_wy //change mouse position while it is in a zoom window
|
||||
&& x<sdl_scale*(zoom_wx+ZFACTOR*ZSIZE)
|
||||
&& y<sdl_scale*(zoom_wy+ZFACTOR*ZSIZE))
|
||||
|
68
src/misc.c
68
src/misc.c
@ -552,5 +552,73 @@ int register_extension()
|
||||
#endif
|
||||
}
|
||||
|
||||
void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b)//convert 0-255 HSV values to 0-255 RGB
|
||||
{
|
||||
float hh, ss, vv, c, x;
|
||||
int m;
|
||||
hh = h/42.667f;//normalize values
|
||||
ss = s/256.0f;
|
||||
vv = v/256.0f;
|
||||
c = vv * ss;
|
||||
x = c * ( 1 - fabsf(fmod(hh,2.0) -1) );
|
||||
if(hh<1){
|
||||
*r = (int)(c*256.0);
|
||||
*g = (int)(x*256.0);
|
||||
*b = 0;
|
||||
}
|
||||
else if(hh<2){
|
||||
*r = (int)(x*256.0);
|
||||
*g = (int)(c*256.0);
|
||||
*b = 0;
|
||||
}
|
||||
else if(hh<3){
|
||||
*r = 0;
|
||||
*g = (int)(c*256.0);
|
||||
*b = (int)(x*256.0);
|
||||
}
|
||||
else if(hh<4){
|
||||
*r = 0;
|
||||
*g = (int)(x*256.0);
|
||||
*b = (int)(c*256.0);
|
||||
}
|
||||
else if(hh<5){
|
||||
*r = (int)(x*256.0);
|
||||
*g = 0;
|
||||
*b = (int)(c*256.0);
|
||||
}
|
||||
else if(hh<6){
|
||||
*r = (int)(c*256.0);
|
||||
*g = 0;
|
||||
*b = (int)(x*256.0);
|
||||
}
|
||||
m = (int)((vv-c)*256.0);
|
||||
*r += m;
|
||||
*g += m;
|
||||
*b += m;
|
||||
}
|
||||
|
||||
void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 HSV values to 0-255 RGB
|
||||
{
|
||||
float rr, gg, bb, a,x,c,d;
|
||||
rr = r/256.0f;//normalize values
|
||||
gg = g/256.0f;
|
||||
bb = b/256.0f;
|
||||
a = fmin(rr,gg);
|
||||
a = fmin(a,bb);
|
||||
x = fmax(rr,gg);
|
||||
x = fmax(x,bb);
|
||||
if (a==x)//greyscale
|
||||
{
|
||||
*h = 0;
|
||||
*s = 0;
|
||||
*v = a;
|
||||
}
|
||||
|
||||
c = (rr==a) ? gg-bb : ((bb==a) ? rr-gg : bb-rr);
|
||||
d = (rr==a) ? 3 : ((bb==a) ? 1 : 5);
|
||||
*h = (int)(42.667*(d - c/(x - a)));
|
||||
*s = (int)(256.0*((x - a)/x));
|
||||
*v = (int)(256.0*x);
|
||||
}
|
||||
vector2d v2d_zero = {0,0};
|
||||
matrix2d m2d_identity = {1,0,0,1};
|
||||
|
Reference in New Issue
Block a user