home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / contool2.2 / part01 / button.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-26  |  2.7 KB  |  73 lines

  1. /************************************************************************/
  2. /*    Copyright 1988, 1989 by Chuck Musciano and Harris Corporation    */
  3. /*                                    */
  4. /*    Permission to use, copy, modify, and distribute this software    */
  5. /*    and its documentation for any purpose and without fee is    */
  6. /*    hereby granted, provided that the above copyright notice    */
  7. /*    appear in all copies and that both that copyright notice and    */
  8. /*    this permission notice appear in supporting documentation, and    */
  9. /*    that the name of Chuck Musciano and Harris Corporation not be    */
  10. /*    used in advertising or publicity pertaining to distribution    */
  11. /*    of the software without specific, written prior permission.    */
  12. /*    Chuck Musciano and Harris Corporation make no representations    */
  13. /*    about the suitability of this software for any purpose.  It is    */
  14. /*    provided "as is" without express or implied warranty.  This     */
  15. /*    software may not be sold without the prior explicit permission    */
  16. /*    of Harris Corporation.                        */
  17. /************************************************************************/
  18.  
  19. #include    <stdio.h>
  20.  
  21. #include    <suntool/sunview.h>
  22. #include    <suntool/panel.h>
  23.  
  24. #include    "contool.h"
  25.  
  26. /************************************************************************/
  27. PRIVATE    text_width(text, font)
  28.  
  29. char    *text;
  30. struct    pixfont    *font;
  31.  
  32. {    int    width;
  33.  
  34.     for (width = 0; *text; text++)
  35.        width += font->pf_char[*text].pc_adv.x;
  36.     return(width);
  37. }
  38.  
  39. /************************************************************************/
  40. EXPORT    struct    pixrect    *better_button_image(panel, text, chars, pixels, font)
  41.  
  42. Panel    panel;
  43. char    *text;
  44. int    chars;
  45. int    pixels;
  46. struct    pixfont    *font;
  47.  
  48. {    struct    pixrect    *pr;
  49.     struct    pr_prpos    pos;
  50.     int    width, true_width, height;
  51.  
  52.     if (font == NULL)
  53.        font = (struct pixfont *) window_get(panel, WIN_FONT);
  54.     width = chars * font->pf_char['0'].pc_adv.x + pixels;
  55.     true_width = text_width(text, font);
  56.     if (width < true_width)
  57.        width = true_width;
  58.     pr = mem_create(width + 8, height = font->pf_defaultsize.y + 6, 1);
  59.     pr_rop(pr, 3, 0, width + 2, 2, PIX_SRC | PIX_COLOR(1), NULL, 0, 0);
  60.     pr_rop(pr, 3, height - 2, width + 2, 2, PIX_SRC | PIX_COLOR(1), NULL, 0, 0);
  61.     pr_rop(pr, 0, 3, 2, height - 6, PIX_SRC | PIX_COLOR(1), NULL, 0, 0);
  62.     pr_rop(pr, width + 6, 3, 2, height - 6, PIX_SRC | PIX_COLOR(1), NULL, 0, 0);
  63.     pr_rop(pr, 1, 1, 3, 3, PIX_SRC | PIX_DST, &better_button_cross, 0, 0);
  64.     pr_rop(pr, width + 4, 1, 3, 3, PIX_SRC | PIX_DST, &better_button_cross, 0, 0);
  65.     pr_rop(pr, width + 4, height - 4, 3, 3, PIX_SRC | PIX_DST, &better_button_cross, 0, 0);
  66.     pr_rop(pr, 1, height - 4, 3, 3, PIX_SRC | PIX_DST, &better_button_cross, 0, 0);
  67.     pos.pr = pr;
  68.     pos.pos.x = 4 + (width - true_width) / 2;
  69.     pos.pos.y = 4 - font->pf_char['T'].pc_home.y;
  70.     pf_ttext(pos, PIX_SRC | PIX_COLOR(1), font, text);
  71.     return(pr);
  72. }
  73.