source: golgotha/src/i4/gui/image_win.cc @ 608

Last change on this file since 608 was 80, checked in by Sam Hocevar, 15 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.2 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 "gui/image_win.hh"
10
11#include "window/window.hh"
12#include "window/win_evt.hh"
13
14#include "image/image.hh"
15
16
17void i4_image_window_class::reparent(i4_image_class *draw_area, i4_parent_window_class *parent)
18{
19  if (draw_area)
20  {
21    if (darken_im)
22      delete darken_im;
23
24    if (darken && im)
25    {
26      int x,y, w=im->width(), h=im->height();
27     
28      i4_image_class *d=i4_create_image(w, h, draw_area->get_pal());
29
30      for (y=0; y<h; y++)
31        for (x=0; x<w; x++)
32        {
33          i4_color c=im->get_pixel(x,y);
34          int r= (((c>>16)&0xff)*3/4)<<16;
35          int g= (((c>>8)&0xff)*3/4)<<8;
36          int b= (((c>>0)&0xff)*3/4)<<0;
37
38          d->put_pixel(x,y, r|g|b);
39        }
40
41      darken_im=d;
42
43     
44    }
45    else darken_im=0;
46  }
47  i4_parent_window_class::reparent(draw_area, parent);
48}
49
50
51void i4_image_window_class::change_image(i4_image_class *new_im)
52{
53  if (del && im)
54    delete im;
55
56  im = new_im;
57  reparent(local_image, parent);
58}
59
60
61i4_image_window_class::i4_image_window_class(i4_image_class *im,
62                                             i4_bool delete_on_destructor,
63                                             i4_bool dark_when_not_active)
64  : i4_parent_window_class(im->width(),im->height()),
65    im(im),
66    del(delete_on_destructor),
67    darken(dark_when_not_active)
68{
69  active=i4_F;
70  darken_im=0;
71}
72
73void i4_image_window_class::parent_draw(i4_draw_context_class &context)
74{
75  if (darken && !active && darken_im)
76    darken_im->put_image(local_image, 0,0, context);
77  else
78  {
79    i4_rect_list_class child_clip(&context.clip,0,0);
80    child_clip.intersect_list(&undrawn_area);
81
82    child_clip.swap(&context.clip);
83
84 
85    for (i4_rect_list_class::area_iter c=context.clip.list.begin();c!=context.clip.list.end();++c)
86      im->put_part(local_image, c->x1, c->y1, c->x1, c->y1, c->x2, c->y2, context);
87
88   
89    child_clip.swap(&context.clip);
90    i4_parent_window_class::parent_draw(context);
91
92  }
93
94}
95
96void i4_image_window_class::receive_event(i4_event *ev)
97{
98  CAST_PTR(wev, i4_window_message_class, ev);
99  if (ev->type()==i4_event::WINDOW_MESSAGE &&
100      wev->sub_type==i4_window_message_class::GOT_MOUSE_FOCUS)
101  {
102    active=i4_T;
103    if (darken && darken_im)
104      request_redraw(i4_F);
105  }
106  else if (ev->type()==i4_event::WINDOW_MESSAGE &&
107           wev->sub_type==i4_window_message_class::LOST_MOUSE_FOCUS)
108  {
109    active=i4_F;
110    if (darken && darken_im)
111      request_redraw(i4_F);
112
113  }
114 
115  i4_parent_window_class::receive_event(ev);
116}
117
118i4_image_window_class::~i4_image_window_class()
119{
120  if (del && im)
121    delete im;
122  if (darken_im)
123    delete darken_im;
124}
125
Note: See TracBrowser for help on using the repository browser.