home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Enlightenment / enl_DR-0.10.tar.gz / enl_DR-0.10.tar / enl / alert.c < prev    next >
C/C++ Source or Header  |  1997-05-13  |  4KB  |  199 lines

  1. #include "enlightenment.h"
  2. #include <stdarg.h>
  3.  
  4. /* Mod. 5/1/97 Bill Garrett <garrett@qcsn.com>
  5.    Let Alert() take a variable argument list, ie
  6.    Alert( "Can't find file %s in directory %s", filename, dirname );
  7.  
  8.    Use GNU extension "vsnprintf" for size limiting if available. */
  9. void Alert(char *fmt, ...)
  10. {
  11.    char text[4096];
  12.    va_list ap;
  13.  
  14.    va_start( ap, fmt );
  15. #ifdef __USE_GNU
  16.    vsnprintf( text, 4096, fmt, ap );
  17. #else
  18.    vsprintf( text, fmt, ap );
  19. #endif
  20.    va_end( ap );
  21.  
  22.    if (imd)
  23.      {
  24.     if (cfg.font) _Alert_Imlib_Font(text);
  25.     else _Alert_Imlib(text);
  26.      }
  27.    else _Alert(text);
  28. }
  29.  
  30. void _Alert_Imlib_Font(char *text)
  31. {
  32.    Window win;
  33.    int wid,hih;
  34.    int c1,c2,c3;
  35.    int r,g,b;
  36.    int w,h;
  37.    XGCValues gcv;
  38.    GC gc;
  39.    char line[1024];
  40.    int i,j,k;
  41.    XEvent ev;
  42.    
  43.    if (!text) return;
  44.  
  45.    r=192,g=192,b=192;
  46.    c1=ImlibBestColorMatch(imd,&r,&g,&b);
  47.    r=128,g=128,b=128;
  48.    c2=ImlibBestColorMatch(imd,&r,&g,&b);
  49.    r=64,g=64,b=64;
  50.    c3=ImlibBestColorMatch(imd,&r,&g,&b);
  51.    wid=DisplayWidth(disp,screen);
  52.    hih=DisplayHeight(disp,screen);
  53.    w=(wid-512)/2;
  54.    h=(hih-384)/2;
  55.    win=XCreateSimpleWindow(disp,root,w,h,512,384,0,0,c2);
  56.    gc=XCreateGC(disp,win,0,&gcv);
  57.    XMapWindow(disp,win);
  58.    XSync(disp,False);
  59.    XSetForeground(disp,gc,c1);
  60.    XDrawLine(disp,win,gc,0,0,0,382);
  61.    XDrawLine(disp,win,gc,0,0,510,0);
  62.    XSetForeground(disp,gc,c3);
  63.    XDrawLine(disp,win,gc,0,383,511,383);
  64.    XDrawLine(disp,win,gc,511,0,511,383);
  65.    
  66.    i=0;
  67.    j=0;
  68.    k=0;
  69.    while(text[i])
  70.      {
  71.     line[j++]=text[i++];
  72.     if (line[j-1]=='\n')
  73.       {
  74.          line[j-1]=0;
  75.          j=0;
  76.          DrawText(win,line,6,6+k,500,14);
  77.          k+=14;
  78.       }
  79.      }
  80.    XSync(disp,False);
  81.    XSelectInput(disp,win,ButtonPressMask);
  82.    XWindowEvent(disp,win,ButtonPressMask,&ev);
  83.    XDestroyWindow(disp,win);
  84. }
  85.  
  86. void _Alert_Imlib(char *text)
  87. {
  88.    Window win;
  89.    int wid,hih;
  90.    int c1,c2,c3;
  91.    int r,g,b;
  92.    int w,h;
  93.    XGCValues gcv;
  94.    GC gc;
  95.    char line[1024];
  96.    int i,j,k;
  97.    XEvent ev;
  98.    
  99.    XFontStruct *xfs;
  100.    Font font;
  101.  
  102.    if (!text) return;
  103.  
  104.    r=192,g=192,b=192;
  105.    c1=ImlibBestColorMatch(imd,&r,&g,&b);
  106.    r=128,g=128,b=128;
  107.    c2=ImlibBestColorMatch(imd,&r,&g,&b);
  108.    r=64,g=64,b=64;
  109.    c3=ImlibBestColorMatch(imd,&r,&g,&b);
  110.    wid=DisplayWidth(disp,screen);
  111.    hih=DisplayHeight(disp,screen);
  112.    w=(wid-512)/2;
  113.    h=(hih-384)/2;
  114.    win=XCreateSimpleWindow(disp,root,w,h,512,384,0,0,c2);
  115.    gc=XCreateGC(disp,win,0,&gcv);
  116.    XMapWindow(disp,win);
  117.    XSync(disp,False);
  118.    XSetForeground(disp,gc,c1);
  119.    XDrawLine(disp,win,gc,0,0,0,382);
  120.    XDrawLine(disp,win,gc,0,0,510,0);
  121.    XSetForeground(disp,gc,c3);
  122.    XDrawLine(disp,win,gc,0,383,511,383);
  123.    XDrawLine(disp,win,gc,511,0,511,383);
  124.  
  125.    font=XLoadFont(disp,"fixed");   
  126.    xfs=XLoadQueryFont(disp,"fixed");
  127.    XSetForeground(disp,gc,BlackPixel(disp,screen));
  128.    XSetFont(disp,gc,font);
  129.    i=0;
  130.    j=0;
  131.    k=0;
  132.    while(text[i])
  133.      {
  134.     line[j++]=text[i++];
  135.     if (line[j-1]=='\n')
  136.       {
  137.          line[j-1]=0;
  138.          j=0;
  139.          XDrawString(disp,win,gc,6,6+k+14,line,strlen(line));
  140.          k+=14;
  141.       }
  142.      }
  143.    XFreeFont(disp,xfs);
  144.    XSync(disp,False);
  145.    XSelectInput(disp,win,ButtonPressMask);
  146.    XWindowEvent(disp,win,ButtonPressMask,&ev);
  147.    XDestroyWindow(disp,win);
  148. }
  149.  
  150. void _Alert(char *text)
  151. {
  152.    Window win;
  153.    int wid,hih;
  154.    int w,h;
  155.    XGCValues gcv;
  156.    GC gc;
  157.    char line[1024];
  158.    int i,j,k;
  159.    XEvent ev;
  160.  
  161.    XFontStruct *xfs;
  162.    Font font;
  163.    
  164.    if (!text) return;
  165.    
  166.    wid=DisplayWidth(disp,screen);
  167.    hih=DisplayHeight(disp,screen);
  168.    w=(wid-512)/2;
  169.    h=(hih-384)/2;
  170.    win=XCreateSimpleWindow(disp,root,w,h,512,384,1,BlackPixel(disp,screen),WhitePixel(disp,screen));
  171.    gc=XCreateGC(disp,win,0,&gcv);
  172.    XMapWindow(disp,win);
  173.    XSync(disp,False);
  174.    XSetForeground(disp,gc,WhitePixel(disp,screen));
  175.  
  176.    font=XLoadFont(disp,"fixed");   
  177.    xfs=XLoadQueryFont(disp,"fixed");
  178.    XSetFont(disp,gc,font);
  179.    i=0;
  180.    j=0;
  181.    k=0;
  182.    while(text[i])
  183.      {
  184.     line[j++]=text[i++];
  185.     if (line[j-1]=='\n')
  186.       {
  187.          line[j-1]=0;
  188.          j=0;
  189.          XDrawString(disp,win,gc,6,6+k+14,line,strlen(line));
  190.          k+=14;
  191.       }
  192.      }
  193.    XSync(disp,False);
  194.    XSelectInput(disp,win,ButtonPressMask);
  195.    XWindowEvent(disp,win,ButtonPressMask,&ev);
  196.    XDestroyWindow(disp,win);
  197. }
  198.  
  199.