home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Enlightenment / enl_BETA-0.13.src.tar.gz / enl_BETA-0.13.src.tar / enl-0.13 / alert.c < prev    next >
C/C++ Source or Header  |  1997-11-17  |  5KB  |  222 lines

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