/* 25.02.2000 - Bad Sector

     * Save to... dialog box added
     * Double buffer used for faster saving
     * Desktop's bounds used for smaller file size (old version's files
       was always 2048x2048)

*/

/*
   SAVESCR.C

	Copyright 1999 (c) by Michal Stencl

	stenclpmd@ba.telecom.sk
*/

/*
 - save screen = ALT+F8
*/

#include"allegro.h"
#include"seal.h"
#include"iodlg.h"

static p_list get_file_items()
{
  p_list p = list_init(malloc(sizeof(t_list)), &free_filehistory_item, 0);
  if (p) {
    p->insert(p, new_filehistory_item("BMP files", "*.bmp"));
    p->insert(p, new_filehistory_item("JPG files", "*.bmp"));
  };
  return p;
}

void  trans_ev ( p_object o, p_event event ) {

   if ( keyb->code == TO_ALT(KB_F8) ) {

       l_text file;
       t_rect r = desktop->get_local_extent(desktop);
       BITMAP *sbuff = create_bitmap(r.b.x+1, r.b.y+1);

       blit(screen, sbuff, 0, 0, 0, 0, r.b.x+1, r.b.y+1);

       file = save_dialog("./", "*.*", get_file_items());

//       set_clip(screen, 0, 0, SCREEN_W, SCREEN_H);

       save_bitmap(file, sbuff, NULL);

       destroy_bitmap(sbuff);

       free(file);

   };

};



app_begin ( void ) {


  if ( ap_process == AP_INIT ) {

     t_object *o = obj_init(_malloc(sizeof(t_object)));

     o->translate_event = &trans_ev;

     OBJECT(drivers)->insert(OBJECT(drivers), o);

  };

} app_end;

