⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imgedit.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 3 页
字号:
        };
      };
    };
  };

  o->end_of_paint(o, r);

  imgedit_update_status(imgedit(o));
};

////////////////////////////////////////////////////////////////////////////////

void imgedit_save ( p_imgedit o, l_text filename, l_long quality ) {
  if ( o->filename ) _free(o->filename);
  o->filename = _strdup(filename);
  save_bitmap(filename, o->picture, NULL);
};

////////////////////////////////////////////////////////////////////////////////

void imgedit_load ( p_imgedit o, l_text filename ) {
  imgedit_reset(o);
  o->picture = load_image(filename);
  if ( o->filename ) _free(o->filename);
  o->filename = _strdup(filename);
  imgedit_undo_add(o);
  VIEW(o)->draw_me(VIEW(o));
};

////////////////////////////////////////////////////////////////////////////////

void imgedit_newbmp ( p_imgedit o, l_long width, l_long height ) {
  imgedit_reset(o);
  o->picture = create_bitmap(width,height);
  rectfill(o->picture, 0, 0, width, height, o->col2);
  imgedit_undo_add(o);
  VIEW(o)->draw_me(VIEW(o));
};

////////////////////////////////////////////////////////////////////////////////

void imgedit_newpts ( p_imgedit o, l_int x, l_int y, l_int oldx, l_int oldy, l_color wc1, l_color wc2, l_int bt ) {
  if ( !o || !o->zoom ) return;

  switch ( o->tool ) {
    case TOOL_ZOOM : {
      if ( !bt ) { o->zoom++; } else { if (o->zoom > 1) o->zoom--; };
      imgedit_settop ( o,
                       x - (((VIEW(o)->bounds.b.x - VIEW(o)->bounds.a.x) / o->zoom) / 2),
                       y - (((VIEW(o)->bounds.b.y - VIEW(o)->bounds.a.y) / o->zoom) / 2));
    }; break;
    case TOOL_GET : {
      if ( !bt )
        o->col1 = getpixel(o->picture, x, y);
      else
        o->col2 = getpixel(o->picture, x, y);
      VIEW(o->colsel)->draw_me(VIEW(o->colsel));
    }; break;
    case TOOL_POINT : {
      go_draw_point( o->picture, x, y, wc1 ,o->border,o->penstyle ,o->floodmode,o->floodlevel);
      imgedit_undo_add(o);
    }; break;
    case TOOL_FILL : {
      if ( o->floodstyle ) {
        if ( demon_bmp ) destroy_bitmap(demon_bmp);
        demon_bmp = create_bitmap(IMAGE_WIDTH(o->picture), IMAGE_HEIGHT(o->picture));
        rectfill(demon_bmp,0,0,IMAGE_WIDTH(demon_bmp), IMAGE_HEIGHT(demon_bmp),wc2);
        if (o->select == 1)
          x_gardient(demon_bmp,o->actsel.a.x,o->actsel.a.y,o->actsel.b.x,o->actsel.b.y,wc1,wc2,o->floodstyle-1,o->set1,o->set2);
        else
          x_gardient(demon_bmp,0,0,IMAGE_WIDTH(demon_bmp),IMAGE_HEIGHT(demon_bmp),wc1,wc2,o->floodstyle-1,o->set1,o->set2);
        wc1 = -1;
      };
      floodit( o->picture, x, y, wc1 ,o->floodtol);
      imgedit_undo_add(o);
    }; break;
    case TOOL_FORME : {
      if ( !o->editing )
        o->editing = 1;
      else {
        go_draw_it (o->picture,oldx,oldy, x , y , wc1, wc2,o->fillmode,o->border,o->forme,o->penstyle);
        o->editing = 0;
        imgedit_undo_add(o);
      };
    }; break;
    case TOOL_SELECT : { //select
      if ( !o->editing && !o->select && !bt) {
        o->editing = 1;
      } else if ( !o->select && !bt) {
        o->actsel = rect_assign(min(oldx,x),min(oldy,y),max(x,oldx),max(y,oldy));
        o->editing = 0;
        imgedit_change_select_mode ( o , 1 );
        imgedit_undo_add(o);
      } else if ( bt ) {
        imgedit_change_select_mode ( o , 0 );
        o->editing = 0;
        imgedit_undo_add(o);
      };
    }; break;
    case TOOL_TEXT : {
      l_text t = inputbox ("Tool Text","Text ?","");
      if ( !t ) return;
      imgedit_make_it_sel( o, make_bmp_with_text(t,wc1,VIEW(o)->font), x,y);
      o->tool = TOOL_SELECT;
      _free(t);
    }; break;
  };
};

