summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorCinder <cinder.roxley@phoenixviewer.com>2014-06-20 13:43:31 -0600
committerCinder <cinder.roxley@phoenixviewer.com>2014-06-20 13:43:31 -0600
commit8d2e0fb3a047e349b88db80afa09fc97a7f4ff74 (patch)
tree78016c75a1d170fae191203e45208bcbb134ba57 /indra/newview
parent984353d7ca6184d7252c716150d42139aae94e5c (diff)
STORM-2035 - Invert the background color in script editors for highlighting sections. Since the background color can be changed by the user, this ensures distinctive highlighting
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llscripteditor.cpp104
-rw-r--r--indra/newview/llscripteditor.h5
-rwxr-xr-xindra/newview/skins/default/xui/en/panel_script_ed.xml1
3 files changed, 107 insertions, 3 deletions
diff --git a/indra/newview/llscripteditor.cpp b/indra/newview/llscripteditor.cpp
index df46380130..3bbfbad477 100644
--- a/indra/newview/llscripteditor.cpp
+++ b/indra/newview/llscripteditor.cpp
@@ -183,3 +183,107 @@ void LLScriptEditor::clearSegments()
mSegments.clear();
}
}
+
+// Most of this is shamelessly copied from LLTextBase
+void LLScriptEditor::drawSelectionBackground()
+{
+ // Draw selection even if we don't have keyboard focus for search/replace
+ if( hasSelection() && !mLineInfoList.empty())
+ {
+ std::vector<LLRect> selection_rects;
+
+ S32 selection_left = llmin( mSelectionStart, mSelectionEnd );
+ S32 selection_right = llmax( mSelectionStart, mSelectionEnd );
+
+ // Skip through the lines we aren't drawing.
+ LLRect content_display_rect = getVisibleDocumentRect();
+
+ // binary search for line that starts before top of visible buffer
+ line_list_t::const_iterator line_iter = std::lower_bound(mLineInfoList.begin(), mLineInfoList.end(), content_display_rect.mTop, LLTextBase::compare_bottom());
+ line_list_t::const_iterator end_iter = std::upper_bound(mLineInfoList.begin(), mLineInfoList.end(), content_display_rect.mBottom, LLTextBase::compare_top());
+
+ bool done = false;
+
+ // Find the coordinates of the selected area
+ for (;line_iter != end_iter && !done; ++line_iter)
+ {
+ // is selection visible on this line?
+ if (line_iter->mDocIndexEnd > selection_left && line_iter->mDocIndexStart < selection_right)
+ {
+ segment_set_t::iterator segment_iter;
+ S32 segment_offset;
+ getSegmentAndOffset(line_iter->mDocIndexStart, &segment_iter, &segment_offset);
+
+ LLRect selection_rect;
+ selection_rect.mLeft = line_iter->mRect.mLeft;
+ selection_rect.mRight = line_iter->mRect.mLeft;
+ selection_rect.mBottom = line_iter->mRect.mBottom;
+ selection_rect.mTop = line_iter->mRect.mTop;
+
+ for(;segment_iter != mSegments.end(); ++segment_iter, segment_offset = 0)
+ {
+ LLTextSegmentPtr segmentp = *segment_iter;
+
+ S32 segment_line_start = segmentp->getStart() + segment_offset;
+ S32 segment_line_end = llmin(segmentp->getEnd(), line_iter->mDocIndexEnd);
+
+ if (segment_line_start > segment_line_end) break;
+
+ S32 segment_width = 0;
+ S32 segment_height = 0;
+
+ // if selection after beginning of segment
+ if(selection_left >= segment_line_start)
+ {
+ S32 num_chars = llmin(selection_left, segment_line_end) - segment_line_start;
+ segmentp->getDimensions(segment_offset, num_chars, segment_width, segment_height);
+ selection_rect.mLeft += segment_width;
+ }
+
+ // if selection_right == segment_line_end then that means we are the first character of the next segment
+ // or first character of the next line, in either case we want to add the length of the current segment
+ // to the selection rectangle and continue.
+ // if selection right > segment_line_end then selection spans end of current segment...
+ if (selection_right >= segment_line_end)
+ {
+ // extend selection slightly beyond end of line
+ // to indicate selection of newline character (use "n" character to determine width)
+ S32 num_chars = segment_line_end - segment_line_start;
+ segmentp->getDimensions(segment_offset, num_chars, segment_width, segment_height);
+ selection_rect.mRight += segment_width;
+ }
+ // else if selection ends on current segment...
+ else
+ {
+ S32 num_chars = selection_right - segment_line_start;
+ segmentp->getDimensions(segment_offset, num_chars, segment_width, segment_height);
+ selection_rect.mRight += segment_width;
+
+ break;
+ }
+ }
+ selection_rects.push_back(selection_rect);
+ }
+ }
+
+ gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+ const LLColor4& color = mReadOnly ? mReadOnlyBgColor : mWriteableBgColor;
+ F32 alpha = hasFocus() ? 0.7f : 0.3f;
+ alpha *= getDrawContext().mAlpha;
+ // We want to invert the background color in script editors
+ LLColor4 selection_color(1.f - color.mV[VRED],
+ 1.f - color.mV[VGREEN],
+ 1.f - color.mV[VBLUE],
+ alpha);
+
+ for (std::vector<LLRect>::iterator rect_it = selection_rects.begin();
+ rect_it != selection_rects.end();
+ ++rect_it)
+ {
+ LLRect selection_rect = *rect_it;
+ selection_rect = *rect_it;
+ selection_rect.translate(mVisibleTextRect.mLeft - content_display_rect.mLeft, mVisibleTextRect.mBottom - content_display_rect.mBottom);
+ gl_rect_2d(selection_rect, selection_color);
+ }
+ }
+}
diff --git a/indra/newview/llscripteditor.h b/indra/newview/llscripteditor.h
index 8c5ab362a3..f458203a39 100644
--- a/indra/newview/llscripteditor.h
+++ b/indra/newview/llscripteditor.h
@@ -48,7 +48,7 @@ public:
void initKeywords();
void loadKeywords();
- void clearSegments();
+ /* virtual */ void clearSegments();
LLKeywords::keyword_iterator_t keywordsBegin() { return mKeywords.begin(); }
LLKeywords::keyword_iterator_t keywordsEnd() { return mKeywords.end(); }
@@ -58,7 +58,8 @@ protected:
private:
void drawLineNumbers();
- void updateSegments();
+ /* virtual */ void updateSegments();
+ /* virtual */ void drawSelectionBackground();
void loadKeywords(const std::string& filename_keywords,
const std::string& filename_colors);
diff --git a/indra/newview/skins/default/xui/en/panel_script_ed.xml b/indra/newview/skins/default/xui/en/panel_script_ed.xml
index 5971082380..eb1b954e61 100755
--- a/indra/newview/skins/default/xui/en/panel_script_ed.xml
+++ b/indra/newview/skins/default/xui/en/panel_script_ed.xml
@@ -176,7 +176,6 @@
bg_focus_color="ScriptBackground"
text_readonly_color="ScriptText"
bg_readonly_color="ScriptBackground"
- bg_selected_color="ScriptSelectedColor"
cursor_color="ScriptCursorColor"
enable_tooltip_paste="true"
word_wrap="true"