[Freeciv-Dev] (PR#12412) common client function to draw the spaceship
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12412 >
This patch adds two new functions, get_spaceship_dimensions and
put_spaceship. These are added into mapview_common.c (along with other
miscellaneous drawing code, but there should probably be a
client/spaceshipdlg.c or something, and a lot of the common/spaceship.h
code is client-specific).
The gtk2 client uses these new spaceship functions.
-jason
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.203
diff -u -r1.203 mapview_common.c
--- client/mapview_common.c 2 Mar 2005 19:00:33 -0000 1.203
+++ client/mapview_common.c 2 Mar 2005 21:03:47 -0000
@@ -2885,3 +2885,75 @@
/* Create a dummy map to make sure mapview.store is never NULL. */
map_canvas_resized(1, 1);
}
+
+/****************************************************************************
+ Return the desired width of the spaceship canvas.
+****************************************************************************/
+void get_spaceship_dimensions(int *width, int *height)
+{
+ get_sprite_dimensions(sprites.spaceship.habitation, width, height);
+ *width *= 7;
+ *height *= 7;
+}
+
+/****************************************************************************
+ Draw the spaceship onto the canvas.
+****************************************************************************/
+void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y,
+ const struct player *pplayer)
+{
+ int i, x, y;
+ const struct player_spaceship *ship = &pplayer->spaceship;
+ int w, h;
+
+ get_sprite_dimensions(sprites.spaceship.habitation, &w, &h);
+
+ canvas_put_rectangle(pcanvas, COLOR_STD_BLACK, 0, 0, w * 7, h * 7);
+
+ for (i = 0; i < NUM_SS_MODULES; i++) {
+ const int j = i / 3;
+ const int k = i % 3;
+ struct Sprite *sprite;
+
+ if ((k == 0 && j >= ship->habitation)
+ || (k == 1 && j >= ship->life_support)
+ || (k == 2 && j >= ship->solar_panels)) {
+ continue;
+ }
+ x = modules_info[i].x * w / 4 - w / 2;
+ y = modules_info[i].y * h / 4 - h / 2;
+
+ sprite = (k == 0 ? sprites.spaceship.habitation
+ : k == 1 ? sprites.spaceship.life_support
+ : sprites.spaceship.solar_panels);
+ canvas_put_sprite_full(pcanvas, x, y, sprite);
+ }
+
+ for (i=0; i < NUM_SS_COMPONENTS; i++) {
+ const int j = i / 2;
+ const int k = i % 2;
+ struct Sprite *sprite;
+
+ if ((k == 0 && j >= ship->fuel)
+ || (k == 1 && j >= ship->propulsion)) {
+ continue;
+ }
+ x = components_info[i].x * w / 4 - w / 2;
+ y = components_info[i].y * h / 4 - h / 2;
+
+ sprite = ((k == 0) ? sprites.spaceship.fuel
+ : sprites.spaceship.propulsion);
+
+ canvas_put_sprite_full(pcanvas, x, y, sprite);
+ }
+
+ for (i = 0; i < NUM_SS_STRUCTURALS; i++) {
+ if (!ship->structure[i]) {
+ continue;
+ }
+ x = structurals_info[i].x * w / 4 - w / 2;
+ y = structurals_info[i].y * h / 4 - h / 2;
+
+ canvas_put_sprite_full(pcanvas, x, y, sprites.spaceship.structural);
+ }
+}
Index: client/mapview_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.h,v
retrieving revision 1.101
diff -u -r1.101 mapview_common.h
--- client/mapview_common.h 28 Feb 2005 20:24:38 -0000 1.101
+++ client/mapview_common.h 2 Mar 2005 21:03:47 -0000
@@ -317,4 +317,8 @@
bool map_canvas_resized(int width, int height);
void init_mapcanvas_and_overview(void);
+void get_spaceship_dimensions(int *width, int *height);
+void put_spaceship(struct canvas *pcanvas, int canvas_x, int canvas_y,
+ const struct player *pplayer);
+
#endif /* FC__MAPVIEW_COMMON_H */
Index: client/gui-gtk-2.0/spaceshipdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/spaceshipdlg.c,v
retrieving revision 1.15
diff -u -r1.15 spaceshipdlg.c
--- client/gui-gtk-2.0/spaceshipdlg.c 1 Feb 2005 01:08:45 -0000 1.15
+++ client/gui-gtk-2.0/spaceshipdlg.c 2 Mar 2005 21:03:47 -0000
@@ -208,6 +208,7 @@
{
struct spaceship_dialog *pdialog;
GtkWidget *hbox, *frame;
+ int w, h;
pdialog=fc_malloc(sizeof(struct spaceship_dialog));
pdialog->pplayer=pplayer;
@@ -232,9 +233,8 @@
pdialog->image_canvas=gtk_drawing_area_new();
GTK_WIDGET_SET_FLAGS(pdialog->image_canvas, GTK_CAN_FOCUS);
- gtk_widget_set_size_request(pdialog->image_canvas,
- sprites.spaceship.habitation->width*7,
- sprites.spaceship.habitation->height*7);
+ get_spaceship_dimensions(&w, &h);
+ gtk_widget_set_size_request(pdialog->image_canvas, w, h);
gtk_widget_set_events(pdialog->image_canvas, GDK_EXPOSURE_MASK);
gtk_container_add(GTK_CONTAINER(frame), pdialog->image_canvas);
@@ -278,64 +278,9 @@
*****************************************************************/
void spaceship_dialog_update_image(struct spaceship_dialog *pdialog)
{
- int i, j, k, x, y;
- struct Sprite *sprite = sprites.spaceship.habitation; /* for size */
- struct player_spaceship *ship = &pdialog->pplayer->spaceship;
-
- gdk_gc_set_foreground(fill_bg_gc, colors_standard[COLOR_STD_BLACK]);
- gdk_draw_rectangle(pdialog->image_canvas->window, fill_bg_gc, TRUE,
- 0, 0, sprite->width * 7, sprite->height * 7);
-
- for (i=0; i < NUM_SS_MODULES; i++) {
- j = i/3;
- k = i%3;
- if ((k==0 && j >= ship->habitation)
- || (k==1 && j >= ship->life_support)
- || (k==2 && j >= ship->solar_panels)) {
- continue;
- }
- x = modules_info[i].x * sprite->width / 4 - sprite->width / 2;
- y = modules_info[i].y * sprite->height / 4 - sprite->height / 2;
-
- sprite = (k==0 ? sprites.spaceship.habitation :
- k==1 ? sprites.spaceship.life_support :
- sprites.spaceship.solar_panels);
- gdk_draw_pixbuf(pdialog->image_canvas->window, civ_gc,
- sprite_get_pixbuf(sprite),
- 0, 0, x, y, sprite->width, sprite->height,
- GDK_RGB_DITHER_NONE, 0, 0);
- }
-
- for (i=0; i < NUM_SS_COMPONENTS; i++) {
- j = i/2;
- k = i%2;
- if ((k==0 && j >= ship->fuel)
- || (k==1 && j >= ship->propulsion)) {
- continue;
- }
- x = components_info[i].x * sprite->width / 4 - sprite->width / 2;
- y = components_info[i].y * sprite->height / 4 - sprite->height / 2;
-
- sprite = (k==0) ? sprites.spaceship.fuel : sprites.spaceship.propulsion;
-
- gdk_draw_pixbuf(pdialog->image_canvas->window, civ_gc,
- sprite_get_pixbuf(sprite),
- 0, 0, x, y, sprite->width, sprite->height,
- GDK_RGB_DITHER_NONE, 0, 0);
- }
-
- sprite = sprites.spaceship.structural;
-
- for (i=0; i < NUM_SS_STRUCTURALS; i++) {
- if (!ship->structure[i])
- continue;
- x = structurals_info[i].x * sprite->width / 4 - sprite->width / 2;
- y = structurals_info[i].y * sprite->height / 4 - sprite->height / 2;
-
- gdk_draw_pixbuf(pdialog->image_canvas->window, civ_gc,
- sprite_get_pixbuf(sprite),
- 0, 0, x, y, sprite->width, sprite->height,
- GDK_RGB_DITHER_NONE, 0, 0);
- }
+ struct canvas store = {.type = CANVAS_PIXMAP,
+ .v.pixmap = pdialog->image_canvas->window};
+
+ put_spaceship(&store, 0, 0, pdialog->pplayer);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12412) common client function to draw the spaceship,
Jason Short <=
|
|