| 
									
										
										
										
											2010-02-08 00:40:26 -05:00
										 |  |  | ! Copyright (C) 2009, 2010 Slava Pestov. | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							| 
									
										
										
										
											2010-02-08 00:40:26 -05:00
										 |  |  | USING: kernel arrays assocs sequences math math.order cache | 
					
						
							|  |  |  | opengl opengl.gl opengl.textures strings fonts colors accessors | 
					
						
							|  |  |  | namespaces ui.gadgets.worlds ;
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  | IN: ui.text | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: font-renderer | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 00:44:38 -04:00
										 |  |  | : world-text-handle ( world -- handle )
 | 
					
						
							| 
									
										
										
										
											2009-04-02 14:05:26 -04:00
										 |  |  |     dup text-handle>> [ <cache-assoc> >>text-handle ] unless
 | 
					
						
							| 
									
										
										
										
											2009-04-01 00:44:38 -04:00
										 |  |  |     text-handle>> ;
 | 
					
						
							| 
									
										
										
										
											2009-01-27 00:11:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 00:44:38 -04:00
										 |  |  | HOOK: flush-layout-cache font-renderer ( -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | [ flush-layout-cache ] flush-layout-cache-hook set-global
 | 
					
						
							| 
									
										
										
										
											2009-01-27 00:11:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-30 04:36:39 -05:00
										 |  |  | HOOK: string-dim font-renderer ( font string -- dim )
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-13 18:35:42 -04:00
										 |  |  | : string-width ( font string -- w ) string-dim first ; inline
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-13 18:35:42 -04:00
										 |  |  | : string-height ( font string -- h ) string-dim second ; inline
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | HOOK: free-fonts font-renderer ( world -- )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : combine-text-dim ( dim1 dim2 -- dim3 )
 | 
					
						
							| 
									
										
										
										
											2012-07-13 18:35:42 -04:00
										 |  |  |     [ first2 ] bi@ swapd [ max ] [ + ] 2bi* 2array ; inline
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HOOK: x>offset font-renderer ( x font string -- n )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HOOK: offset>x font-renderer ( n font string -- x )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | GENERIC: text-dim ( font text -- dim )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-30 04:36:39 -05:00
										 |  |  | M: string text-dim string-dim ;
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-09 01:22:41 -05:00
										 |  |  | M: array text-dim | 
					
						
							| 
									
										
										
										
											2009-01-30 04:36:39 -05:00
										 |  |  |     [ { 0 0 } ] 2dip [ string-dim combine-text-dim ] with each ;
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : text-width ( font text -- w ) text-dim first ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : text-height ( font text -- h ) text-dim second ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-13 21:19:57 -05:00
										 |  |  | HOOK: font-metrics font-renderer ( font -- metrics )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-02 00:58:05 -05:00
										 |  |  | HOOK: line-metrics font-renderer ( font string -- metrics )
 | 
					
						
							| 
									
										
										
										
											2009-02-01 21:32:49 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-08 00:40:26 -05:00
										 |  |  | HOOK: string>image font-renderer ( font string -- image loc )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <PRIVATE
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : string-empty? ( obj -- ? )
 | 
					
						
							|  |  |  |     dup selection? [ string>> ] when empty? ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : draw-string ( font string -- )
 | 
					
						
							|  |  |  |     dup string-empty? [ 2drop ] [ | 
					
						
							|  |  |  |         world get world-text-handle | 
					
						
							|  |  |  |         [ string>image <texture> ] 2cache
 | 
					
						
							|  |  |  |         draw-texture | 
					
						
							|  |  |  |     ] if ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PRIVATE>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-10 19:47:34 -05:00
										 |  |  | GENERIC: draw-text ( font text -- )
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | M: string draw-text draw-string ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-07 19:05:11 -05:00
										 |  |  | M: selection draw-text draw-string ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-02-09 01:22:41 -05:00
										 |  |  | M: array draw-text | 
					
						
							| 
									
										
										
										
											2009-04-04 21:03:30 -04:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  |         [ | 
					
						
							| 
									
										
										
										
											2009-02-10 19:47:34 -05:00
										 |  |  |             [ draw-string ] | 
					
						
							|  |  |  |             [ [ 0.0 ] 2dip string-height 0.0 glTranslated ] 2bi
 | 
					
						
							| 
									
										
										
										
											2009-01-21 20:34:42 -05:00
										 |  |  |         ] with each
 | 
					
						
							| 
									
										
										
										
											2009-04-01 00:44:38 -04:00
										 |  |  |     ] do-matrix ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-02 14:23:41 -04:00
										 |  |  | USING: vocabs system combinators ;
 | 
					
						
							| 
									
										
										
										
											2009-04-01 00:44:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-02 22:52:18 -04:00
										 |  |  | { | 
					
						
							|  |  |  |     { [ os macosx? ] [ "core-text" ] } | 
					
						
							|  |  |  |     { [ os windows? ] [ "uniscribe" ] } | 
					
						
							|  |  |  |     { [ os unix? ] [ "pango" ] } | 
					
						
							|  |  |  | } cond "ui.text." prepend require |