📄 imgedit.c
字号:
if ( m ) {
blit(bmp,m,0,0,0,0,bmp->w,bmp->h);
return m;
};
return NULL;
};
return NULL;
};
#define mk_copy_of bmpdup
////////////////////////////////////////////////////////////////////////////////
void imgedit_undo_add ( p_imgedit o ) {
/*p_undoimgedit u = undoimgedit(_malloc(sizeof(t_undoimgedit)));
u->select = o->select;
u->actsel = o->actsel;
u->selection = mk_copy_of(o->selection);
u->picture = mk_copy_of(o->picture);
u->temp = mk_copy_of(o->temp);
list_insert (o->undolist, u ); */
};
////////////////////////////////////////////////////////////////////////////////
void imgedit_undo ( p_imgedit o ) {
/*if ( o->undolist->last ) {
l_int x = o->undolist->get_max_item(o->undolist);
p_undoimgedit u = undoimgedit( o->undolist->at( o->undolist, x ) );
o->select = u->select ;
o->actsel = u->actsel;
o->selection = mk_copy_of(u->selection);
o->picture = mk_copy_of(u->picture);
o->temp = mk_copy_of(u->temp);
o->undolist->free_index( o->undolist, x );
VIEW(o)->draw_me(VIEW(o));
};*/
};
////////////////////////////////////////////////////////////////////////////////
void imgedit_pcopy_act ( p_imgedit o, l_int action ) {
if ( action == PCOPY_COPY ) {
clear_type(&clipboard,sizeof(t_data));
clipboard.info_obj = OBJECT(o);
l_tag_cpy(clipboard.id, DAT_IMAGE);
if ( !o->select ) {
clipboard.data = (void *)bmpdup(o->picture);
} else {
clipboard.data = (void *)bmpdup(o->selection);
};
} else if (action == PCOPY_PASTASNEWPIC ) {
if ( l_tag_cmp(DAT_IMAGE, clipboard.id) ) {
imgedit_reset( o );
o->picture = mk_copy_of(clipboard.data);
VIEW(o)->draw_me(VIEW(o));
};
} else if (action == PCOPY_PASTASNEWSEL ) {
if ( l_tag_cmp(DAT_IMAGE, clipboard.id) ) {
imgedit_make_it_sel ( o, bmpdup(clipboard.data), 0, 0 );
VIEW(o)->draw_me(VIEW(o));
};
};
};
////////////////////////////////////////////////////////////////////////////////
void imgedit_make_it_sel ( p_imgedit o, BITMAP *bmp, l_int x , l_int y ) {
t_rect r = rect_assign( x, y, x + bmp->w, y + bmp->h );
if ( o->selection ) destroy_bitmap(o->selection);
if ( o->temp ) destroy_bitmap(o->temp);
o->temp = bmpdup(o->picture);
o->selection = bmpdup(bmp);
rectfill(o->picture,0,0,IMAGE_WIDTH(o->picture),IMAGE_HEIGHT(o->picture),makecol(255,0,255));
draw_sprite(o->picture,o->selection,r.a.x,r.a.y);
o->actsel = r;
o->select = 1;
imgedit_undo_add(o);
};
////////////////////////////////////////////////////////////////////////////////
void imgedit_change_select_mode ( p_imgedit o, l_int newvalue ) {
if ( newvalue && !o->select ) {
t_rect r = o->actsel;
if ( o->selection ) destroy_bitmap(o->selection);
o->selection = create_bitmap(abs(r.a.x-r.b.x),abs(r.a.y-r.b.y));
blit(o->picture,o->selection,r.a.x,r.a.y,0,0,abs(r.a.x-r.b.x),abs(r.a.y-r.b.y));
if ( o->temp ) destroy_bitmap(o->temp);
o->temp = create_bitmap(IMAGE_WIDTH(o->picture),IMAGE_HEIGHT(o->picture));
blit(o->picture,o->temp,0,0,0,0,IMAGE_WIDTH(o->picture),IMAGE_HEIGHT(o->picture));
rectfill(o->temp,r.a.x,r.a.y,r.b.x-1,r.b.y-1,o->temp->vtable->mask_color);
clear_to_color(o->picture,o->picture->vtable->mask_color);
draw_sprite(o->picture,o->selection,r.a.x,r.a.y);
o->select = 1;
} else if ( !newvalue && o->select ) {
t_rect r = o->actsel;
t_rect u = rect_assign( max(r.a.x, 0),
max(r.a.y, 0),
min(r.b.x, IMAGE_WIDTH( o->picture )),
min(r.b.y, IMAGE_HEIGHT( o->picture )) );
blit( o->picture, o->selection, u.a.x, u.a.y, abs(r.a.x - u.a.x), abs(r.a.y - u.a.y), abs(u.a.x - u.b.x), abs(u.a.y - u.b.y) );
blit(o->temp,o->picture,0,0,0,0,IMAGE_WIDTH(o->temp),IMAGE_HEIGHT(o->temp));
draw_sprite(o->picture,o->selection,r.a.x,r.a.y);
o->select = 0;
if ( o->selection ) {
destroy_bitmap(o->selection);
o->selection = NULL;
};
if ( o->temp ) {
destroy_bitmap(o->temp);
o->temp = NULL;
};
};
};
////////////////////////////////////////////////////////////////////////////////
t_point imgedit_get_x_y ( p_imgedit o ) {
if ( o && o->zoom ) {
t_point p = VIEW(o)->get_local_point(VIEW(o), mouse->where);
return point_assign( (p.x / o->zoom ) + o->topx, (p.y / o->zoom ) + o->topy );
} else
return point_assign(0,0);
};
////////////////////////////////////////////////////////////////////////////////
void imgedit_update_mouse ( p_imgedit o ) {
BITMAP *bmp = NULL;
if (o->tool == TOOL_ZOOM) bmp = TOOL_ZOOM_CUR;
else if (o->tool == TOOL_GET) bmp = TOOL_GET_CUR;
else if (o->tool == TOOL_POINT) bmp = TOOL_POINT_CUR;
else if (o->tool == TOOL_FILL) bmp = TOOL_FILL_CUR;
else if (o->tool == TOOL_TEXT) bmp = TOOL_TEXT_CUR;
else if (o->tool == TOOL_SELECT) bmp = TOOL_SELECT_CUR;
else if (o->tool == TOOL_FORME) {
if (o->forme == FORME_RECT) bmp = FORME_RECT_CUR;
else if (o->forme == FORME_LINE) bmp = FORME_LINE_CUR;
else if (o->forme == FORME_OVAL) bmp = FORME_OVAL_CUR;
else if (o->forme == FORME_CIRCLE) bmp = FORME_CIRCLE_CUR;
};
if ( bmp ) {
VIEW(o)->cursor = -1;
if ( !is_same_bitmap(bmp, mouse_sprite ) ) {
set_mouse_sprite(bmp);
set_mouse_sprite_focus(2,2);
};
} else {
VIEW(o)->cursor = CUR_ARROW;
mouse_set_sys_cursor(CUR_ARROW);
};
};
////////////////////////////////////////////////////////////////////////////////
void imgedit_update_mouse_cursor ( p_view o ) {
imgedit_update_mouse(imgedit(o));
};
////////////////////////////////////////////////////////////////////////////////
void imgedit_update_status ( p_imgedit o ) {
if ( o->status ) {
t_point p = imgedit_get_x_y(o);
if ( !o->editing ) {
o->status->set_text(o->status, "(%d,%d) - zoom : x%d - tool : %d - border : %d - image : %d x %d",p.x,p.y,o->zoom,o->tool,o->border,IMAGE_WIDTH(o->picture),IMAGE_HEIGHT(o->picture));
} else {
o->status->set_text(o->status, "(%d,%d) -> (%d,%d) - zoom : x%d - tool : %d - border : %d - image : %d x %d",o->oldx,o->oldy,p.x,p.y,o->zoom,o->tool,o->border,IMAGE_WIDTH(o->picture),IMAGE_HEIGHT(o->picture));
};
};
};
////////////////////////////////////////////////////////////////////////////////
#ifndef st_b
#define st_b( a, b, c ) if ( b < a ) b = a; if ( c < b ) b = c;
#endif
void imgedit_settop ( p_imgedit o, l_int x, l_int y) {
if ( o && o->zoom ) {
t_rect r = VIEW(o)->get_local_extent(VIEW(o));
l_int img_w = IMAGE_WIDTH(o->picture);
l_int img_h = IMAGE_HEIGHT(o->picture);
l_int v_w = r.b.x / o->zoom;
l_int v_h = r.b.y / o->zoom;
l_int maxx = img_w - v_w + 10;
l_int maxy = img_h - v_h + 10;
l_int minx = - 10 ;
l_int miny = - 10 ;
if ( img_w > v_w ) {
st_b ( minx, x, maxx )
o->topx = x;
} else {
o->topx = -(v_w - img_w) / 2;
};
if ( img_h > v_h ) {
st_b ( miny, y, maxy )
o->topy = y;
} else {
o->topy = -(v_h - img_h) / 2;
};
};
};
////////////////////////////////////////////////////////////////////////////////
void imgedit_draw ( p_view o )
{
t_rect r = o->get_local_extent(o);
t_point p;
BITMAP *out = o->begin_paint(o, &p, r);
if ( out ) {
l_int f = 0;
l_int max = ((max(r.b.x,r.b.y)/10)*10)+10;
l_color bc = color_flat_face;
l_color lc = color_3d_face;
rectfill(out, p.x+r.a.x, p.y+r.a.y, p.x + r.b.x, p.y + r.b.y, bc);
set_clip(out, p.x+r.a.x, p.y+r.a.y, p.x + r.b.x, p.y + r.b.y);
while ( f < max ) {
line( out, p.x + f , p.y, p.x + max , p.y + max - f, lc );
line( out, p.x, p.y + f, p.x + max - f, p.y + max, lc );
line( out, p.x + f , p.y, p.x , p.y + f, lc );
line( out, p.x + f , p.y + max, p.x + max, p.y + f , lc );
f += 10;
};
textout_draw_rect(out, font_system, "SIMP' 0.1 by Julien Etelain", -1, r.a.x+p.x, r.a.y+p.y,
r.b.x+p.x, r.b.y+p.y, TX_ALIGN_DEFAULT, lc, bc, 0);
if ( imgedit(o)->picture ) {
imgedit_settop( imgedit(o), imgedit(o)->topx, imgedit(o)->topy );
if ( imgedit(o)->select )
stretch_sprite(out, imgedit(o)->temp, p.x - (imgedit(o)->topx * imgedit(o)->zoom),
p.y - (imgedit(o)->topy * imgedit(o)->zoom),
IMAGE_WIDTH(imgedit(o)->temp) * imgedit(o)->zoom,
IMAGE_HEIGHT(imgedit(o)->temp)* imgedit(o)->zoom);
stretch_sprite(out, imgedit(o)->picture , p.x - (imgedit(o)->topx * imgedit(o)->zoom),
p.y - (imgedit(o)->topy * imgedit(o)->zoom),
IMAGE_WIDTH(imgedit(o)->picture) * imgedit(o)->zoom,
IMAGE_HEIGHT(imgedit(o)->picture)* imgedit(o)->zoom);
rect(out, (p.x - (imgedit(o)->topx * imgedit(o)->zoom)) - 1,
(p.y - (imgedit(o)->topy * imgedit(o)->zoom)) - 1,
(p.x - (imgedit(o)->topx * imgedit(o)->zoom)) + (IMAGE_WIDTH(imgedit(o)->picture) * imgedit(o)->zoom),
(p.y - (imgedit(o)->topy * imgedit(o)->zoom)) + (IMAGE_HEIGHT(imgedit(o)->picture) * imgedit(o)->zoom), lc);
if ( imgedit(o)->zoom >= 10 ) { // Auto - Grid
l_int tx = max(p.x,(p.x + r.a.x - (imgedit(o)->topx * imgedit(o)->zoom)));
l_int ty = max(p.y,(p.y + r.a.y - (imgedit(o)->topy * imgedit(o)->zoom)));
l_int x = tx;
l_int y = ty;
l_int bx = min(r.b.x + p.x, (p.x + r.a.x - (imgedit(o)->topx * imgedit(o)->zoom)) + (IMAGE_WIDTH(imgedit(o)->picture) * imgedit(o)->zoom));
l_int by = min(r.b.y + p.y, (p.y + r.a.y - (imgedit(o)->topy * imgedit(o)->zoom)) + (IMAGE_HEIGHT(imgedit(o)->picture) * imgedit(o)->zoom));
while ( x <= bx ) {
vline (out,x,ty,by,lc);
x += imgedit(o)->zoom;
};
while ( y <= by ) {
hline (out,tx,y,bx,lc);
y += imgedit(o)->zoom;
};
};
if ( imgedit(o)->select ) {
p_imgedit vo = IMGEDIT(o);
t_rect b = vo->actsel;
rect( out, p.x + (b.a.x * vo->zoom) - (vo->topx * vo->zoom) - 1,
p.y + (b.a.y * vo->zoom) - (vo->topy * vo->zoom) - 1,
p.x + (b.b.x * vo->zoom) - (vo->topx * vo->zoom),
p.y + (b.b.y * vo->zoom) - (vo->topy * vo->zoom), color_selected_face );
};
if ( imgedit(o)->editing ) {
p_imgedit vo = IMGEDIT(o);
l_int d = vo->zoom / 2;
l_int x = (vo->oldx * vo->zoom) + p.x + r.a.x - (vo->topx * vo->zoom) + d;
l_int y = (vo->oldy * vo->zoom) + p.y + r.a.y - (vo->topy * vo->zoom) + d;
t_point pe = imgedit_get_x_y(vo);
l_color wc1 = vo->col1;
l_color wc2 = vo->col2;
pe.x = pe.x * vo->zoom - (vo->topx * vo->zoom) + d;
pe.y = pe.y * vo->zoom - (vo->topy * vo->zoom) + d;
if ( vo->bt == 1) {
wc1 = vo->col2;
wc2 = vo->col1;
};
if ( vo-> tool == TOOL_FORME )
go_draw_it (out,x,y, p.x + pe.x , p.y + pe.y , wc1, wc2,0,1, vo->forme,PEN_RECT);
else if ( vo->tool == TOOL_SELECT ) {
t_point pb = imgedit_get_x_y(vo);
t_rect b = rect_assign(vo->oldx,vo->oldy,pb.x,pb.y);
rect( out, p.x + (min(b.a.x,b.b.x) * vo->zoom) - (vo->topx * vo->zoom) - 1,
p.y + (min(b.a.y,b.b.y) * vo->zoom) - (vo->topy * vo->zoom) - 1,
p.x + (max(b.a.x,b.b.x) * vo->zoom) - (vo->topx * vo->zoom),
p.y + (max(b.a.y,b.b.y) * vo->zoom) - (vo->topy * vo->zoom), color_selected_face );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -