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 » CalendarCtrl » Little improvement of Caledar & DropDate controls
Little improvement of Caledar & DropDate controls [message #40095] Mon, 10 June 2013 00:40 Go to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I propose little improvement of Calendar class. It's help to paint color every day of month in user-defined colors depend on variety conditions (on database data, on calculatable expressions ...)

Example of result:
index.php?t=getfile&id=4221&private=0

with code:
TestColoredCalendar::TestColoredCalendar()
{
	CtrlLayout(*this, "Window title");
	drop_date.WhenPaintDay = THISBACK(MarkDate);
	calend.WhenPaintDay = THISBACK(MarkDate10);
}

void TestColoredCalendar::MarkDate(Date date,Color& fg, Color& bg){
	int day = date.Get();
	if (day % 2 == 0) {
		fg = Color(255,0,0);
		bg = Color(255,100,255);
	} else {
		fg = Color(60,60,255);
		bg = Color(255,255,100);
	}
}

void TestColoredCalendar::MarkDate10(Date date,Color& fg, Color& bg){
	int day = date.Get();
	if (day % 10 == 0) {
		fg = Color(255,255,255);
		bg = Color(255,0,0);
	} else {
		fg = Color(0,155,155);
		bg = Color(230,255,255);
	}
}


Full testcode in attachments.



SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Little improvement of Caledar & DropDate controls [message #40096 is a reply to message #40095] Mon, 10 June 2013 01:02 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I propose to make this changes in DateTimeCtrl.cpp & DateTimeCtrl.h

DateTimeCtrl.h have 3 changes:

1. After line 212 add line

Callback3 <Date , Color&, Color& > WhenPaintDay;
result:
public:
	Calendar();
	Callback1<Time &> WhenTime;
	Callback3 <Date , Color&, Color& > WhenPaintDay; // <== Inserted line

	static const Style& StyleDefault();

	void Reset();



2. After line 491 add line

Callback3 <Date , Color&, Color& > WhenPaintDay;

3. After line 501 add line

cc.calendar.WhenPaintDay = Proxy(WhenPaintDay);

result of items 2 & 3 will be:
public:
	typedef DateTimeCtrl CLASSNAME;
	Callback3 <Date , Color&, Color& > WhenPaintDay; // <== Inserted line
	DateTimeCtrl(int m) : cc(m) {
		drop.AddTo(*this);
		drop.AddButton().Main() <<= THISBACK(OnDrop);
		drop.NoDisplay();
		drop.SetStyle(drop.StyleFrame());
		drop.GetButton(0).SetMonoImage(Grayscale(CtrlsImg::DA()));
		cc.calendar   <<= THISBACK(OnCalendarChoice);
		cc.clock      <<= THISBACK(OnClockChoice);
		cc.WhenPopDown  = THISBACK(OnClose);
		cc.calendar.WhenSelect = Proxy(WhenSelect);
		cc.calendar.WhenPaintDay = Proxy(WhenPaintDay); // <== Inserted line
	}
	virtual void GotFocus()  { T::GotFocus(); drop.RefreshFrame(); }
	virtual void LostFocus() { T::LostFocus(); drop.RefreshFrame(); }
	virtual Size GetMinSize() const { return drop.GetMinSize(); }


DateTimeCtrl.cpp have 1 changes:

1. After line 530 add lines:
					if (!WhenPaintDay.Empty()){
						WhenPaintDay(Date(y,m,d),fg,bg);
					}


result code:

					if(d == today.day && m == today.month && y == today.year)
					{
						fg = st.fgtoday;
						bg = st.bgtoday;
						fnt.Bold();
						special = true;

						curday.x = j;
						curday.y = i;
					}
					if(d == sel.day && m == sel.month && y == sel.year)
					{
						fg = st.fgselect;
						bg = st.bgselect;
						fnt.Bold();
						special = true;

						prevday.x = j;
						prevday.y = i;
					}
					if (!WhenPaintDay.Empty()){              // <== Inserted line
						WhenPaintDay(Date(y,m,d),fg,bg); // <== Inserted line
					}                                        // <== Inserted line

				}
				else
				{
					fg = st.outofmonth;
					sd = d > 0 ? -d : d;
					Day(j, i) = sd;
				}


In attachment these 2 files based on 6113svn

PS
Please include my addition into standard code.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Mon, 10 June 2013 08:06]

