source: golgotha/src/test/cloud_test/cloud_test.cc @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 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: 2.3 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 "window/window.hh"
10#include "app/app.hh"
11#include "main/main.hh"
12#include "window/style.hh"
13#include "file/file.hh"
14#include "loaders/load.hh"
15#include "window/wmanager.hh"
16#include "math/transform.hh"
17#include "gui/text.hh"
18#include "gui/button.hh"
19#include "loaders/load.hh"
20
21
22// merge test
23// merge test 2.5
24
25float interp(float c1, float c2, float r)
26{
27  return (c1-c2)*r+c2;
28}
29
30
31class test_win_class : public i4_window_class
32
33  i4_image_class *cloud;
34  float cx,cy;
35public:
36
37  test_win_class(w16 w, w16 h)
38    : i4_window_class(w,h) 
39  {
40    cloud=i4_load_image("cloud.tga");
41    cx=cy=5;
42  }
43
44  void draw(i4_draw_context_class &context)
45  {
46    local_image->clear(0,context);
47
48
49    float rx=(cx-(int)cx), ry=(cy-(int)cy);
50
51    w32 *d=(w32 *)cloud->data;
52    int w=cloud->width(), h=cloud->height();
53
54    int dx=(int)cx, dy=(int)cy;
55
56    for (int y=0; y<h; y++)
57      for (int x=0; x<w; x++)
58      {
59        float x1=interp(d[0]&0xff, d[1]&0xff, rx);
60        float x2=interp(d[w]&0xff, d[w+1]&0xff, rx);
61        int yc=(int)interp(x1,x2, ry);
62       
63        local_image->put_pixel(dx+x, dy+y,  yc|(yc<<8)|(yc<<16));               
64        d++;
65      }
66
67   
68
69    cx+=0.1;
70    cy+=0.2;
71
72    request_redraw();
73  }
74 
75  char *name() { return "test_win"; }
76};
77
78class test_app : public i4_application_class
79{
80public:
81  enum { QUIT };
82
83  void init()
84  {
85    i4_application_class::init();
86    get_window_manager()->add_child(0,0, new test_win_class(300,300));
87
88  } 
89
90
91  void receive_event(i4_event *ev)
92  {
93    if (ev->type()==i4_event::USER_MESSAGE && ((i4_user_message_event_class *)ev)->sub_type==QUIT)
94      quit();
95    else
96      i4_application_class::receive_event(ev);
97  }
98
99
100
101  char *name() { return "test_app"; }
102};
103
104void i4_main(w32 argc, i4_const_str *argv)
105{
106  test_app test;
107  test.run();
108}
109
Note: See TracBrowser for help on using the repository browser.