osx - Need sample code to swing needle in Cocoa/Quartz 2d Speedometer for Mac App -


i'm building run on mac, not ios - quit different. i'm there speedo, math of making needle move , down scale data input eludes me. i'm measuring wind speed live, , want display gauge - speedometer, needle moving windspeed changes. have fundamentals ok. can - , - load images holders, later. want working ...

    - (void)drawrect:(nsrect)rect {       nsrect myrect = nsmakerect ( 21, 21, 323, 325 ); // set graphics class square size match guage image     [[nscolor bluecolor] set]; // colour in in blue - because can...     nsrectfill ( myrect );        [[nsgraphicscontext currentcontext]                     // set graphics context      setimageinterpolation: nsimageinterpolationhigh];      // highres image      //-------------------------------------------      nssize viewsize  = [self bounds].size;     nssize imagesize = { 320, 322 };                        // actual image rectangle size. can scale image here if like. x , y remember      nspoint viewcenter;     viewcenter.x = viewsize.width  * 0.50;                  // set view center, both x & y     viewcenter.y = viewsize.height * 0.50;      nspoint imageorigin = viewcenter;     imageorigin.x -= imagesize.width  * 0.50;               // set origin of first point     imageorigin.y -= imagesize.height * 0.50;      nsrect destrect;     destrect.origin = imageorigin;                          // set image origin     destrect.size = imagesize;                              // , size      nsstring * file = @"/users/robert/documents/xcode projects/xweather graphics/gauge_mph_320x322.png";  // stuff in image     nsimage * image = [[nsimage alloc] initwithcontentsoffile:file];      //-------------------------------------------      nssize view2size  = [self bounds].size;     nssize image2size = { 149, 17 };                          // orange needle     nspoint view2center;     view2center.x = view2size.width  * 0.50;                  // set view center, both x & y     view2center.y = view2size.height * 0.50;      nspoint image2origin = view2center;     //image2origin.x -= image2size.width  * 0.50;               // set origin of first point     image2origin.x = 47;     image2origin.y -= image2size.height * 0.50;      nsrect dest2rect;     dest2rect.origin = image2origin;                          // set image origin     dest2rect.size = image2size;                              // , size needle size       nsstring * file2  = @"/users/robert/documents/xcode projects/xweather graphics/orange-needle01.png";     nsimage * image2 = [[nsimage alloc] initwithcontentsoffile:file2];                                                               // image 1     [image setflipped:yes];                                 // flip because else in exerecise                                                             // image 2     [image2 setflipped:yes];                                // flip because else in exerecise       [image drawinrect: destrect              fromrect: nszerorect             operation: nscompositesourceover              fraction: 1.0];       [image2 drawinrect: dest2rect              fromrect: nszerorect             operation: nscompositesourceover              fraction: 1.0];          nsbezierpath * path = [nsbezierpath bezierpathwithrect:destrect]; // draw red border around whole thing     [path setlinewidth:3];     [[nscolor redcolor] set];     [path stroke];   } 

// flip ocords - (bool) isflipped { return yes; }

@end

the result here. gauge part is. have make needle move in response input.

apple has sample code, called speedometerview, you're asking. it'll surely take doing adapt use, it's decent starting point.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -