Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » CodeEditor current caret position mark on gutter
CodeEditor current caret position mark on gutter [message #25069] Tue, 09 February 2010 16:05 Go to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
Maybe someone would like something like this:
CodeEditor current caret position mark on gutter

I like it esp. when using Alt_I Alt_J

index.php?t=getfile&id=2239&private=0

if yes, then use those 2 changes in EditorBar.cpp:


void EditorBar::Paint(Draw& w)
{
	static Image (*numeri[])() = {
		CodeEditorImg::N0, CodeEditorImg::N1, CodeEditorImg::N2, CodeEditorImg::N3, CodeEditorImg::N4,
		CodeEditorImg::N5, CodeEditorImg::N6, CodeEditorImg::N7, CodeEditorImg::N8, CodeEditorImg::N9,
	};
	Size sz = GetSize();
	w.DrawRect(0, 0, sz.cx, sz.cy, SColorLtFace);
	if(!editor) return;
	int fy = editor->GetFontSize().cy;
	int hy = fy >> 1;
	int y = 0;
	int i = editor->GetScrollPos().y;
	int cy = GetSize().cy;
	bool hi_if = (hilite_if_endif && (editor->highlight == CodeEditor::HIGHLIGHT_CPP
		|| editor->highlight == CodeEditor::HIGHLIGHT_JAVA));
	Vector<CodeEditor::IfState> previf;
	if(hi_if)
		previf <<= editor->ScanSyntax(i).ifstack;
	int ptri[2];
	for(int q = 0; q < 2; q++)
		ptri[q] = ptrline[q] >= 0 ? GetLineNo(ptrline[q]) : -1;
	while(y < cy) {
		String b;
		int err = 0;
		int edit = 0;
		String ann;
		Image  icon;
		if(i < li.GetCount()) {
			const LnInfo& l = li[i];
			b = l.breakpoint;
			err = l.error;
			edit = l.edited;
			icon = l.icon;
			ann = l.annotation;
		}
		if (editor->GetCaret().top==y)  //aris002
			w.DrawRect(0, y, sz.cx, fy,  Yellow);

		if(line_numbers && i < editor->GetLineCount()) {
			String n = AsString(i + 1);
			for(int q = 0; q < 4 && q < n.GetLength(); q++) {
				w.DrawImage(sz.cx - 8 - q * 6,
					y + (fy - CodeEditorImg::N0().GetSize().cy) / 2,
					numeri[n[n.GetLength() - 1 - q] - '0'],
					// CodeEditorImg::Vector[n[n.GetLength() - 1 - q] - '0' + CodeEditorImg::I_N0],
					Brown);
			}
		}
		if(hi_if) {
			Vector<CodeEditor::IfState> nextif;
			if(i < li.GetCount())
				nextif <<= editor->ScanSyntax(i + 1).ifstack;
			int pifl = previf.GetCount(), nifl = nextif.GetCount();
			int dif = max(pifl, nifl);
			if(--dif >= 0) {
				char p = (dif < pifl ? previf[dif].state : 0);
				char n = (dif < nifl ? nextif[dif].state : 0);
				int wd = min(2 * (dif + 1), sz.cx);
				int x = sz.cx - wd;
				Color cn = CodeEditor::SyntaxState::IfColor(n);
				if(p == n)
					w.DrawRect(x, y, 1, fy, cn);
				else {
					Color cp = CodeEditor::SyntaxState::IfColor(p);
					w.DrawRect(x, y, 1, hy, cp);
					w.DrawRect(x, y + hy, wd, 1, Nvl(cn, cp));
					w.DrawRect(x, y + hy, 1, fy - hy, cn);
					if(--dif >= 0) {
						x = sz.cx - min(2 * (dif + 1), sz.cx);
						if(!p)
							w.DrawRect(x, y, 1, hy, CodeEditor::SyntaxState::IfColor(dif < pifl ? previf[dif].state : 0));
						if(!n)
							w.DrawRect(x, y + hy, 1, fy - hy, CodeEditor::SyntaxState::IfColor(dif < nifl ? nextif[dif].state : 0));
					}
				}
			}
			previf = nextif;
		}
		if(editor->GetMarkLines()) {
			int width = CodeEditorImg::Breakpoint().GetWidth() >> 1;
			if(edit)
			{
				int age = (int)(log((double)(editor->GetUndoCount() + 1 - edit)) * 30);
				w.DrawRect(0, y, width, fy, Blend(LtBlue, SColorLtFace(), min(220, age)));
			}
			if(err)
				w.DrawRect(width, y, width, fy, err == 1 ? LtRed : (err == 2 ? Color(255, 175, 0) : Green));
		}

		if(!b.IsEmpty())
			sPaintImage(w, y, fy, b == "1"   ? CodeEditorImg::Breakpoint() :
			                      b == "\xe" ? CodeEditorImg::InvalidBreakpoint() :
			                                   CodeEditorImg::CondBreakpoint());
		for(int q = 0; q < 2; q++)
			if(ptri[q] == i)
				sPaintImage(w, y, fy, ptrimg[q]);

		if(annotations && !IsNull(icon))
			w.DrawImage(sz.cx - annotations, y + (fy - icon.GetSize().cy) / 2, icon);

		y += fy;
		i++;
	}
}



and CodeEditor.cpp:
void CodeEditor::SelectionChanged()
{
	if(!foundsel) {
		CloseFindReplace();
		found = false;
		notfoundfw = notfoundbk = false;
		findreplace.amend.Disable();
	}
	CheckBrackets();
	bar.Refresh(); //aris002
}

[Updated on: Tue, 09 February 2010 16:06]

Report message to a moderator

Re: CodeEditor current caret position mark on gutter [message #25075 is a reply to message #25069] Tue, 09 February 2010 16:51 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
What a nice idea - adopted.

(I have played with color a bit and added an option - but this time it is ON by default).
Previous Topic: TheIDE Find/Replace
Next Topic: Graduation thesis - Camouflage - a replacement of(a part of) Chameleon
Goto Forum:
  


Current Time: Sat Apr 20 11:54:57 CEST 2024

Total time taken to generate the page: 0.06541 seconds