home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / Mac / QuickDraw.pm < prev    next >
Text File  |  1998-04-05  |  13KB  |  616 lines

  1.  
  2. =head1 NAME
  3.  
  4. Mac::QuickDraw - Macintosh Toolbox Interface to QuickDraw
  5.  
  6. =head1 SYNOPSIS
  7.  
  8.  
  9. =head1 DESCRIPTION
  10.  
  11. Access to Inside Macintosh is essential for proper use of these functions.
  12. Explanations of terms, processes and procedures are provided there.
  13. Any attempt to use these functions without guidance can cause severe errors in 
  14. your machine, including corruption of data. B<You have been warned.>
  15.  
  16. =cut
  17.  
  18. use strict;
  19.  
  20. package Mac::QuickDraw;
  21.  
  22. BEGIN {
  23.     use Exporter   ();
  24.     use DynaLoader ();
  25.     
  26.     use vars qw(@ISA @EXPORT %Cursors);
  27.     
  28.     @ISA = qw(Exporter DynaLoader);
  29.     @EXPORT = qw(
  30.         SetPort
  31.         GetPort
  32.         SetOrigin
  33.         SetClip
  34.         GetClip
  35.         ClipRect
  36.         BackPat
  37.         InitCursor
  38.         SetCursor
  39.         HideCursor
  40.         ShowCursor
  41.         ObscureCursor
  42.         HidePen
  43.         ShowPen
  44.         GetPen
  45.         GetPenState
  46.         SetPenState
  47.         PenSize
  48.         PenMode
  49.         PenPat
  50.         PenNormal
  51.         MoveTo
  52.         Move
  53.         LineTo
  54.         Line
  55.         ForeColor
  56.         BackColor
  57.         OffsetRect
  58.         InsetRect
  59.         SectRect
  60.         UnionRect
  61.         EqualRect
  62.         EmptyRect
  63.         FrameRect
  64.         PaintRect
  65.         EraseRect
  66.         InvertRect
  67.         FillRect
  68.         FrameOval
  69.         PaintOval
  70.         EraseOval
  71.         InvertOval
  72.         FillOval
  73.         FrameRoundRect
  74.         PaintRoundRect
  75.         EraseRoundRect
  76.         InvertRoundRect
  77.         FillRoundRect
  78.         FrameArc
  79.         PaintArc
  80.         EraseArc
  81.         InvertArc
  82.         FillArc
  83.         NewRgn
  84.         OpenRgn
  85.         CloseRgn
  86.         DisposeRgn
  87.         CopyRgn
  88.         SetEmptyRgn
  89.         SetRectRgn
  90.         OffsetRgn
  91.         InsetRgn
  92.         SectRgn
  93.         UnionRgn
  94.         DiffRgn
  95.         XorRgn
  96.         RectInRgn
  97.         EqualRgn
  98.         EmptyRgn
  99.         FrameRgn
  100.         PaintRgn
  101.         EraseRgn
  102.         InvertRgn
  103.         FillRgn
  104.         ScrollRect
  105.         CopyBits
  106.         CopyMask
  107.         OpenPicture
  108.         PicComment
  109.         ClosePicture
  110.         DrawPicture
  111.         KillPicture
  112.         OpenPoly
  113.         ClosePoly
  114.         KillPoly
  115.         OffsetPoly
  116.         FramePoly
  117.         PaintPoly
  118.         ErasePoly
  119.         InvertPoly
  120.         FillPoly
  121.         LocalToGlobal
  122.         GlobalToLocal
  123.         Random
  124.         GetPixel
  125.         ScalePt
  126.         MapPt
  127.         MapRect
  128.         MapRgn
  129.         MapPoly
  130.         PtInRect
  131.         AddPt
  132.         SubPt
  133.         EqualPt
  134.         Pt2Rect
  135.         PtToAngle
  136.         PtInRgn
  137.         NewPixMap
  138.         DisposePixMap
  139.         CopyPixMap
  140.         NewPixPat
  141.         DisposePixPat
  142.         CopyPixPat
  143.         PenPixPat
  144.         BackPixPat
  145.         GetPixPat
  146.         FillCRect
  147.         FillCOval
  148.         FillCRoundRect
  149.         FillCArc
  150.         FillCRgn
  151.         FillCPoly
  152.         RGBForeColor
  153.         RGBBackColor
  154.         SetCPixel
  155.         SetPortPix
  156.         GetCPixel
  157.         GetForeColor
  158.         GetBackColor
  159.         OpenCPicture
  160.         OpColor
  161.         HiliteColor
  162.         DisposeCTable
  163.         GetCTable
  164.         GetCCursor
  165.         SetCCursor
  166.         DisposeCCursor
  167.         GetCIcon
  168.         PlotCIcon
  169.         DisposeCIcon
  170.         GetMaxDevice
  171.         GetDeviceList
  172.         GetMainDevice
  173.         GetNextDevice
  174.         TestDeviceAttribute
  175.         SetDeviceAttribute
  176.         NewGDevice
  177.         DisposeGDevice
  178.         SetGDevice
  179.         GetGDevice
  180.         Color2Index
  181.         Index2Color
  182.         InvertColor
  183.         RealColor
  184.         QDError
  185.         CopyDeepMask
  186.         GetPattern
  187.         GetCursor
  188.         GetPicture
  189.         ShieldCursor
  190.         ScreenRes
  191.         GetIndPattern
  192.         SetRect
  193.         BitMapToRegion
  194.         RectRgn
  195.         PixelToChar
  196.         CharToPixel
  197.         DrawJustified
  198.         PortionLine
  199.         VisibleLength
  200.         TextFont
  201.         TextFace
  202.         TextMode
  203.         TextSize
  204.         SpaceExtra
  205.         DrawString
  206.         StringWidth
  207.         GetFontInfo
  208.         CharExtra
  209.         
  210.         invalColReq
  211.         srcCopy
  212.         srcOr
  213.         srcXor
  214.         srcBic
  215.         notSrcCopy
  216.         notSrcOr
  217.         notSrcXor
  218.         notSrcBic
  219.         patCopy
  220.         patOr
  221.         patXor
  222.         patBic
  223.         notPatCopy
  224.         notPatOr
  225.         notPatXor
  226.         notPatBic
  227.         grayishTextOr
  228.         hilitetransfermode
  229.         blend
  230.         addPin
  231.         addOver
  232.         subPin
  233.         addMax
  234.         adMax
  235.         subOver
  236.         adMin
  237.         ditherCopy
  238.         transparent
  239.         blackColor
  240.         whiteColor
  241.         redColor
  242.         greenColor
  243.         blueColor
  244.         cyanColor
  245.         magentaColor
  246.         yellowColor
  247.         picLParen
  248.         picRParen
  249.         clutType
  250.         fixedType
  251.         directType
  252.         gdDevType
  253.         interlacedDevice
  254.         roundedDevice
  255.         hasAuxMenuBar
  256.         burstDevice
  257.         ext32Device
  258.         ramInit
  259.         mainScreen
  260.         allInit
  261.         screenDevice
  262.         noDriver
  263.         screenActive
  264.         hiliteBit
  265.         pHiliteBit
  266.         defQDColors
  267.         RGBDirect
  268.         sysPatListID
  269.         iBeamCursor
  270.         crossCursor
  271.         plusCursor
  272.         watchCursor
  273.         leftCaret
  274.         rightCaret
  275.         hilite
  276.         smLeftCaret
  277.         smRightCaret
  278.         smHilite
  279.         onlyStyleRun
  280.         leftStyleRun
  281.         rightStyleRun
  282.         middleStyleRun
  283.         smOnlyStyleRun
  284.         smLeftStyleRun
  285.         smRightStyleRun
  286.         smMiddleStyleRun
  287.         normal
  288.         bold
  289.         italic
  290.         underline
  291.         outline
  292.         shadow
  293.         condense
  294.         extend
  295.     );
  296. }
  297.  
  298. package Mac::QuickDraw;
  299.  
  300. sub invalColReq ()                 {         -1; }
  301.  
  302. sub srcCopy ()                     {          0; }
  303. sub srcOr ()                       {          1; }
  304. sub srcXor ()                      {          2; }
  305. sub srcBic ()                      {          3; }
  306. sub notSrcCopy ()                  {          4; }
  307. sub notSrcOr ()                    {          5; }
  308. sub notSrcXor ()                   {          6; }
  309. sub notSrcBic ()                   {          7; }
  310. sub patCopy ()                     {          8; }
  311. sub patOr ()                       {          9; }
  312. sub patXor ()                      {         10; }
  313. sub patBic ()                      {         11; }
  314. sub notPatCopy ()                  {         12; }
  315. sub notPatOr ()                    {         13; }
  316. sub notPatXor ()                   {         14; }
  317. sub notPatBic ()                   {         15; }
  318. sub grayishTextOr ()               {         49; }
  319. sub hilitetransfermode ()          {         50; }
  320. sub blend ()                       {         32; }
  321. sub addPin ()                      {         33; }
  322. sub addOver ()                     {         34; }
  323. sub subPin ()                      {         35; }
  324. sub addMax ()                      {         37; }
  325. sub adMax ()                       {         37; }
  326. sub subOver ()                     {         38; }
  327. sub adMin ()                       {         39; }
  328. sub ditherCopy ()                  {         64; }
  329. sub transparent ()                 {         36; }
  330.  
  331. sub blackColor ()                  {         33; }
  332. sub whiteColor ()                  {         30; }
  333. sub redColor ()                    {        205; }
  334. sub greenColor ()                  {        341; }
  335. sub blueColor ()                   {        409; }
  336. sub cyanColor ()                   {        273; }
  337. sub magentaColor ()                {        137; }
  338. sub yellowColor ()                 {         69; }
  339.  
  340. sub picLParen ()                   {          0; }
  341. sub picRParen ()                   {          1; }
  342.  
  343. sub clutType ()                    {          0; }
  344. sub fixedType ()                   {          1; }
  345. sub directType ()                  {          2; }
  346.  
  347. sub gdDevType ()                   {          0; }
  348. sub interlacedDevice ()            {          2; }
  349. sub roundedDevice ()               {          5; }
  350. sub hasAuxMenuBar ()               {          6; }
  351. sub burstDevice ()                 {          7; }
  352. sub ext32Device ()                 {          8; }
  353. sub ramInit ()                     {         10; }
  354. sub mainScreen ()                  {         11; }
  355. sub allInit ()                     {         12; }
  356. sub screenDevice ()                {         13; }
  357. sub noDriver ()                    {         14; }
  358. sub screenActive ()                {         15; }
  359.  
  360. sub defQDColors ()                 {        127; }
  361. sub RGBDirect ()                   {         16; }
  362.  
  363. sub sysPatListID ()                {          0; }
  364.  
  365. sub iBeamCursor ()                 {          1; }
  366. sub crossCursor ()                 {          2; }
  367. sub plusCursor ()                  {          3; }
  368. sub watchCursor ()                 {          4; }
  369.  
  370. sub smLeftCaret ()                 {          0; }
  371. sub smRightCaret ()                {         -1; }
  372. sub smHilite ()                    {          1; }
  373.  
  374. sub smOnlyStyleRun ()              {          0; }
  375. sub smLeftStyleRun ()              {          1; }
  376. sub smRightStyleRun ()             {          2; }
  377. sub smMiddleStyleRun ()            {          3; }
  378.  
  379. sub normal ()                      {          0; }
  380. sub bold ()                        {          1; }
  381. sub italic ()                      {          2; }
  382. sub underline ()                   {          4; }
  383. sub outline ()                     {          8; }
  384. sub shadow ()                      {       0x10; }
  385. sub condense ()                    {       0x20; }
  386. sub extend ()                      {       0x40; }
  387.  
  388. sub _PackImage {
  389.     my($str,$width) = @_;
  390.     my($image);
  391.     for (split(/\s*\n\s*/, $str)) {
  392.         next unless /\S/;
  393.         s/[. _]/0/g;
  394.         s/[^01]/1/g;
  395.         $image .= pack("B$width", $_);
  396.     }
  397.     $image;
  398. }
  399.  
  400. =head2 Types
  401.  
  402. =over 4
  403.  
  404. =cut
  405. package Pattern;
  406.  
  407. =item Pattern
  408.  
  409. A QuickDraw pattern
  410.  
  411. =over 4
  412.  
  413. =item new Pattern BITS
  414.  
  415. =item new Pattern IMAGE
  416.  
  417. Create a new pattern, either from a binary string of length 8, or from an ASCII
  418. image, where ".", " ", "_", and "0" are interpreted as clear pixels, everything 
  419. else as set pixels. Indent is removed.
  420.  
  421.     $love = new Pattern q{
  422.         .XX.XX..
  423.         X..X..X.
  424.         X.....X.
  425.         .X...X..
  426.         ..X.X...
  427.         ...X....
  428.         ........
  429.         ........
  430.     };
  431.  
  432. =back
  433.  
  434. =cut
  435. sub new {
  436.     my($class,$patstr) = @_;
  437.     my($p);
  438.     if (length($patstr) == 8) {
  439.         $p = $patstr;
  440.     } else {
  441.         $p = Mac::QuickDraw::_PackImage($patstr, 8);
  442.     }
  443.     bless \$p, $class;
  444. }
  445.  
  446. package Cursor;
  447.  
  448. =item Cursor
  449.  
  450. A QuickDraw cursor
  451.  
  452. =over 4
  453.  
  454. =item new Cursor DATA
  455.  
  456. =item new Cursor DATABITS, MASKBITS, HOTSPOT
  457.  
  458. =item new Cursor DATAIMAGE, MASKIMAGE, HOTSPOT
  459.  
  460. Create a new cursor, either from a binary string of length 68, from two binary
  461. strings of length 32 and a hotspot C<Point>, or from two ASCII images similar
  462. to the patterns above, and a hotspot point.
  463.  
  464.     $sniper = new Cursor q{
  465.        .......@........
  466.        .......@........
  467.        .....@@@@@......
  468.        ....@..@..@.....
  469.        ...@...@...@....
  470.        ..@....@....@...
  471.        ..@.........@...
  472.        @@@@@@...@@@@@@.
  473.        ..@.........@...
  474.        ..@....@....@...
  475.        ...@...@...@....
  476.        ....@..@..@.....
  477.        .....@@@@@......
  478.        .......@........
  479.        .......@........
  480.        ................
  481.     }, q{
  482.        .......@........
  483.        .......@........
  484.        .....@@@@@......
  485.        ....@..@..@.....
  486.        ...@...@...@....
  487.        ..@....@....@...
  488.        ..@.........@...
  489.        @@@@@@...@@@@@@.
  490.        ..@.........@...
  491.        ..@....@....@...
  492.        ...@...@...@....
  493.        ....@..@..@.....
  494.        .....@@@@@......
  495.        .......@........
  496.        .......@........
  497.        ................
  498.    }, new Point(7,7);
  499.  
  500. =back
  501.  
  502. =cut
  503. sub new {
  504.     my($class,$data,$mask,$hotspot) = @_;
  505.     my($p);
  506.     if (length($data) == 68) {
  507.         $p = $data;
  508.     } elsif (length($data) == 32) {
  509.         $p = $data.$mask.$$hotspot;
  510.     } else {
  511.         $p = Mac::QuickDraw::_PackImage($data, 16)
  512.            . Mac::QuickDraw::_PackImage($mask, 16)
  513.            . $$hotspot;
  514.     }
  515.     bless \$p, $class;
  516. }
  517.  
  518. package PicHandle;
  519.  
  520. use Mac::Memory ();
  521.  
  522. sub new {
  523.     my($class,$data) = @_;
  524.     
  525.     $data = new Handle($data) unless ref($data) && $data->isa("Handle");
  526.     
  527.     bless $data, $class;
  528. }
  529.  
  530. package RgnHandle;
  531.  
  532. sub new {
  533.     Mac::QuickDraw::NewRgn();
  534. }
  535.  
  536. package RGBColor;
  537.  
  538. sub new {
  539.     my($class, $red, $green, $blue) = @_;
  540.     my($color) = pack("SSS", $red, $green, $blue);
  541.     
  542.     bless \$color, $class;
  543. }
  544.  
  545. package Rect;
  546.  
  547. sub new {
  548.     my $class = shift @_;
  549.     my $r;
  550.  
  551.     if (ref($_[0]) && $_[0]->isa("Point")) {
  552.         $r = _new();
  553.         $r->topLeft($_[0]);
  554.         $r->botRight($_[1]) if $_[1];
  555.     } else {
  556.         $r = _new(@_);
  557.     }
  558.     $r;
  559. }
  560.  
  561. package Mac::QuickDraw;
  562.  
  563. bootstrap Mac::QuickDraw;
  564.  
  565. =include QuickDraw.xs
  566.  
  567. =item RECT = SetRect LEFT, TOP, RIGHT, BOTTOM
  568.  
  569. =cut
  570. sub SetRect {
  571.     new Rect @_;
  572. }
  573.  
  574. =item PT = SetPt H, V
  575.  
  576. =cut
  577. sub SetPt {
  578.     new Point @_;
  579. }
  580.  
  581. sub BitMapToRegion {
  582.     unshift @_, NewRgn() unless @_ >= 2;
  583.     &_BitMapToRegion(@_);
  584. }
  585.  
  586. sub RectRgn {
  587.     unshift @_, NewRgn() unless @_ >= 2;
  588.     &_RectRgn(@_);
  589. }
  590.  
  591. sub MakeRGBPat {
  592.     unshift @_, NewPixPat() unless @_ >= 2;
  593.     &_MakeRGBPat(@_);
  594. }
  595.  
  596. sub SetCursor {
  597.     my($crsr) = @_;
  598.     if (defined($crsr) && !ref($crsr)) {
  599.         $Cursors{$crsr} ||= GetCursor($crsr);
  600.         @_ = ($Cursors{$crsr});
  601.     }
  602.     _SetCursor(@_);
  603. }
  604.  
  605. =head1 BUGS/LIMITATIONS
  606.  
  607. =head1 FILES
  608.  
  609. =head1 AUTHOR(S)
  610.  
  611. Matthias Ulrich Neeracher <neeri@iis.ee.ethz.ch> 
  612.  
  613. =cut
  614.  
  615. __END__
  616.