2024-11-14 14:55:44 -07:00
|
|
|
/* -*- c++ -*- */
|
2024-11-14 15:16:41 -07:00
|
|
|
|
|
|
|
|
#include <cstdlib>
|
2024-11-16 18:37:14 -07:00
|
|
|
#include <vector>
|
|
|
|
|
|
2024-11-14 14:55:44 -07:00
|
|
|
#include <stdio.h>
|
2024-11-15 17:54:14 -07:00
|
|
|
|
2024-11-16 18:37:14 -07:00
|
|
|
#include "meter.h"
|
2024-11-14 14:55:44 -07:00
|
|
|
#include "view.h"
|
|
|
|
|
|
2024-11-16 18:37:14 -07:00
|
|
|
extern std::vector<Meter*> meters;
|
2024-11-20 20:15:41 -07:00
|
|
|
extern int queued_draws;
|
2024-11-16 18:37:14 -07:00
|
|
|
|
2024-11-14 14:55:44 -07:00
|
|
|
@implementation CTView
|
|
|
|
|
|
|
|
|
|
-(BOOL)acceptsFirstResponder
|
|
|
|
|
{
|
|
|
|
|
printf ("acceptsFirstResponder\n");
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)noop: (id)sender
|
|
|
|
|
{
|
|
|
|
|
printf ("noop\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(BOOL)isFlipped
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-16 18:37:14 -07:00
|
|
|
-(BOOL)opaque
|
|
|
|
|
{
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-15 17:54:14 -07:00
|
|
|
-(void) timedUpdate
|
|
|
|
|
{
|
2024-11-18 14:59:09 -07:00
|
|
|
#if 0
|
|
|
|
|
int n = random() % meters.size();
|
|
|
|
|
meters[n]->set_level ((random() % (int) meters[n]->height) / meters[n]->height);
|
|
|
|
|
#endif
|
2024-11-16 18:37:14 -07:00
|
|
|
for (auto & m : meters) {
|
2024-11-18 14:59:09 -07:00
|
|
|
if ((random() % 100) == 0) {
|
|
|
|
|
m->set_level ((random() % (int) m->height) / m->height);
|
|
|
|
|
}
|
2024-11-16 18:37:14 -07:00
|
|
|
}
|
2024-11-15 17:54:14 -07:00
|
|
|
}
|
|
|
|
|
|
2024-11-14 14:55:44 -07:00
|
|
|
-(void)drawRect: (NSRect)rect
|
|
|
|
|
{
|
2024-11-20 20:15:41 -07:00
|
|
|
|
|
|
|
|
if (NSContainsRect (rect, [self bounds])) {
|
|
|
|
|
printf ("full redraw, queued = %d\n", queued_draws);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 14:59:09 -07:00
|
|
|
#if 0
|
|
|
|
|
if (rect.size.width != 10 && rect.size.height != 50) {
|
2024-11-20 20:15:41 -07:00
|
|
|
NSRect me = [self bounds];
|
|
|
|
|
printf ("%g, %g %g x %g vs %g, %g %g x %g\n",
|
|
|
|
|
rect.origin.x, rect.origin.y, rect.size.width, rect.size.height,
|
|
|
|
|
me.origin.x, me.origin.y, me.size.width, me.size.height);
|
2024-11-18 14:59:09 -07:00
|
|
|
}
|
|
|
|
|
#endif
|
2024-11-16 18:37:14 -07:00
|
|
|
|
|
|
|
|
|
2024-11-20 20:15:41 -07:00
|
|
|
#if 0
|
2024-11-14 15:16:41 -07:00
|
|
|
const NSRect *drawn_rects;
|
2024-11-15 17:54:14 -07:00
|
|
|
long count;
|
2024-11-14 15:16:41 -07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
[self getRectsBeingDrawn: &drawn_rects count: &count];
|
|
|
|
|
|
2024-11-16 18:37:14 -07:00
|
|
|
printf ("%ld rects to draw\n", count);
|
2024-11-20 20:15:41 -07:00
|
|
|
|
2024-11-14 15:16:41 -07:00
|
|
|
for (i = 0; i < count; i++) {
|
2024-11-20 20:15:41 -07:00
|
|
|
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);
|
2024-11-14 15:16:41 -07:00
|
|
|
}
|
2024-11-16 18:37:14 -07:00
|
|
|
#endif
|
2024-11-20 20:15:41 -07:00
|
|
|
|
|
|
|
|
CGContextRef cg = [[NSGraphicsContext currentContext] CGContext];
|
|
|
|
|
|
|
|
|
|
for (auto & m : meters) {
|
|
|
|
|
m->draw (cg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
queued_draws = 0;
|
2024-11-15 17:54:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)windowWillClose:(NSNotification *)notification
|
|
|
|
|
{
|
|
|
|
|
[NSApp terminate:self];
|
2024-11-14 14:55:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|