\ WinDrawTruncChars 05.09.16 NAB \ A version of WinDrawTruncChars \ that works all the way back to \ Palm OS 1. needs core-ext module WinDrawTruncChars : trunc? ( maxwidth len caddr. -- width len trunc? ) 2>r 0 ( maxwidth len fitwithin ) sp@ \ fitWithinWidth 2dup 2 m+ \ stringLength 2dup 2 m+ \ stringWidth 2r> \ c-addr FntCharsInWidth 0= ; 2variable caddr variable len 2variable coords public: : WinDrawTruncChars ( maxwidth y x len caddr. -- ) \ Store the parameters: caddr 2! len ! coords 2! ( -- maxwidth ) \ See if the string needs truncation: dup len @ caddr 2@ trunc? nip nip if ( -- maxwidth ) \ Re-calculate fit with room for '...' \ Subtract '...' width from maxwidth: [ char . >byte ] literal FntCharWidth 3 * - ( -- newmaxwidth ) \ Calculate adjusted width & length: len @ caddr 2@ trunc? drop ( -- width len ) swap >r \ new width in pixels \ Draw the truncated string: coords 2@ rot ( -- y x len ) caddr 2@ WinDrawChars \ Set up to draw '...' at the right spot: coords 2@ r> + s" ..." swap >abs else drop \ maxwidth \ Set up to draw the full string: coords 2@ len @ caddr 2@ then WinDrawChars ; end-module