diff options
author | Ian Thompson <quornian@googlemail.com> | 2008-08-06 17:46:44 +0400 |
---|---|---|
committer | Ian Thompson <quornian@googlemail.com> | 2008-08-06 17:46:44 +0400 |
commit | 6c0f4660ed60ea8dd46519e3367ee5c0efdcf4f8 (patch) | |
tree | de0167eb5e5e09392121212816cca55a5b1cd9ac /source/blender/blenkernel/intern/text.c | |
parent | 799ba2c3517df4df6c8ddbd508af85fec77167df (diff) |
Various UI drawing and event tweaks to make markers feel more natural and avoid getting in the way. If there is a marker under the cursor, ESC will remove it and others in its group. Otherwise all temporary markers are removed. Tab finds/cycles/removes temp. markers, cycles non-temp. markers (under cursor) and behaves normally in all other cases.
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 76 |
1 files changed, 59 insertions, 17 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 47f8fc708c2..bcaf7bbc0ac 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -83,12 +83,19 @@ The st->top determines at what line the top of the text is displayed. If the user moves the cursor the st containing that cursor should be popped ... other st's retain their own top location. -*/ /***************/ - +Markers +-- +The mrk->flags define the behaviour and relationships between markers. The +upper two bytes are used to hold a group ID, the lower two are normal flags. If +TMARK_EDITALL is set the group ID defines which other markers should be edited. -/****************/ /* - Undo +The mrk->clr field is used to visually group markers where the flags may not +match. A template system, for example, may allow editing of repeating tokens +(in one group) but include other marked positions (in another group) all in the +same template with the same colour. +Undo +-- Undo/Redo works by storing events in a queue, and a pointer to the current position in the @@ -2657,6 +2664,13 @@ int setcurr_tab (Text *text) /* Text marker utility functions */ /*********************************/ +static int color_match(TextMarker *a, TextMarker *b) { + return (a->clr[0]==b->clr[0] && + a->clr[1]==b->clr[1] && + a->clr[2]==b->clr[2] && + a->clr[3]==b->clr[3]); +} + /* Creates and adds a marker to the list maintaining sorted order */ void txt_add_marker(Text *text, TextLine *line, int start, int end, char clr[4], int flags) { TextMarker *tmp, *marker; @@ -2681,8 +2695,9 @@ void txt_add_marker(Text *text, TextLine *line, int start, int end, char clr[4], else BLI_addhead(&text->markers, marker); } -/* Returns the first matching marker on the specified line between two points - If flags is zero, all markers will be searched */ +/* Returns the first matching marker on the specified line between two points, + with at least the specified flags set. If flags is zero, all markers will be + searched */ TextMarker *txt_find_marker_region(Text *text, TextLine *line, int start, int end, int flags) { TextMarker *marker, *next; int lineno= txt_get_span(text->lines.first, line); @@ -2690,7 +2705,7 @@ TextMarker *txt_find_marker_region(Text *text, TextLine *line, int start, int en for (marker=text->markers.first; marker; marker=next) { next= marker->next; - if (flags && marker->flags != flags) continue; + if ((marker->flags & flags) != flags) continue; else if (marker->lineno < lineno) continue; else if (marker->lineno > lineno) break; @@ -2701,8 +2716,8 @@ TextMarker *txt_find_marker_region(Text *text, TextLine *line, int start, int en return NULL; } -/* Clears all matching markers on the specified line between two points - If flags is zero, all markers will be cleared */ +/* Clears all markers on the specified line between two points with at least + the specified flags set. If flags is zero, all markers will be cleared */ void txt_clear_marker_region(Text *text, TextLine *line, int start, int end, int flags) { TextMarker *marker, *next; int lineno= txt_get_span(text->lines.first, line); @@ -2710,7 +2725,7 @@ void txt_clear_marker_region(Text *text, TextLine *line, int start, int end, int for (marker=text->markers.first; marker; marker=next) { next= marker->next; - if (flags && marker->flags != flags) continue; + if ((marker->flags & flags) != flags) continue; else if (marker->lineno < lineno) continue; else if (marker->lineno > lineno) break; @@ -2720,26 +2735,27 @@ void txt_clear_marker_region(Text *text, TextLine *line, int start, int end, int } } -/* Clears all markers with matching flags (useful for clearing temporary markers) */ +/* Clears all markers with at least the specified flags set (useful for + clearing temporary markers) */ void txt_clear_markers(Text *text, int flags) { TextMarker *marker, *next; for (marker=text->markers.first; marker; marker=next) { next= marker->next; - if (marker->flags == flags) + if ((marker->flags & flags) == flags) BLI_freelinkN(&text->markers, marker); } } -/* Finds the marker at the specified line and cursor position with matching flags. - If flags is zero, all markers will be searched */ +/* Finds the marker at the specified line and cursor position with at least the + specified flags set. If flags is zero, all markers will be searched */ TextMarker *txt_find_marker(Text *text, TextLine *line, int curs, int flags) { TextMarker *marker; int lineno= txt_get_span(text->lines.first, line); for (marker=text->markers.first; marker; marker=marker->next) { - if (flags && marker->flags != flags) continue; + if ((marker->flags & flags) != flags) continue; else if (marker->lineno < lineno) continue; else if (marker->lineno > lineno) break; @@ -2749,8 +2765,8 @@ TextMarker *txt_find_marker(Text *text, TextLine *line, int curs, int flags) { return NULL; } -/* Finds the previous marker with matching flags. If no other marker is found, the - same one will be returned */ +/* Finds the previous marker with matching flags. If no other marker is found, + the same one will be returned */ TextMarker *txt_prev_marker(Text *text, TextMarker *marker) { TextMarker *tmp= marker; while (tmp) { @@ -2774,3 +2790,29 @@ TextMarker *txt_next_marker(Text *text, TextMarker *marker) { } return NULL; /* Only if marker==NULL */ } + +/* Finds the previous marker with matching colour. If no other marker is found, + the same one will be returned */ +TextMarker *txt_prev_marker_color(Text *text, TextMarker *marker) { + TextMarker *tmp= marker; + while (tmp) { + if (tmp->prev) tmp= tmp->prev; + else tmp= text->markers.last; + if (color_match(tmp, marker)) + return tmp; + } + return NULL; /* Only if marker==NULL */ +} + +/* Finds the next marker with matching colour. If no other marker is found, the + same one will be returned */ +TextMarker *txt_next_marker_color(Text *text, TextMarker *marker) { + TextMarker *tmp= marker; + while (tmp) { + if (tmp->next) tmp= tmp->next; + else tmp= text->markers.first; + if (color_match(tmp, marker)) + return tmp; + } + return NULL; /* Only if marker==NULL */ +} |