Commit 8b18cd96 authored by Sebastien Barre's avatar Sebastien Barre

better UI

parent c46925a8
......@@ -15,17 +15,21 @@ renWin SetSize 600 600
set vtkw [vtkTkRenderWidget .ren -width 450 -height 450 -rw renWin]
::vtk::bind_tk_render_widget $vtkw
pack $vtkw -side top -fill both -expand yes
[[renWin GetInteractor] GetInteractorStyle] SetCurrentStyleToTrackballCamera
pack $vtkw -side left -fill both -expand yes
# Base text property
vtkTextProperty base_text_prop
base_text_prop SetFontSize 24
base_text_prop SetFontSize 48
base_text_prop ShadowOn
base_text_prop SetColor 1.0 0.0 0.0
base_text_prop SetFontFamilyToArial
set base_scale 0.005
set base_scale 0.0025
set base_text "This is a test"
# The text actors
......@@ -49,11 +53,9 @@ proc add_sphere {} {
# Add one text actor, centered
proc add_one_text_actor {} {
global base_scale text_actors
global text_actors
vtkTextActor3D ia
ia SetInput "This is a test"
ia SetScale $base_scale
lappend text_actors ia
set tprop [ia GetTextProperty]
......@@ -63,7 +65,7 @@ proc add_one_text_actor {} {
# Add many text actor
proc add_many_text_actors {} {
global base_scale text_actors
global text_actors
vtkColorTransferFunction lut
lut SetColorSpaceToHSV
......@@ -73,25 +75,39 @@ proc add_many_text_actors {} {
for {set i 0} {$i < 10} {incr i} {
set name "ia$i"
vtkTextActor3D $name
$name SetInput " This is a test ($i)"
$name SetScale $base_scale
$name SetOrientation 0 [expr $i * 36] 0
# $name SetPosition [expr cos($i * 0.0314)] 0 0
lappend text_actors $name
set tprop [$name GetTextProperty]
$tprop ShallowCopy base_text_prop
set value [expr $i / 10.0]
eval $tprop SetColor [lut GetColor $value]
eval $tprop SetColor [lut GetRedValue $value] [lut GetGreenValue $value] [lut GetBlueValue $value]
}
lut Delete
}
set scale_length 200
frame .controls -relief groove -bd 2
pack .controls -padx 2 -pady 2 -anchor nw -side left -fill both -expand n
# Add control of text
set entry_text [entry .controls.text]
$entry_text insert 0 "$base_text"
pack $entry_text -padx 4 -pady 4 -side top -fill x -expand n
bind $entry_text <Return> {update_text_actors 0}
bind $entry_text <FocusOut> {update_text_actors 0}
# Add control of orientation
set scale_orientation [scale .orientation \
set scale_orientation [scale .controls.orientation \
-from 0 -to 360 -res 1 \
-length $scale_length \
-orient horizontal \
-label "Text orientation:" \
-command update_text_actors]
......@@ -101,8 +117,9 @@ pack $scale_orientation -side top -fill x -expand n
# Add control of font size
set scale_font_size [scale .font_size \
set scale_font_size [scale .controls.font_size \
-from 5 -to 150 -res 1 \
-length $scale_length \
-orient horizontal \
-label "Font Size:" \
-command update_text_actors]
......@@ -112,8 +129,9 @@ pack $scale_font_size -side top -fill x -expand n
# Add control of scale
set scale_scale [scale .scale \
set scale_scale [scale .controls.scale \
-from 0 -to 100 -res 1 \
-length $scale_length \
-orient horizontal \
-label "Actor scale:" \
-command update_text_actors]
......@@ -121,20 +139,38 @@ set scale_scale [scale .scale \
$scale_scale set [expr $base_scale * 10000.0]
pack $scale_scale -side top -fill x -expand n
# Add control of opacity
set scale_opacity [scale .controls.opacity \
-from 0.0 -to 1.0 -res 0.01 \
-length $scale_length \
-orient horizontal \
-label "Text opacity:" \
-command update_text_actors]
$scale_opacity set [base_text_prop GetOpacity]
pack $scale_opacity -side top -fill x -expand n
# Update all text actors
proc update_text_actors {dummy} {
global scale_orientation scale_font_size scale_scale
global scale_orientation scale_font_size scale_scale entry_text scale_opacity
set orientation [$scale_orientation get]
set font_size [$scale_font_size get]
set scale [expr [$scale_scale get] / 10000.0]
set text [$entry_text get]
set opacity [$scale_opacity get]
global text_actors
set i 0
foreach actor $text_actors {
$actor SetScale $scale
$actor SetInput "$text"
set tprop [$actor GetTextProperty]
$tprop SetFontSize $font_size
$tprop SetOrientation $orientation
$tprop SetOpacity $opacity
incr i
}
renWin Render
......@@ -152,9 +188,11 @@ if {0} {
set cam [ren1 GetActiveCamera]
$cam Elevation 30
$cam Dolly 0.3
$cam Dolly 0.4
}
update_text_actors 0
foreach actor $text_actors {
ren1 AddActor $actor
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment