1 /* 2 * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef TERMVIEW_HIGHLIGHT_H 6 #define TERMVIEW_HIGHLIGHT_H 7 8 9 #include <GraphicsDefs.h> 10 11 #include "TermPos.h" 12 13 14 class TermViewHighlighter { 15 public: 16 virtual ~TermViewHighlighter(); 17 18 virtual rgb_color ForegroundColor() = 0; 19 virtual rgb_color BackgroundColor() = 0; 20 virtual uint32 AdjustTextAttributes(uint32 attributes); 21 }; 22 23 24 class TermViewHighlight { 25 public: 26 TermViewHighlight() 27 : 28 fHighlighter(NULL), 29 fStart(-1, -1), 30 fEnd(-1, -1) 31 { 32 } 33 34 TermViewHighlighter* Highlighter() const 35 { 36 return fHighlighter; 37 } 38 39 void SetHighlighter(TermViewHighlighter* highligher) 40 { 41 fHighlighter = highligher; 42 } 43 44 const TermPos& Start() const 45 { 46 return fStart; 47 } 48 49 const TermPos& End() const 50 { 51 return fEnd; 52 } 53 54 bool IsEmpty() const 55 { 56 return fStart == fEnd; 57 } 58 59 bool RangeContains(const TermPos& pos) const 60 { 61 return pos >= fStart && pos < fEnd; 62 } 63 64 void SetRange(const TermPos& start, const TermPos& end) 65 { 66 fStart = start; 67 fEnd = end; 68 } 69 70 void ScrollRange(int32 byLines) 71 { 72 fStart.y -= byLines; 73 fEnd.y -= byLines; 74 } 75 76 private: 77 TermViewHighlighter* fHighlighter; 78 TermPos fStart; 79 TermPos fEnd; 80 }; 81 82 83 #endif // TERMVIEW_HIGHLIGHT_H 84