今回も、前回と同じソフトウェアからの抜粋です。ただし、前回とは違う人のプログラムなので、 また違う「味わい」があります。
数人での共同開発プログラムが、全体にほぼ万遍なく汚いのですが、人により汚さの方向が異な ります。だから、慣れてくると、そのプログラムを見るだけで、汚さの方向ベクトルの向きから、 「この部分はあの人だ」と断言できるようになります。
今回のプログラムは、Xウィンド、より正確にはX-Viewでのイベントハンドラと呼ばれるもので す。汚さを理解するには、Xについての知識は全く必要ありません。 プログラムは、リスト11−1にあります。もちろん今回も、「あれれ?」と思う個所がありま す。まず、リストを鑑賞してください。
リスト11−1 オリジナルプログラム |
1 void mac_up_event( xwin, event ) 2 Xv_Window xwin; 3 Event *event; 4 { 5 int x; 6 int y; 7 RECT rectdisp; 8 RECT rectbase; 9 POINT point1; 10 POINT point2; 11 Display *dpy; 12 Window win_disp; 13 Xv_Window xwin_disp; 14 15 if ( !event_is_ascii( event ) ) 16 { 17 if ( event_is_down( event ) && 18 ( event_action( event ) == ACTION_SELECT || 19 event_action( event ) == MS_LEFT || 20 event_action( event ) == ACTION_ADJUST || 21 event_action( event ) == MS_MIDDLE || 22 event_action( event ) == ACTION_MENU || 23 event_action( event ) == MS_RIGHT ) ) 24 { 25 mac_y -= (int)((DOUBLE)mac_height / mac_mag) / 2; 26 if ( mac_y < 0 ) 27 mac_y = 0; 28 mac_posx = mac_x + (int)((DOUBLE)mac_width/mac_mag) / 2; 29 mac_posy = mac_y + (int)((DOUBLE)mac_height/mac_mag) / 2; 30 rectdisp.x = 0; 31 rectdisp.y = 0; 32 rectdisp.size_x = mac_width; 33 rectdisp.size_y = mac_height; 34 rectbase.x = mac_x; 35 rectbase.y = mac_y; 36 xwin_disp = (Xv_Window)canvas_paint_window( mac_canvas ); 37 dpy = (Display *)xv_get( base_frame, XV_DISPLAY ); 38 win_disp = (Window)xv_get( xwin_disp, XV_XID ); 39 mac_cur = OFF; 40 disp_data( (PRECT)&rectdisp, (PRECT)&rectbase, 41 mac_mag, (PPOINT)&mac_point, 42 mac_image_ad, mac_image -> bytes_per_line, 43 ON ); 44 XPutImage( dpy, win_disp, mac_paint_gc, mac_image, 45 rectdisp.x, rectdisp.y, 46 rectdisp.x, rectdisp.y, 47 rectdisp.size_x, rectdisp.size_y ); 48 } 49 } 50 } 51 52 void mac_down_event( xwin, event ) 53 Xv_Window xwin; 54 Event *event; 55 { 56 int x; 57 int y; 58 RECT rectdisp; 59 RECT rectbase; 60 POINT point1; 61 POINT point2; 62 Display *dpy; 63 Window win_disp; 64 Xv_Window xwin_disp; 65 66 if ( !event_is_ascii( event ) ) 67 { 68 if ( event_is_down( event ) && 69 ( event_action( event ) == ACTION_SELECT || 70 event_action( event ) == MS_LEFT || 71 event_action( event ) == ACTION_ADJUST || 72 event_action( event ) == MS_MIDDLE || 73 event_action( event ) == ACTION_MENU || 74 event_action( event ) == MS_RIGHT ) ) 75 { 76 mac_y += (int)((DOUBLE)mac_height / mac_mag) / 2; 77 if ( mac_y > ydot - (int)((DOUBLE)mac_height / mac_mag ) ) 78 { 79 mac_y = ydot - (int)((DOUBLE)mac_height / mac_mag ); 80 if ( mac_y < 0 ) 81 mac_y = 0; 82 } 83 mac_posx = mac_x + (int)((DOUBLE)mac_width/mac_mag) / 2; 84 mac_posy = mac_y + (int)((DOUBLE)mac_height/mac_mag) / 2; 85 rectdisp.x = 0; 86 rectdisp.y = 0; 87 rectdisp.size_x = mac_width; 88 rectdisp.size_y = mac_height; 89 rectbase.x = mac_x; 90 rectbase.y = mac_y; 91 xwin_disp = (Xv_Window)canvas_paint_window( mac_canvas ); 92 dpy = (Display *)xv_get( base_frame, XV_DISPLAY ); 93 win_disp = (Window)xv_get( xwin_disp, XV_XID ); 94 mac_cur = OFF; 95 disp_data( (PRECT)&rectdisp, (PRECT)&rectbase, 96 mac_mag, (PPOINT)&mac_point, 97 mac_image_ad, mac_image -> bytes_per_line, 98 ON ); 99 XPutImage( dpy, win_disp, mac_paint_gc, mac_image, 100 rectdisp.x, rectdisp.y, 101 rectdisp.x, rectdisp.y, 102 rectdisp.size_x, rectdisp.size_y ); 103 } 104 } 105 } 106 107 void mac_left_event( xwin, event ) 108 Xv_Window xwin; 109 Event *event; 110 { 111 int x; 112 int y; 113 RECT rectdisp; 114 RECT rectbase; 115 POINT point1; 116 POINT point2; 117 Display *dpy; 118 Window win_disp; 119 Xv_Window xwin_disp; 120 121 if ( !event_is_ascii( event ) ) 122 { 123 if ( event_is_down( event ) && 124 ( event_action( event ) == ACTION_SELECT || 125 event_action( event ) == MS_LEFT || 126 event_action( event ) == ACTION_ADJUST || 127 event_action( event ) == MS_MIDDLE || 128 event_action( event ) == ACTION_MENU || 129 event_action( event ) == MS_RIGHT ) ) 130 { 131 mac_x -= (int)((DOUBLE)mac_width / mac_mag) / 2; 132 if ( mac_x < 0 ) 133 mac_x = 0; 134 mac_posx = mac_x + (int)((DOUBLE)mac_width/mac_mag) / 2; 135 mac_posy = mac_y + (int)((DOUBLE)mac_height/mac_mag) / 2; 136 rectdisp.x = 0; 137 rectdisp.y = 0; 138 rectdisp.size_x = mac_width; 139 rectdisp.size_y = mac_height; 140 rectbase.x = mac_x; 141 rectbase.y = mac_y; 142 xwin_disp = (Xv_Window)canvas_paint_window( mac_canvas ); 143 dpy = (Display *)xv_get( base_frame, XV_DISPLAY ); 144 win_disp = (Window)xv_get( xwin_disp, XV_XID ); 145 mac_cur = OFF; 146 disp_data( (PRECT)&rectdisp, (PRECT)&rectbase, 147 mac_mag, (PPOINT)&mac_point, 148 mac_image_ad, mac_image -> bytes_per_line, 149 ON ); 150 XPutImage( dpy, win_disp, mac_paint_gc, mac_image, 151 rectdisp.x, rectdisp.y, 152 rectdisp.x, rectdisp.y, 153 rectdisp.size_x, rectdisp.size_y ); 154 } 155 } 156 } 157 158 void mac_right_event( xwin, event ) 159 Xv_Window xwin; 160 Event *event; 161 { 162 int x; 163 int y; 164 RECT rectdisp; 165 RECT rectbase; 166 POINT point1; 167 POINT point2; 168 Display *dpy; 169 Window win_disp; 170 Xv_Window xwin_disp; 171 172 if ( !event_is_ascii( event ) ) 173 { 174 if ( event_is_down( event ) && 175 ( event_action( event ) == ACTION_SELECT || 176 event_action( event ) == MS_LEFT || 177 event_action( event ) == ACTION_ADJUST || 178 event_action( event ) == MS_MIDDLE || 179 event_action( event ) == ACTION_MENU || 180 event_action( event ) == MS_RIGHT ) ) 181 { 182 mac_x += (int)((DOUBLE)mac_width / mac_mag ) / 2; 183 if ( mac_x > xdot - (int)((DOUBLE)mac_width / mac_mag ) ) 184 { 185 mac_x = xdot - (int)((DOUBLE)mac_width / mac_mag ); 186 if ( mac_x < 0 ) 187 mac_x = 0; 188 } 189 mac_posx = mac_x + (int)((DOUBLE)mac_width/mac_mag) / 2; 190 mac_posy = mac_y + (int)((DOUBLE)mac_height/mac_mag) / 2; 191 rectdisp.x = 0; 192 rectdisp.y = 0; 193 rectdisp.size_x = mac_width; 194 rectdisp.size_y = mac_height; 195 rectbase.x = mac_x; 196 rectbase.y = mac_y; 197 xwin_disp = (Xv_Window)canvas_paint_window( mac_canvas ); 198 dpy = (Display *)xv_get( base_frame, XV_DISPLAY ); 199 win_disp = (Window)xv_get( xwin_disp, XV_XID ); 200 mac_cur = OFF; 201 disp_data( (PRECT)&rectdisp, (PRECT)&rectbase, 202 mac_mag, (PPOINT)&mac_point, 203 mac_image_ad, mac_image -> bytes_per_line, 204 ON ); 205 XPutImage( dpy, win_disp, mac_paint_gc, mac_image, 206 rectdisp.x, rectdisp.y, 207 rectdisp.x, rectdisp.y, 208 rectdisp.size_x, rectdisp.size_y ); 209 } 210 } 211 } |