OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
mattexview.c
Go to the documentation of this file.
1 /*
2  * mape - C4 Landscape.txt editor
3  *
4  * Copyright (c) 2005-2009, Armin Burgmeier
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #include <stdlib.h>
17 #include <gtk/gtk.h>
18 #include "mape/material.h"
19 #include "mape/texture.h"
20 #include "mape/fileicon.h"
21 #include "mape/iconview.h"
22 #include "mape/mattexview.h"
23 
25  GError** error)
26 {
27  MapeMatTexView* view;
28  view = malloc(sizeof(MapeMatTexView) );
29 
30  view->mat_map = NULL;
31  view->tex_map = NULL;
32  view->icon_set = icon_set;
33 
34  view->view_mat = mape_icon_view_new(error);
35  if(view->view_mat == NULL)
36  {
37  free(view);
38  return NULL;
39  }
40 
41  view->view_tex = mape_icon_view_new(error);
42  if(view->view_tex == NULL)
43  {
45  free(view);
46  return NULL;
47  }
48 
49  view->notebook = gtk_notebook_new();
50 
51  gtk_notebook_append_page(
52  GTK_NOTEBOOK(view->notebook),
53  view->view_mat->window,
54  NULL
55  );
56 
57  gtk_notebook_set_tab_label_text(
58  GTK_NOTEBOOK(view->notebook),
59  view->view_mat->window,
60  "Materials"
61  );
62 
63  gtk_notebook_append_page(
64  GTK_NOTEBOOK(view->notebook),
65  view->view_tex->window,
66  NULL
67  );
68 
69  gtk_notebook_set_tab_label_text(
70  GTK_NOTEBOOK(view->notebook),
71  view->view_tex->window,
72  "Textures"
73  );
74 
75  gtk_widget_set_size_request(view->notebook, -1, 150);
76  gtk_widget_show(view->notebook);
77  return view;
78 }
79 
81 {
82  if(view->mat_map != NULL)
83  g_object_unref(view->mat_map);
84  if(view->tex_map != NULL)
85  g_object_unref(view->tex_map);
86 
89 
90  free(view);
91 }
92 
94  MapeTextureMap* new_tex_map,
95  MapeGroup* base_group,
96  gboolean overload_materials,
97  gboolean overload_textures,
98  MapeGroup* overload_from,
99  GError** error)
100 {
101  MapeMaterialMap* new_mat_map;
102  MapeFileIcon* icon;
103  const MapeMaterial* mat;
104  unsigned int i;
105 
106  new_mat_map = mape_material_map_new();
107  if(!mape_material_map_load(new_mat_map, base_group, error))
108  {
109  g_object_unref(new_mat_map);
110  return FALSE;
111  }
112 
113  if(overload_materials && overload_from != NULL)
114  {
115  if(!mape_material_map_load(new_mat_map, overload_from, error))
116  {
117  g_object_unref(new_mat_map);
118  return FALSE;
119  }
120  }
121 
122  if(!mape_texture_map_load_textures(new_tex_map, base_group, error))
123  {
124  g_object_unref(new_mat_map);
125  return FALSE;
126  }
127 
128  if(overload_textures && overload_from != NULL)
129  {
130  if(!mape_texture_map_load_textures(new_tex_map, overload_from, error))
131  {
132  g_object_unref(new_mat_map);
133  return FALSE;
134  }
135  }
136 
137  /* Load the texture map again, because now that we have materials
138  * and textures loaded, we can actually assign the indices in the
139  * texture map. */
140  if (!mape_texture_map_load_map(new_tex_map, base_group, error))
141  {
142  g_object_unref(new_mat_map);
143  return FALSE;
144  }
145 
146  mape_material_map_set_default_textures(new_mat_map, new_tex_map);
147 
148  if(view->mat_map != NULL) g_object_unref(view->mat_map);
149  if(view->tex_map != NULL) g_object_unref(view->tex_map);
150  view->mat_map = new_mat_map; view->tex_map = new_tex_map;
151  g_object_ref(new_tex_map);
152 
154  for(i = 0; i < mape_material_map_get_material_count(new_mat_map); ++ i)
155  {
156  mat = mape_material_map_get_material(new_mat_map, i);
157 
159  view->icon_set,
161  );
162 
164  view->view_mat,
165  mape_file_icon_get(icon),
167  );
168  }
169 
171  for(i = 0; i < mape_texture_map_get_texture_count(new_tex_map); ++ i)
172  {
174  view->view_tex,
176  new_tex_map,
177  mape_texture_map_get_texture_name(new_tex_map, i)
178  ),
179  mape_texture_map_get_texture_name(new_tex_map, i)
180  );
181  }
182 
183  return TRUE;
184 }
185 
void mape_icon_view_clear(MapeIconView *view)
Definition: iconview.c:108
MapeFileIcon * mape_file_icon_set_lookup(MapeFileIconSet *set, MapeFileIconType type)
Definition: fileicon.c:129
GdkPixbuf * mape_file_icon_get(MapeFileIcon *icon)
Definition: fileicon.c:137
MapeMatTexView * mape_mat_tex_view_new(MapeFileIconSet *icon_set, GError **error)
Definition: mattexview.c:24
guint mape_material_map_get_material_count(MapeMaterialMap *map)
Definition: material.c:274
gboolean mape_mat_tex_view_reload(MapeMatTexView *view, MapeTextureMap *new_tex_map, MapeGroup *base_group, gboolean overload_materials, gboolean overload_textures, MapeGroup *overload_from, GError **error)
Definition: mattexview.c:93
gboolean mape_material_map_load(MapeMaterialMap *map, MapeGroup *from, GError **error)
Definition: material.c:242
MapeTextureMap * tex_map
Definition: mattexview.h:33
void mape_icon_view_destroy(MapeIconView *view)
Definition: iconview.c:102
gboolean mape_texture_map_load_map(MapeTextureMap *texture_map, MapeGroup *group, GError **error)
Definition: texture.c:265
GtkWidget * window
Definition: iconview.h:30
void mape_mat_tex_view_destroy(MapeMatTexView *view)
Definition: mattexview.c:80
MapeFileIconSet * icon_set
Definition: mattexview.h:35
void mape_material_map_set_default_textures(MapeMaterialMap *matmap, MapeTextureMap *texmap)
Definition: material.c:290
MapeIconView * mape_icon_view_new(GError **error)
Definition: iconview.c:19
MapeMaterialMap * mape_material_map_new(void)
Definition: material.c:223
MapeMaterialMap * mat_map
Definition: mattexview.h:32
MapeIconView * view_tex
Definition: mattexview.h:30
gboolean mape_texture_map_load_textures(MapeTextureMap *texture_map, MapeGroup *group, GError **error)
Definition: texture.c:304
GdkPixbuf * mape_texture_map_lookup_texture(MapeTextureMap *texture_map, const gchar *name)
Definition: texture.c:504
guint mape_texture_map_get_texture_count(MapeTextureMap *texture_map)
Definition: texture.c:459
const gchar * mape_texture_map_get_texture_name(MapeTextureMap *texture_map, guint index)
Definition: texture.c:478
const MapeMaterial * mape_material_map_get_material(MapeMaterialMap *map, guint index)
Definition: material.c:310
const gchar * mape_material_get_name(const MapeMaterial *material)
Definition: material.c:371
GtkWidget * notebook
Definition: mattexview.h:27
struct _MapeMaterial MapeMaterial
Definition: material.h:35
MapeIconView * view_mat
Definition: mattexview.h:29
void mape_icon_view_add(MapeIconView *view, GdkPixbuf *icon, const char *name)
Definition: iconview.c:113