home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / HSPASCAL.LZH / HSPASCAL / GEM.TST / WINDOWS.PAS < prev   
Pascal/Delphi Source File  |  1992-10-26  |  7KB  |  164 lines

  1. {$R-,S-,D+}
  2. program Window_Demo;
  3.  
  4. uses Gem_1, GemDecl, GemAES, GemVDI;
  5.  
  6. const
  7.   LeftButton    = 0;            { left mouse button             }
  8.   RightButton   = 1;            { right mouse button            }
  9.  
  10. var
  11.   w1, w2, w3    : integer;      { window handles                }
  12.   x, y, w, h    : integer;      { used for various purposes     }
  13.   Title2        : string;       { window 2's title string       }
  14.   Title3        : string;       { window 3's title string       }
  15.   InfoLine      : string;       { window 3's info line string   }
  16.   AllElements   : integer;      { all window elements           }
  17.   i             : 0..1000;      { slider position index         }
  18.   j             : 0..2;         { FOR index                     }
  19.   mouseX        : integer;      { mouse x pos                   }
  20.   mouseY        : integer;      { mouse y pos                   }
  21.   mouseKeys     : integer;      { mouse button state            }
  22.   window        : integer;      { window handle from wind_find  }
  23.   s             : string;       { message string                }
  24.  
  25. { Clear the work rectangle of the given window }
  26. procedure ClearWindow(window : integer);
  27. var
  28.   p : Array_4;                  { rectangle to clear            }
  29. begin
  30.   wind_update(BEG_UPDATE);      { we're working !               }
  31.   wind_get(window, WF_WORKXYWH, x, y, w, h);    { get work area }
  32.   p[0] := x;                    { set up rectangle              }
  33.   p[1] := y;
  34.   p[2] := x + w - 1;
  35.   p[3] := y + h - 1;
  36.   vs_clip(VDI_handle, 1, p);            { set clip rectangle    }
  37.   vsf_color(VDI_handle, WHITE);         { white,                }
  38.   vsf_interior(VDI_handle, SOLID);      { solid                 }
  39.   vr_recfl(VDI_handle, p);              { fill                  }
  40.   v_gtext(VDI_handle, x, y + CharDefs.h_char,
  41.           ' HighSpeed Pascal window demonstration program '#00);
  42.   wind_update(END_UPDATE)               { we're through working }
  43. end;
  44.  
  45. begin  { main }
  46.   if Init_Gem then begin
  47.     Message('Welcome to the window library demonstration!');
  48.  
  49.     Message('We will now create and open a simple window...');
  50.     x := MinX + 5;                      { make border size      }
  51.     y := MinY;
  52.     w := MaxW div 2 - 5;
  53.     h := MaxH div 2 - 5;
  54.     w1 := wind_create(0, x, y, w, h);   { create the window     }
  55.     wind_open(w1, x, y, w, h);          { open (display) it     }
  56.     ClearWindow(w1);                    { clear work area       }
  57.  
  58.     Message('and a second, more complex, one...');
  59.     x := x + w + 5;                     { make x pos            }
  60.     Title2 := ' Window 2 '#00#00;       { create title          }
  61.     { create window #2 }
  62.     w2 := wind_create(NAME + CLOSER + SIZER, MinX + 5, MinY + 5, MaxW - 10, MaxH - 10);
  63.     { set title : }
  64.     wind_set(w2, WF_NAME, HiPtr(Title2[1]), LoPtr(Title2[1]), 0, 0);
  65.     wind_open(w2, x, y, w, h);          { display window        }
  66.     ClearWindow(w2);                    { clear work rectangle  }
  67.  
  68.     Message('and finally the most advanced available.');
  69.     AllElements := NAME + CLOSER + FULLER + INFO + SIZER + UPARROW +
  70.                    DNARROW + VSLIDE + LFARROW + RTARROW + HSLIDE;
  71.     x := MinX + 5;                      { make border pos, size }
  72.     y := MinY + MaxH div 2;
  73.     w := MaxW - 2*5;
  74.     h := MaxH div 2;
  75.     Title3   := ' Window 3 '#00#00;     { create title          }
  76.     InfoLine := 'This is the window''s'
  77.                  + ' info line'#00#00;  { create info line      }
  78.     w3 := wind_create(AllElements, x, y, w, h);
  79.     { set title : }
  80.     wind_set(w3, WF_NAME, HiPtr(Title3[1]), LoPtr(Title3[1]), 0, 0);
  81.     { set info line : }
  82.     wind_set(w3, WF_INFO, HiPtr(InfoLine[1]), LoPtr(InfoLine[1]), 0, 0);
  83.     wind_open(w3, x, y, w, h);          { display window #3     }
  84.     ClearWindow(w3);                    { clear work area       }
  85.  
  86.     Message('Now we''ll activate the second window...');
  87.     wind_set(w2, WF_TOP, 0, 0, 0, 0);   { top #2                }
  88.  
  89.     Message('and change the size of it...');
  90.     wind_get(w2, WF_CURRXYWH, x, y, w, h);     { get curr. size }
  91.     w := w div 2;                              { make half width}
  92.     wind_set(w2, WF_CURRXYWH, x, y, w, h);     { set new size   }
  93.     ClearWindow(w2);                           { clear work area}
  94.  
  95.     Message('full it...');
  96.     wind_get(w2, WF_FULLXYWH, x, y, w, h);     { get max size   }
  97.     wind_set(w2, WF_CURRXYWH, x, y, w, h);     { set it         }
  98.     ClearWindow(w2);                           { clear work area}
  99.  
  100.     Message('and restore to previous size.');
  101.     wind_get(w2, WF_PREVXYWH, x, y, w, h);     { get prev. size }
  102.     wind_set(w2, WF_CURRXYWH, x, y, w, h);     { set it         }
  103.     { As window #2 overlaid the other two windows, thereby
  104.       destroying their work areas, they have to be cleared again}
  105.     ClearWindow(w1);                           { clear work #1  }
  106.     ClearWindow(w2);                           {            #2  }
  107.     ClearWindow(w3);                           {            #3  }
  108.  
  109.     Message('A window can be closed...');
  110.     wind_get(w3, WF_CURRXYWH, x, y, w, h);     { save size      }
  111.     wind_close(w3);                            { remove from VDU}
  112.  
  113.     Message('and opened again later.');
  114.     wind_open(w3, x, y, w, h);                 { display        }
  115.     ClearWindow(w3);                           { clear work area}
  116.  
  117.     Message('Let''s change the horizontal slider''s size in #3');
  118.     wind_set(w3, WF_HSLSIZE, 333, 0, 0, 0);    { size = 1/3 of  }
  119.                                                { max. possible  }
  120.  
  121.     Message('Now we''ll move the vertical slider.');
  122.     i := 0;
  123.     for j := 0 to 2 do begin
  124.       while i < 1000 do begin
  125.         inc(i, 100);
  126.         wind_set(w3, WF_VSLIDE, i, 0, 0, 0)    { set size       }
  127.       end;
  128.       while i > 0 do begin
  129.         dec(i, 100);
  130.         wind_set(w3, WF_VSLIDE, i, 0, 0, 0)    { set size       }
  131.       end
  132.     end;
  133.  
  134.     Inform('Move and click left mouse button; right completes');
  135.     graf_mouse(M_ON, NIL);
  136.     repeat
  137.       vq_mouse(VDI_handle, mouseKeys, mouseX, mouseY);
  138.       if BitTest(LeftButton, mouseKeys) then begin
  139.         window := wind_find(mouseX, mouseY);
  140.         if window = 0 then s := '-No window-'
  141.         else begin
  142.           str(window, s);
  143.           s := 'Window handle = ' + s
  144.         end;
  145.         s := s + '   Right button completes';
  146.         Inform(s)
  147.       end
  148.     until BitTest(RightButton, mouseKeys);
  149.     graf_mouse(M_OFF, NIL);
  150.  
  151.     Message('Now all is shown, so let''s close all windows...');
  152.     wind_close(w1);
  153.     wind_close(w2);
  154.     wind_close(w3);
  155.  
  156.     Message('remove them from memory and terminate!');
  157.     wind_delete(w1);
  158.     wind_delete(w2);
  159.     wind_delete(w3);
  160.  
  161.     Exit_Gem
  162.   end
  163. end.
  164.