00001
00002
00003
00004 #include <OVGA.H>
00005 #include <OSYS.H>
00006 #include <OMOUSE.H>
00007 #include <OWORLD.H>
00008
00009
00010
00011 void MapMatrix::draw_all() {
00012 Matrix::draw_all();
00013
00014 draw_zoom_box(1);
00015 }
00016
00017
00018
00019
00020
00021 void MapMatrix::draw_update() {
00022 }
00023
00024
00025
00026
00027
00028 void MapMatrix::draw_zoom_box(int useVgaBack) {
00029 static short colorIndex = 0;
00030 static short colorAdd = 1;
00031
00032 int boxX1, boxY1, boxX2, boxY2;
00033
00034 loc_to_abs_center_left( boxX1, boxY1, world.active_zoom_matrix->top_x_loc,
00035 world.active_zoom_matrix->top_y_loc );
00036
00037 boxX1 = boxX1 - abs_top_x + MAP_X1;
00038 boxY1 = boxY1 - abs_top_y + MAP_Y1;
00039
00040 boxX2 = boxX1 + (ZOOM_WIDTH * loc_width / world.active_zoom_matrix->loc_width) - 1;
00041 boxY2 = boxY1 + (ZOOM_HEIGHT * loc_height / world.active_zoom_matrix->loc_height) - 1;
00042
00043
00044
00045 colorIndex += colorAdd;
00046
00047 if( colorIndex >= 6 )
00048 colorAdd = -1;
00049
00050 else if( colorIndex <= 0 )
00051 colorAdd = 1;
00052
00053 colorIndex=0;
00054
00055 if( useVgaBack )
00056 vga_back.rect( boxX1, boxY1, boxX2, boxY2, 2, V_ORANGE+colorIndex);
00057 else
00058 vga_front.rect( boxX1, boxY1, boxX2, boxY2, 2, V_ORANGE+colorIndex);
00059 }
00060
00061
00062
00063
00064
00065 int MapMatrix::detect() {
00066
00067
00068 enum {
00069 EFFECTIVE_BORDER = 15
00070 };
00071
00072 if(mouse.single_click(win_x1-EFFECTIVE_BORDER,win_y1-EFFECTIVE_BORDER,win_x2+EFFECTIVE_BORDER,win_y2+EFFECTIVE_BORDER, LEFT_BUTTON)) {
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 int zoomFrameWidth = (ZOOM_WIDTH * loc_width / world.active_zoom_matrix->loc_width);
00091 int zoomFrameHeight = (ZOOM_HEIGHT * loc_height / world.active_zoom_matrix->loc_height);
00092
00093 int absX = (mouse.cur_x-win_x1)-zoomFrameWidth/2;
00094 int absY = (mouse.cur_y-win_y1)-zoomFrameHeight/2;
00095 absX=max(absX,1);
00096 absY=max(absY,1);
00097 absX=min(absX,win_x2-win_x1-zoomFrameWidth+1);
00098 absY=min(absY,win_y2-win_y1-zoomFrameHeight+1);
00099 absX+=abs_top_x;
00100 absY+=abs_top_y;
00101
00102 int locX, locY;
00103 static int old_locX=-1,old_locY=-1;
00104
00105 abs_to_loc( locX, locY, absX, absY );
00106
00107 if(locX!=old_locX)
00108 if(locY!=old_locY) {
00109
00110 world.active_zoom_matrix->set_top_loc( locX, locY );
00111
00112
00113
00114
00115
00116
00117
00118
00119 }
00120 old_locX=locX;
00121 old_locY=locY;
00122
00123 sys.redraw_zoom_flag = 1;
00124
00125 return 1;
00126 }
00127
00128 if( mouse.press_area(win_x1-EFFECTIVE_BORDER,win_y1-EFFECTIVE_BORDER,win_x2+EFFECTIVE_BORDER,win_y2+EFFECTIVE_BORDER, LEFT_BUTTON )) {
00129 int zoomFrameWidth = (ZOOM_WIDTH * loc_width / world.active_zoom_matrix->loc_width);
00130 int zoomFrameHeight = (ZOOM_HEIGHT * loc_height / world.active_zoom_matrix->loc_height);
00131
00132 int absX = (mouse.cur_x-win_x1)-zoomFrameWidth/2;
00133 int absY = (mouse.cur_y-win_y1)-zoomFrameHeight/2;
00134
00135 absX=max(absX,1);
00136 absY=max(absY,1);
00137 absX=min(absX,win_x2-win_x1-zoomFrameWidth+1);
00138 absY=min(absY,win_y2-win_y1-zoomFrameHeight+1);
00139 absX+=abs_top_x;
00140 absY+=abs_top_y;
00141
00142
00143
00144 int locX, locY;
00145 static int old_locX=-1,old_locY=-1;
00146
00147 abs_to_loc( locX, locY, absX, absY );
00148
00149 if(locX!=old_locX)
00150 if(locY!=old_locY) {
00151
00152 world.active_zoom_matrix->set_top_loc( locX, locY );
00153
00154
00155
00156
00157
00158
00159
00160
00161 }
00162 old_locX=locX;
00163 old_locY=locY;
00164
00165 sys.redraw_zoom_flag = 1;
00166
00167 return 1;
00168 }
00169
00170 return 0;
00171 }
00172
00173
00174
00175
00176
00177 void MapMatrix::scroll(int scrollX, int scrollY) {
00178
00179
00180 int boxX1, boxY1;
00181
00182 loc_to_abs_center_left( boxX1, boxY1, world.active_zoom_matrix->top_x_loc,
00183 world.active_zoom_matrix->top_y_loc );
00184
00185 boxX1 = boxX1 - abs_top_x + MAP_X1;
00186 boxY1 = boxY1 - abs_top_y + MAP_Y1;
00187
00188 int boxWidth = (ZOOM_WIDTH * loc_width / world.active_zoom_matrix->loc_width);
00189 int boxHeight = (ZOOM_HEIGHT * loc_height / world.active_zoom_matrix->loc_height);
00190
00191
00192
00193 boxX1 += scrollX * loc_width;
00194 boxY1 += scrollY * loc_height;
00195
00196 if( boxX1 < MAP_X1 )
00197 boxX1 = MAP_X1;
00198
00199 if( boxY1 < MAP_Y1 )
00200 boxY1 = MAP_Y1;
00201
00202 if( boxX1 + boxWidth - 1 > MAP_X2 )
00203 boxX1 = MAP_X2 - boxWidth + 1;
00204
00205 if( boxY1 + boxHeight - 1 > MAP_Y2 )
00206 boxY1 = MAP_Y2 - boxHeight + 1;
00207
00208
00209
00210 int absX = boxX1 - MAP_X1 + abs_top_x;
00211 int absY = boxY1 - MAP_Y1 + abs_top_y;
00212
00213 int locX, locY;
00214
00215 abs_to_loc( locX, locY, absX, absY );
00216
00217 world.active_zoom_matrix->set_top_loc( locX, locY );
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 sys.redraw_zoom_flag = 1;
00229 }
00230
00231