4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 Cursor_::Cursor_(BC_SubWindow *canvas)
26 this->canvas = canvas;
27 selectionstart = selectionend = zoom_sample = viewstart = 0;
34 int Cursor_::show(int flash, long selectionstart, long selectionend, long zoom_sample, long viewstart, int vertical)
37 this->selectionstart = selectionstart;
38 this->selectionend = selectionend;
39 this->viewstart = viewstart;
40 this->zoom_sample = zoom_sample;
41 this->vertical = vertical;
42 draw(flash, selectionstart, selectionend, zoom_sample, viewstart, vertical);
45 int Cursor_::hide(int flash)
48 draw(flash, selectionstart, selectionend, zoom_sample, viewstart, vertical);
51 int Cursor_::draw(int flash, long selectionstart, long selectionend, long zoom_sample, long viewstart, int vertical)
55 if(canvas->get_h() * canvas->get_w() == 0) return 1;
56 if(zoom_sample == 0) return 1; // no canvas
58 long start = viewstart;
59 long end = start + (long)(vertical ? canvas->get_h() : canvas->get_w()) * zoom_sample;
62 if((selectionstart >= start && selectionstart <= end) ||
63 (selectionend >= start && selectionend <= end) ||
64 (start >= selectionstart && end <= selectionend))
66 if(selectionstart < start)
72 pixel1 = (selectionstart - start) / zoom_sample;
75 if(selectionend > end)
77 pixel2 = (vertical ? canvas->get_h() : canvas->get_w());
81 pixel2 = (selectionend - start) / zoom_sample;
85 canvas->set_inverse();
86 canvas->set_color(WHITE);
89 canvas->draw_box(0, pixel1, canvas->get_w(), pixel2 - pixel1);
91 canvas->draw_box(pixel1, 0, pixel2 - pixel1, canvas->get_h());
96 if(flash) canvas->flash();
100 int Cursor_::resize(int w, int h)