.examples

git-svn-id: svn://ultimatepp.org/upp/trunk@14205 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-03-31 15:04:59 +00:00
parent 38df12a9b9
commit d400a792fc
6 changed files with 41 additions and 79 deletions

View file

@ -233,7 +233,6 @@ void GeoFun::SaveToAutoCadScript ( String fileName )
fo.Put ( sScr );
fo.Close();
}
}
@ -284,7 +283,6 @@ void GeoFun::SaveToSVG ( String fileName )
fo.Put ( sXML );
fo.Close();
}
}
void GeoFun::Print()
@ -309,14 +307,13 @@ void GeoFun::Print()
// This function calculates curve data points for display
void GeoFun::PrepareData0()
void GeoFun::PrepareData()
{
int p, q, pw;
double a, b, h ;
double x, y;
double Period, step, t ;
static int prepd = 0;
step = 1.0 ; // value in deg
@ -405,8 +402,6 @@ void GeoFun::PrepareData0()
InputPane.RollingRad = "Rolling Radius : " + Format ( "%0.2f", b ) ;
// ShowAnimation = ~InputPane.optAnimate ;
dc1.Zoomed = InputPane.optZoom.GetData();
if ( dc1.Zoomed )
@ -479,19 +474,14 @@ void GeoFun::PrepareData0()
p1.x = dc1.data[0].point[0].x ;
p1.y = dc1.data[0].point[0].y ;
dc1.data[0].point.Add ( p1 );
prepd++;
}
void GeoFun::PrepareData()
{
PrepareData0();
dc1.Refresh();
}
void GeoFun::ShowAnimated()
{
int MaxCnt = dc1.data[0].point.GetCount();
// static dword LastTickCount = GetTickCount() ;
if ( dc1.ShowAnimation )
{
@ -499,17 +489,17 @@ void GeoFun::ShowAnimated()
{
dc1.Refresh();
dc1.ShowTo += dc1.AnimSpeed ;
DUMP("Animation");
}
else
{
dc1.ShowAnimation = false ;
dc1.ColorFill = ~InputPane.optColorFill ;
dc1.Refresh();
Animate.Kill();
DUMP("End Animation");
}
}
// RLOG("TickCount - " <<( GetTickCount() - LastTickCount));
// LastTickCount = GetTickCount();
}
void GeoFun::SetAnimation()
@ -518,6 +508,7 @@ void GeoFun::SetAnimation()
dc1.ShowTo = 5 ;
dc1.ShowAnimation = true ;
dc1.ColorFill = false ;
Animate.KillSet(-50, THISBACK(ShowAnimated));
}
@ -525,7 +516,9 @@ void GeoFun::FirstDraw()
{
First = false ;
PrepareData();
SetTimeCallback ( -30, THISBACK ( ShowAnimated ), 50 );
// SetTimeCallback ( 1030, THISBACK ( ShowAnimated ), 50 );
// Animate.KillSet(-50, THISBACK(ShowAnimated));
DUMP("First Draw");
}
@ -562,7 +555,7 @@ void GeoFun::Layout()
{
if ( !First )
{
PrepareData0();
PrepareData();
}
TopWindow::Layout();
@ -570,23 +563,19 @@ void GeoFun::Layout()
void GeoFun::About()
{
WithAboutLayout<TopWindow> dlg;
dlg.AboutText = GetTopic ( "topic://GeoFun/app/About$en-us" ).text;
CtrlLayoutOK ( dlg, "About" );
dlg.CenterScreen();
dlg.Run();
}
void GeoFun::Help()
{
HelpWindow helpme;
helpme.GoTo ( "topic://GeoFun/app/Help$en-us" );
helpme.Execute();
}
@ -598,11 +587,8 @@ void GeoFun::Exit()
void GeoFun::SetAnimationSpeed()
{
dc1.AnimSpeed = InputPane.edAnimSpeed.GetData();
if ( dc1.AnimSpeed < 1 ) dc1.AnimSpeed = 1;
if ( dc1.AnimSpeed > 20 ) dc1.AnimSpeed = 20;
InputPane.edAnimSpeed.SetData ( dc1.AnimSpeed );
}
@ -637,16 +623,11 @@ void GeoFun::SetCurveType ( int CrvType )
SetCurveTypeMenu ( CrvType );
}
void GeoFun::SetCurveTypeMenu1 ( )
{
int CrvType = InputPane.CurveType.GetData();
SetCurveTypeMenu ( CrvType );
}
void GeoFun::SetCurveTypeMenu ( int CrvType )
{
EpiCyclo = HypoCyclo = EpiTroch = HypoTroch = false ;
switch ( CrvType )
switch ( CrvType )
{
case 1 : HypoCyclo = true ; break ;
case 2 : EpiTroch = true ; break ;
@ -761,7 +742,7 @@ GeoFun::GeoFun()
InputPane.CurveType.SetData ( 2 );
}
InputPane.CurveType.WhenAction << THISBACK (SetCurveTypeMenu1);
InputPane.CurveType.WhenAction << THISBACK1 (SetCurveTypeMenu,(int)InputPane.CurveType.GetData());
InputPane.optGradient.WhenAction << THISBACK ( PrepareData );
InputPane.optColorFill.WhenAction << THISBACK ( PrepareData );
@ -794,7 +775,6 @@ GUI_APP_MAIN
gf.First = true ;
String cfgfile = ConfigFile();
if ( FileExists ( cfgfile ) )
{
cfgAvailable = true ;
@ -810,8 +790,6 @@ GUI_APP_MAIN
cfgAvailable = false ;
}
// gf.Icon(Image::(5555, true), Image::ICON(5555, false));
gf.Run();
StoreToFile ( gf );

View file

@ -65,6 +65,8 @@ class GeoFun : public WithGeoFunLayout<TopWindow> {
Splitter sp1;
QtfRichObject qtfim;
TimeCallback Animate;
int ValP, ValQ, PenW, CurvT, GradientY;
Color PenC, M1C, M2C, B1C, B2C;
@ -90,7 +92,7 @@ class GeoFun : public WithGeoFunLayout<TopWindow> {
void OptionZoom();
void PrepareData();
void PrepareData0();
void Print();
void SaveToImageFile ( String fileName );
@ -99,7 +101,7 @@ class GeoFun : public WithGeoFunLayout<TopWindow> {
void SetAnimation();
void SetAnimationSpeed();
void SetCurveType ( int CrvType );
void SetCurveTypeMenu1 ( );
void SetCurveTypeMenu ( int CrvType );
void Serialize ( Stream& s );
void ShowAnimated();

View file

@ -19,8 +19,6 @@ struct Preview : Ctrl {
struct TextToSvgPathDlg : public WithTextToSvgPathLayout<TopWindow> {
Preview preview;
void Render();
TextToSvgPathDlg();
};

View file

@ -1,15 +1,15 @@
LAYOUT(TextToSvgPathLayout, 704, 588)
ITEM(Label, dv___0, SetLabel(t_("Text")).LeftPosZ(8, 33).TopPosZ(28, 19))
ITEM(EditString, text, LeftPosZ(44, 652).TopPosZ(28, 19))
ITEM(EditString, text, HSizePosZ(44, 8).TopPosZ(28, 19))
ITEM(Label, dv___2, SetLabel(t_("Font")).LeftPosZ(8, 33).TopPosZ(4, 19))
ITEM(DropList, face, LeftPosZ(44, 188).TopPosZ(4, 19))
ITEM(Label, dv___4, SetLabel(t_("Height")).LeftPosZ(252, 39).TopPosZ(4, 19))
ITEM(WithDropChoice<EditInt>, height, LeftPosZ(292, 56).TopPosZ(4, 19))
ITEM(Option, bold, SetLabel(t_("Bold")).LeftPosZ(356, 52).TopPosZ(4, 18))
ITEM(Option, italic, SetLabel(t_("Italic")).LeftPosZ(408, 52).TopPosZ(4, 18))
ITEM(LineEdit, svgpath, LeftPosZ(8, 688).TopPosZ(52, 268))
UNTYPED(preview, LeftPosZ(8, 688).TopPosZ(324, 260))
ITEM(Button, copy, SetLabel(t_("Copy path to clipboard")).LeftPosZ(568, 128).TopPosZ(4, 20))
ITEM(Option, bold, SetLabel(t_("Bold")).LeftPosZ(356, 52).TopPosZ(4, 20))
ITEM(Option, italic, SetLabel(t_("Italic")).LeftPosZ(408, 52).TopPosZ(4, 20))
ITEM(LineEdit, svgpath, HSizePosZ(8, 8).VSizePosZ(52, 268))
UNTYPED(preview, HSizePosZ(8, 8).BottomPosZ(4, 260))
ITEM(Button, copy, SetLabel(t_("Copy path to clipboard")).RightPosZ(8, 128).TopPosZ(4, 20))
ITEM(Option, singleline, SetLabel(t_("Single line")).LeftPosZ(484, 80).TopPosZ(4, 20))
END_LAYOUT

View file

@ -1,7 +1,7 @@
#include "TextToSvgPath.h"
struct TextToSvg : FontGlyphConsumer {
String t;
String t; // here we accumulate the SVG path text
void Put(Pointf p);
@ -55,7 +55,7 @@ String TextToSvgPath(double x, double y, const char *text, Font fnt, bool single
TextToSvg t;
for(const wchar *s = ~ws; *s; s++) {
fnt.Render(t, x, y, *s);
x += fnt[*s];
x += fnt[*s]; // move the reference point
if(!singleline)
t.t << "\n";
}

View file

@ -10,31 +10,12 @@ void Preview::Paint(Draw& w)
TextToSvgPathDlg::TextToSvgPathDlg()
{
CtrlLayout(*this, "Text to SVG path converter");
for(Ctrl *q = GetFirstChild(); q; q = q->GetNext())
if(!dynamic_cast<Button *>(q))
q->WhenAction = [=] { Render(); };
face.Add(Font::ARIAL);
face.Add(Font::ROMAN);
face.Add(Font::COURIER);
for(int i = Font::COURIER + 1; i < Font::GetFaceCount(); i++)
if(Font::GetFaceInfo(i) & Font::SCALEABLE)
face.Add(i);
for(int i = 1; i < Font::GetFaceCount(); i++)
if(Font::GetFaceInfo(i) & Font::SCALEABLE)
face.Add(i, Font::GetFaceName(i));
struct DisplayFace : public Display {
void Paint(Draw& w, const Rect& r, const Value& q, Color ink, Color paper, dword style) const {
int ii = q;
Font fnt = StdFont();
if(!(Font::GetFaceInfo(ii) & Font::SPECIAL))
fnt.Face(ii);
w.DrawRect(r, paper);
w.DrawText(r.left, r.top + (r.Height() - fnt.Info().GetHeight()) / 2,
Font::GetFaceName((int)q), fnt, ink);
}
};
face.SetDisplay(Single<DisplayFace>());
face <<= Font::ARIAL;
face <<= Font::SANSSERIF;
height.MinMax(6, 500);
for(int i = 4; i < 500; i += i < 16 ? 1 : i < 32 ? 4 : i < 48 ? 8 : 16)
@ -43,21 +24,24 @@ TextToSvgPathDlg::TextToSvgPathDlg()
svgpath.SetReadOnly();
preview.SetFrame(ViewFrame());
for(Ctrl *q = GetFirstChild(); q; q = q->GetNext())
if(!dynamic_cast<Button *>(q))
*q << [=] {
Font fnt(~face, ~height);
fnt.Bold(~bold);
fnt.Italic(~italic);
svgpath <<= preview.svgpath = TextToSvgPath(0, 0, (String)~text, fnt, ~singleline);
preview.Refresh();
};
copy.SetImage(CtrlImg::copy());
copy << [=] {
WriteClipboardText(preview.svgpath);
};
}
void TextToSvgPathDlg::Render()
{
Font fnt(~face, ~height);
fnt.Bold(~bold);
fnt.Italic(~italic);
svgpath <<= preview.svgpath = TextToSvgPath(0, 0, (String)~text, fnt, ~singleline);
preview.Refresh();
Sizeable().Zoomable();
}
GUI_APP_MAIN