image_item.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "menu/image_item.hh"
  9. #include "image/image.hh"
  10. i4_image_item_class::i4_image_item_class(const i4_const_str *context_help,
  11. i4_image_class *normal_image,
  12. i4_graphical_style_class *style,
  13. i4_image_class *active_image, // if 0, then image will brighten
  14. i4_bool delete_images_on_death,
  15. i4_event_reaction_class *press,
  16. i4_event_reaction_class *depress,
  17. i4_event_reaction_class *activate,
  18. i4_event_reaction_class *deactivate)
  19. : i4_menu_item_class(context_help, style, normal_image->width(),
  20. normal_image->height(), press,depress,activate,deactivate)
  21. {
  22. I4_ASSERT(normal_image, "no normal");
  23. im=normal_image;
  24. del_im=delete_images_on_death;
  25. if (active_image)
  26. {
  27. act=active_image;
  28. del_act=delete_images_on_death;
  29. }
  30. else
  31. {
  32. del_act=i4_T;
  33. int w=im->width(), h=im->height();
  34. act=i4_create_image(w,h, im->pal);
  35. for (int y=0; y<h; y++)
  36. for (int x=0; x<w; x++)
  37. {
  38. w32 c=im->get_pixel(x,y);
  39. int r=((c&0xff0000)>>16)<<1; if (r>255) r=255;
  40. int g=((c&0xff00)>>8)<<1; if (g>255) g=255;
  41. int b=((c&0xff)>>0)<<1; if (b>255) b=255;
  42. act->put_pixel(x,y, (r<<16)|(g<<8)|b);
  43. }
  44. }
  45. }
  46. i4_image_item_class::~i4_image_item_class()
  47. {
  48. if (del_im)
  49. delete im;
  50. if (del_act)
  51. delete act;
  52. }
  53. void i4_image_item_class::parent_draw(i4_draw_context_class &context)
  54. {
  55. if (active)
  56. act->put_image(local_image,0,0,context);
  57. else
  58. im->put_image(local_image,0,0,context);
  59. }
  60. void i4_image_item_class::receive_event(i4_event *ev)
  61. {
  62. if (ev->type()==i4_event::MOUSE_BUTTON_DOWN)
  63. {
  64. CAST_PTR(b,i4_mouse_button_down_event_class,ev);
  65. if (b->but==i4_mouse_button_down_event_class::LEFT)
  66. {
  67. do_press();
  68. send_event(send.press, PRESSED);
  69. do_depress();
  70. send_event(send.depress, DEPRESSED);
  71. } else i4_menu_item_class::receive_event(ev);
  72. }
  73. else i4_menu_item_class::receive_event(ev);
  74. }
  75. i4_menu_item_class *i4_image_item_class::copy()
  76. {
  77. return new i4_image_item_class(context_help,
  78. im->copy(),
  79. hint,
  80. act->copy(),
  81. i4_T,
  82. send.press ? send.press->copy() : 0,
  83. send.depress ? send.depress->copy() : 0,
  84. send.activate ? send.activate->copy() : 0,
  85. send.deactivate ? send.deactivate->copy() : 0);
  86. }