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 » Draw, Display, Images, Bitmaps, Icons » Option Label on Left Side draw
Option Label on Left Side draw [message #60070] Thu, 03 August 2023 23:27 Go to next message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
So I figured this would be a simple patch but I can seem to find what is causing me the problem.

Original Code:
void Option::Paint(Draw& w) {
	Size sz = GetSize();
	
	if(!IsTransparent())
		w.DrawRect(0, 0, sz.cx, sz.cy, SColorFace);
	
	Size isz = CtrlsImg::O0().GetSize();
	Size tsz = GetSmartTextSize(label, font);
	int ix = 0;
	int d = tsz.cy >> 1;
	int ty = (sz.cy - tsz.cy) / 2;
	int iy = (tsz.cy - isz.cy) / 2 + ty;

	if(box) {
		ix = d + DPI(4);
		if(tsz.cy > isz.cy) {
			ty = 0;
			iy = (tsz.cy - isz.cy) / 2;
		}
		else {
			iy = 0;
			ty = (isz.cy - tsz.cy) / 2;
		}
	}
	else
	if(!showlabel) {
		ix = (sz.cx - isz.cx) / 2;
		iy = (sz.cy - isz.cy) / 2;
	}
	
	int q = GetVisualState();
	int g = (!notnull || threestate) && IsNull(option) ? CtrlsImg::I_O2
	                                                   : option == 1 ? CtrlsImg::I_O1
	                                                                 : CtrlsImg::I_O0;
	if(switchimage)
		g = option ? CtrlsImg::I_S1 : CtrlsImg::I_S0;
	
	w.DrawImage(ix, iy, CtrlsImg::Get(g + q));
	
	if(showlabel) {
		bool ds = !IsShowEnabled();
		DrawSmartText(w, ix + isz.cx + DPI(2), ty, tsz.cx, label, font,
		              ds || IsReadOnly() ? SColorDisabled : Nvl(color, GetLabelTextColor(this)),
		              VisibleAccessKeys() ? accesskey : 0);
		if(HasFocus())
			DrawFocus(w, RectC(ix + isz.cx + DPI(2), ty - DPI(1), tsz.cx + DPI(3), tsz.cy + DPI(2)) & sz);
	}
	
	if(box) {
		w.Begin();
		w.ExcludeClip(ix - DPI(3), 0, isz.cx + DPI(8) + tsz.cx, tsz.cy);
		PaintLabelBox(w, sz, Null, d);
		w.End();
	}
}


As you can tell it pre gets the size of the image and the label.

It should be just a simple as this to get it on the left side. This i only for testing
void Option::Paint(Draw& w) {
	Size sz = GetSize();

	if(!IsTransparent())
		w.DrawRect(0, 0, sz.cx, sz.cy, SColorFace);

	Size isz = CtrlsImg::O0().GetSize();
	Size tsz = GetSmartTextSize(label, font);
	int ix = 0;
	int d = tsz.cy >> 1;
	int ty = (sz.cy - tsz.cy) / 2;
	int iy = (tsz.cy - isz.cy) / 2 + ty;

	if(box) {
		ix = d + DPI(4);
		if(tsz.cy > isz.cy) {
			ty = 0;
			iy = (tsz.cy - isz.cy) / 2;
		}
		else {
			iy = 0;
			ty = (isz.cy - tsz.cy) / 2;
		}
	}
	else
	if(!showlabel) {
		ix = (sz.cx - isz.cx) / 2;
		iy = (sz.cy - isz.cy) / 2;
	}

	int q = GetVisualState();
	int g = (!notnull || threestate) && IsNull(option) ? CtrlsImg::I_O2
	                                                   : option == 1 ? CtrlsImg::I_O1
	                                                                 : CtrlsImg::I_O0;
	if(switchimage)
		g = option ? CtrlsImg::I_S1 : CtrlsImg::I_S0;

	w.DrawImage(ix + tsz.cx + DPI(2), iy, CtrlsImg::Get(g + q));

	if(showlabel) {
		bool ds = !IsShowEnabled();
		DrawSmartText(w, ix, ty, tsz.cx, label, font,
		              ds || IsReadOnly() ? SColorDisabled : Nvl(color, GetLabelTextColor(this)),
		              VisibleAccessKeys() ? accesskey : 0);
		if(HasFocus())
			DrawFocus(w, RectC(ix, ty - DPI(1), tsz.cx + DPI(3), tsz.cy + DPI(2)) & sz);
	}

	if(box) {
		w.Begin();
		w.ExcludeClip(ix - DPI(3), 0, isz.cx + DPI(8) + tsz.cx, tsz.cy);
		PaintLabelBox(w, sz, Null, d);
		w.End();
	}
}


But this results in anything beyond where the checkbox button image not drawing anything on click

This code shows exactly what I mean when testing a app
void Option::Paint(Draw& w) {
	Size sz = GetSize();

	if(!IsTransparent())
		w.DrawRect(0, 0, sz.cx, sz.cy, SColorFace);

	Size isz = CtrlsImg::O0().GetSize();
	Size tsz = GetSmartTextSize(label, font);
	int ix = 0;
	int d = tsz.cy >> 1;
	int ty = (sz.cy - tsz.cy) / 2;
	int iy = (tsz.cy - isz.cy) / 2 + ty;

	if(box) {
		ix = d + DPI(4);
		if(tsz.cy > isz.cy) {
			ty = 0;
			iy = (tsz.cy - isz.cy) / 2;
		}
		else {
			iy = 0;
			ty = (isz.cy - tsz.cy) / 2;
		}
	}
	else
	if(!showlabel) {
		ix = (sz.cx - isz.cx) / 2;
		iy = (sz.cy - isz.cy) / 2;
	}

	int q = GetVisualState();
	int g = (!notnull || threestate) && IsNull(option) ? CtrlsImg::I_O2
	                                                   : option == 1 ? CtrlsImg::I_O1
	                                                                 : CtrlsImg::I_O0;
	if(switchimage)
		g = option ? CtrlsImg::I_S1 : CtrlsImg::I_S0;

  if(option != 1) {
		w.DrawRect(0, 0, sz.cx, sz.cy, Red());
  } else {
		w.DrawRect(0, 0, sz.cx, sz.cy, Green());
  }

	if(showlabel) {
		bool ds = !IsShowEnabled();
		DrawSmartText(w, ix, ty, tsz.cx, label, font,
		              ds || IsReadOnly() ? SColorDisabled : Nvl(color, GetLabelTextColor(this)),
		              VisibleAccessKeys() ? accesskey : 0);
		if(HasFocus())
			DrawFocus(w, RectC(ix, ty - DPI(1), tsz.cx + DPI(3), tsz.cy + DPI(2)) & sz);
	}

	if(box) {
		w.Begin();
		w.ExcludeClip(ix - DPI(3), 0, isz.cx + DPI(8) + tsz.cx, tsz.cy);
		PaintLabelBox(w, sz, Null, d);
		w.End();
	}
}


There is something choosing where the control painting will get updated and only painting that part. I have no clue what code is doing that.
Re: Option Label on Left Side draw [message #60071 is a reply to message #60070] Thu, 03 August 2023 23:30 Go to previous messageGo to next message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
Never mind. I think it is in this

void Option::RefreshPush() {
	if(box)
		Refresh(0, 0, GetSize().cx, GetSmartTextSize(label, font).cy);
	else
	if(showlabel)
		Refresh(0, 0, CtrlsImg::O0().GetSize().cx, GetSize().cy);
	else
		Pusher::RefreshPush();
}
Re: Option Label on Left Side draw [message #60072 is a reply to message #60070] Thu, 03 August 2023 23:39 Go to previous messageGo to next message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
This is of it working with label to the left. I am going to patch mine too support left and right labels

void Option::RefreshPush() {
	if(box)
		Refresh(0, 0, GetSize().cx, GetSmartTextSize(label, font).cy);
	else
	if(showlabel)
		Refresh(GetSmartTextSize(label, font).cx + DPI(2), 0, CtrlsImg::O0().GetSize().cx, GetSize().cy);
	else
		Pusher::RefreshPush();
}

void Option::Paint(Draw& w) {
	Size sz = GetSize();

	if(!IsTransparent())
		w.DrawRect(0, 0, sz.cx, sz.cy, SColorFace);

	Size isz = CtrlsImg::O0().GetSize();
	Size tsz = GetSmartTextSize(label, font);
	int ix = 0;
	int d = tsz.cy >> 1;
	int ty = (sz.cy - tsz.cy) / 2;
	int iy = (tsz.cy - isz.cy) / 2 + ty;

	if(box) {
		ix = d + DPI(4);
		if(tsz.cy > isz.cy) {
			ty = 0;
			iy = (tsz.cy - isz.cy) / 2;
		}
		else {
			iy = 0;
			ty = (isz.cy - tsz.cy) / 2;
		}
	}
	else
	if(!showlabel) {
		ix = (sz.cx - isz.cx) / 2;
		iy = (sz.cy - isz.cy) / 2;
	}

	int q = GetVisualState();
	int g = (!notnull || threestate) && IsNull(option) ? CtrlsImg::I_O2
	                                                   : option == 1 ? CtrlsImg::I_O1
	                                                                 : CtrlsImg::I_O0;
	if(switchimage)
		g = option ? CtrlsImg::I_S1 : CtrlsImg::I_S0;

	w.DrawImage(ix + tsz.cx + DPI(2), iy, CtrlsImg::Get(g + q));

	if(showlabel) {
		bool ds = !IsShowEnabled();
		DrawSmartText(w, ix, ty, tsz.cx, label, font,
		              ds || IsReadOnly() ? SColorDisabled : Nvl(color, GetLabelTextColor(this)),
		              VisibleAccessKeys() ? accesskey : 0);
		if(HasFocus())
			DrawFocus(w, RectC(ix, ty - DPI(1), tsz.cx + DPI(3), tsz.cy + DPI(2)) & sz);
	}

	if(box) {
		w.Begin();
		w.ExcludeClip(ix - DPI(3), 0, isz.cx + DPI(8) + tsz.cx, tsz.cy);
		PaintLabelBox(w, sz, Null, d);
		w.End();
	}
}
Re: Option Label on Left Side draw [message #60073 is a reply to message #60070] Fri, 04 August 2023 02:19 Go to previous messageGo to next message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
I did a quick hack to Option called it eOption just as an example. It allows left oriented label and also allows adding space between the image and the label.

LabelLeft(true/false)
LabelGap(#)
  • Attachment: eOption.zip
    (Size: 2.36KB, Downloaded 36 times)
Re: Option Label on Left Side draw [message #60074 is a reply to message #60070] Fri, 04 August 2023 17:43 Go to previous message
devilsclaw is currently offline  devilsclaw
Messages: 72
Registered: August 2022
Member
Sorry the quick hack had bugs in it. It was late and I was getting off work. Here is a fully working example in project form
Previous Topic: Font and Image rendering slow
Next Topic: plugin/tga
Goto Forum:
  


Current Time: Sat May 04 22:38:55 CEST 2024

Total time taken to generate the page: 0.01904 seconds