home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / MM1 / SOUNDUTILS / mm1_tracker.lzh / TRACKER4.6 / Amiga / scroll_window.c < prev    next >
Text File  |  1994-11-24  |  6KB  |  220 lines

  1. /* amiga/scroll_window.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: scroll_window.c,v 1.6 1994/06/22 21:54:12 Espie Exp Espie $
  6.  * $Log: scroll_window.c,v $
  7.  * Revision 1.4  1994/01/09  04:49:18  Espie
  8.  * Stupid: forgot that a window font can very well be proportional.
  9.  * It's easier to rely on GfxBase->DefaultFont after all.
  10.  * Uncentralized event handling using event management functions.
  11.  * Handle own's clipping without Layers.
  12.  * Use dynamic colours/masks according to current screen.
  13.  * Added forbid_reopen to avoid dangling window.
  14.  *
  15.  */
  16.  
  17. /* The line scroller implemented as a window */
  18.  
  19. #include <assert.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22.  
  23. #include <intuition/screens.h>
  24. #include <graphics/text.h>
  25. #include <graphics/gfxmacros.h>
  26. #include <proto/intuition.h>
  27. #include <proto/exec.h>
  28. #include <proto/graphics.h>
  29. #include <graphics/gfxbase.h>
  30.  
  31. #include "defs.h"
  32. #include "extern.h"
  33. #include "amiga/amiga.h"
  34. #include "prefs.h"
  35.  
  36. ID("$Id: scroll_window.c,v 1.6 1994/06/22 21:54:12 Espie Exp Espie $")
  37.  
  38. LOCAL void init_scroller(void);
  39. LOCAL void (*INIT)(void) = init_scroller;
  40. LOCAL int forbid_reopen = FALSE;
  41. LOCAL void handle_scroller(GENERIC nothing);
  42.  
  43. XT struct IntuitionBase *IntuitionBase;
  44. XT struct GfxBase *GfxBase;
  45.  
  46. LOCAL struct Screen *pubscreen;
  47.  
  48. /* our window */
  49. LOCAL struct Window *scroll_win = 0;
  50. LOCAL struct TextFont *font;
  51.    
  52.  
  53. /* to build up write masks */
  54. LOCAL ULONG text, highlight, background;
  55.  
  56.  
  57. LOCAL void close_scroller()    
  58.    {
  59.    if (scroll_win)
  60.       {
  61.       remove_signal_handler(scroll_win->UserPort->mp_SigBit);
  62.       CloseWindow(scroll_win);
  63.       }
  64.    scroll_win = 0;               /* and get ready for reopen */
  65.    }
  66.  
  67. LOCAL void really_close_scroller()
  68.    {
  69.    forbid_reopen = TRUE;
  70.    close_scroller();
  71.    }
  72.  
  73. /* graphic niceties: draw vertical lines at the right separation points
  74.  * all the way between y1 and the bottom
  75.  */
  76. LOCAL void separation_lines(int y1)
  77.    {
  78.    int x, xs, i, c;
  79.    
  80.    xs = font->tf_XSize;
  81.    
  82.    SetWrMsk(scroll_win->RPort, background | highlight);  
  83.    SetAPen(scroll_win->RPort, highlight);   
  84.    x = scroll_win->BorderLeft;
  85.    for (i = 1; i < 4; i++)
  86.       {
  87.       x += 14 * xs;     /* 14 chars per column */
  88.       c = x - xs/2;
  89.       if (c >= scroll_win->Width - scroll_win->BorderRight -1)
  90.          break;
  91.       Move(scroll_win->RPort, x - xs/2, y1);
  92.       Draw(scroll_win->RPort, x - xs/2, scroll_win->Height - scroll_win->BorderBottom - 1);
  93.       }
  94.    }
  95.    
  96. LOCAL void init_scroller()
  97.    {
  98.    struct DrawInfo *dr;
  99.    
  100.    at_end(really_close_scroller);
  101.       /* default text, background, etc */
  102.    text = 1;
  103.    background = 0;
  104.    highlight = 7;
  105.    pubscreen = obtain_pubscreen();
  106.    dr = GetScreenDrawInfo(pubscreen);
  107.    if (dr)
  108.       {
  109.       if (dr->dri_Version >= 1)  /* for V 2.04 */
  110.          {
  111.          text = dr->dri_Pens[TEXTPEN];
  112.          background = dr->dri_Pens[BACKGROUNDPEN];
  113.          highlight = dr->dri_Pens[SHINEPEN];
  114.          }
  115.       FreeScreenDrawInfo(pubscreen, dr);
  116.       }
  117.    }
  118.    
  119.  
  120. LOCAL void open_scroller()
  121.    {
  122.    INIT_ONCE;
  123.    font = GfxBase->DefaultFont;
  124.    scroll_win = OpenWindowTags(NULL,
  125.       WA_Title, "Scroll",
  126.       WA_DepthGadget, TRUE,
  127.       WA_SmartRefresh, TRUE,
  128.       WA_DragBar, TRUE,
  129.       WA_SizeGadget, TRUE,
  130.       WA_CloseGadget, TRUE,
  131.       WA_InnerWidth, font->tf_XSize * 60, /* 60 = 14 * 4 + some margin */
  132.       WA_InnerHeight, font->tf_YSize * 15,
  133.       WA_MinWidth, 15 * font->tf_XSize,
  134.       WA_MaxWidth, ~0,           /* need some room for the size gadget */
  135.       WA_MinHeight, 2 * pubscreen->WBorTop,   
  136.       WA_MaxHeight, ~0,
  137.       WA_AutoAdjust, TRUE,
  138.       WA_NoCareRefresh, TRUE,
  139.       WA_PubScreen, pubscreen,
  140.       WA_IDCMP, IDCMP_NEWSIZE | IDCMP_CLOSEWINDOW,
  141.       TAG_END);
  142.  
  143.    if (!scroll_win)
  144.       end_all(0);
  145.       
  146.    SetFont(scroll_win->RPort, font);
  147.    install_signal_handler(scroll_win->UserPort->mp_SigBit, handle_scroller, 0);
  148.    separation_lines(scroll_win->BorderTop);
  149.    }
  150.  
  151.  
  152.  
  153. LOCAL void handle_scroller(GENERIC nothing)   
  154.    {
  155.    struct IntuiMessage *msg;
  156.    while (scroll_win && (msg = GetMsg(scroll_win->UserPort)))
  157.       switch(msg->Class)
  158.          {
  159.       case IDCMP_NEWSIZE:
  160.          ReplyMsg(msg);
  161.          separation_lines(scroll_win->BorderTop);  /* redraw lines where applicable */
  162.          break;
  163.       case IDCMP_SIZEVERIFY:
  164.          ReplyMsg(msg);
  165.          break;
  166.       case IDCMP_CLOSEWINDOW:
  167.          ReplyMsg(msg);
  168.          close_scroller();
  169.          set_pref_scalar(PREF_SHOW, FALSE);
  170.          break;
  171.       default:
  172.          ReplyMsg(msg);
  173.          }
  174.    }
  175.  
  176. void add_scroller(char *s)
  177.    {
  178.    int max_length;
  179.  
  180.    if (forbid_reopen)
  181.       return;
  182.    if (!scroll_win)
  183.       open_scroller();
  184.       
  185.       /* critical section for size changes */
  186.    ModifyIDCMP(scroll_win, scroll_win->IDCMPFlags | IDCMP_SIZEVERIFY);
  187.    handle_scroller(0);   /* handle size problems first */
  188.  
  189.    if (!scroll_win)     /* window may have closed on us... */
  190.       return;
  191.  
  192.       /* add the characters */
  193.    SetDrMd(scroll_win->RPort, JAM1);
  194.    SetWrMsk(scroll_win->RPort, background | text);
  195.    SetAPen(scroll_win->RPort, text);
  196.    Move(scroll_win->RPort, scroll_win->BorderLeft, 
  197.       scroll_win->Height - scroll_win->BorderBottom 
  198.     - font->tf_YSize + font->tf_Baseline);
  199.    max_length = scroll_win->Width - scroll_win->BorderLeft - scroll_win->BorderRight;
  200.    max_length /= font->tf_XSize;
  201.    if (max_length > 14 * 4 - 1)
  202.       max_length = 14 * 4 -1;    /* line length = 14 * 4 - 1 */
  203.    Text(scroll_win->RPort, s, max_length);
  204.    
  205.       /* add the separation lines */
  206.    separation_lines(scroll_win->Height - scroll_win->BorderBottom 
  207.     - font->tf_YSize);
  208.       
  209.       /* and scroll *JUST* the characters */
  210.    SetWrMsk(scroll_win->RPort, 1);
  211.    ScrollRaster(scroll_win->RPort, 0, font->tf_YSize, 
  212.                   scroll_win->BorderLeft, scroll_win->BorderTop, 
  213.                   scroll_win->Width - scroll_win->BorderRight - 1,
  214.                   scroll_win->Height - scroll_win->BorderBottom - 1);
  215.    
  216.       /* end of critical section: allow resize again */
  217.    ModifyIDCMP(scroll_win, scroll_win->IDCMPFlags & ~IDCMP_SIZEVERIFY);
  218.    handle_scroller(0); 
  219.    }
  220.