Logo Search packages:      
Sourcecode: aclock.app version File versions  Download package

- (void) drawRect: (NSRect)  r [implementation]

done Shadow

Definition at line 315 of file Clock.m.

References showsArc.

                : (NSRect)r
{
      NSGraphicsContext *ctxt=GSCurrentContext();
      id defaults = [NSUserDefaults standardUserDefaults];
      /*
      BOOL smoothSeconds = [defaults boolForKey: @"SmoothSeconds"];
      */

      if (radius<5)
            return;

      DPSsetlinewidth(ctxt,base_width);

      /* alarm */
      if (arcStartTime > arcEndTime)
      {
            id target = [_cell target];
            SEL action = [_cell action];
            if (showsArc)
            {
                  [self sendAction: action to: target];
            }
            [self setArcEndTime: arcEndTime];
      }


      /* no cache window, create one */
      if (_cacheFrame == nil)
      {
            _cacheFrame = [[NSImage alloc] initWithSize:_bounds.size];

            [_cacheFrame lockFocus];

            /* draw face */
            [faceColor set];
            DPSgsave(ctxt);
            DPSsetalpha(ctxt, faceTrans);
            DPSmoveto(ctxt,center.x+radius,center.y);
            DPSarc(ctxt,center.x,center.y,radius,0,360);
            DPSfill(ctxt);
            DPSgrestore(ctxt);

            /* draw frame and frame shadow */
            [frameColor set];
            DPSsetlinewidth(ctxt, base_width*2);
            DPSmoveto(ctxt,center.x+radius,center.y);
            DPSarc(ctxt,center.x,center.y,radius,0,360);
            DPSclosepath(ctxt);
            DPSstroke(ctxt);

            if (shadow)
            {
                  DPSgsave(ctxt);
                  [[NSColor blackColor] set];
                  DPSsetlinewidth(ctxt, base_width*1.5);
                  DPSsetalpha(ctxt,0.4);
                  DPSmoveto(ctxt,center.x+radius,center.y);
                  DPSarc(ctxt,center.x + 0.5*base_width,center.y-0.5*base_width,radius,0,360);
                  DPSclosepath(ctxt);
                  DPSstroke(ctxt);
                  DPSgrestore(ctxt);

                  [[NSColor whiteColor] set];
                  DPSgsave(ctxt);
                  DPSsetlinewidth(ctxt, base_width*1.0);
                  DPSsetalpha(ctxt,0.3);
                  DPSmoveto(ctxt,center.x+radius,center.y);
                  DPSarc(ctxt,center.x - 0.5*base_width,center.y + 0.5*base_width,radius,0,360);
                  DPSclosepath(ctxt);
                  DPSstroke(ctxt);
                  DPSgrestore(ctxt);
            }

            [_cacheFrame unlockFocus];

      }

      if (_cacheMark == nil)
      {
            _cacheMark = [[NSImage alloc] initWithSize:_bounds.size];

            /* print numbers and draw mark */

            [_cacheMark lockFocus];

            /* print AM PM */
            if (showAMPM)
            {
                  NSMutableAttributedString *str = [[NSMutableAttributedString alloc]
                        initWithString:(handsTime - 86400 * floor(handsTime/86400))/3600 >= 12?@"PM":@"AM"];
                  [str addAttribute:NSForegroundColorAttributeName
                        value:marksColor
                        range:NSMakeRange(0,[str length])];
                  [str addAttribute:NSFontAttributeName
                        value:font
                        range:NSMakeRange(0,[str length])];
                  NSSize strSize = [str size];
                  [str drawAtPoint:NSMakePoint(center.x - strSize.width/2, center.y - radius * 0.8 + strSize.height/2)];
                  RELEASE(str);
            }


            {
                  int i;
                  double a,x,y;

                  [marksColor set];

                  if (numberType != 0 && radius >= 27)
                        for (i=0;i<60;i++)
                        {
                              if (i%5)
                              {
                                    a=i/60.0*2*PI;
                                    x=sin(a);
                                    y=cos(a);
                                    DPSarc(ctxt,center.x+x*radius*0.90,center.y+y*radius*0.90,0.5*base_width,0,360);
                                    DPSfill(ctxt);
                              }
                        }

                  for (i=0;i<12;i++)
                  {
                        a=i/12.0*2*PI;
                        x=sin(a);
                        y=cos(a);

                        if (numberType != 0)
                        {
                              DPSmoveto(ctxt,center.x+x*radius*0.95,center.y+y*radius*0.95);
                              DPSlineto(ctxt,center.x+x*radius*0.83,center.y+y*radius*0.83);
                              DPSstroke(ctxt);
                        }

                        if (numberType == 1)
                        {
                              NSMutableAttributedString *str = [[NSMutableAttributedString alloc]
                                    initWithString:[numArray[1] objectAtIndex:i]];
                              [str addAttribute:NSForegroundColorAttributeName
                                    value:marksColor
                                    range:NSMakeRange(0,[str length])];
                              [str addAttribute:NSFontAttributeName
                                    value:font
                                    range:NSMakeRange(0,[str length])];
                              NSSize size = [str size];
                              [str drawAtPoint:NSMakePoint(center.x+x*radius*0.7 - size.width/2, center.y+y*radius*0.7 - size.height/2)];
                              RELEASE(str);

                              if (dayColor && i == (int)[_date monthOfYear])
                              {
                                    DPSgsave(ctxt);
                                    DPSsetalpha(ctxt,0.7);
                                    DPSarc(ctxt,center.x+x*radius*0.7,center.y+y*radius*0.7,3*base_width,0,360);
                                    DPSstroke(ctxt);
                                    DPSgrestore(ctxt);
                              }

                        }
                        else if (numberType == 0)
                        {
                              NSMutableAttributedString *str = [[NSMutableAttributedString alloc]
                                    initWithString:[numArray[0] objectAtIndex:i]];
                              [str addAttribute:NSForegroundColorAttributeName
                                    value:marksColor
                                    range:NSMakeRange(0,[str length])];
                              [str addAttribute:NSFontAttributeName
                                    value:font
                                    range:NSMakeRange(0,[str length])];
                              NSSize size = [str size];
                              [str drawAtPoint:NSMakePoint(center.x+x*radius*0.80 - size.width/2.5, center.y+y*radius*0.80 - size.height/2)];
                              RELEASE(str);
                        }

                  }
            }

            [_cacheMark unlockFocus];
            NSLog(@"create cache");
      }

      [_cacheFrame compositeToPoint:NSZeroPoint
            operation:NSCompositeSourceAtop];


/*
      if ((handsTime - 86400 * floor(handsTime/86400))/3600 > 12);
      {
      }
      */

      /* draw arc */
      if (showsArc)
      {
            double a1,a2,x,y;
            double r1;

//          [arcColor set];

/*
            {
                  hours=handsTime-43200*floor(handsTime/43200);
                  hours/=3600*12;
                  if (hours>=1) hours-=1;
                  a=hours*2*PI;
                  x=sin(a);
                  y=cos(a);
            }
            */

            a1 = 90 - (arcStartTime - 43200 * floor(arcStartTime/43200))/43200 * 360;
            a2 = 90 - (arcEndTime - 43200 * floor(arcEndTime/43200))/43200 * 360;

            //a2=90-arcEndTime/60/12*360;

/*
            x=sin(a2) * radius * 0.4;
            y=cos(a2) * radius * 0.4;
            */

            r1=radius * 0.8;

            /*
            x=cos(a2/360*2*PI)*r1;
            y=sin(a2/360*2*PI)*r1;
            */

            DPSnewpath(ctxt);
/*
            DPSmoveto(ctxt,center.x,center.y+r1);
            */
//          DPSlineto(ctxt,center.x,center.y);

            if (a2 < a1)
            {
                  a2 += 360;
            }

            DPSsetlinewidth(ctxt,radius*0.4* (0.1 + (a2-a1)/400));

            [[NSColor colorWithDeviceHue: 0.5 - (a2 - a1)/720
                  saturation:0.1 + (a2 - a1)/400
                  brightness:0.8
                  alpha:faceTrans + 0.7] set];

            DPSarc(ctxt,center.x,center.y,r1,a2,a1);
            DPSstroke(ctxt);

      }

      [_cacheMark compositeToPoint:NSZeroPoint
            operation:NSCompositeSourceAtop];

      DPSsetlinewidth(ctxt,base_width);





      {
            double hours,minutes,seconds;
            double a,x,y;

            /* Shadows */

            if (shadow)
            {
                  DPSgsave(ctxt);
                  DPStranslate(ctxt, base_width*1.0, -1.5*base_width);
                  [[NSColor blackColor] set];
                  DPSsetalpha(ctxt, 0.3);

                  if (second)
                  {
                        seconds=handsTime-60*floor(handsTime/60);
                        /*
                        if (smoothSeconds == NO)
                              seconds = floor(seconds);
                              */
                        seconds/=60;
                        a=seconds*2*PI;
                        x=sin(a);
                        y=cos(a);

                        DPSsetlinewidth(ctxt,base_width*0.8);
                        DPSmoveto(ctxt,center.x+x*radius*0.89,center.y+y*radius*0.89);

                        seconds=handsTime-60*floor(handsTime/60)+30;
                        /*
                        if (smoothSeconds == NO)
                              seconds = floor(seconds);
                              */
                        seconds/=60;
                        a=seconds*2*PI;
                        x=sin(a);
                        y=cos(a);

                        DPSlineto(ctxt,center.x+x*radius*0.30,center.y+y*radius*0.30);
                        DPSstroke(ctxt);

                        DPSarc(ctxt,center.x,center.y,1.5*base_width,0,360);
                        DPSfill(ctxt);
                  }
                  else
                  {
                        DPSarc(ctxt,center.x,center.y,1.5*base_width,0,360);
                        DPSfill(ctxt);
                  }

                  minutes=handsTime-3600*floor(handsTime/3600);
                  minutes/=3600;
                  a=minutes*2*PI;
                  x=sin(a);
                  y=cos(a);

                  DPSsetlinewidth(ctxt,base_width);
                  DPSmoveto(ctxt,center.x,center.y);
                  DPSlineto(ctxt,center.x+x*radius*0.89,center.y+y*radius*0.89);
                  DPSstroke(ctxt);

                  hours=handsTime-43200*floor(handsTime/43200);
                  hours/=3600*12;
                  if (hours>=1) hours-=1;
                  a=hours*2*PI;
                  x=sin(a);
                  y=cos(a);

/*
                  {
                        int x2,y2;
                        float f;
                        f=0.06;
                        DPSmoveto(ctxt,center.x,center.y);
                        x2=sin(a+PI/2)*radius*f+center.x+x/2*radius*0.5;
                        y2=cos(a+PI/2)*radius*f+center.y+y/2*radius*0.5;
                        DPScurveto(ctxt,
                                    x2,y2,x2,y2,
                                    center.x+x*radius*0.5,center.y+y*radius*0.5);
                        x2=-sin(a+PI/2)*radius*f+center.x+x/2*radius*0.5;
                        y2=-cos(a+PI/2)*radius*f+center.y+y/2*radius*0.5;
                        DPScurveto(ctxt,
                                    x2,y2,x2,y2,
                                    center.x,center.y);
                        DPSfill(ctxt);

                  }
                  */

                  DPSsetlinewidth(ctxt,base_width*1.5);
                  DPSsetlinecap(ctxt,1);
                  DPSmoveto(ctxt,center.x,center.y);
                  DPSlineto(ctxt,center.x+x*radius*0.5,center.y+y*radius*0.5);
                  DPSstroke(ctxt);
                  DPSsetlinecap(ctxt,0);

                  DPSgrestore(ctxt);

                  /** done Shadow **/
            }

            [handsColor set];
            minutes=handsTime-3600*floor(handsTime/3600);
            minutes/=3600;
            a=minutes*2*PI;
            x=sin(a);
            y=cos(a);

            DPSsetlinewidth(ctxt,base_width);
            DPSmoveto(ctxt,center.x,center.y);
            DPSlineto(ctxt,center.x+x*radius*0.89,center.y+y*radius*0.89);
            DPSstroke(ctxt);

            hours=handsTime-43200*floor(handsTime/43200);
            hours/=3600*12;
            if (hours>=1) hours-=1;
            a=hours*2*PI;
            x=sin(a);
            y=cos(a);

/*
            {
                  int x2,y2;
                  float f;
                  f=0.06;
                  DPSmoveto(ctxt,center.x,center.y);
                  x2=sin(a+PI/2)*radius*f+center.x+x/2*radius*0.5;
                  y2=cos(a+PI/2)*radius*f+center.y+y/2*radius*0.5;
                  DPScurveto(ctxt,
                              x2,y2,x2,y2,
                              center.x+x*radius*0.5,center.y+y*radius*0.5);
                  x2=-sin(a+PI/2)*radius*f+center.x+x/2*radius*0.5;
                  y2=-cos(a+PI/2)*radius*f+center.y+y/2*radius*0.5;
                  DPScurveto(ctxt,
                              x2,y2,x2,y2,
                              center.x,center.y);
                  DPSfill(ctxt);
                  
            }
            */
            DPSsetlinewidth(ctxt,base_width*1.5);
            DPSsetlinecap(ctxt,1);
            DPSmoveto(ctxt,center.x,center.y);
            DPSlineto(ctxt,center.x+x*radius*0.5,center.y+y*radius*0.5);
            DPSstroke(ctxt);
            DPSsetlinecap(ctxt,0);

            if (second)
            {
                  [secHandColor set];
                  seconds=handsTime-60*floor(handsTime/60);
                  /*
                  if (smoothSeconds == NO)
                        seconds = floor(seconds);
                        */
                  seconds/=60;
                  a=seconds*2*PI;
                  x=sin(a);
                  y=cos(a);

                  DPSsetlinewidth(ctxt,base_width*0.8);
                  DPSmoveto(ctxt,center.x+x*radius*0.89,center.y+y*radius*0.89);

                  seconds=handsTime-60*floor(handsTime/60)+30;
                  /*
                  if (smoothSeconds == NO)
                        seconds = floor(seconds);
                        */
                  seconds/=60;
                  a=seconds*2*PI;
                  x=sin(a);
                  y=cos(a);

                  DPSlineto(ctxt,center.x+x*radius*0.30,center.y+y*radius*0.30);
                  DPSstroke(ctxt);

                  DPSarc(ctxt,center.x,center.y,1.5*base_width,0,360);
                  DPSfill(ctxt);
            }
            else
            {
                  DPSarc(ctxt,center.x,center.y,1.5*base_width,0,360);
                  DPSfill(ctxt);
            }

      }


      if (dayColor)
      {
            NSMutableAttributedString *str;
            NSSize strSize;

            [dayColor set];
            DPSarc(ctxt,center.x,center.y,radius/3,0,360);
            DPSsetalpha(ctxt, 0.5);
            DPSfill(ctxt);


            /*
            DPSgsave(ctxt);
            DPSnewpath(ctxt);
            DPSarc(ctxt,center.x,center.y,radius/4,0,360);
            DPSclosepath(ctxt);
            */
            str = [[NSMutableAttributedString alloc]
                  initWithString:[NSString stringWithFormat:@"%d",[_date dayOfMonth]]];
            [str addAttribute:NSForegroundColorAttributeName
                              value:faceColor
                              range:NSMakeRange(0,[str length])];
            [str addAttribute:NSFontAttributeName
                              value:[NSFont boldSystemFontOfSize:radius/2.5]
                              range:NSMakeRange(0,[str length])];
            strSize = [str size];
            DPSsetalpha(ctxt,0.1);
            [str drawAtPoint:NSMakePoint(center.x - strSize.width/2, center.y - strSize.height/2)];
            /*
            DPSgrestore(ctxt);
            */

            /*
            NSCalendarDate *date;

            date = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate:[_date timeIntervalSinceReferenceDate] + _tzv];
            */

      }

}

Generated by  Doxygen 1.6.0   Back to index