User Tools

Site Tools


drawing_20text_20with_20a_20translucent_20dropshadow

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

drawing_20text_20with_20a_20translucent_20dropshadow [2018/03/31 13:19]
127.0.0.1 external edit
drawing_20text_20with_20a_20translucent_20dropshadow [2018/04/13 15:40] (current)
richardrussell Added syntax highlighting
Line 1: Line 1:
 =====Drawing text with a translucent dropshadow===== =====Drawing text with a translucent dropshadow=====
  
-//by Richard Russell, October 2007//\\ \\  It is straightforward to draw text with an //opaque// dropshadow: you simply draw the '​shadow'​ text first (probably in a suitable shade of grey) then draw the foreground text on top, offset by a few pixels, in whatever colour you want. The effect can be acceptable, particularly when drawn on a uniformly-coloured background, but isn't very realistic when drawn over something like a picture. Ideally in that case you should be able to see the picture '​through'​ the shadow, in other words the shadow should be //​translucent//​.\\ \\  The **PROCdrawshadowedtext** procedure listed below allows you to draw text with a realistic translucent dropshadow:​\\ \\ {{shadow.gif}}\\ \\  Note that you can see the clouds through the shadow, and the shadow is '​darker'​ over the hillside than it is over the sky. When run under Windows XP or Windows Vista both the text and the dropshadow are antialiased (if your display properties are set appropriately).\\ \\  To display text similar to that shown above you would call **PROCdrawshadowedtext** as follows:\\ \\ +//by Richard Russell, October 2007//\\ \\  It is straightforward to draw text with an //opaque// dropshadow: you simply draw the '​shadow'​ text first (probably in a suitable shade of grey) then draw the foreground text on top, offset by a few pixels, in whatever colour you want. The effect can be acceptable, particularly when drawn on a uniformly-coloured background, but isn't very realistic when drawn over something like a picture. Ideally in that case you should be able to see the picture '​through'​ the shadow, in other words the shadow should be //​translucent//​.\\ \\  The **PROCdrawshadowedtext** procedure listed below allows you to draw text with a realistic translucent dropshadow:​\\ \\ {{shadow.gif}}\\ \\  Note that you can see the clouds through the shadow, and the shadow is '​darker'​ over the hillside than it is over the sky. When run under Windows XP or Windows Vista both the text and the dropshadow are antialiased (if your display properties are set appropriately).\\ \\  To display text similar to that shown above you would call **PROCdrawshadowedtext** as follows: 
 + 
 +<code bb4w>
         PROCdrawshadowedtext("​Shadow",​ 0, xpos%, ypos%, colour%, 5, -5, 0.4)         PROCdrawshadowedtext("​Shadow",​ 0, xpos%, ypos%, colour%, 5, -5, 0.4)
-Here **xpos%** and **ypos%** are the position in which the text should be drawn (in BBC BASIC graphics coordinates) and **colour%** is the required foreground text colour represented by the hexadecimal value "&​bbggrr"​ (where "​bb"​ is the amount of blue, "​gg"​ the amount of green and "​rr"​ the amount of red, in each case in the range 00 to FF). **colour%** must not be zero (black); if it is you will receive a //Division by zero// error. To ensure that the dropshadow is effectively antialiased one of "​rr",​ "​gg"​ or "​bb"​ must be at least 32 (hex 20).\\ \\  The final three parameters are the horizontal and vertical //offsets// between the text and the shadow (in pixels), and the //opacity// of the shadow from 0.0 (transparent) to 1.0 (opaque). In the normal case of the dropshadow appearing to the //right// and //below// the text, the horizontal (x) offset should be positive and the vertical (y) offset negative, as in the example.\\ \\  The second **flags** parameter may be zero or include one or more of the folowing values:\\ \\ +</​code>​ 
 + 
 +Here **xpos%** and **ypos%** are the position in which the text should be drawn (in BBC BASIC graphics coordinates) and **colour%** is the required foreground text colour represented by the hexadecimal value "&​bbggrr"​ (where "​bb"​ is the amount of blue, "​gg"​ the amount of green and "​rr"​ the amount of red, in each case in the range 00 to FF). **colour%** must not be zero (black); if it is you will receive a //Division by zero// error. To ensure that the dropshadow is effectively antialiased one of "​rr",​ "​gg"​ or "​bb"​ must be at least 32 (hex 20).\\ \\  The final three parameters are the horizontal and vertical //offsets// between the text and the shadow (in pixels), and the //opacity// of the shadow from 0.0 (transparent) to 1.0 (opaque). In the normal case of the dropshadow appearing to the //right// and //below// the text, the horizontal (x) offset should be positive and the vertical (y) offset negative, as in the example.\\ \\  The second **flags** parameter may be zero or include one or more of the folowing values: ​
  
   * DT_EXPANDTABS (&40) Expands tab characters; the default column width is 8.   * DT_EXPANDTABS (&40) Expands tab characters; the default column width is 8.
   * DT_NOPREFIX (&800) Disables special processing of the **&** character.   * DT_NOPREFIX (&800) Disables special processing of the **&** character.
-\\  ​The text can consist of two or more lines, separated by CRLF (**CHR$13+CHR$10**) sequences:\\ + 
 +The text can consist of two or more lines, separated by CRLF (**CHR$13+CHR$10**) sequences: 
 + 
 +<code bb4w>
         text$ = "First line"​+CHR$13+CHR$10+"​Second line"         text$ = "First line"​+CHR$13+CHR$10+"​Second line"
         PROCdrawshadowedtext(text$,​ 0, xpos%, ypos%, colour%, 5, -5, 0.4)         PROCdrawshadowedtext(text$,​ 0, xpos%, ypos%, colour%, 5, -5, 0.4)
-Here is the procedure. It requires Windows 98 or later (it will not run under Windows 95):\\ \\ +</​code>​ 
 + 
 +Here is the procedure. It requires Windows 98 or later (it will not run under Windows 95): 
 + 
 +<code bb4w>
         DEF PROCdrawshadowedtext(text$,​flags%,​xpos%,​ypos%,​colr%,​xoff%,​yoff%,​opacity)         DEF PROCdrawshadowedtext(text$,​flags%,​xpos%,​ypos%,​colr%,​xoff%,​yoff%,​opacity)
         LOCAL msimg32%, hang%, hdc%, hbm%, old%, bits%, delta%, max%, P%, f, b         LOCAL msimg32%, hang%, hdc%, hbm%, old%, bits%, delta%, max%, P%, f, b
Line 84: Line 95:
         SYS "​FreeLibrary",​ msimg32%         SYS "​FreeLibrary",​ msimg32%
         ENDPROC         ENDPROC
 +</​code>​
drawing_20text_20with_20a_20translucent_20dropshadow.txt · Last modified: 2018/04/13 15:40 by richardrussell