drawing text with multi shadow effect
*See some rendered screenshotw below
can see also:
*Begin code
Do Locfile("system.app")
Set Classlib To Locfile("gdiplusX") AddI
Publi yform
yform=Newobject("asup")
Release Classlib "gdiplusX"
yform.Show
Read Events
Return
*
Define Class asup As Form
Height = 526
Width = 799
ShowWindow = 2
ShowTips = .T.
AutoCenter = .T.
Caption = "Form1"
BackColor = Rgb(0,0,0)
Name = "Form1"
Add Object ymulti_shadow1 As ymulti_shadow With ;
Anchor = 15, ;
Height = 370, ;
Left = 12, ;
Top = 2, ;
Width = 780, ;
rendermode = 4, ;
maincolor = (Rgb(120,180,140)), ;
Name = "Ymulti_shadow1"
Add Object text1 As TextBox With ;
Height = 25, ;
Left = 143, ;
ToolTipText = "Enter a text and valid", ;
Top = 390, ;
Width = 264, ;
Name = "Text1"
Add Object command1 As CommandButton With ;
Top = 420, ;
Left = 103, ;
Height = 25, ;
Width = 121, ;
Caption = "Font+size", ;
Name = "Command1"
Add Object text2 As TextBox With ;
Height = 25, ;
Left = 227, ;
Top = 420, ;
Width = 37, ;
Name = "Text2"
Add Object label1 As Label With ;
FontBold = .T., ;
FontSize = 9, ;
BackStyle = 0, ;
BorderStyle = 1, ;
Caption = "", ;
Height = 25, ;
Left = 271, ;
Top = 420, ;
Width = 229, ;
ForeColor = Rgb(255,0,0), ;
Name = "Label1"
Add Object combo1 As ComboBox With ;
Height = 25, ;
Left = 577, ;
Top = 432, ;
Width = 61, ;
Name = "Combo1"
Add Object label2 As Label With ;
AutoSize = .T., ;
FontBold = .T., ;
BackStyle = 0, ;
Caption = "Style", ;
Height = 17, ;
Left = 533, ;
Top = 432, ;
Width = 30, ;
ForeColor = Rgb(255,255,255), ;
Name = "Label2"
Add Object command2 As CommandButton With ;
Top = 456, ;
Left = 113, ;
Height = 25, ;
Width = 85, ;
Caption = "Maincolor", ;
Name = "Command2"
Add Object spinner1 As Spinner With ;
Height = 24, ;
KeyboardHighValue = 1, ;
KeyboardLowValue = -1, ;
Left = 233, ;
SpinnerHighValue = 1.00, ;
SpinnerLowValue = -1.00, ;
Top = 456, ;
Width = 48, ;
Value = 0, ;
Name = "Spinner1"
Add Object spinner2 As Spinner With ;
Height = 24, ;
KeyboardHighValue = 1, ;
KeyboardLowValue = -1, ;
Left = 233, ;
SpinnerHighValue = 1.00, ;
SpinnerLowValue = -1.00, ;
Top = 485, ;
Width = 48, ;
Value = 0, ;
Name = "Spinner2"
Add Object label3 As Label With ;
AutoSize = .T., ;
Caption = "dirH", ;
Height = 17, ;
Left = 203, ;
Top = 460, ;
Width = 25, ;
Name = "Label3"
Add Object label4 As Label With ;
AutoSize = .T., ;
Caption = "dirV", ;
Height = 17, ;
Left = 203, ;
Top = 487, ;
Width = 23, ;
Name = "Label4"
Add Object spinner3 As Spinner With ;
Height = 24, ;
KeyboardHighValue = 255, ;
KeyboardLowValue = 0, ;
Left = 332, ;
SpinnerHighValue = 255.00, ;
SpinnerLowValue = 0.00, ;
Top = 452, ;
Width = 67, ;
Value = 80, ;
Name = "Spinner3"
Add Object label5 As Label With ;
AutoSize = .T., ;
FontBold = .T., ;
BackStyle = 0, ;
Caption = "Alpha", ;
Height = 17, ;
Left = 294, ;
Top = 458, ;
Width = 34, ;
ForeColor = Rgb(255,255,255), ;
Name = "Label5"
Add Object spinner4 As Spinner With ;
Height = 24, ;
KeyboardHighValue = 10, ;
KeyboardLowValue = 0, ;
Left = 581, ;
SpinnerHighValue = 10.00, ;
SpinnerLowValue = 0.00, ;
Top = 396, ;
Width = 60, ;
Value = 5, ;
Name = "Spinner4"
Add Object label6 As Label With ;
AutoSize = .T., ;
FontBold = .T., ;
BackStyle = 0, ;
Caption = "Shadow PX", ;
Height = 17, ;
Left = 509, ;
Top = 396, ;
Width = 67, ;
ForeColor = Rgb(255,255,255), ;
Name = "Label6"
Add Object command4 As CommandButton With ;
Top = 432, ;
Left = 657, ;
Height = 36, ;
Width = 38, ;
Anchor = 768, ;
Picture = home(1)+"graphics\icons\win95\explorer.ico", ;
Caption = "", ;
MousePointer = 15, ;
Name = "Command4"
Add Object label7 As Label With ;
FontBold = .T., ;
FontSize = 10, ;
WordWrap = .T., ;
BackStyle = 0, ;
Caption = "Right click on canevas to save as image", ;
Height = 41, ;
Left = 530, ;
Top = 468, ;
Width = 151, ;
ForeColor = Rgb(255,0,0), ;
BackColor = Rgb(255,0,0), ;
Name = "Label7"
Add Object command6 As CommandButton With ;
Top = 396, ;
Left = 656, ;
Height = 27, ;
Width = 36, ;
FontBold = .T., ;
FontSize = 14, ;
Caption = "?", ;
MousePointer = 15, ;
ForeColor = Rgb(255,0,0), ;
BackColor = Rgb(0,255,0), ;
Name = "Command6"
Add Object yspinner1 As Spinner With ;
Height = 25, ;
KeyboardHighValue = 1024, ;
KeyboardLowValue = 0, ;
Left = 343, ;
SpinnerHighValue = 1024.00, ;
SpinnerLowValue = 0.00, ;
Top = 484, ;
Width = 61, ;
Name = "ySpinner1"
Add Object yspinner2 As Spinner With ;
Height = 25, ;
KeyboardHighValue = 1024, ;
KeyboardLowValue = 0, ;
Left = 462, ;
SpinnerHighValue = 1024.00, ;
SpinnerLowValue = 0.00, ;
Top = 483, ;
Width = 61, ;
Name = "ySpinner2"
Add Object label8 As Label With ;
FontBold = .T., ;
BackStyle = 0, ;
Caption = "Width", ;
Height = 17, ;
Left = 301, ;
Top = 489, ;
Width = 40, ;
ForeColor = Rgb(255,255,255), ;
Name = "Label8"
Add Object label9 As Label With ;
FontBold = .T., ;
BackStyle = 0, ;
Caption = "Height", ;
Height = 17, ;
Left = 416, ;
Top = 487, ;
Width = 40, ;
ForeColor = Rgb(255,255,255), ;
Name = "Label9"
Add Object command3 As CommandButton With ;
Top = 450, ;
Left = 408, ;
Height = 25, ;
Width = 96, ;
Caption = "form.backcolor", ;
Name = "Command3"
Add Object label10 As Label With ;
AutoSize = .T., ;
FontBold = .T., ;
BackStyle = 0, ;
Caption = "TEXT", ;
Height = 17, ;
Left = 101, ;
Top = 393, ;
Width = 31, ;
ForeColor = Rgb(255,255,255), ;
Name = "Label10"
Procedure Init
With Thisform
.SetAll("mousepointer",15,"commandbutton")
For i=1 To .ControlCount
If ! Lower(.Controls(i).Class)=="imgcanvas"
.Controls(i).Anchor=768
Endi
Endfor
Endwith
Endproc
Procedure Destroy
Clea Events
Endproc
Procedure text1.Valid
With Thisform.ymulti_shadow1
.xtext=This.Value
.Draw
Endwith
Endproc
Procedure text1.Init
This.Value=Thisform.ymulti_shadow1.xtext
Endproc
Procedure command1.Click
Local m.xfont
m.xfont=Getfont()
If Empty(m.xfont)
Return .F.
Endi
With Thisform.ymulti_shadow1
.xfontname=Getwordnum(m.xfont,1,",")
.xfontsize=Int(Val(Getwordnum(m.xfont,2,",")))
This.Parent.text2.Value=.xfontsize
This.Parent.label1.Caption=.xfontname
.Draw
Endwith
Endproc
Procedure text2.Init
This.Value=Thisform.ymulti_shadow1.xfontsize
Endproc
Procedure text2.Valid
With Thisform.ymulti_shadow1
.xfontsize=This.Value
.Draw
Endwith
Endproc
Procedure label1.Init
This.Caption=Thisform.ymulti_shadow1.xfontname
Endproc
Procedure combo1.Click
With Thisform.ymulti_shadow1
.lcstyle=This.Value
.Draw
Endwith
Endproc
Procedure combo1.Init
With This
.AddItem("N")
.AddItem("B")
.AddItem("I")
.AddItem("BI")
.ListIndex=1
.Style=2
Endwith
Endproc
Procedure command2.Click
Local M.XCOLOR
m.XCOLOR=Getcolor()
If M.XCOLOR=-1
Return .F.
Endi
With Thisform.ymulti_shadow1
.maincolor=M.XCOLOR
.Draw
Endwith
Endproc
Procedure spinner1.Init
This.Value=Thisform.ymulti_shadow1.ydirH
Endproc
Procedure spinner1.InteractiveChange
With Thisform.ymulti_shadow1
.ydirH=This.Value
.Draw
Endwith
Endproc
Procedure spinner2.Init
This.Value=Thisform.ymulti_shadow1.YdirV
Endproc
Procedure spinner2.InteractiveChange
With Thisform.ymulti_shadow1
.YdirV=This.Value
.Draw
Endwith
Endproc
Procedure spinner3.InteractiveChange
With Thisform.ymulti_shadow1
.alphashadow=This.Value
.Draw
Endwith
Endproc
Procedure spinner3.Init
This.Value=Thisform.ymulti_shadow1.alphashadow
Endproc
Procedure spinner4.InteractiveChange
With Thisform.ymulti_shadow1
.shadowpx=This.Value
.Draw
Endwith
Endproc
Procedure command4.Click
Local m.oo
m.oo=Addbs(Justpath(Sys(16,1)))+"images\"
Run/N EXPLORER &oo
Endproc
Procedure command6.Click
Local m.myvar
TEXT to m.myvar noshow
the class ymulti_shadow.vcx make stacked shadows on a text in imgcanvas
of gdiplusX.
on form load must execute system.app(put it in the project folder)
simply put it on any form and imitialize the wanted parameters
as this demo can provides.
Can ajust any of its properties (right click on and make changes).
Right click on canvas to save the work as png image (the folder images
is created if dont exists in project folder).In this case can adjust the
exact image dimensions for exporting.
NB: the font box limits the fontsize to 127.can extend it in the textbox to
upper values
ENDTEXT
Messagebox(m.myvar,0+32+4096,"ymulti_shadow.vcx")
Endproc
Procedure yspinner1.InteractiveChange
With Thisform.ymulti_shadow1
.Width=This.Value
.Draw
Thisform.ForeColor=255
Thisform.Box(.Left,.Top,.Width,.Height)
Inke(0.5)
Thisform.Cls
Endwith
Endproc
Procedure yspinner1.Init
This.Value=Thisform.ymulti_shadow1.Width
Endproc
Procedure yspinner2.Init
This.Value=Thisform.ymulti_shadow1.Height
Endproc
Procedure yspinner2.InteractiveChange
With Thisform.ymulti_shadow1
.Height=This.Value
.Draw
Thisform.ForeColor=255
Thisform.Box(.Left,.Top,.Width,.Height)
Inke(0.5)
Thisform.Cls
Endwith
Endproc
Procedure command3.Click
Local M.XCOLOR
m.XCOLOR=Getcolor()
If M.XCOLOR=-1
Return .F.
Endi
Thisform.BackColor=m.XCOLOR
Endproc
Enddefine
*
*-- EndDefine: asup
*ymulti_shadow class
Define Class ymulti_shadow As imgcanvas
lcstyle = "B"
xfontname = "Arial Black"
xfontsize = 72
xtext = "Hello World !"
alphashadow = 80
shadowpx = 5
maincolor = 255
ydirH = 1
YdirV = 0
rendermode = 4
Name = "ymulti_shadow"
Procedure yrandom
Local m.myvar
TEXT to m.myvar noshow
black
red
green
maroon
magenta
bisque
blueviolet
brown
chartreuse
chocolate
darkblue
darkgreen
darkorange
greenyellow
navy
midnightblue
yellowgreen
yellow
cyan
blue
orange
purple
ENDTEXT
Local gnlower,gnupper,i
gnlower = 1
gnupper = Memlines(m.myvar)
i=Int((gnupper - gnlower + 1) * Rand( ) + gnlower)
Return Alltrim(Mline(m.myvar,i))
Endproc
Procedure beforedraw
Local loFont As xfcFont
Local lcstyle,lcstyle,xfontname,xfontsize,ts_x,ts_y,xtext,alphashadow,shadowpx,maincolor,shadowcolor
lcstyle=This.lcstyle
xfontname=This.xfontname
xfontsize=This.xfontsize
ts_x=0
ts_y=0
xtext=This.xtext
alphashadow=This.alphashadow
shadowpx=This.shadowpx
maincolor=This.maincolor
With _Screen.System.Drawing
This.Clear(.Color.transparent)
Do Case
Case lcstyle == "B"
loStyle = .FontStyle.Bold
Case lcstyle == "I"
loStyle = .FontStyle.Italic
Case lcstyle == "BI"
loStyle = .FontStyle.BoldItalic
Otherwise
loStyle = .FontStyle.Regular
Endcase
Local loFont As xfcFont
loFont = .Font.New(xfontname, xfontsize, loStyle)
For N = 1 To shadowpx
ts_x=ts_x+Sign(This.ydirH)
ts_y=ts_y+Sign(This.YdirV)
This.oGfx.TranslateTransform(ts_x,ts_y)
shadowcolor=Eval('.color.'+This.yrandom() )
This.oGfx.DrawString(xtext, loFont, ;
.SolidBrush.New(.Color.FromARGB(alphashadow,shadowcolor)), ;
This.Rectangle)
Endfor
This.oGfx.ResetTransform()
This.oGfx.DrawString(xtext, loFont, ;
.SolidBrush.New(.Color.FromRGB(maincolor)), ;
This.Rectangle)
Endwith
Endproc
Procedure RightClick
If Messagebox("Save as image ?",4+64+4096,"Saving")=6
Local m.lcDir
m.lcDir=Addbs(Justpath(Sys(16,1)))+"images\"
If !Directory(m.lcDir)
Md (m.lcDir)
Endi
Local m.lcdest
m.lcdest=m.lcDir+"img_"+Sys(2015)+".png"
This.obmp.Save(m.lcdest,_Screen.System.Drawing.imaging.imageformat.png)
Messagebox("Saved as image:"+m.lcdest,0+32+4096,"Saving as image",1000)
Endi
Endproc
Enddefine
*
*-- EndDefine: ymulti_shadow
*ENDCODE