// // file name: display.C // written by Ting-jen Yen // // All the functions are pulled out from the // function display_thread() in win.C. // It should get bigger when more works // are doing in win.C. // #include "window.h" #include "tcpstream.h" #include "block_item.h" #include "sparse_mask.h" #include "sparse_2.h" #include "GLOBAL_VARIABLE.h" #include "display.h" // // The 3 variables are the location and size // of previous request. // static int loc_x, loc_y, loc_r; // // SendReq converts mouse events into request of // data, and put the requests into queue. // void SendReq(int x,int y, int r, int level_10) { int level = level_10 / 10; double level_1 = table[ level_10 % 10 ]; loc_x = (int) ((x << level) * level_1 + .5); loc_y = (int) ((y << level) * level_1 + .5); loc_r = (int) (r * level_1 + .5); SendReq_All(level); } // SendReq_R is similar to SendReq(), except that // is would using the same location as previous // request, with larger radius. // void SendReq_R(int level_10) { int level = level_10 / 10; int old_r = loc_r; loc_r += (300/loc_r) + 5; if (loc_r < 256) SendReq_All(level); else loc_r = old_r; } // // SendReq_All() is called by previous 2 functions. // It does the real work. The previous 2 functions // are just preprocessing the data. // void SendReq_All(int level) { int r_0 = loc_r >> 1; for (int i = levels-1; i >= level; i --) { int rel_y = loc_y >> (i+1); int rel_x = loc_x >> (i+1); int w = C[i+1].get_non_padding_width(); int h = C[i+1].get_non_padding_height(); Q.enqueue(i, (rel_y-r_0>0)? rel_y-r_0:0, (rel_y+r_00)? rel_x-r_0:0, (rel_x+r_0> 1); y_pos = (cursor_y << (levels - level)) - (win_h >> 1); } // Zooming out. Similar to zooming. Though it will not // do the zooming when the image would become small than // the Viewing Window. // Return value: // -1 : Does not zoom. // 0 : Does Zoom out. int ZoomOut_View(int &level_10, int &x_pos, int &y_pos, int win_w, int win_h, int cursor_x, int cursor_y, int current_x, int current_y) { int old_level = level_10; level_10 += 1; if (level_10 > (levels - 1) * 10) level_10 = (levels -1) * 10; int level = level_10 / 10; double level_1 = table[level_10 % 10]; int image_w = (int)(C[level] .get_non_padding_width() / level_1 +.5); int image_h = (int)(C[level] .get_non_padding_height() / level_1 +.5); if (win_w > image_w || win_h > image_h) { level_10 = old_level; return -1; } x_pos = (int) ((current_x + cursor_x) / table[1] + .5) - cursor_x; y_pos = (int) ((current_y + cursor_y) / table[1] + .5) - cursor_y; return 0; } int ZoomOut_Nav(int &level_10, int &x_pos, int &y_pos, int cursor_x, int cursor_y, int win_w, int win_h) { int old_level = level_10; level_10 += 10; if (level_10 < 0) level_10 = 0; int level = level_10 / 10; level_10 = level * 10; int image_w = C[level] .get_non_padding_width(); int image_h = C[level] .get_non_padding_height(); if (win_w > image_w || win_h > image_h) { level_10 = old_level; return -1; } x_pos = (cursor_x << (levels - level)) - (win_w >> 1); y_pos = (cursor_y << (levels - level)) - (win_h >> 1); return 0; } // Adjust_Image_Size() and AdjustLocation() are called // AFTER we do the zooming. It would modify the image size // in current resolution, and adjust the current viewing // location in the Viewing Window according to the boundary // of the image. void Adjust_Image_Size(int level_10, int &image_w, int &image_h) { int level = level_10 / 10; int tmp; double level_1; image_w = C[level].get_non_padding_width(); image_h = C[level].get_non_padding_height(); if ((tmp = level_10 % 10) != 0) { level_1 = table[tmp]; image_w = (int) (image_w / level_1 + .5); image_h = (int) (image_h / level_1 + .5); } } void AdjustLocation(int &x_pos, int &y_pos, int win_w, int win_h, int image_w, int image_h) { if (x_pos < 0) x_pos = 0; if (x_pos > image_w -win_w) x_pos = image_w-win_w; if (y_pos < 0) y_pos = 0; if (y_pos > image_h -win_h) y_pos = image_h - win_h; } // // This function RemoveIndicator() removes the indicator box // in the Navigation Window which indicates the current // location of the image in the Viewing Window. We call // this function when we zoom, pan the image. // void RemoveIndicator(int x, int y, int w, int h, int min_width, int min_height, Window win, XImage *image) { x -= 2; y -= 2; if (x < 0) x = 0; if (y < 0) y = 0; w += 4; h += 4; if (x + w < min_width) w = min_width - x; if (y + h < min_height) h = min_height - y; XPutImage(display, win, gcx, image, x, y, x, y, w, h); }