Compare commits
3 Commits
bb19a59315
...
2884c502c1
Author | SHA1 | Date | |
---|---|---|---|
2884c502c1 | |||
bfffe101de | |||
56a2c9978c |
@ -34,8 +34,13 @@ main (int argc, char* argv[])
|
||||
NSRect rect = NSMakeRect (100, 100, 1800, 399);
|
||||
NSRect frameRect = NSMakeRect (0, 0, 1800, 399);
|
||||
|
||||
NSUInteger style_mask = (NSTitledWindowMask |
|
||||
NSClosableWindowMask |
|
||||
NSMiniaturizableWindowMask |
|
||||
NSResizableWindowMask);
|
||||
|
||||
NSWindow* win = [[NSWindow alloc] initWithContentRect:rect
|
||||
styleMask:NSWindowStyleMaskClosable
|
||||
styleMask:style_mask
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
|
||||
@ -47,7 +52,6 @@ main (int argc, char* argv[])
|
||||
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
|
||||
[win makeKeyAndOrderFront:win];
|
||||
|
||||
[NSRunLoop currentRunLoop];
|
||||
[NSTimer scheduledTimerWithTimeInterval:0.02 target:view selector:@selector(timedUpdate) userInfo:nil repeats:YES];
|
||||
|
||||
[[NSApplication sharedApplication] run];
|
||||
|
23
cocoatea/meter.h
Normal file
23
cocoatea/meter.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
#include "view.h"
|
||||
|
||||
struct Meter {
|
||||
double x;
|
||||
double y;
|
||||
double width;
|
||||
double height;
|
||||
double r;
|
||||
double g;
|
||||
double b;
|
||||
double a;
|
||||
double level;
|
||||
NSView* view;
|
||||
|
||||
Meter (NSView* view, double ax, double ay, double aw, double ah, double ar, double ag, double ab, double aa);
|
||||
|
||||
void set_level (double);
|
||||
void draw (CGContextRef);
|
||||
};
|
44
cocoatea/meter.mm
Normal file
44
cocoatea/meter.mm
Normal file
@ -0,0 +1,44 @@
|
||||
/* -*- c++ -*- */
|
||||
#include "meter.h"
|
||||
#include "view.h"
|
||||
|
||||
Meter::Meter (NSView* v, double ax, double ay, double aw, double ah, double ar, double ag, double ab, double aa)
|
||||
: x (ax)
|
||||
, y (ay)
|
||||
, width (aw)
|
||||
, height (ah)
|
||||
, r (ar)
|
||||
, g (ag)
|
||||
, b (ab)
|
||||
, a (aa)
|
||||
, level (0.)
|
||||
, view (v)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
Meter::draw (CGContextRef cg)
|
||||
{
|
||||
NSRect bbox = NSMakeRect (x, y, width, height);
|
||||
|
||||
if (! [view needsToDrawRect:bbox]) {
|
||||
return;
|
||||
}
|
||||
|
||||
CGContextSetRGBStrokeColor (cg, 1., 1., 1., 1.);
|
||||
CGContextStrokeRect (cg, NSMakeRect (x, y, width, height));
|
||||
|
||||
CGContextSetRGBFillColor (cg, r, g, b, a);
|
||||
double fill_height = height - (height * level);
|
||||
CGContextFillRect (cg, NSMakeRect (x, y + fill_height, width, height - fill_height));
|
||||
|
||||
CGContextSetRGBFillColor (cg, 0, 0., 0., 1.0);
|
||||
CGContextFillRect (cg, NSMakeRect (x, y, width, fill_height));
|
||||
}
|
||||
|
||||
void
|
||||
Meter::set_level (double f)
|
||||
{
|
||||
level = f;
|
||||
[view setNeedsDisplayInRect:NSMakeRect (x, y, width, height)];
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
@interface CTView : NSView
|
||||
|
@ -35,28 +35,37 @@ extern std::vector<Meter*> meters;
|
||||
|
||||
-(void) timedUpdate
|
||||
{
|
||||
#if 0
|
||||
int n = random() % meters.size();
|
||||
meters[n]->set_level ((random() % (int) meters[n]->height) / meters[n]->height);
|
||||
#endif
|
||||
for (auto & m : meters) {
|
||||
m->set_level ((random() % (int) m->height) / m->height);
|
||||
if ((random() % 100) == 0) {
|
||||
m->set_level ((random() % (int) m->height) / m->height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)drawRect: (NSRect)rect
|
||||
{
|
||||
// printf ("%g, %g %g x %g\n", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
||||
|
||||
#if 0
|
||||
if (rect.size.width != 10 && rect.size.height != 50) {
|
||||
printf ("%g, %g %g x %g\n", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
||||
}
|
||||
#endif
|
||||
CGContextRef cg = [[NSGraphicsContext currentContext] CGContext];
|
||||
|
||||
for (auto & m : meters) {
|
||||
m->draw (cg);
|
||||
}
|
||||
|
||||
#if 0
|
||||
const NSRect *drawn_rects;
|
||||
long count;
|
||||
int i;
|
||||
|
||||
[self getRectsBeingDrawn: &drawn_rects count: &count];
|
||||
|
||||
#if 0
|
||||
printf ("%ld rects to draw\n", count);
|
||||
for (i = 0; i < count; i++) {
|
||||
//printf ("\trect %d: %g, %g %g x %g\n", i, drawn_rects[i].origin.x, drawn_rects[i].origin.y, drawn_rects[i].size.width, drawn_rects[i].size.height);
|
||||
|
Loading…
Reference in New Issue
Block a user