////////////////////////////////////////////////////////////////////////////////

void imgedit_autopts ( p_imgedit o, l_int x, l_int y, l_int oldx, l_int oldy, l_color wc1, l_color wc2, l_int bt ) {
  if ( !o || !o->zoom ) return;
  o->pr = 1;
  switch ( o->tool ) {
    case TOOL_MOVE : {
      t_point m = VIEW(o)->get_local_point(VIEW(o), mouse->where);

      imgedit_settop( o, o->topx + (o->realold.x - m.x) / o->zoom,
                         o->topy + (o->realold.y - m.y) / o->zoom);
    }; break;
    case TOOL_POINT :
      go_draw_line ( o->picture, x, y, oldx, oldy, wc1, o->border, o->penstyle ,o->floodmode,o->floodlevel );
    break;
    case TOOL_SELECT : if ( !bt && 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) );
      rectfill(o->picture,r.a.x,r.a.y,r.b.x,r.b.y,makecol(255,0,255));
      r.a.x -= oldx - x;
      r.b.x -= oldx - x;
      r.a.y -= oldy - y;
      r.b.y -= oldy - y;
      draw_sprite(o->picture,o->selection ,r.a.x,r.a.y);
      o->actsel = r;
    }; break;
  };
};

////////////////////////////////////////////////////////////////////////////////

void imgedit_func_callback ( p_object o ) {
if ( o ) {
if ( imgedit(o)->editing ) {
t_point m = VIEW(o)->get_local_point(VIEW(o), mouse->where);
t_rect  r = VIEW(o)->get_local_extent(VIEW(o));
l_bool  c = 0;
t_point p = point_assign(imgedit(o)->topx,imgedit(o)->topy);

if ( is_b ( r.a.x, m.x, r.a.x + 20) ) { p.x-=2; c = 1; };
if ( is_b ( r.b.x - 20, m.x, r.b.x) ) { p.x+=2; c = 1; };

if ( is_b ( r.a.y, m.y, r.a.y + 20) ) { p.y-=2; c = 1; };
if ( is_b ( r.b.y - 20, m.y, r.b.y) ) { p.y+=2; c = 1; };

if ( c )  imgedit_settop(imgedit(o),p.x,p.y);
};
};
};
////////////////////////////////////////////////////////////////////////////////
void   imgedit_translate_event ( p_object o, t_event *event ) {
 if ( o ) {
   RETVIEW(o, event);

   if ( event->type & EV_MOUSE ) {  // MO_SF_MOUSELDOWN
     l_char ok = 0;

     if ( OBJECT(mouse)->state & MO_SF_MOUSELDOWN ) ok = 1;
     if ( OBJECT(mouse)->state & MO_SF_MOUSERDOWN ) ok = 2;

     if ( OBJECT(mouse)->state & MO_SF_MOUSELAUTO ) ok = 3;
     if ( OBJECT(mouse)->state & MO_SF_MOUSERAUTO ) ok = 4;

     if ( ok ) {

       p_imgedit vo = IMGEDIT(o);

       l_long    bt = ( ok == 2 || ok == 4 ) ? 1 : 0;

       t_point p   = imgedit_get_x_y(vo);

       clear_event(event);

       if (ok == 1) imgedit_newpts(vo, p.x, p.y, vo->oldx, vo->oldy, vo->col1, vo->col2, bt);
       if (ok == 2) imgedit_newpts(vo, p.x, p.y, vo->oldx, vo->oldy, vo->col2, vo->col1, bt);

       if ( vo->oldx != p.x || vo->oldy != p.y ) {

          if (ok == 3)
            imgedit_autopts(vo, p.x, p.y, vo->oldx, vo->oldy, vo->col1, vo->col2, bt);
          else if ( ok == 4 )
            imgedit_autopts(vo, p.x, p.y, vo->oldx, vo->oldy, vo->col2, vo->col1, bt);


          vo->oldx = p.x;
          vo->oldy = p.y;

          vo->realold  = VIEW(vo)->get_local_point(VIEW(vo), mouse->where);

          VIEW(o)->draw_me(VIEW(o));

        /*} else {

          VIEW(o)->draw_me(VIEW(o));*/

        };

      } else if ((OBJECT(mouse)->state & MO_SF_MOUSEMOVE) && imgedit(o)->editing ) {
        VIEW(o)->draw_me(VIEW(o));
        clear_event(event);
      };

      // if (OBJECT(mouse)->state & MO_SF_MOUSEMOVE) imgedit_update_status(imgedit(o));

      if ( OBJECT(mouse)->state & MO_SF_MOUSEUP && imgedit(o)->editing && imgedit(o)->pr == 1 ) {
        imgedit_undo_add(imgedit(o));
        imgedit(o)->pr = 0;
        clear_event(event);
      };
    };
  };
};

