comparison src/shape_image.c @ 822:586e50f82c1f

Unify coding style tag for emacs and vim.
author Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
date Tue, 14 Sep 2010 01:08:39 +0800
parents 8e9481bf1cc0
children a8d20bc8ce40
comparison
equal deleted inserted replaced
821:bfdc82bbd6e4 822:586e50f82c1f
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
2 // vim: sw=4:ts=8:sts=4
1 #include <stdio.h> 3 #include <stdio.h>
2 #include <string.h> 4 #include <string.h>
3 #include "mb_graph_engine.h" 5 #include "mb_graph_engine.h"
4 #include "mb_types.h" 6 #include "mb_types.h"
5 #include "mb_shapes.h" 7 #include "mb_shapes.h"
51 53
52 /*! \brief Image shape. 54 /*! \brief Image shape.
53 */ 55 */
54 typedef struct _sh_image { 56 typedef struct _sh_image {
55 shape_t shape; 57 shape_t shape;
56 58
57 co_aix x, y; 59 co_aix x, y;
58 co_aix w, h; 60 co_aix w, h;
59 co_aix poses[4][2]; 61 co_aix poses[4][2];
60 62
61 redraw_man_t *rdman; 63 redraw_man_t *rdman;
62 } sh_image_t; 64 } sh_image_t;
63 65
64 static void sh_image_free(shape_t *shape); 66 static void sh_image_free(shape_t *shape);
65 67
84 img->y = y; 86 img->y = y;
85 img->w = w; 87 img->w = w;
86 img->h = h; 88 img->h = h;
87 89
88 rdman_shape_man(rdman, (shape_t *)img); 90 rdman_shape_man(rdman, (shape_t *)img);
89 91
90 return (shape_t *)img; 92 return (shape_t *)img;
91 } 93 }
92 94
93 void sh_image_free(shape_t *shape) { 95 void sh_image_free(shape_t *shape) {
94 sh_image_t *img = (sh_image_t *)shape; 96 sh_image_t *img = (sh_image_t *)shape;
104 co_aix img_matrix[6]; 106 co_aix img_matrix[6];
105 co_aix rev_matrix[6]; 107 co_aix rev_matrix[6];
106 co_aix x_factor, y_factor; 108 co_aix x_factor, y_factor;
107 int img_w, img_h; 109 int img_w, img_h;
108 int i; 110 int i;
109 111
110 poses = img->poses; 112 poses = img->poses;
111 poses[0][0] = img->x; 113 poses[0][0] = img->x;
112 poses[0][1] = img->y; 114 poses[0][1] = img->y;
113 poses[1][0] = img->x + img->w; 115 poses[1][0] = img->x + img->w;
114 poses[1][1] = img->y; 116 poses[1][1] = img->y;
116 poses[2][1] = img->y + img->h; 118 poses[2][1] = img->y + img->h;
117 poses[3][0] = img->x; 119 poses[3][0] = img->x;
118 poses[3][1] = img->y + img->h; 120 poses[3][1] = img->y + img->h;
119 for(i = 0; i < 4; i++) 121 for(i = 0; i < 4; i++)
120 coord_trans_pos(img->shape.coord, &poses[i][0], &poses[i][1]); 122 coord_trans_pos(img->shape.coord, &poses[i][0], &poses[i][1]);
121 123
122 geo_from_positions(sh_get_geo(shape), 4, poses); 124 geo_from_positions(sh_get_geo(shape), 4, poses);
123 125
124 paint = sh_get_fill(shape); 126 paint = sh_get_fill(shape);
125 if(paint == NULL) 127 if(paint == NULL)
126 return; 128 return;
127 129
128 ASSERT(paint.pnt_type == MBP_IMAGE); 130 ASSERT(paint.pnt_type == MBP_IMAGE);
129 131
130 paint_image_get_size(paint, &img_w, &img_h); 132 paint_image_get_size(paint, &img_w, &img_h);
131 133
132 /* Transformation from image space to user space */ 134 /* Transformation from image space to user space */
133 img_matrix[0] = (poses[1][0] - poses[0][0]) / img->w; 135 img_matrix[0] = (poses[1][0] - poses[0][0]) / img->w;
134 img_matrix[1] = (poses[3][0] - poses[3][0]) / img->h; 136 img_matrix[1] = (poses[3][0] - poses[3][0]) / img->h;
135 img_matrix[2] = poses[0][0]; 137 img_matrix[2] = poses[0][0];
136 img_matrix[3] = (poses[1][1] - poses[0][1]) / img->w; 138 img_matrix[3] = (poses[1][1] - poses[0][1]) / img->w;
154 * 156 *
155 * \note Image is not rescaled for size of the shape. 157 * \note Image is not rescaled for size of the shape.
156 */ 158 */
157 void sh_image_draw(shape_t *shape, mbe_t *cr) { 159 void sh_image_draw(shape_t *shape, mbe_t *cr) {
158 sh_image_t *img = (sh_image_t *)shape; 160 sh_image_t *img = (sh_image_t *)shape;
159 161
160 mbe_move_to(cr, img->poses[0][0], img->poses[0][1]); 162 mbe_move_to(cr, img->poses[0][0], img->poses[0][1]);
161 mbe_line_to(cr, img->poses[1][0], img->poses[1][1]); 163 mbe_line_to(cr, img->poses[1][0], img->poses[1][1]);
162 mbe_line_to(cr, img->poses[2][0], img->poses[2][1]); 164 mbe_line_to(cr, img->poses[2][0], img->poses[2][1]);
163 mbe_line_to(cr, img->poses[3][0], img->poses[3][1]); 165 mbe_line_to(cr, img->poses[3][0], img->poses[3][1]);
164 mbe_close_path(cr); 166 mbe_close_path(cr);