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 » U++ Widgets - General questions or Mixed problems » there is no fontpusher class (just checking)
there is no fontpusher class (just checking) [message #10933] Sun, 05 August 2007 18:07 Go to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
is that right?

Is there a reason for this?

I see that there are all the Face functions which should allow me to make my own so no worries. Am just a little confused that there isn't a FontPusher equivalent of ColorPusher. Guess if I don't like it I should make my own and submit it eh? Smile

Nick
Re: there is no fontpusher class (just checking) [message #10938 is a reply to message #10933] Sun, 05 August 2007 21:38 Go to previous messageGo to next message
andrei-catalin is currently offline  andrei-catalin
Messages: 62
Registered: May 2006
Location: Romania
Member
Reference/Display is a good start point.

Andrei
Re: there is no fontpusher class (just checking) [message #10943 is a reply to message #10938] Mon, 06 August 2007 18:09 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Thanks, that was a very good starting point. So now I got my little font picker dialog complete with preview but I'm having trouble with the FontPusher object which will popup the FontDlg when left-clicked.

<edited/cut - I found a silly error so I actually do not know how Buttons behave when you set their font - however, the code below works,is self-contained and should continue to work regardless of how buttons behave>

Cheers,

Nick

p.s. apart from this it all works very nicely and is small and neat. I will post it in this thread once it works in case anyone else ever searches the forums for FontChooser, FontPicker, FontPusher, Font or FontDialog Smile

p.p.s. I am using the latest release version of UPP

[Updated on: Mon, 06 August 2007 21:27]

Report message to a moderator

Re: there is no fontpusher class (just checking) [message #10944 is a reply to message #10943] Mon, 06 August 2007 18:54 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
nixnixnix wrote on Mon, 06 August 2007 17:09


...
For some reason, buttons and other similar objects do not behave well when I try to set their fonts.
...
Label is the only class I've found which can display fonts correctly.
...


My very strong guess is that in CtrlLib/Button.cpp ~line 182:
	font = StdFont();

when CtrlLib/LabelBase.cpp ~line 301:
LabelBase& LabelBase::SetFont(Font font) {
	if(lbl.font != font) {
		lbl.font = font;
		LabelUpdate();
	}
	return *this;
}

And what you want (and I wanted long time ago... Smile ) is to have options to exclude Ctrls from Chameleon (or sytem unified look) dictatorship... Ok, at least fonts for the beginning. Smile
Re: there is no fontpusher class (just checking) [message #10945 is a reply to message #10944] Mon, 06 August 2007 21:02 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Thanks Fudadmin, for stopping me barking up the wrong tree. I went back to overriding the Paint routine and it works fine.

Cheers,

Nick

#define LAYOUTFILE <OpenWind/FontPusher.lay>
#include <CtrlCore/lay.h>

class FontDlg : public WithFontPopupLayout<TopWindow> 
{
	typedef FontDlg CLASSNAME;
public:

	FontDlg();
	~FontDlg();
	
	void Set(Font font,Color col);
	Font GetFont();
	Color GetColor(){return color.GetData();}	

protected:
	Font m_font;
	
	void OnChange();
	void Set();
	
};

class FontPusher : public Ctrl
{
	typedef FontPusher CLASSNAME;
public:

	FontPusher();
	virtual ~FontPusher();
	
	virtual void  Paint(Draw& w);
	virtual void  LeftDown(Point p, dword);

	void Set(Font font,Color col){m_font = font; m_color = col; Refresh();};
	Font GetFont(){return m_font;}
	Color GetColor(){return m_color;}	
		
protected:
	Color m_color;
	Font m_font;
	FontDlg fonts;
	String text;
	
	void Drop();

};


#include "FontPusher.h"

FontDlg::FontDlg()
{
	CtrlLayoutOKCancel(*this, "Choose Font");

	size.Add(4);
	size.Add(5);
	size.Add(6);
	size.Add(7);
	size.Add(8);
	size.Add(9);
	size.Add(10);
	size.Add(11);
	size.Add(12);
	size.Add(14);
	size.Add(16);
	size.Add(18);
	size.Add(20);
	size.Add(22);
	size.Add(24);
	size.Add(26);
	size.Add(28);
	size.Add(36);
	size.Add(42);
	size.Add(48);
	size.Add(60);
	size.Add(72);
	
	for(int i=0;i<Font::GetFaceCount();i++)
	{
		face.Add(Font::GetFaceName(i));	
	}
	
	face.WhenAction = THISBACK(OnChange);
	strikeout.WhenAction = THISBACK(OnChange);
	bold.WhenAction = THISBACK(OnChange);
	underline.WhenAction = THISBACK(OnChange);
	italic.WhenAction = THISBACK(OnChange);
	size.WhenAction = THISBACK(OnChange);
	color.WhenAction = THISBACK(OnChange);
		
}

void FontDlg::OnChange()
{
	GetFont();
	Set();
	
	Refresh();
	
}

FontDlg::~FontDlg()
{
}

void FontDlg::Set(Font font,Color col)
{
	m_font = font;
	color.SetData(col);
	
	Set();
}

void FontDlg::Set()
{
	size.SetValue(m_font.GetHeight());
	face.SetIndex(m_font.GetFace());
	
	strikeout = m_font.IsStrikeout();
	italic = m_font.IsItalic();
	bold = m_font.IsBold();
	underline = m_font.IsUnderline();

	preview.SetText(m_font.GetFaceName());
	preview.SetFont(m_font);
	preview.SetInk(color.GetData());
	
	Refresh();	
}

Font FontDlg::GetFont()
{
	m_font = Font().Face(face.GetIndex()).Height(size.GetData()).Strikeout(strikeout).Italic(italic).Bold(bold).Underline(underline);
	
	return m_font;
}

FontPusher::FontPusher()
{
	text = "Choose Font";
}

FontPusher::~FontPusher()
{
}

void  FontPusher::LeftDown(Point p, dword)
{
	Drop();	
}

void FontPusher::Drop()
{

	fonts.Set(m_font,m_color);
	if(fonts.Execute()!=IDOK)return;
	
	m_color = fonts.GetColor();
	m_font = fonts.GetFont();
	
	Refresh();	
}

void FontPusher::Paint(Draw& w)
{
	Size sz = GetSize();
//	String txt = m_font.GetFaceName();
	Size tsz = GetTextSize(text, m_font);

	w.DrawRect(1, 1, sz.cx - 2, sz.cy - 2, SWhite);
	DrawFrame(w, 0, 0, sz.cx, sz.cy, SBlack);
	w.DrawText((sz.cx - tsz.cx) / 2, (sz.cy - tsz.cy) / 2, text, m_font, m_color);

}


LAYOUT(FontPopupLayout, 332, 228)
	ITEM(Label, dv___0, SetLabel(t_("Font")).LeftPosZ(16, 52).TopPosZ(16, 20))
	ITEM(DropList, face, LeftPosZ(72, 172).TopPosZ(16, 19))
	ITEM(Option, italic, SetLabel(t_("Italic")).LeftPosZ(16, 48).TopPosZ(44, 18))
	ITEM(Option, bold, SetLabel(t_("Bold")).LeftPosZ(16, 44).TopPosZ(68, 18))
	ITEM(Option, underline, SetLabel(t_("Underline")).LeftPosZ(72, 68).TopPosZ(44, 18))
	ITEM(Option, strikeout, SetLabel(t_("Strikeout")).LeftPosZ(72, 64).TopPosZ(68, 18))
	ITEM(DropList, size, LeftPosZ(256, 64).TopPosZ(16, 19))
	ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(10, 68).BottomPosZ(12, 20))
	ITEM(Button, cancel, SetLabel(t_("Cancel")).HCenterPosZ(68, 44).BottomPosZ(12, 20))
	ITEM(LabelBox, dv___10, SetLabel(t_("Preview")).LeftPosZ(16, 304).TopPosZ(96, 92))
	ITEM(ColorPusher, color, LeftPosZ(232, 76).TopPosZ(60, 24))
	ITEM(LabelBox, dv___12, SetLabel(t_("Color")).HSizePosZ(220, 12).TopPosZ(44, 48))
	ITEM(Label, preview, LeftPosZ(28, 276).TopPosZ(112, 68))
END_LAYOUT



So its not a gold standard class - it could use a SetText function as well as a nulltext option which makes it default back to the Face name but hey, its a start for anyone out there who wants the equivalent of the MSWord fontpicker.


[Updated on: Mon, 06 August 2007 21:17]

Report message to a moderator

Re: there is no fontpusher class (just checking) [message #10946 is a reply to message #10944] Mon, 06 August 2007 21:06 Go to previous messageGo to next message
andrei-catalin is currently offline  andrei-catalin
Messages: 62
Registered: May 2006
Location: Romania
Member
In Upp707-dev1 it is OK to set a font for a button.


b3.SetFont(Font().FaceName("Monotype Corsiva").Height(18));

b4.SetFont(Font().FaceName("Bonk Offset").Height(18));	


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

Andrei
  • Attachment: buttons.png
    (Size: 1.58KB, Downloaded 735 times)
Re: there is no fontpusher class (just checking) [message #10949 is a reply to message #10945] Mon, 06 August 2007 23:50 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
nixnixnix wrote on Mon, 06 August 2007 20:02

Thanks Fudadmin, for stopping me barking up the wrong tree. I went back to overriding the Paint routine and it works fine.


I'm getting old and blind Embarassed

Button.cpp ~line 135
Pusher&  Pusher::SetFont(Font fnt) {
	font = fnt;
	Refresh();
	return *this;
}

Re: there is no fontpusher class (just checking) [message #10951 is a reply to message #10949] Tue, 07 August 2007 01:00 Go to previous message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Yeah I need to set the colour too though so I think overriding paint is the best way.

Thanks for your help though,

Nick
Previous Topic: Missing Functions for Layouter
Next Topic: howto force evaluation after <CR>
Goto Forum:
  


Current Time: Fri Mar 29 16:22:30 CET 2024

Total time taken to generate the page: 0.01449 seconds