Report message to a moderator

Re: Little improvement of Caledar & DropDate controls [message #40108 is a reply to message #40096] Thu, 13 June 2013 10:28 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Sorry. Maybe exist alternative method?

Say please.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Little improvement of Caledar & DropDate controls [message #40109 is a reply to message #40108] Thu, 13 June 2013 10:46 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Sorry for not responding. I need to think it over (maybe some customizations can be delegated to control style). I'll let you know soon.
Re: Little improvement of Caledar & DropDate controls [message #40110 is a reply to message #40109] Thu, 13 June 2013 11:14 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Thanks for reply.

Very needed custom colors of days based on database data.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Thu, 13 June 2013 11:15]

Report message to a moderator

Re: Little improvement of Caledar & DropDate controls [message #40111 is a reply to message #40110] Thu, 13 June 2013 21:45 Go to previous messageGo to next message
BioBytes is currently offline  BioBytes
Messages: 307
Registered: October 2008
Location: France
Senior Member
Hi Sergey and Uno,

Features proposed by Sergey are very interesting.

Biobytes

[Updated on: Thu, 13 June 2013 21:45]

Report message to a moderator

Re: Little improvement of Caledar & DropDate controls [message #40112 is a reply to message #40111] Thu, 13 June 2013 22:07 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Thank you for your words!

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Little improvement of Caledar & DropDate controls [message #40125 is a reply to message #40109] Sun, 16 June 2013 19:06 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

unodgs wrote on Thu, 13 June 2013 12:46

Sorry for not responding. I need to think it over (maybe some customizations can be delegated to control style). I'll let you know soon.


By the way. First of all , I have thinking about using some style information and delegate some color settings of the control to style. In practice it make more difficult to integrate and more hardly to use in real application.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Little improvement of Caledar & DropDate controls [message #40533 is a reply to message #40095] Sat, 10 August 2013 19:16 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
I agree with BioBytes. This feature proposed by sergeynikitin would allow users to select multiple dates on a plain calendar or easily display stored database dates for edit.
Hope it gets included. Smile
Re: Little improvement of Caledar & DropDate controls [message #40534 is a reply to message #40125] Sat, 10 August 2013 19:43 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Totally cool feature, but, why not include it in DateTimeCtrl.cpp right before the day gets drawn, around line 581, so as to enable user to highlight out-of-current-month days too? It would look like:
				if(sd == char(view.day))
				{
					if(sd < 0 && selall)
					{
						fg = st.outofmonth;
						fnt.Bold().Underline(!special);
					}
					if(sd > 0 && view.month == m)
					{
						fg = st.selectday;
						fnt.Bold().Underline(!special);
					}
				}
				if (!WhenPaintDay.Empty()){             // <== Inserted line
					WhenPaintDay(Date(y,m,d),fg,bg); 	// <== Inserted line
				}                                       // <== Inserted line

				w.DrawRect(xp, yp, cw, rh, bg);
				if(special)
				{
					DrawFrame(w, xp + 1, yp + 1, cw - 2, rh - 2, Black);
					DrawFrame(w, xp, yp, cw, rh, st.bgmain);
				}

				str = AsString(abs(d));
				w.DrawText(xp + (cw - GetTextSize(str, fnt).cx) / 2, yp + yc , str, fnt, fg);
			}

thanks!

[Updated on: Sat, 10 August 2013 19:43]

Report message to a moderator

Re: Little improvement of Caledar & DropDate controls [message #40535 is a reply to message #40109] Sat, 10 August 2013 21:24 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
BTW, talking about style, I'm afraid I can't modify text colors for either current view month days or weekend days, apparently because you hard-coded them to Black and Red, respectively, in DateTimeCtrl.cpp around line #526:
...
if(m == view.month)
{
	Day(j, i) = d;

	fg = Black;  // Shouldn't it be st.fgmain, instead??

	if(j == 6)
	{
		fg = Red; // Looks like there's no style color for this
	}
...

I didn't check your code in depth, so pls let me know if there's any workaround I missed here...
Tks!

[Updated on: Sat, 10 August 2013 21:32]

Report message to a moderator

Re: Little improvement of Caledar & DropDate controls [message #40539 is a reply to message #40109] Sun, 11 August 2013 03:21 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Actually, after peering further into your code, I observed a few aspects I'd like to submit to your review, for I guess they might be relevant to other Upp users too:

1. Class member
String curdate;
, defined in DateTimeCtrl.h around line #170 gets initialized in DateTimeCtrl.cpp like
curdate = Format("%s %d", MonthName(view.month - 1), view.year);
, around line #462, but is never used; I just commented both lines out and it didn't make any difference whatsoever. So what role does this member play?

2. When assingning the following style to Calendar
	Calendar::Style& st = cal.StyleDefault().Write();
	st.font = Arial(8);
	st.bgmain = Color(33, 33, 33);
	st.bgselect = Color(190, 150, 80);
	st.bgtoday = Color(66, 66, 66);
	st.fgmain = Color(198, 198, 198);
	st.dayname = Color(190, 150, 80);
	st.fgselect = Color(198, 198, 198);
	st.selectday = Color(198, 198, 198);
	st.selecttoday = Color(190, 150, 80);
	st.today = Color(198, 198, 198);
	st.curdate = Color(198, 198, 198);
	st.cursorday = Color(255, 255, 192);
	st.fgtoday = Color(198, 198, 198);
	st.week = Color(127, 127, 127);
	st.header = Color(255, 127, 0);
	
	cal.SetStyle(Calendar::StyleDefault());
        cal.OneButton();

, that's the graphic result I got:index.php?t=getfile&id=4283&private=0
(they say an image is worth a thousand words)Smile
Please, observe that the year + month header is not initialized centered between the left and right buttons when using a smaller font size (Arial(8 )). I assume Calendar does not initialize its FlatSpin members with the assigned calendar font promptly right after the call to SetStyle, so I propose this modification
Calendar& Calendar::SetStyle(const Style& s)
{
	style = &s;
	nbg = Colorize(CtrlImg::Bg(), s.header, 150);
	spin_month.SetFont(s.font);  // inserted line
	spin_year.SetFont(s.font);   // inserted line
	spin_all.SetFont(s.font);    // inserted line
	UpdateFields();              // inserted line
	Refresh();
	return *this;
}
, which corrects all misalignments, with or without SwapMonthYear(), OneButton() or the combination of both.

3. Yet insisting on my last posting before this one, the week days and weekend day numbers would be hardly visible without the following modifications, which then again I'd like to submit to your appreciation:
// Add new member Color weekend to Calendar Style definition:
class Calendar : public PopUpCtrl
{
public:
	struct Style : ChStyle<Style> {
		Color header;

		Color bgmain;
		Color bgtoday;
		Color bgselect;

		Color fgmain;
		Color fgtoday;
		Color fgselect;
		Color outofmonth;
		Color curdate;
		Color today;
		Color selecttoday;
		Color cursorday;
		Color selectday;
		Color line;
		Color dayname;
		Color week;
		Color weekend;				// <== Inserted line
		Font  font;
		Image spinleftimg;
		Image spinrightimg;
		bool  spinhighlight;
	};
...
, together with
...
if(m == view.month)
{
	Day(j, i) = d;

	fg = st.fgmain;	// fg = Black;			// <== Modified line

	if(j == 6)
	{
		fg = st.weekend; // fg = Red;		// <== Modified line
	}

...

, in Calendars Paint function, fixes this issue.

Sorry for the very long post.
Thank you.
  • Attachment: Calendar.png
    (Size: 5.06KB, Downloaded 817 times)

[Updated on: Sun, 11 August 2013 03:38]

Report message to a moderator

Re: Little improvement of Caledar & DropDate controls [message #40693 is a reply to message #40095] Wed, 04 September 2013 06:02 Go to previous messageGo to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Hello, folks?
Is there anybody there??
Re: Little improvement of Caledar & DropDate controls [message #40695 is a reply to message #40693] Wed, 04 September 2013 07:22 Go to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Thanks for remanding... Smile I'll take care of it
Previous Topic: [Minor bug & patch] CalendarCtrl should offer support for native cursor icon.
Next Topic: Clock bug?
Goto Forum:
  


Current Time: Fri Mar 29 08:31:05 CET 2024

Total time taken to generate the page: 0.01271 seconds