screen_shot.cc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "device/event.hh"
  9. #include "video/display.hh"
  10. #include "device/device.hh"
  11. #include "image/image.hh"
  12. #include "quantize/histogram.hh"
  13. #include "quantize/median.hh"
  14. #include "loaders/tga_write.hh"
  15. #include "video/display.hh"
  16. #include "palette/pal.hh"
  17. #include "device/kernel.hh"
  18. #include "loaders/tga_write.hh"
  19. #include "app/app.hh"
  20. #include "device/keys.hh"
  21. class g1_screen_shot_watcher_class : public i4_event_handler_class
  22. {
  23. int num_shots;
  24. w16 key;
  25. public:
  26. g1_screen_shot_watcher_class()
  27. {
  28. key=I4_F2;
  29. i4_kernel.request_events(this, i4_device_class::FLAG_KEY_PRESS);
  30. num_shots = 0;
  31. }
  32. ~g1_screen_shot_watcher_class()
  33. {
  34. i4_kernel.unrequest_events(this, i4_device_class::FLAG_KEY_PRESS);
  35. }
  36. void save_shot()
  37. {
  38. i4_display_class *display=i4_current_app->get_display();
  39. if (display)
  40. {
  41. char outname[200];
  42. sprintf(outname, "shot%03d.tga", num_shots++);
  43. i4_file_class *fp=i4_open(outname, I4_WRITE);
  44. i4_image_class *screen=display->lock_frame_buffer(I4_BACK_FRAME_BUFFER, I4_FRAME_BUFFER_READ);
  45. if (screen)
  46. {
  47. i4_tga_write(screen, fp);
  48. display->unlock_frame_buffer(I4_BACK_FRAME_BUFFER);
  49. }
  50. delete fp;
  51. }
  52. }
  53. void receive_event(i4_event *ev)
  54. {
  55. if (ev->type()==i4_event::KEY_PRESS)
  56. {
  57. CAST_PTR(kev, i4_key_press_event_class, ev);
  58. if (kev->key == key)
  59. save_shot();
  60. }
  61. }
  62. char *name() { return "screen_shot watcher"; }
  63. };
  64. static g1_screen_shot_watcher_class *g1_screen_shot_instance=0;
  65. class g1_screen_shot_adder : public i4_init_class
  66. {
  67. public:
  68. void init() { g1_screen_shot_instance=new g1_screen_shot_watcher_class(); }
  69. void uninit() { delete g1_screen_shot_instance; g1_screen_shot_instance=0; }
  70. } g1_screen_shot_adder_instance;