source: golgotha/src/golg/editor/commands/terrain_bitmap.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: 5.1 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 "file/get_filename.hh"
10#include "editor/editor.hh"
11#include "gui/create_dialog.hh"
12#include "mess_id.hh"
13#include "loaders/load.hh"
14#include "image/image32.hh"
15#include "loaders/tga_write.hh"
16#include "status/status.hh"
17#include "editor/e_res.hh"
18#include "map_vert.hh"
19
20void g1_editor_class::load_height_bitmap()
21{
22  i4_create_file_open_dialog(style,
23                             g1_ges("load_height_map_title"),
24                             g1_ges("load_height_start_dir"),
25                             g1_ges("load_height_file_mask"),
26                             g1_ges("load_height_mask_name"),
27                             this,
28                             G1_EDITOR_LOAD_TERRAIN_HEIGHT_OK,
29                             G1_EDITOR_NO_OP);
30}
31
32void g1_editor_class::save_height_bitmap()
33{
34  if (get_map())
35  {
36    i4_filename_struct fn;
37    i4_split_path(get_map()->get_filename(), fn);
38
39    char dname[256];
40    sprintf(dname, "%s.tga", fn.filename);
41   
42    i4_create_file_save_dialog(style,
43                               dname,
44                               g1_ges("save_height_map_title"),
45                               g1_ges("save_height_start_dir"),
46                               g1_ges("save_height_file_mask"),
47                               g1_ges("save_height_mask_name"),
48                               this,
49                               G1_EDITOR_SAVE_TERRAIN_HEIGHT_OK,
50                               G1_EDITOR_NO_OP);
51  }
52}
53
54
55void g1_editor_class::save_height_bitmap_ok(i4_event *ev)
56{
57  int i;
58  CAST_PTR(fo, i4_file_open_message_class, ev);
59 
60  if (fo->filename && get_map())
61  {
62    i4_file_class *fp=i4_open(*fo->filename, I4_WRITE);
63    if (!fp)
64    {
65      create_modal(500, 100, "save_height_bad_file_tile");
66      i4_create_dialog(g1_ges("save_height_bad_file_dialog"),
67                         modal_window.get(), style, fo->filename,
68                         this, G1_EDITOR_MODAL_BOX_CANCEL);
69    }
70    else
71    {
72      i4_pixel_format fmt;
73      fmt.default_format();
74     
75      const i4_pal *pal=i4_pal_man.register_pal(&fmt);
76
77      int mw=get_map()->width()+1, mh=get_map()->height()+1;
78
79      i4_image_class *im=i4_create_image(mw, mh, pal);
80      w32 *i32=(w32 *)im->data;
81
82      g1_map_vertex_class *v=get_map()->verts;
83      int x,y;
84      for (y=0; y<mh; y++)
85        for (x=0; x<mw; x++, v++)
86        {
87          *i32=get_map()->vertex(x,mh-y-1)->height;
88          i32++;
89        }
90
91
92      i4_tga_write(im,fp);
93      delete fp;
94      delete im;
95
96    }
97  }
98}
99
100
101
102
103void g1_editor_class::load_height_bitmap_ok(i4_event *ev)
104{
105  int i;
106  CAST_PTR(fo, i4_file_open_message_class, ev);
107 
108  if (fo->filename && get_map())
109  {
110    int mw=get_map()->width()+1, mh=get_map()->height()+1;
111
112   
113    i4_status_class *stat=i4_create_status(g1_ges("loading_terrain_bitmap"));
114
115    i4_image_class *im=i4_load_image(*fo->filename, stat);
116
117    if (stat)
118      delete stat;
119
120   
121
122    if (im)
123    {
124
125      if (im->width()!=mw && im->height()!=mh)
126      {
127        create_modal(500, 100, "load_height_bad_size_title");
128        i4_create_dialog(g1_ges("load_height_bad_size_dialog"),
129                         modal_window.get(), style, fo->filename,
130                         im->width(), im->height(), get_map()->width()+1, get_map()->height()+1,
131                         this, G1_EDITOR_MODAL_BOX_CANCEL);
132        delete im;
133      }
134      else
135      {
136        i4_status_class *stat=i4_create_status(g1_ges("applying_terrain_map"));
137
138        const i4_pixel_format *fmt=&im->get_pal()->source;
139        i4_draw_context_class c(0,0,mw-1, mh-1);
140        g1_map_vertex_class *v=get_map()->verts;
141
142        g1_object_class *olist[G1_MAX_OBJECTS];
143        sw32 t=get_map()->make_object_list(olist, G1_MAX_OBJECTS);
144        for (i=0; i<t; i++)
145          olist[i]->unoccupy_location();
146
147        int x,y;
148        for (y=0; y<mh; y++)
149        {
150          if (stat)
151            stat->update(y/(float)mh);
152
153          for (x=0; x<mw; x++, v++)
154          {
155            w8 h=i4_pal_man.convert_32_to(im->get_pixel(x,y,c), fmt) & 0xff;
156            get_map()->change_vert_height(x,mh-y-1, h);
157          }
158         
159        }
160
161        if (stat)
162          delete stat;
163        delete im;
164
165        for (i=0; i<t; i++)
166          olist[i]->occupy_location();
167      }
168    }
169    else
170    {
171      create_modal(500, 100, "couldn't_load_image_title");
172      i4_create_dialog(g1_ges("couldn't_load_image_dialog"),
173                       modal_window.get(), style, fo->filename, this, G1_EDITOR_MODAL_BOX_CANCEL);
174    }
175  }
176}
Note: See TracBrowser for help on using the repository browser.