1 /*************************************************************************** 2 MouseMark.h - Handling of mouse selection 3 ------------------- 4 begin : Sun Nov 12 2000 5 copyright : (C) 2000 by Thomas Eschenbacher 6 email : Thomas.Eschenbacher@gmx.de 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef MOUSE_MARK_H 19 #define MOUSE_MARK_H 20 21 #include "config.h" 22 23 #include "libkwave/Sample.h" 24 25 namespace Kwave 26 { 27 /** 28 * Simple class that can be used whenever the user selects something 29 * with the mouse. 30 */ 31 class MouseMark 32 { 33 34 public: 35 36 /** Constructor */ 37 MouseMark(); 38 39 /** Destructor */ 40 virtual ~MouseMark(); 41 42 /** 43 * Sets the selection to a new range. 44 * @param l start position 45 * @param r end position 46 */ 47 void set(sample_index_t l, sample_index_t r); 48 49 /** 50 * Update the last known position of the mouse. This should be 51 * used for continuous update of the selection during mouse 52 * movement. 53 * @param x new last position 54 */ 55 void update(sample_index_t x); 56 57 /** 58 * Re-enters the selection process at a new position. The last 59 * position will be set to the left or the right margin, depending 60 * on which side is nearer. 61 */ 62 void grep(sample_index_t x); 63 64 /** 65 * Returns the left border of the selection. 66 */ 67 sample_index_t left() const; 68 69 /** 70 * Returns the right border of the selection. 71 */ 72 sample_index_t right() const; 73 74 /** 75 * Returns the length of the selection 76 */ length()77 inline sample_index_t length() const { 78 return right() - left() + 1; 79 } 80 81 private: 82 /** initial position of the mouse */ 83 sample_index_t m_initial; 84 85 /** last known position of the mouse */ 86 sample_index_t m_last; 87 }; 88 } 89 90 #endif /* MOUSE_MARK_H */ 91 92 //*************************************************************************** 93 //*************************************************************************** 94