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 » U++ Library support » Look and Chameleon Technology » Chameleon-ized EditField
Chameleon-ized EditField [message #9190] Fri, 20 April 2007 13:30 Go to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
I would like EditFields to change color when they have focus (as they do when they have invalid data). However, because so many controls are derived from EditField it is unpleasant to modify the Paint method.

Instead I have given the control a simple Chameleon style that functions identically to the original but exposes a Color that can be set when it has focus. My version is attatched.

Would it be possible to have something similar incorporated into the Upp::CtrlLib package so that I don't have to update the source myself?
  • Attachment: EditField.cpp
    (Size: 16.07KB, Downloaded 574 times)

[Updated on: Fri, 20 April 2007 13:31]

Report message to a moderator

Re: Chameleon-ized EditField [message #9191 is a reply to message #9190] Fri, 20 April 2007 13:30 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Header file.
  • Attachment: EditCtrl.h
    (Size: 9.16KB, Downloaded 542 times)
Re: Chameleon-ized EditField [message #9193 is a reply to message #9191] Fri, 20 April 2007 15:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK. I did two changes:

Invalid color - moved that Blend to default style, so that in Paint no blending, just invalid is used.

Renamed hligght to select.

Mirek

Re: Chameleon-ized EditField [message #10352 is a reply to message #9193] Tue, 03 July 2007 18:41 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Currently disabled EditFields show pink if they have invalid data, which doesn't make sense to me, so I've added an extra check (and it now caches the result of IsShowEnabled since it's called 5 times):

void EditField::Paint(Draw& w)
{
	Size sz = GetSize();
	bool f = HasBorder();
	bool enabled = IsShowEnabled();
	const EditField::Style *st = style ? style : &StyleDefault();
	Color paper = enabled && !IsReadOnly() ? (HasFocus() ? st->focus : st->paper) : st->disabled;
	if(nobg)
		paper = Null;
	Color ink = enabled ? st->text : st->textdisabled;
	if(convert && enabled && convert->Scan(text).IsError())
		paper = st->invalid;
	int fcy = font.Info().GetHeight();
	int yy = GetTy();
	w.DrawRect(0, 0, 2, sz.cy, paper);
	w.DrawRect(0, 0, sz.cx, yy, paper);
	w.DrawRect(0, yy + fcy, sz.cx, sz.cy - yy - fcy, paper);
	w.DrawRect(sz.cx - 2, 0, 2, sz.cy, paper);
	w.Clipoff(2, yy, sz.cx - 4, fcy);
	int x = -sc;
	if(IsNull(text) && !IsNull(nulltext)) {
		const wchar *txt = nulltext;
		Paints(w, x, fcy, txt, nullink, paper, nulltext.GetLength(), false);
	}
	else {
		const wchar *txt = text;
		int l, h;
		if(GetSelection(l, h)) {
			Paints(w, x, fcy, txt, ink, paper, l, password);
			Paints(w, x, fcy, txt, enabled ? st->selectedtext : paper,
			                       enabled ? st->selected : ink, h - l, password);
			Paints(w, x, fcy, txt, ink, paper, text.GetLength() - h, password);
		}
		else
			Paints(w, x, fcy, txt, ink, paper, text.GetLength(), password);
	}
	w.DrawRect(x, 0, 9999, fcy, paper);
	w.End();
//	w.DrawRect(dropcaret, LtBlue());
	DrawTiles(w, dropcaret, CtrlImg::checkers());
}

Could this be added to Uppsrc please?

James
Re: Chameleon-ized EditField [message #10354 is a reply to message #10352] Tue, 03 July 2007 19:45 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Yes. The base code has changed meanwhile, but I hope I have preserved the spirit of your change;)

Mirek
Previous Topic: OS X Aqua look and feel?
Next Topic: Native Icon Themeing
Goto Forum:
  


Current Time: Fri Mar 29 01:01:26 CET 2024

Total time taken to generate the page: 0.03008 seconds