////////////////////////////////////////////////////////////////////////////////

p_colsel2   _colsel2_init ( p_colsel2 o, t_rect r )
{
  if ( !o ) return NULL;

  clear_type(o, sizeof(t_colsel2));

  view_init(VIEW(o), r);

  VIEW(o)->draw = &colsel2_draw;
  OBJECT(o)->translate_event = &colsel2_translate_event;

  OBJECT(o)->set_options(OBJECT(o), OB_OF_SELECTABLE+OB_OF_ENABLE, false);
  OBJECT(o)->set_options(OBJECT(o), OB_OF_STILLPROCESS, true);


  return o;

};

////////////////////////////////////////////////////////////////////////////////

p_imgedit   _imgedit_init ( p_imgedit o, t_rect r, p_colsel2 cc, p_stattext st  )
{
  if ( !o ) return NULL;

  clear_type(o, sizeof(t_imgedit));

  // Get some space for scrollbars
  // r.b.y -= 18;
  // r.b.x -= 18;

  view_init(VIEW(o), r);
  // Initialise ScrollBars ...
  // scroller_init(SCROLLER(o), r, SF_HORSCROLLBAR+SF_VERSCROLLBAR);

  VIEW(o)->draw = &imgedit_draw;
  VIEW(o)->set_mouse_cursor = &imgedit_update_mouse_cursor;

  OBJECT(o)->translate_event = &imgedit_translate_event;

  o->save       = &imgedit_save;
  o->load       = &imgedit_load;
  o->newbmp     = &imgedit_newbmp;
  o->col1       = COLOR(CO_BLACK);
  o->col2       = COLOR(CO_WHITE);
  o->border     = 1;
  o->fillmode   = FILL_NO;
  o->forme      = FORME_LINE;
  o->penstyle   = PEN_RECT;
  o->floodmode  = FLOOD_NO;
  o->floodlevel = 100;
  o->floodtol   = 0;
  o->tool       = TOOL_MOVE;

  imgedit_reset(o);
  //OBJECT(o)->func_callback = &imgedit_func_callback;
  OBJECT(o)->set_options(OBJECT(o), OB_OF_SELECTABLE+OB_OF_ENABLE, false);
  OBJECT(o)->set_options(OBJECT(o), OB_OF_STILLPROCESS, true);

  o->status = st;
  o->colsel = cc;
  if ( cc ) cc->imgedit = o;

  return o;

};

////////////////////////////////////////////////////////////////////////////////

void imgedit_xdl_init ( ) {

  img_bmps[0] = Get_Bitmap(COLORS);
  img_bmps[1] = Get_Bitmap(ZOOM_CUR);
  img_bmps[2] = Get_Bitmap(MOVE_CUR);
  img_bmps[3] = Get_Bitmap(PEN_CUR);
  img_bmps[4] = Get_Bitmap(FLOOD_CUR);
  img_bmps[5] = Get_Bitmap(TEXT_CUR);
  img_bmps[6] = Get_Bitmap(SELECT_CUR);
  img_bmps[7] = Get_Bitmap(RECT_CUR);
  img_bmps[8] = Get_Bitmap(LINE_CUR);
  img_bmps[9] = Get_Bitmap(OVAL_CUR);
  img_bmps[10] = Get_Bitmap(OVAL_CUR);

  init_imgfilters();

};

/*#include"imgedit.exp"

SetInfoAppName("Image Editor Control");
SetInfoDesciption("Image Editor Control used by The SIMP'");
SetInfoCopyright("(c) Copyright 2001 Point Mad. All rights reserved");
SetInfoManufacturer("Point Mad");

lib_begin ( void ) {
  if ( ap_process == AP_ALLOC ) {
    AP_EXPORTLIB();
  };
  if ( ap_process == AP_INIT ) {
      imgedit_xdl_init();
  };

  if ( ap_process == AP_DONE ) {

  };

} lib_end;*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -