Home » U++ Library support » U++ Widgets - General questions or Mixed problems » there is no fontpusher class (just checking)
|
|
Re: there is no fontpusher class (just checking) [message #10943 is a reply to message #10938] |
Mon, 06 August 2007 18:09   |
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 
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 #10945 is a reply to message #10944] |
Mon, 06 August 2007 21:02   |
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
|
|
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 23:05:47 CEST 2025
Total time taken to generate the page: 0.00792 seconds
|