source: golgotha/src/i4/menu/image_item.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 12 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.4 KB
Line 
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
9#include "menu/image_item.hh"
10#include "image/image.hh"
11
12i4_image_item_class::i4_image_item_class(const i4_const_str *context_help,
13                                         i4_image_class *normal_image,
14                                         i4_graphical_style_class *style,
15                                         i4_image_class *active_image,     // if 0, then image will brighten
16                                         i4_bool delete_images_on_death,
17                                         i4_event_reaction_class *press,
18                                         i4_event_reaction_class *depress,
19                                         i4_event_reaction_class *activate,
20                                         i4_event_reaction_class *deactivate)
21
22  : i4_menu_item_class(context_help, style, normal_image->width(),
23                       normal_image->height(), press,depress,activate,deactivate)
24{
25  I4_ASSERT(normal_image, "no normal");
26
27  im=normal_image;
28
29  del_im=delete_images_on_death;
30
31  if (active_image)
32  {
33    act=active_image;
34    del_act=delete_images_on_death;
35  }
36  else
37  {
38    del_act=i4_T;
39
40
41
42    int w=im->width(), h=im->height();
43    act=i4_create_image(w,h, im->pal);
44
45
46    for (int y=0; y<h; y++)
47      for (int x=0; x<w; x++)
48      {
49        w32 c=im->get_pixel(x,y);
50        int r=((c&0xff0000)>>16)<<1;  if (r>255) r=255;
51        int g=((c&0xff00)>>8)<<1;    if (g>255) g=255;
52        int b=((c&0xff)>>0)<<1;      if (b>255) b=255;
53       
54        act->put_pixel(x,y, (r<<16)|(g<<8)|b);
55      }
56
57
58
59  }
60 
61 
62}
63
64
65i4_image_item_class::~i4_image_item_class()
66{
67  if (del_im)
68    delete im;
69 
70  if (del_act)
71    delete act;
72}
73
74void i4_image_item_class::parent_draw(i4_draw_context_class &context)
75{
76  if (active)
77    act->put_image(local_image,0,0,context);
78  else
79    im->put_image(local_image,0,0,context);
80
81}
82
83void i4_image_item_class::receive_event(i4_event *ev)
84{
85  if (ev->type()==i4_event::MOUSE_BUTTON_DOWN)
86  {
87    CAST_PTR(b,i4_mouse_button_down_event_class,ev);
88    if (b->but==i4_mouse_button_down_event_class::LEFT)
89    {       
90      do_press();
91      send_event(send.press, PRESSED);
92
93      do_depress();
94      send_event(send.depress, DEPRESSED);
95
96    } else i4_menu_item_class::receive_event(ev);
97  }
98  else i4_menu_item_class::receive_event(ev);
99}
100
101
102i4_menu_item_class *i4_image_item_class::copy()
103{
104  return new i4_image_item_class(context_help,
105                                 im->copy(),
106                                 hint,
107                                 act->copy(),
108                                 i4_T,
109                                 send.press ? send.press->copy() : 0,
110                                 send.depress ? send.depress->copy() : 0,
111                                 send.activate ? send.activate->copy() : 0,
112                                 send.deactivate ? send.deactivate->copy() : 0);
113}
Note: See TracBrowser for help on using the repository browser.