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)
54 if(canvas->get_h() * canvas->get_w() == 0) return 1;
55 if(zoom_sample == 0) return 1; // no canvas
57 long start = viewstart;
58 long end = start + (long)(vertical ? canvas->get_h() : canvas->get_w()) * zoom_sample;
61 if((selectionstart >= start && selectionstart <= end) ||
62 (selectionend >= start && selectionend <= end) ||
63 (start >= selectionstart && end <= selectionend))
65 if(selectionstart < start)
71 pixel1 = (selectionstart - start) / zoom_sample;
74 if(selectionend > end)
76 pixel2 = (vertical ? canvas->get_h() : canvas->get_w());
80 pixel2 = (selectionend - start) / zoom_sample;
84 canvas->set_inverse();
85 canvas->set_color(WHITE);
88 canvas->draw_box(0, pixel1, canvas->get_w(), pixel2 - pixel1);
90 canvas->draw_box(pixel1, 0, pixel2 - pixel1, canvas->get_h());
95 if(flash) canvas->flash();
98 int Cursor_::resize(int w, int h)