From 3c2094d6877a82561388d46fad44b23c530f6054 Mon Sep 17 00:00:00 2001 From: Gary Macbook Date: Fri, 23 Aug 2013 08:53:53 +0200 Subject: [PATCH] Added a keystroke for permuting the mouse buttons, very useful on macbook... Added a function for swapping endpoints of axis to get around bugs in python software Improved the default "auto" settings on the hist2d and vi_to_iv widgets. --- spyview/ImageData.C | 17 +++++++++++++++++ spyview/ImageData.H | 1 + spyview/ImageWindow.C | 40 ++++++++++++++++++++++------------------ spyview/ImageWindow.H | 4 ++++ spyview/help.txt | 12 +++++++++--- spyview/spyview.C | 37 ++++++++++++++++++++++++++----------- 6 files changed, 79 insertions(+), 32 deletions(-) diff --git a/spyview/ImageData.C b/spyview/ImageData.C index abdb3ad..6a4c760 100644 --- a/spyview/ImageData.C +++ b/spyview/ImageData.C @@ -1672,6 +1672,23 @@ void ImageData::plane(double b, double a) raw(x,y) -= a * (x-width/2) + b*(y-height/2); } +void ImageData::flip_endpoints(bool flipx, bool flipy) +{ + double tmp; + if (flipx) + { + tmp = xmin; + xmin = xmax; + xmax = tmp; + } + if (flipy) + { + tmp = ymin; + ymin = ymax; + ymax = tmp; + } +} + void ImageData::xflip() { double tmp[width]; diff --git a/spyview/ImageData.H b/spyview/ImageData.H index 5bdb167..9a21c1f 100644 --- a/spyview/ImageData.H +++ b/spyview/ImageData.H @@ -316,6 +316,7 @@ public: void plane(double b, double a); // subtract a plane void xflip(); void yflip(); + void flip_endpoints(bool flipx, bool flipy); void rotate_cw(); void rotate_ccw(); void grad_mag(double bias); // Replace each pixel with the magnitude of the gradient. 01 2->2 3->3 + // Mouse order = 1: 2->1 3->2 1->3 + // Mouse order = 2: 3->1 1->2 2->3 - if ((button == 3) && (Fl::event_state() & FL_ALT)) - button = 2; + //if (event == FL_PUSH || event == FL_DRAG || event == FL_RELEASE) + //info("Button %d -> ", button); + button = button + mouse_order; + if (button == 4) button = 1; + if (button == 5) button = 2; + //if (event == FL_PUSH || event == FL_DRAG || event == FL_RELEASE) + //info("%d\n", button); switch (event) { @@ -559,6 +571,10 @@ int ImageWindow::handle(int event) return 1; } break; + case 'm': + mouse_order = (mouse_order+1)%3; + external_update(); + break; case 'z': if (Fl::event_state() & FL_CTRL) exportMTX(false, true); @@ -692,21 +708,6 @@ int ImageWindow::handle(int event) case FL_DRAG: // Falling case! case FL_RELEASE: - // For FL_DRAG, we cannot rely on Fl::event_button() (although - // it seems to work on unix) I don't know why I can't replace - // the Fl::event_buttion() above with this, but if I do, the - // zoom window stops working... - if (Fl::event_state() & FL_BUTTON1) - button = 1; - else if (Fl::event_state() & FL_BUTTON2) - button = 2; - else if (Fl::event_state() & FL_BUTTON3) - { - if (Fl::event_state() & FL_ALT) - button = 2; - else - button = 3; - } // Let's only eat a non-modified button 1 click if(stupid_windows_focus && (button == 1) && !(Fl::event_state() & FL_SHIFT) && !(Fl::event_state() & FL_CTRL)) { @@ -1690,6 +1691,8 @@ void ImageWindow::runQueue() if(op->parameters[1].value) id.yflip(); } + else if(op->name == "flip endpoints") + id.flip_endpoints(op->parameters[0].value, op->parameters[1].value); else if (op->name == "autoflip") { if (id.xmin > id.xmax) @@ -1763,6 +1766,7 @@ void ImageWindow::runQueue() // have updated the iw width and height properly yet. pf->calculate(); + external_update(); } // a little procedure diff --git a/spyview/ImageWindow.H b/spyview/ImageWindow.H index 4fab1d4..30e94ba 100644 --- a/spyview/ImageWindow.H +++ b/spyview/ImageWindow.H @@ -212,6 +212,10 @@ public: // If this is true, eat initial clicks. bool stupid_windows_focus; + // New feature for permutating mouse button order for poor people + // (like me) who have only one mouse button on their MacBook + int mouse_order; // 0 = (123), 1 = (231), 2 = (312) + // These variables store the levels of the 16 bit greymap data that // get mapped to the edges of the of the colormap int hmin; diff --git a/spyview/help.txt b/spyview/help.txt index 7b34f0e..04f6b35 100644 --- a/spyview/help.txt +++ b/spyview/help.txt @@ -1,6 +1,11 @@ Global ------ +NEW FEATURE FOR PEOPLE WITH LESS THAN 3 MOUSE BUTTONS! +m Permutate mouse buttons in image window: + (123) -> (231) -> (312) -> (123) + Current mouse order is shown in image window title + Left Next file (also "." or SPACE) Right Prev file (also "," or BACKSPACE) e Reload file @@ -55,13 +60,14 @@ Alt-s Snap windowsize to nearest integer zoom Ctrl-s Turn on autonormalize in zoom window Shft-s Normalize based on contents of zoom window +For systems with less than 3 mouse buttons, you can access +the other features by permutating the mouse button order +using the "m" shortcut (see above). + B1 = left mouse button B2 = middle mouse button B3 = right mouse button -For two button mice, hold down the ALT key to emulate the middle -buttion (B2) using the right mouse button (B3). - B3 Toggle controls Esc,c Clear linecut diff --git a/spyview/spyview.C b/spyview/spyview.C index e704493..368016c 100644 --- a/spyview/spyview.C +++ b/spyview/spyview.C @@ -276,15 +276,22 @@ void cb_hist2d_autorange(Fl_Widget *w, void *p) double tmp; char buf[1024]; - tmp = iw->id.quant_to_raw(iw->hmin); - snprintf(buf,sizeof(buf),"%e",tmp); + double min = iw->id.quant_to_raw(iw->hmin); + double max = iw->id.quant_to_raw(iw->hmax); + + if (abs(min)>abs(max)) + tmp = abs(min); + else + tmp = abs(max); + + snprintf(buf,sizeof(buf),"%e", -tmp); proc_parameters[0]->value(buf); - tmp = iw->id.quant_to_raw(iw->hmax); - snprintf(buf,sizeof(buf),"%e",tmp); + snprintf(buf,sizeof(buf),"%e", tmp); proc_parameters[1]->value(buf); - snprintf(buf,sizeof(buf),"%d",iw->id.height); + //snprintf(buf,sizeof(buf),"%d",iw->id.height*50); + snprintf(buf,sizeof(buf),"%d",10000); proc_parameters[2]->value(buf); proc_parameters[0]->do_callback(); @@ -553,6 +560,11 @@ int main(int argc, char **argv) flip.addParameter("!Flip Y Axis",0); Define_Image_Operation(&flip); + Image_Operation flip_endpoints("flip endpoints","Flip axis endpoints"); + flip_endpoints.addParameter("!Flip X Axis",0); + flip_endpoints.addParameter("!Flip Y Axis",0); + Define_Image_Operation(&flip_endpoints); + Image_Operation crop("crop","Crop the Image (0 to keep current, negative possible for lower/right)"); crop.addParameter("left col #", 0); crop.addParameter("right col #", 0); @@ -979,8 +991,9 @@ void cmapch_cb(Fl_Widget *o, void*) index = reinterpret_cast(cmapch->mvalue()->user_data()); static char label[1024]; - snprintf(label, 1024, "%s - %s", filech->text(), cmapch->text()); - iw->label(label); + // This seems to be an old piece of code: where is the image window + // being labelled? + update_title(); snprintf(label, 1024, "Colormap %s", cmapch->text()); (iw->colormap_window)->label(label); @@ -1170,13 +1183,15 @@ void update_title() { char buf[256]; if (iw->id.data3d) - snprintf(buf, 256, "%s %.0f (%.3g to %.3g), (%.3g to %.3g)", + snprintf(buf, 256, "%s %s %.0f (%.3g to %.3g), (%.3g to %.3g)", current_filename.c_str(), indexbox->value(), xmin->value(), xmax->value(), ymin->value(), ymax->value()); else - snprintf(buf, 256, "%s (%.3g to %.3g), (%.3g to %.3g)", + snprintf(buf, 256, "%s %s (%.3g to %.3g), (%.3g to %.3g)", + (iw->mouse_order == 0) ? "(123)" : + ((iw->mouse_order == 1) ? "(231)" : "(312)"), current_filename.c_str(), xmin->value(), xmax->value(), ymin->value(), ymax->value()); @@ -1291,7 +1306,7 @@ void update_widgets() max = iw->hmax; width = (max - min); center = (max + min)/2; - + minv->value(min); minslider->value(min); minroller->value(min); @@ -1447,7 +1462,7 @@ void update_widgets() mtx_zname->value(iw->id.mtx.axisname[2].c_str()); xrange->value(iw->line_cut_xauto); - + update_title(); } void Fetch_ProcWindow_Settings(Image_Operation *op) -- 2.25.1