Nsviewcomponent hwndcomponent

https://docs.juce.com/master/classNSViewComponent.html

How do we use this class anyone can write an example with a circle drawn from an ns view and repainted ? Thank you appreciate it

figured it out thanks



#include "MetalWaveView.h"
#include <objc/objc-runtime.h>
#include <nanovg.h>
#include <nanovg_mtl.h>

#import <Cocoa/Cocoa.h>

@interface CircleView : NSView

- (instancetype)initWithFrame:(NSRect)frame;

@end

@implementation CircleView

- (instancetype)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Custom initialization if needed
    }
    return self;
}

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    
    // Set the circle color
    [[NSColor blueColor] setFill];
    
    // Calculate the circle's frame
    NSRect circleRect = NSMakeRect(10, 10, self.bounds.size.width - 20, self.bounds.size.height - 20);
    
    // Create the circle path
    NSBezierPath *circlePath = [NSBezierPath bezierPathWithOvalInRect:circleRect];
    
    // Fill the circle
    [circlePath fill];
}

@end

MetalWaveView::MetalWaveView(const VisibleRangeDataModel & model):visibleRange(model) {

    auto b = getLocalBounds();
    NSRect viewRect = NSMakeRect(b.getX(), b.getY(), b.getWidth(), b.getHeight());
    CircleView *circleView = [[CircleView alloc] initWithFrame:viewRect];
    comp.setView(circleView);
    addAndMakeVisible(comp);
}

MetalWaveView::~MetalWaveView() {
    
}

void MetalWaveView::resized() {
    
    comp.setBounds(getLocalBounds());
    
    CircleView * circleView = (CircleView*) comp.getView();
    auto b = getLocalBounds();
    NSRect viewRect = NSMakeRect(b.getX(), b.getY(), b.getWidth(), b.getHeight());
    circleView.frame = viewRect;
    [circleView setNeedsDisplay:YES];
    //repaint();
    
}


void MetalWaveView::paint(juce::Graphics & g) {
    
    //g.setColour(juce::Colours::black);
    //g.drawRect(getLocalBounds());
    
    
}






#define JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS 1

this will save you a lot of time if you are trying to mess with any graphics stuff It was not enabled by default in my project which is insane