Hi, I have a window with a text field and some buttons and I would like to know how you can set the background using NSGradient. I firstly did something like this with NSColor properties:
set backgroundColor to current application's NSColor's colorWithCalibratedRed_green_blue_alpha_(126.0, 231.0, 165.0, 1)
dialogWindow's setBackgroundColor_(backgroundColor)
And it works properly, that’s it fills all the window without leaving empty (for example the outline of buttons). Instead, if I try to use NSGradient like this:
set backgroundColor to current application's NSGradient's alloc()'s initWithStartingColor_endingColor_(yellowColor, greenColor)
backgroundColor's drawFromPoint_toPoint_options_((100,0),(500,0), 1)
Yes, it draws the window but not as NSColor did, I mean, there are some kind of white space (outlines of buttons, rect of text field etc.). What might the problem be?
You could make an ASObjC subclass, and implement it as on drawRect:theRect.
But drawing code has to be very efficient because it can be called so often, so I’m always a bit wary about suggesting things like drawRect: in AppleScript code.
You might want to look here and see if someone has a ready-made window you can use:
Could you be more specific about what should be done? I created the window on the MainMenu.xib, not via AS (using e.g. NSWindow’s alloc()'s initWithContentRect_styleMask_backing_defer_), so what could I do if I don’t have a Rect?
I’ve already seen it but it’s not actually what I was looking for as I don’t have a Custom View. Anyway, many thanks, I’ll try implement it differently.
Each window (NSWindow) must have a content view (NSView) to draw the contents in.
When you’re creating the window in IB, the view is automatically created for you