Re: Connecting a button to MyView zeros integers

2015-02-15 Thread N!K
It was left checked. Please see my reply to Dave Duncan.

Nick

On Feb 13, 2015, at 9:16 AM, Kyle Sluder  wrote:

> On Fri, Feb 13, 2015, at 10:42 AM, David Duncan wrote:
>> Since you elided your header file, this begs a question – is this iOS or
>> OS X?
>> 
>> If I’m not mistaken, subclasses of NSView do not get -initWithCoder:, but
>> rather -initWithFrame:, which begs the question of have you confirmed
>> that your -initWithCoder: method is being called?
> 
> This depends on whether the "prefer coder" checkbox was checked when the
> XIB was authored. If that checkbox is checked, instantiation behaves
> like iOS, where custom views get -initWithCoder: instead of
> -initWithFrame:.
> 
> --Kyle Sluder
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/pu56ucla62%40alumni.purdue.edu
> 
> This email sent to pu56ucl...@alumni.purdue.edu


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-15 Thread N!K

On Feb 13, 2015, at 6:49 AM, Uli Kusterer  wrote:

> On 12 Feb 2015, at 06:36, N!K  wrote:
>> Control-clicking the button in .xib does show the outlet panel but it does 
>> not list an IBAction, so it cannot connect to the IBAction entered into the 
>> MyView.h and .m files. Also, control-dragging from the button to MyView (in 
>> .xib, not in editor) sets up the position constraints. Control-dragging from 
>> the button to any icon does nothing.
> 
> You mean to File's Owner? Is the “Custom Class" of File's Owner set to the 
> right class?

Yes.

> Both right-drag and ctrl-drag still work for me to connect button actions in 
> 6.1.1 (which is the latest on the MAS).

For me, control-dragging does not work with anything except AppDelegate, 
following Apple’s current example.

> 
>> I haven’t needed a control for quite some time, and I found that things have 
>> changed in Xcode 6.1.1.  I’m attempting to follow Apple’s current 
>> instruction.
>> 
>> Here’s the instruction from Apple’s Xcode_Overview.pdf, 2014-03-10, pp 
>> 64-65. The pictures have to be omitted here due to space constraints of this 
>> forum.
>> 
>> Control-drag from the control in Interface Builder to the implementation 
>> file. (In the screenshot, the assistant editor displays the implementation 
>> file of the view controller for the Warrior button.) Xcode indicates where 
>> you can insert an action method in your code.
>> 
>> [picture shows a line with a leading circle in a space in .m]
>> 
>> Release the Control-drag. The assistant editor displays a Connection menu. 
>> In this menu, type the name of the action method (chooseWarrior in the 
>> screenshot below), and click Connect. 
>> 
>> [picture shows a menu with space to enter name of action]
> 
> This is for adding a new outlet/action.

Which also makes the connection.  But following Apple’s current example works 
only with AppDelegate in my system.

> I was under the impression you had an existing one that you just wanted to 
> hook up?

I had also tried entering the IBAction in .h and .m. Initially I failed because 
I was constrained by what I learned in Hillegas’ 3rd edition. I succeeded when 
I followed Roland King’s specific directions, which showed me that some of the 
old constraints no longer apply. Please see my reply to Roland’s email.

Nick

> 
>> Connect User Interface Objects to Code
>> 
>> In the implementation file, Xcode inserts a skeletal definition for the new 
>> method, as shown below. The IBAction return type is a special keyword 
>> indicating that this instance method can be connected to your storyboard or 
>> xib file. Xcode also sets the action selector for the control to this 
>> method. As a result, the method gets invoked whenever the control receives 
>> an action message. 
>> 
>> [picture shows - (IBAction)chooseWarrior:(id)sender { }  ]
>> 
>> 
>> This Xcode_Overview example uses an implementation file, not AppDelegate. It 
>> does not add an empty object in IB.
>> 
>> Xcode is not allowing connection to my MyView file. Insertion of  - 
>> (IBAction)act:(id)sender { } occurs only in my AppDelegate, which of course 
>> responds to the button. Clicking the button in the View initiates the 
>> IBAction, which indicates that I’m following the instruction correctly.  I 
>> do the same steps when  I try it with my MyView file, which fails.
>> 
>> Might this be a bug? Or a defective copy of Xcode? Has anyone observed the 
>> same behavior?
> 
> I'm not sure what you're trying to do. Can you give us a better description? 
> Your app delegate has an act: method but you're trying to connect to it by 
> dragging to a MyView?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-15 Thread N!K

On Feb 13, 2015, at 8:42 AM, David Duncan  wrote:

> Since you elided your header file, this begs a question – is this iOS or OS X?

This is OSX.

I was following Apple’s example, which control-drags from a button to the .m 
file.  The .h file isn’t used. I supplied the shortest possible file to avoid 
confusion.

> 
> If I’m not mistaken, subclasses of NSView do not get -initWithCoder:, but 
> rather -initWithFrame:, which begs the question of have you confirmed that 
> your -initWithCoder: method is being called?

Yes. With a breakpoint.

InitWithCoder is called because Runtime Behavior, Instantiation,  Prefer Coder 
is checked in xib’s inspector.
There was quite a discussion about why it works this way 12/23/14 - 12/30/14, 
in response to my request for help, “initWithFrame fails”  Roland King nailed 
it in his email 12/26/2014.


Nick

> 
>> On Feb 6, 2015, at 6:22 PM, N!K  wrote:
>> 
>> 
>> I would like to connect a button to MyView class, but Xcode 6.1.1 only 
>> allows control-dragging a button to AppDelegate to create an IBAction. I 
>> have not encountered this previously. Looking for a workaround, I found this 
>> recommendation in a couple of Stack Overflow and other web pages as well as 
>> a YouTube video. It enables the button to work, but unfortunately it zeros 
>> all the integers in MyView.
>> 
>> The recommendation is:
>> 1. Drag an empty Object from the IB library to the column of blue icons.
>> 2. Set its class to MyView.
>> 3. Control-drag from the button to MyView.m
>> 4. Fill in the name (“act”) in the popup.
>> This puts the IBAction template into MyView, ready to fill in.
>> 
>> #import "MyView.h"
>> 
>> @implementation MyView
>> 
>> - (id)initWithCoder:(NSCoder *)aDecoder
>> {
>>   self = [super initWithCoder:aDecoder];
>>   if (self) {
>>   iii=1000;
>>   k=99;
>>   }
>>   return self;
>> }
>> 
>> - (IBAction)act:(id)sender {
>>   iii=iii+1;
>>   NSLog(@"  iba i= %i",iii);
>> }
>> 
>> 
>> In MyView.m, iii=1000 is initialized in initWithCoder. At the breakpoint 
>> after IBAction, iii is seen in both places to have the value 1, not 1001,  
>> by hovering. It was zeroed and then incremented after clicking on Button in 
>> the View. Similarly, k is initialized to 99 and then zeroed. Both are ivars 
>> in MyView.h.
>> 
>> Clearly, zeroing all the integers is not acceptable. Can this approach be 
>> saved? Having the IBAction in MyView is desirable for directly relating its 
>> functions to the rest of MyView, rather than indirectly from AppDelegate. On 
>> the other hand, Xcode may have very good reasons – unknown to me – for 
>> restricting IBAction to AppDelegate. Maybe timing?
>> 
>> Thanks in advance,
>> 
>> Nick
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
>> 
>> This email sent to david.dun...@apple.com
> 
> --
> David Duncan
> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Connecting a button to MyView zeros integers

2015-02-15 Thread N!K

On Feb 11, 2015, at 9:56 PM, Roland King  wrote:

> 
>> On 12 Feb 2015, at 13:36, N!K  wrote:
>> 
>> Control-clicking the button in .xib does show the outlet panel but it does 
>> not list an IBAction, so it cannot connect to the IBAction entered into the 
>> MyView.h and .m files. Also, control-dragging from the button to MyView (in 
>> .xib, not in editor) sets up the position constraints. Control-dragging from 
>> the button to any icon does nothing.
>> 
> 
> Ctrl click the view, not the button. When you ctrl-click the view you will 
> see the actions listed and you can drag BACK to the button. Or you can go 
> find the ‘connections inspector’ (View->Utilities->Show Connections 
> Inspector) panel for the button and drag ‘selector’ to the view you want to 
> perform the action on and then you can select the action performed. Either 
> way works, there’s probably a load more ways like the connections inspector 
> on the view which you can probably drag the IBAction to whatever button you 
> want. 

Thank you. This indeed works. This is  essentially an improvement over what I 
learned in Hillegas’ 3rd edition, which always worked.

So how have I been going astray? Well, things have changed since then. Your 
instruction above got me up to today’s relaxed rules.

1. Hillegas made a big point of dragging from the button, which doesn’t list 
the IBAction. So I never got as far as trying to drag from the view, which does 
have the IBAction in its list. This works.
2. The button’s list doesn’t have an IBAction in it, but it does have a 
selector. It didn’t occur to me to try dragging from that, and then the panel 
with the IBAction shows up. This works, too.
3. It’s no longer necessary to add an empty object icon, as Hillegas did in his 
example on pp.20-21.

On my original path, I was able to make  the current example – in Apple’s 
Xcode_Overview.pdf, 2014-03-10, pp 64-65 – work with MyView by adding an empty 
object icon. But this zeroed all my integers; not acceptable.

> 
>> 
>> This Xcode_Overview example uses an implementation file, not AppDelegate. It 
>> does not add an empty object in IB.
>> 
>> Xcode is not allowing connection to my MyView file. Insertion of  - 
>> (IBAction)act:(id)sender { } occurs only in my AppDelegate, which of course 
>> responds to the button. Clicking the button in the View initiates the 
>> IBAction, which indicates that I’m following the instruction correctly.  I 
>> do the same steps when  I try it with my MyView file, which fails.
>> 
>> Might this be a bug? Or a defective copy of Xcode? Has anyone observed the 
>> same behavior?
> 
> No somehow you are just flapping at it and failing. Not a bug, not a 
> defective copy of Xcode. 

Maybe this remains to be seen. Although the advice above works, my original 
request for help was based on my attempt to follow Apple’s current example, 
which works only with AppDelegate.  This just can’t be right. 

Nick


> 
> Go to your view header file and type in the IBAction, you will then find it 
> listed either on ctrl-click on the view (assuming you have the view in your 
> NIB set to the right class, you do right, you did set the view class in IB) 
> or by going to the connection inspector for the button and dragging the 
> ‘selector’ to the view, when it will list only the IBActions. 
> 
>> 
>> Nick
>> 
>> 
>> 
>> On Feb 7, 2015, at 10:27 PM, Uli Kusterer  
>> wrote:
>> 
>>> So quick to discount Stack Overflow. What they’re suggesting is simply how 
>>> to create a new object and define a new outlet on it that points to an 
>>> object in a quick way. Seems like a perfectly good answer to a problem to 
>>> me, and my guess is the OP might not have quite matched it up to the right 
>>> question. Without a link to the answer, it’s hard to tell.
>>> 
>>> My guess is the OP is experiencing a common beginners’ confusion about how 
>>> NIB files work and is creating a second object while all they want to do is 
>>> really just hook something up to an existing object in the NIB, likely to 
>>> File’s Owner. Creating a new object instead of using an existing one of 
>>> course means that all ivars get new (likely default) values, which would be 
>>> completely consistent with the observed behaviour of “everything going to 
>>> 0”.
>>> 
>>> Cheers,
>>> -- Uli Kusterer
>>> “The Witnesses of TeachText are everywhere...”
>>> http://zathras.de
>>> 
>>>> On 07 Feb 2015, at 03:43, Roland King  wrote:
>>>> 
>>>> I have no idea what stackoverflow is suggesting here but it looks entirely 
>>>> wron

Re: Connecting a button to MyView zeros integers

2015-02-11 Thread N!K
Control-clicking the button in .xib does show the outlet panel but it does not 
list an IBAction, so it cannot connect to the IBAction entered into the 
MyView.h and .m files. Also, control-dragging from the button to MyView (in 
.xib, not in editor) sets up the position constraints. Control-dragging from 
the button to any icon does nothing.


I haven’t needed a control for quite some time, and I found that things have 
changed in Xcode 6.1.1.  I’m attempting to follow Apple’s current instruction.

Here’s the instruction from Apple’s Xcode_Overview.pdf, 2014-03-10, pp 64-65. 
The pictures have to be omitted here due to space constraints of this forum.

Control-drag from the control in Interface Builder to the implementation file. 
(In the screenshot, the assistant editor displays the implementation file of 
the view controller for the Warrior button.) Xcode indicates where you can 
insert an action method in your code.

[picture shows a line with a leading circle in a space in .m]

Release the Control-drag. The assistant editor displays a Connection menu. In 
this menu, type the name of the action method (chooseWarrior in the screenshot 
below), and click Connect. 

[picture shows a menu with space to enter name of action]

Connect User Interface Objects to Code

In the implementation file, Xcode inserts a skeletal definition for the new 
method, as shown below. The IBAction return type is a special keyword 
indicating that this instance method can be connected to your storyboard or xib 
file. Xcode also sets the action selector for the control to this method. As a 
result, the method gets invoked whenever the control receives an action 
message. 

[picture shows - (IBAction)chooseWarrior:(id)sender { }  ]


This Xcode_Overview example uses an implementation file, not AppDelegate. It 
does not add an empty object in IB.

Xcode is not allowing connection to my MyView file. Insertion of  - 
(IBAction)act:(id)sender { } occurs only in my AppDelegate, which of course 
responds to the button. Clicking the button in the View initiates the IBAction, 
which indicates that I’m following the instruction correctly.  I do the same 
steps when  I try it with my MyView file, which fails.

Might this be a bug? Or a defective copy of Xcode? Has anyone observed the same 
behavior?

Nick



On Feb 7, 2015, at 10:27 PM, Uli Kusterer  wrote:

> So quick to discount Stack Overflow. What they’re suggesting is simply how to 
> create a new object and define a new outlet on it that points to an object in 
> a quick way. Seems like a perfectly good answer to a problem to me, and my 
> guess is the OP might not have quite matched it up to the right question. 
> Without a link to the answer, it’s hard to tell.
> 
> My guess is the OP is experiencing a common beginners’ confusion about how 
> NIB files work and is creating a second object while all they want to do is 
> really just hook something up to an existing object in the NIB, likely to 
> File’s Owner. Creating a new object instead of using an existing one of 
> course means that all ivars get new (likely default) values, which would be 
> completely consistent with the observed behaviour of “everything going to 0”.
> 
> Cheers,
> -- Uli Kusterer
> “The Witnesses of TeachText are everywhere...”
> http://zathras.de
> 
>> On 07 Feb 2015, at 03:43, Roland King  wrote:
>> 
>> I have no idea what stackoverflow is suggesting here but it looks entirely 
>> wrong as usual for that junky site. You're just creating a standalone I 
>> referenced object. 
>> 
>> Right click your view in IB then wait a second and right click it again. I 
>> think it's right clicks. You will then get the outlet panel which is the 
>> grey HUD display with all the outlets and actions. You can drag connect to 
>> your buttons. There's some ctrl alt shift cmd combo which does this too but 
>> I never remember it. You can still connect view outlets as before, just that 
>> ctrl-drag was repurposed a couple of xcodes ago for auto layout so you have 
>> to work a little harder to get the inspector up. 
>> 
>> 
>> 
>>> On 7 Feb 2015, at 10:22, N!K  wrote:
>>> 
>>> 
>>> I would like to connect a button to MyView class, but Xcode 6.1.1 only 
>>> allows control-dragging a button to AppDelegate to create an IBAction. I 
>>> have not encountered this previously. Looking for a workaround, I found 
>>> this recommendation in a couple of Stack Overflow and other web pages as 
>>> well as a YouTube video. It enables the button to work, but unfortunately 
>>> it zeros all the integers in MyView.
>>> 
>>> The recommendation is:
>>> 1. Drag an empty Object from the IB library to the column of blue icons.
>>> 2. Set its class to MyView.
>

Connecting a button to MyView zeros integers

2015-02-06 Thread N!K

I would like to connect a button to MyView class, but Xcode 6.1.1 only allows 
control-dragging a button to AppDelegate to create an IBAction. I have not 
encountered this previously. Looking for a workaround, I found this 
recommendation in a couple of Stack Overflow and other web pages as well as a 
YouTube video. It enables the button to work, but unfortunately it zeros all 
the integers in MyView.

The recommendation is:
1. Drag an empty Object from the IB library to the column of blue icons.
2. Set its class to MyView.
3. Control-drag from the button to MyView.m
4. Fill in the name (“act”) in the popup.
This puts the IBAction template into MyView, ready to fill in.

#import "MyView.h"

@implementation MyView

- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
iii=1000;
k=99;
}
return self;
}

- (IBAction)act:(id)sender {
iii=iii+1;
NSLog(@"  iba i= %i",iii);
}


In MyView.m, iii=1000 is initialized in initWithCoder. At the breakpoint after 
IBAction, iii is seen in both places to have the value 1, not 1001,  by 
hovering. It was zeroed and then incremented after clicking on Button in the 
View. Similarly, k is initialized to 99 and then zeroed. Both are ivars in 
MyView.h.

Clearly, zeroing all the integers is not acceptable. Can this approach be 
saved? Having the IBAction in MyView is desirable for directly relating its 
functions to the rest of MyView, rather than indirectly from AppDelegate. On 
the other hand, Xcode may have very good reasons – unknown to me – for 
restricting IBAction to AppDelegate. Maybe timing?

Thanks in advance,

Nick
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: drawRect runs twice, bounds are changed in between

2015-01-29 Thread N!K
Thank you.


On Jan 28, 2015, at 8:30 PM, Graham Cox  wrote:

> 
>> On 29 Jan 2015, at 3:05 pm, N!K  wrote:
>> 
>> NSBezierPath* temp;   is in the list of declarations.
>> This snippet is in drawRect:
>> 
>>   NSAffineTransform* tfm = [[NSAffineTransform alloc] init];
>>   [tfm scaleXBy:scaleX yBy:scaleY];
>>  temp  = [tfm transformBezierPath:_path];
>>  NSLog(@“\n\n temp = %p\n\n",temp);
>> 
>> 
>> I hope ARC keeps cleaning them up. Or do I have a memory leak? If so, I’d 
>> appreciate some guidance on how to fix it.
> 
> 
> You're fine leaks-wise, but your code might be cleaner. The bezier path 
> returned by [tfm transformBezierPath] is autoreleased. ARC cleans up tfm, 
> temp is released at the end of the event cycle. If temp is an ivar, and it's 
> not used anywhere else, just make it a local var (it will be stale after the 
> event cycle completes anyway). If it's an ivar and it is referenced 
> elsewhere, you probably should make it a strong property instead.
> 
> --Graham
> 
> 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: drawRect runs twice, bounds are changed in between

2015-01-28 Thread N!K
Uti, 

Looking further into your uncertainty about where temp comes from (see previous 
email, below) reveals a possible memory leak. 

NSBezierPath* temp;  is in the list of declarations.
This snippet is in drawRect:

NSAffineTransform* tfm = [[NSAffineTransform alloc] init];
[tfm scaleXBy:scaleX yBy:scaleY];
temp  = [tfm transformBezierPath:_path];
NSLog(@“\n\n temp = %p\n\n",temp);

drawRect runs many times while  dragging the corner of the window. 
transformBezierPath: creates a new object each time. 
A new temp is created each time. Just one memory location is not used 
repeatedly. 

Here’s a list of temp addresses — not temp content  —   (from NSLog %p above) 
while dragging the corner of the window slightly. They are all different.

2015-01-28 16:27:44.042 CVone[780:303] 

 temp = 0x608000320960

2015-01-28 16:27:44.094 CVone[780:303] 

 temp = 0x60800013fd60

2015-01-28 16:27:49.465 CVone[780:303] 

 temp = 0x6080003212c0

2015-01-28 16:27:49.484 CVone[780:303] 

 temp = 0x6013ff40

2015-01-28 16:27:49.501 CVone[780:303] 

 temp = 0x608000321180

2015-01-28 16:27:49.523 CVone[780:303] 

 temp = 0x608000320be0

2015-01-28 16:27:49.541 CVone[780:303] 

I hope ARC keeps cleaning them up. Or do I have a memory leak? If so, I’d 
appreciate some guidance on how to fix it.

Nick



On Jan 16, 2015, at 5:30 AM, Uli Kusterer  wrote:

> On 15 Jan 2015, at 07:58, Quincey Morris 
>  wrote:
>> Putting those two ideas together leads to a better approach. Create the 
>> bezier path once, relative to an arbitrary bounding rect — say 1000 x 1000. 
>> (But any rect would do.) When you need to draw the path, set the CTM of the 
>> context to scale 1000 x 1000 (the reference bounds) to the context’s width x 
>> height (the view bounds). Then just draw the original path and AppKit will 
>> scale the bezier path for you.
> 
> That's not the be-all end-all, though. Scaling the CTM scales line widths and 
> heights as well. So if you for example want to skew the path, you'd get lines 
> that are wider than they are tall (kind of calligraphic). Also, changing the 
> CTM means that mouse click coordinates will be in a different coordinate 
> system then your drawing, so if you’re e.g. implementing a graphics editor, 
> you'll have to manually translate the coordinates each time.

> 
> A better idea might be to have a list of original objects and projected 
> objects. The list of projected objects is generated by transforming the 
> paths. Whenever your view's bounds change, you rebuild this list of projected 
> objects from the originals (thus keeping rounding errors etc. to a minimum as 
> they can't accumulate). The drawing code just draws this projected list.
> 
> As I don't know where 'temp' comes from in N!K’s code,

NSBezierPath* temp;  is in the list of declarations.

_path is created once, in -(id)initWithCoder:(NSCoder*)coder . 
_path is scaled to the new size and assigned to  temp each time drawRect is 
called. Thus, there is no error buildup.

> this may be what's already happening, in which case I find that a better 
> approach than mangling the CTM if your interest is in having a shape drawn 
> crisply in a window. If you're instead looking to scale a drawing (whether 
> vector or otherwise), where you want lines to be skewed, then Quincy.s 
> approach is preferrable.
> 
> -- Uli


Nick
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: drawRect runs twice, bounds are changed in between

2015-01-17 Thread N!K

On Jan 16, 2015, at 5:30 AM, Uli Kusterer  wrote:

> On 15 Jan 2015, at 07:58, Quincey Morris 
>  wrote:
>> Putting those two ideas together leads to a better approach. Create the 
>> bezier path once, relative to an arbitrary bounding rect — say 1000 x 1000. 
>> (But any rect would do.) When you need to draw the path, set the CTM of the 
>> context to scale 1000 x 1000 (the reference bounds) to the context’s width x 
>> height (the view bounds). Then just draw the original path and AppKit will 
>> scale the bezier path for you.
> 
> That's not the be-all end-all, though. Scaling the CTM scales line widths and 
> heights as well. So if you for example want to skew the path, you'd get lines 
> that are wider than they are tall (kind of calligraphic). Also, changing the 
> CTM means that mouse click coordinates will be in a different coordinate 
> system then your drawing, so if you’re e.g. implementing a graphics editor, 
> you'll have to manually translate the coordinates each time.

> 
> A better idea might be to have a list of original objects and projected 
> objects. The list of projected objects is generated by transforming the 
> paths. Whenever your view's bounds change, you rebuild this list of projected 
> objects from the originals (thus keeping rounding errors etc. to a minimum as 
> they can't accumulate). The drawing code just draws this projected list.
> 
> As I don't know where 'temp' comes from in N!K’s code,

NSBezierPath* temp;  is in the list of declarations.

_path is created once, in -(id)initWithCoder:(NSCoder*)coder . 
_path is scaled to the new size and assigned to  temp each time drawRect is 
called. Thus, there is no error buildup.

> this may be what's already happening, in which case I find that a better 
> approach than mangling the CTM if your interest is in having a shape drawn 
> crisply in a window. If you're instead looking to scale a drawing (whether 
> vector or otherwise), where you want lines to be skewed, then Quincy.s 
> approach is preferrable.
> 
> -- Uli


Nick
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: drawRect runs twice, bounds are changed in between

2015-01-14 Thread N!K

On Jan 13, 2015, at 10:55 PM, Quincey Morris 
 wrote:

> On Jan 13, 2015, at 21:25 , N!K  wrote:
>> 
>> I have not been able to find  a reason for this behavior. . I don’t know how 
>> to reveal the point between passes where bounds is actually changed. It does 
>> not happen in any other NSView projects of mine; drawRect runs only once in 
>> them
> 
> The immediate reason is probably that the view’s size changed, which is not 
> unlikely when the window is in the process of being displayed. The view may 
> be resized for a “local” reason, such as the application of auto layout 
> constraints, or for a “global” reason, such as the containing being resized 
> and the change filtering down to subviews.
> 
> Another possibility is that the view didn’t change size, but that (as an 
> implementation detail of the Cocoa drawing system) it received two partial 
> invalidations, and these weren’t coalesced in this case.
> 
>> I would like to prevent the second pass, or at least prevent the bounds 
>> change between passes.
> 
> I don’t see any practical way to prevent ‘drawRect’ from being called again.


> Redundant ‘drawRect’ calls can occur any time during the view’s lifetime. 

This I didn’t realize, until you and Jens are explaining to me now. 

> 
> Are you implying that one bounds rect is “right” and one is “wrong”?

No. The system draws the view correctly, as long as I don’t interfere by adding 
my attempt at initialization and scaling.

> If so, how do you know that, and why can’t you just make your code do nothing 
> if the bounds are “wrong”?
> 
> If the only criterion is that the *last* bounds rect is “right”, you’ve got a 
> big problem, because there’s no such concept in the drawing system.
> 
> If you’re hoping that someone can suggest a solution, you probably need to be 
> more specific about what “right” and “wrong” mean. 


> 
>> I’m reluctant to try restoring bounds to its first value. I appreciate Ken 
>> Thomases’ warning in a previous subject not to change bounds in drawRect.
> 
> 
> I’d say it wasn’t a warning, but rather an injunction to never, ever do that. 
> Doing so is Wile E. Coyote stuff.
> 


I wish this had appeared in the Cocoa books I’ve read.


On  a lighter note, the Roadrunner cartoons are my favorites. Every blunder 
presents a classic engineering failure.  :)




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: drawRect runs twice, bounds are changed in between

2015-01-14 Thread N!K

On Jan 13, 2015, at 10:50 PM, Jens Alfke  wrote:

> 
>> On Jan 13, 2015, at 9:25 PM, N!K  wrote:
>> 
>> A breakpoint at the end of drawRect shows that it runs twice. After the 
>> second pass, the view appears, as it should.
>> Between passes, bounds is changed somehow, as shown by NSLog  at the start 
>> and end of drawRect. 
>> Since this will upset code that I will add later, I’d like to stop this. 
> 
> The view's being resized, probably as part of view layout. Ideally AppKit 
> shouldn't draw the view before it gets to its final size, but maybe this is 
> part of an animation, or maybe it's something that hasn't been optimized 100% 
> in AppKit.
> 
> In general, you should not make assumptions about when and how often 
> -drawRect: will be called. That's up to AppKit. Your job is just to draw the 
> view when you’re told to.

OK. Cause is unknown (probably unknowable?) but part of Cocoa. Just because 
there was only one pass in other projects, I can’t depend on it. drawRect can 
happen anytime.

> 
> You haven't said why the bounds change will upset your code; is the view 
> being changed to the wrong size? That would be an actual problem, but it 
> isn't related to being drawn multiple times. You'd need to look at the view 
> constraints in your window to diagnose that.
> 
> —Jens

“Why” takes a little explaining. Thank you for your patience.

I’m trying to learn more about drawing. One stumbling block was getting an 
NSBezierPath to change size proportional to the window size when the corner is 
dragged. Per Graham Cox’s suggestion, the view size change can be detected in 
subsequent passes of drawRect by comparing 
ratioX = NSWidth ([_path bounds])/NSWidth(bounds);
ratioY = NSHeight([_path bounds])/NSHeight(bounds);
with their initial values, which were established in the one pass of drawRect 
before the view appeared.

This worked perfectly. I used the ratios in 
-(void)resize{
scaleX = ratioX0/ratioX;
scaleY = ratioY0/ratioY;
NSAffineTransform* tfm = [[NSAffineTransform alloc] init];
[tfm scaleXBy:scaleX yBy:scaleY];
temp  = [tfm transformBezierPath:_path];
}
The initial view was correct. Then dragging the window corner  induced 
drawRect’s, which detected the changes and scaled the original _path each time; 
no cumulative errors. The path size tracked the view size correctly. 



Next I wanted to learn how to scale the whole view in a new project, not just 
the NSBezierPath. I was  planning to  later include other objects with the 
NSBezierPath and wanted them to be scaled, too. I used the same initialization 
and failed because of the bounds change between two passes, which I failed to 
anticipate. The first pass set the initial values. The second pass detected the 
change and scaled the view before the view appeared.
-(void)resize{
scaleX = ratioX0/ratioX;
scaleY = ratioY0/ratioY;
NSAffineTransform* tfm = [[NSAffineTransform alloc] init];
[tfm scaleXBy:scaleX yBy:scaleY];
temp  = [tfm transformBezierPath:_path];
}
Thus the path in the initial view was quite different from the initial path, 
and dragging the corner of the window caused wildly incorrect scaling.

My hope was that there might be a way of suppressing the second pass before 
display of the view. Now I know better and will figure out another way to 
initialize and track. Thank you for correcting me.

Nick








___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

drawRect runs twice, bounds are changed in between

2015-01-13 Thread N!K



In my simple test project, an NSBezierPath is created and stroked.

-(id)initWithCoder:(NSCoder*)coder{
_path = [[NSBezierPath alloc] init];
create points
}

- (void)drawRect:(NSRect)dirtyRect {
bounds = [self bounds];
NSLog(@"\n\n   bounds: %@\n\n", NSStringFromRect(bounds));

[[NSColor whiteColor] set];
[_path   setLineWidth:07.0];//default width = 1
[_path stroke];

bounds = [self bounds];
NSLog(@"\n\n  emd bounds: %@\n\n", NSStringFromRect(bounds));
}

A breakpoint at the end of drawRect shows that it runs twice. After the second 
pass, the view appears, as it should.

Between passes, bounds is changed somehow, as shown by NSLog  at the start and 
end of drawRect. 
Since this will upset code that I will add later, I’d like to stop this. 

_path is not changed in either pass.

needsToDrawRect: is not used.

I’m using Xcode 6.1.1 in OSX 10.9.5.



I have not been able to find  a reason for this behavior. . I don’t know how to 
reveal the point between passes where bounds is actually changed. It does not 
happen in any other NSView projects of mine; drawRect runs only once in them

I would like to prevent the second pass, or at least prevent the bounds change 
between passes. I’m reluctant to try restoring bounds to its first value. I 
appreciate Ken Thomases’ warning in a previous subject not to change bounds in 
drawRect.

Can anyone explain why this happens? Is it possible to suppress it without 
destroying whatever good it does?

Thanks,

Nick




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: view content not tracking window size

2014-09-29 Thread N!K

On Sep 27, 2014, at 12:27 AM, Ken Thomases  wrote:

> On Sep 27, 2014, at 2:11 AM, N!K  wrote:
> 
>> On Sep 25, 2014, at 10:49 PM, Ken Thomases  wrote:
>> 
>>> On Sep 25, 2014, at 9:38 PM, N!K  wrote:
>>> 
>>>> In Xcode 5 OSX, not ios, I have created a custom view and set auto layout 
>>>> constraints so that the custom view's sides stay a fixed distance from the 
>>>> content view's frame. The custom view resizes correctly while dragging the 
>>>> window's corner while running, but the content of the custom view remains 
>>>> fixed in size. Shrinking the window can crop the content, and expanding it 
>>>> provides lots of open space next to the unchanging content.
>>>> 
>>>> The content consists of a Bezier path, which is created in initwithframe 
>>>> and executed in drawrect with [path stroke]. NSLog shows that bounds is 
>>>> changing while resizing.
>>>> 
>>>> How can I make the content resize along with the view and window? The 
>>>> window, view, and drawing documents explain how to set up a view, but I 
>>>> haven't found any discussion of content tracking the window size.
>>> 
>>> You asked this at 
>>> <http://stackoverflow.com/questions/26006747/xcode-5-auto-layout-view-stretches-but-not-the-views-contents/26007383#26007383>
>>>  and I answered you there.
>> 
>> Thank you for your response there, but  I was not able to use it. If you 
>> like, I can send you  the reasons in detail.
> 
> Well, if you don’t explain then people are just going to keep rehashing the 
> obvious approaches.  


There is nothing to rehash; I was unable to use your inputs.


> But don't send the reasons to _me_.  Send them to the list and/or the 
> StackOverflow community.


I will immediately comment on your answer in StackOverflow. Interested cocoa 
dev readers can see it there. I don’t see a need to clutter this forum with the 
details.


> 
>>> In summary, the easiest thing to do is set the bounds once.  If you ever 
>>> set the bounds of a view, then they stop automatically tracking the frame.  
>>> Therefore, the coordinate space ends up scaling.  Since the bounds are no 
>>> longer always equal to the frame, Cocoa effectively has to transform the 
>>> coordinate space inside the view to the coordinate space of the containing 
>>> view(s) and, ultimately, the window.  That transform is exactly the sort of 
>>> stretching you seem to be expecting.
>>> 
>>> What you set the bounds to is up to you.  You could set the bounds to the 
>>> unit square and then do all of your calculations based on the fraction of 
>>> the view that you want to measure.  So, x = 0 would be the left edge and x 
>>> = 1 would be the right edge.  x = 0.5 would be the center.  x = 1/3.0 would 
>>> be one third of the way across.  Etc.
>> 
>> Simply setting the bounds is very attractive. Unfortunately, setting the 
>> bounds did not work, in initWithFrame or drawRect.
> 
> What does "did not work" mean?  What were the results?


The path did not scale while manually resizing the window.


> 
> In any case, you definitely shouldn't set the bounds in -drawRect:.  That 
> method is for drawing, not for modifying the view.


Not so. This is where scaling the content works. Please see my response in 
cocoa-dev today, 9/29/2014 8:35 PM, about success using Graham Cox’s outline.


> 
> Regards,
> Ken
> 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: view content not tracking window size

2014-09-29 Thread N!K
Success! Many thanks, Graham,

Your explanation enlightened me, and your example got me on the right track. I 
didn’t know that not-scaling the contents is normal; I had been looking for 
whatever was wrong and how to fix it. The thought of scaling in code did occur 
to me, but I had absolutely no idea how to start. Stumped, I sought help and 
you came through.

I also appreciate the inputs from the other responders, but Graham’s help was 
explicit. Thank you all.



A couple of comments, if I may:

Implementing if( scaleThePath ) stumped me. I couldn’t find a good size change 
criterion when I found that drawRect is called twice at the start,  before 
doing any manual resizing. There was about  about a 10% change in scaleX and 
scaleY from the first to the second. This was  greater than the changes while 
resizing.  It got too complicated, so I ignored this after many tries. I 
accepted simply doing the transform every time and found no harm. Perhaps a 
more demanding application would justify more work.

In this part of drawRect, [tfm concat];  was commented out because it was 
doubling the scaling. Without it, the path tracks the frame perfectly during 
resizing. (I still don’t know how to use it properly and haven’t found an 
example.)

// scale the content to track the frame

{
NSBezierPath *path;
NSRect bounds;
CGFloat scaleX,scaleY;
}


scaleX =NSWidth(bounds)/NSWidth([path bounds]);
scaleY =NSHeight(bounds)/NSHeight([path bounds]);


NSAffineTransform* tfm = [[NSAffineTransform alloc] init];
[tfm scaleXBy:scaleX yBy:scaleY];
NSBezierPath* temp  = [tfm transformBezierPath:path];

//   [tfm concat];

[temp stroke];


On Sep 25, 2014, at 9:22 PM, Graham Cox  wrote:

> When the view resizes, the content area changes to become larger or smaller, 
> but the scaling of content within that view does not change. You have to 
> arrange this if that's what you want.
> 
> There are a number of ways to do this, but nothing automatic - no amount of 
> fiddling with constraints will achieve this. You can either scale the view,or 
> you can scale the path that you draw inside the view.
> 
> The latter is probably easiest - using the view's bounds, you can compute a 
> transform that will scale the path to fit that bounds, then use - 
> transformBezierPath: to create a new temporary path the right size. If your 
> original path is calculated based on a "unit square", that is a bounds rect 
> of size 1.0, 1.0, then calculating the scale factor is trivially easy, though 
> any rect isn't much harder.
> 
> Bear in mind that this approach scales the path, but not the stroke width, 
> etc used to draw it. If you scale the view instead, then any stroke widths 
> are also scaled and in that case you don't need to create temporary paths, 
> but you do need to compute the same transform and concat it with the current 
> CTM when you draw the path.
> 
> Off the top of my head (not tested, typed in Mail), the sort of code you need 
> is:
> 
> - (void) drawRect:(NSRect) dirtyRect
> {
>NSRect br = [self bounds];
> 
>CGFloat scaleX, scaleY;
> 
>scaleX = NSWidth([path bounds]) / NSWidth( br );
>scaleY = NSHeight([path bounds]) / NSHeight( br );
> 
>NSAffineTransform* tfm = [NSAffineTransform alloc] init];
> 
>[tfm scaleXBy:scaleX yBy:scaleY];
> 
>if( scaleThePath )
>{
>   NSBezierPath* temp = [tfm transformBezierPath:path];
> 
>   [self drawMyPath:temp];
>}
>else
>{
>[tfm concat];
>[self drawMyPath:path];
>}
> }
> 
> --Graham
> 
> 
> 
> 
> 
> On 26 Sep 2014, at 12:38 pm, N!K  wrote:
> 
>> In Xcode 5 OSX, not ios, I have created a custom view and set auto layout 
>> constraints so that the custom view's sides stay a fixed distance from the 
>> content view's frame. The custom view resizes correctly while dragging the 
>> window's corner while running, but the content of the custom view remains 
>> fixed in size. Shrinking the window can crop the content, and expanding it 
>> provides lots of open space next to the unchanging content.
>> 
>> The content consists of a Bezier path, which is created in initwithframe and 
>> executed in drawrect with [path stroke]. NSLog shows that bounds is changing 
>> while resizing.
>> 
>> How can I make the content resize along with the view and window? The 
>> window, view, and drawing documents explain how to set up a view, but I 
>> haven't found any discussion of content tracking the window size.
> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: view content not tracking window size

2014-09-29 Thread N!K
Thank you for the reference. I have not had to deal with images (except in 
Hillegas’ book example), so I have not read about Quartz. It sounds like it has 
other uses, like line drawings.

I’ll follow up with this soon, and yes, some examples will be a big help. I 
often find that things like Apple’s documentation clearly and exactly defines 
functions, but then I have no idea how to use them. If I can find examples of 
code, the Aha! light goes on.


On Sep 27, 2014, at 5:41 AM, dangerwillrobinsondan...@gmail.com wrote:

> It's the same bezier drawing. Just an API to draw into a context with a 
> little built in convenience methods. 
> 
> You should really read more about Quartz to understand how this is really not 
> different. Just convenient resizing. 
> 
> I can share some example code if it helps. 
> 
> Sent from my iPhone
> 
> On 2014/09/27, at 16:14, N!K  wrote:
> 
>> Thanks, but I want to stay with a line drawing, Bezier path, not images. 
>> Also, I don’t know how to do anything with images.
>> 
>> Nick
>> 
>> 
>> On Sep 25, 2014, at 10:42 PM, dangerwillrobinsondan...@gmail.com wrote:
>> 
>>> 
>>> 
>>> On 2014/09/26, at 11:38, N!K  wrote:
>>> 
>>>> In Xcode 5 OSX, not ios, I have created a custom view and set auto layout 
>>>> constraints so that the custom view's sides stay a fixed distance from the 
>>>> content view's frame. The custom view resizes correctly while dragging the 
>>>> window's corner while running, but the content of the custom view remains 
>>>> fixed in size. Shrinking the window can crop the content, and expanding it 
>>>> provides lots of open space next to the unchanging content.
>>>> 
>>>> The content consists of a Bezier path, which is created in initwithframe 
>>>> and executed in drawrect with [path stroke]. NSLog shows that bounds is 
>>>> changing while resizing.
>>>> 
>>>> How can I make the content resize along with the view and window? The 
>>>> window, view, and drawing documents explain how to set up a view, but I 
>>>> haven't found any discussion of content tracking the window size.
>>>> 
>>>> Thanks,
>>>> 
>>>> 
>>>> 
>>>> Nick
>>> 
>>> One approach is to use an NSImage inside an NSImageView. 
>>> 
>>> NSImage has an awesome class method that takes a block argument for 
>>> drawing. 
>>> 
>>> + (id)imageWithSize:(NSSize)size 
>>> flipped:(BOOL)drawingHandlerShouldBeCalledWithFlippedContext 
>>> drawingHandler:(BOOL (^)(NSRect dstRect))drawingHandler
>>> 
>>> The image view helps for maintaining the aspect and scaling desired. 
>>> 
>>> With this combo you can then simply use auto layout constraints to keep it 
>>> a minimum size or what have you. 
>> 

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

view content not tracking window size

2014-09-25 Thread N!K
In Xcode 5 OSX, not ios, I have created a custom view and set auto layout 
constraints so that the custom view's sides stay a fixed distance from the 
content view's frame. The custom view resizes correctly while dragging the 
window's corner while running, but the content of the custom view remains fixed 
in size. Shrinking the window can crop the content, and expanding it provides 
lots of open space next to the unchanging content.

The content consists of a Bezier path, which is created in initwithframe and 
executed in drawrect with [path stroke]. NSLog shows that bounds is changing 
while resizing.

How can I make the content resize along with the view and window? The window, 
view, and drawing documents explain how to set up a view, but I haven't found 
any discussion of content tracking the window size.

Thanks,



Nick


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

start with OSX 5.1.1

2014-07-29 Thread N!K

After using Xcode 3.2.6 occasionally, I downloaded 5.1.1 and typed in a very 
simple program in .h and .m to try it out.

Run immediately generated the error

"The run destination My Mac 64–bit is not valid for Running the scheme 
‘var,prop,synth'.
The scheme 'var,prop,synth' contains no buildables that can be built for the 
SDKs supported by the run destination My Mac 64–bit. Make sure your targets all 
specify SDKs that are supported by this version of Xcode.”

I couldn’t find any applicable instructions with Google. 
My iMac is 64 bit (runs photoshop cs6}.
Referring to the program as a scheme is new to me, and I don’t know how to 
check what SDKs are in my Xcode 5.1 application, as it is listed in 
Applications.  As much as I could find out is that it has 4.96 Gb. This is not  
like 3.2.6, which came in a Developer folder with a list of items for direct 
access.

Please help me get started.

Nick
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Custom control with 4 vertical sliders

2013-02-23 Thread N!K
I've been following this thread because I have a similar application in mind,  
displaying 6 sets (groupings, not NSSets)  consisting of a label with slider and
textview, both bound to an ivar. 

It seems so simple: create a custom view with one set, duplicate it to make 6 
such custom views, and place them all into another custom view.
I'm not advanced enough to understand why there's a discussion.

On the other hand, there seems to be interest in more complex ways, which 
implies that there are advantages in them that I don't see. Specifically, I 
don't see advantage in going on with collection views or boxes, and I don't 
know what you would do with a subclass (of what?).

What am I missing? It must be elementary.


On Feb 16, 2013, at 10:18 AM, Gordon Apple wrote:

> Don¹t use NSMatrix.  Use NSCollectionView.  I have a popover containing a
> collection view with sliders and all kinds of other stuff.  Depending on
> what you are doing, you may need to make the thing create a new view for
> every collection class element instead of just replicating the prototype.
> (I have individual QTmovie thumbnails playing in mine.)  You will need to
> subclass the collection view to do this.  However, from your description,
> that should not be necessary.  The standard prototype view should work
> without subclassing the collection view.
> 
> On 2/16/13 4:00 AM, "cocoa-dev-requ...@lists.apple.com"
>  wrote:
> 
>> I sometimes find that trying to subclass existing classes such as NSCell is
>> more trouble that it's worth, unless you really need your custom cell to be
>> used anywhere a cell can be used, e.g. buttons, matrices, list rows, etc. If
>> you just want a particular custom control that doesn't need that degree of
>> reusability, subclassing NSView or NSControl is always a lot easier. In this
>> case, if NSSlider isn't suitable, just make a custom view for your custom
>> slider, then add it four times to another custom view that handles the "set"
>> of sliders as needed.
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/pu56ucla62%40alumni.purdue.edu
> 
> This email sent to pu56ucl...@alumni.purdue.edu


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

IB>Button>Attributes>Position almost works

2012-11-16 Thread N!K
This is probably trivial, but I haven't been able to find a reference in a 
couple of textbooks, Apple, Google or a place  in IB Preferences.

IB>Button>Attributes>Position allows you to position the button's text in 
various positions relative to the button. It shows



When I click any one of them, I see a slight movement in the IB window in the 
proper direction, maybe a pixel or two, but never enough to move the text 
outside of the button. (BTW, other attributes respond correctly and the rest of 
IB seems to be functioning.) I'm using Xcode 3.3, OSX 10.6, IB 3.2.4.

Is there a way to set the distance the text should be moved, in order to 
resemble the choices shown above?

Thanks in advance, 

Nick


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Windows and views and controls, oh my!

2011-09-07 Thread N!K
Thank you.  This helps me with higher level issues

On Sep 5, 2011, at 9:42 PM, Quincey Morris wrote:

> On Sep 5, 2011, at 20:43 , N!K wrote:
> 
>> The examples I've seen all show a window with a view in it and how to draw 
>> in that view. But  I want to put up a window with a couple of views in it 
>> and draw in them individually, sometimes clearing and redrawing, sometimes 
>> adding more drawing.
> 
> You're misusing the term "view" and I have to conclude that you've 
> mis-absorbed what a view is.
> 
> A view is not so much a construct for breaking apart the visual *appearance* 
> of a window as a construct for organizing the *process* of drawing window 
> contents. That is, views are mostly about apportioning responsibility, and 
> not so much about providing a canvas (although, in the end, they are that 
> too).
> 
> In Cocoa, you really don't "draw in" views. Rather, views draw themselves. 
> That's the first conceptual hurdle you need to overcome.

Please pardon my loose terminology. By "draw in,"  I meant "draw within." I 
meant using NSBezierpath to create lines which will appear within a view 
whenever it gets displayed.  I didn't mean causing a view to appear. I 
understand that the system takes care of  displaying the views.

> 
> The second hurdle is that in Cocoa the view appearance is conceptually 
> redrawn from scratch as necessary. That is, having drawn something, a view 
> doesn't just assume its previous appearance is persistent and can be erased. 
> Instead, the window appearance is achieved by layering the drawing done by 
> each view in a controlled manner, and this happens every time the window 
> contents needs to be drawn or redrawn.
> 
> Now, a view certainly *can* cache its own previous visual state (as a bitmap, 
> or via some other intermediate representation), but that sort of thing is 
> generally done only if necessary for performance reasons, because it's a lot 
> more coding work.
> 
> Thus, if you have a custom view that draws one or more graphs superimposed, 
> where there is a user option to control which graphs are shown, you don't add 
> a second graph simply by drawing it on top of something that already exists 
> from a previous drawing pass. Instead, you "add" it by redrawing the entire 
> view, but with 2 graphs instead of 1 (except, of course, in the exceptional 
> case already mentioned case of manually caching previous drawing).

This explains the changing process very well.

> 
> You say you want to put up a window "with a couple of views in it", but we 
> have no idea what this means. You want to draw a couple of graphs, or 
> something like that? Well, then, your task is about implementing a custom 
> view that draws itself with some kind of custom appearance.

Exactly. making a second view work is where I'm stumbling.

What I'm trying to do is really very simple. I want a pushbutton to seek data 
input for the model (easily done). Then I want a pushbutton to display two 
different views of the data. 



> That has, typically, very little to do with the mechanics of the window as a 
> whole.
> 
>> (Controller code that takes input from pushbuttons  and data entry are not a 
>> problem.)
> 
> FWIW, keep in mind that buttons and text fields are views, too.

Yes.

> 
>> Do I need an NSWindow Controller at all?
> 
> Nothing in your considerations of views has anything do with the question of 
> whether there's a window controller or not.
> 

The reason I ask if a window controller is necessary is that I do not plan to 
manipulate the window at all. Once it's open, I will leave it alone while 
"drawing within" the views until quitting. Also, I will not be manipulating the 
views as a whole. Many examples, notably in Hillegas' books, successfully 
display views with content in them without using  window and view controllers.

> Others may disagree, but I believe that there's basically no reason ever 
> *not* to use a window controller. Its prime function is to load and manage 
> the nib resource file of its associated window, so using a window controller 
> relieves you of the responsibility of writing that management code yourself. 
> Window controllers are also useful as controller objects in the MVC sense 
> (that is, as places to put certain business logic that links the window 
> contents to the data model) and as window delegates (that is, as places to 
> put certain code that customizes some of the window behavior).

I think I haven't encountered a need for the use a window controller. The 
system loads the nib and window automatically, and I don't know what the 
business logic might be.

>

Re: Windows and views and controls, oh my!

2011-09-05 Thread N!K
Thanks for the description below. It's good.

I, too, am floundering when it comes to specifics that are not shown in 
examples from Apple or BNR books or websites. I understand the examples, but I 
don't see how to extend them.  So,  understanding how the windows and views 
should be structured together will help me. Perhaps an analogy might make this 
clearer. It's like having a cookbook with all kinds of well-understood recipes 
and no idea how to plan a banquet menu that will use the recipes in a good 
order.

The examples I've seen all show a window with a view in it and how to draw in 
that view. But  I want to put up a window with a couple of views in it and draw 
in them individually, sometimes clearing and redrawing, sometimes adding more 
drawing. (Controller code that takes input from pushbuttons  and data entry are 
not a problem.) Do I need an NSWindow Controller at all? Ditto 
NSViewController? I tried separate drawRect's in controllers but couldn't make 
them work.

An outline of how to do this will be greatly appreciated.

I'm using 10.6.8 and Xcode 3.2.4 on an iMac. No iOS.

Nick



On Sep 5, 2011, at 9:07 AM, Ken Thomases wrote:

> On Sep 5, 2011, at 10:32 AM, William Squires wrote:
> 
>> While I can create the UI easily enough in IB, what I don't understand is 
>> how to actually load, instantiate, and display the window from my view 
>> controller object.
> 
> A common approach is to:
> 
> * Create a custom subclass of NSWindowController.  Since a custom window 
> controller is usually intimately tied to a specific NIB, one usually 
> hard-codes the NIB name in the init method.  That is, your custom init method 
> will invoke [super initWithWindowNibName:@"YourNIBName"].  (Note: this is a 
> window controller, which is different from a view controller.)
> 
> * Create a NIB containing your window.  In the Identity inspector, set the 
> class of the File's Owner placeholder to be your custom window controller 
> class.
> 
> * Connect the "window" outlet of File's Owner to the window in the NIB.  If 
> your custom window controller has other outlets, connect them, too.
> 
> * In the code which knows that it wants to display the window (often the app 
> controller), instantiate your custom window controller class.  Then either 
> invoke -showWindow: on it or request its window property and directly 
> manipulate it -- for example, send it -makeKeyAndOrderFront:.
> 
> 
>> [...] how do I:
>> 
>> 1) make sure the window isn't displayed until all it's views (controls) have 
>> had a chance to initialize their default (visual) state properly
> 
> Either the views should obtain their state on demand, such that the very act 
> of drawing themselves makes sure they are showing their proper state, or they 
> should initialize themselves in -awakeFromNib or the like.  In other words, 
> this isn't usually something you have to manage manually from the point of 
> view of the code that displays the window nor the window controller.  If the 
> window controller does need to set stuff up after the window was loaded, do 
> that in an override of -windowDidLoad.
> 
>> 2) actually display the window, either modally, or not.
> 
> Described above.  To run a window modally, use -[NSApplication 
> runModalForWindow:].
> 
>> 3) if modal, how does my client code make sure it doesn't return from the 
>> operation until the user closes the window (by clicking the close box, or by 
>> dismissing it in code from an IBAction tied to an NSButton whose caption is 
>> "Done" or some such.)
> 
> -runModalForWindow: won't return until something invokes -stopModal, 
> -stopModalWithCode:, or -abortModal.
> 
>> 4) Pass information to/from the client code and the view controller?
> 
> The code which instantiates the window controller should either pass 
> arguments to a custom initializer of your own design or simply invoke 
> methods, such as setters, to configure the window controller.
> 
>> 5) Prevent the window from closing (if non-modal) if the contents are 
>> 'dirty'?
> 
> Set the window controller to be the window's delegate by connecting the 
> window's delegate outlet to File's Owner in the NIB.  Then have the window 
> controller implement -windowShouldClose:.
> 
> Regards,
> Ken
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/pu56ucla62%40alumni.purdue.edu
> 
> This email sent to pu56ucl...@alumni.purdue.edu

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/co

Re: Decimation - NSBezierPath or something else?

2011-08-08 Thread N!K
Thank you all for your prompt and appropriate answers. 
NSBezier doesn't decimate although it does interpolate.
Lots and lots of points go slowly.

I could not believe that this is a new problem; it had to be recognizable and 
previously dealt with.
When a number of points occupy one pixel, something has to be done with them. 
With the old fashioned CRT, the points would bloom from repeated 
intensification at one location. Not knowing what that "something"  is in 
NSBezierPath or the rest of the path to today's flat panel screen seems risky.

I'll do the decimation. 
It's straightforward. 
It controls the process. 
It speeds things up. 
It might even be a little bit elegant.  :)


Nick___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Decimation - NSBezierPath or something else?

2011-08-08 Thread N!K
Does NSBezierPath do decimation as well as interpolation? I didn't find it in 
the Class Reference.
Or is there another class that does it? 
Or must I do the decimation before plotting the data with NSBezierPath?

Decimation reduces the original sampling rate for a sequence to a lower rate, 
the opposite of interpolation. The decimation process filters the input data 
with a lowpass filter and then resamples the resulting smoothed signal at a 
lower rate.


In my application, the math generates  hundreds of points for accuracy, for 
every one that needs to be plotted to make a decent looking plot. Signal 
processing theory says that you can't just throw away points, or you can 
generate errors.

For example, I might generate 25,000 points and be happy to look at a 200 point 
plot. Throwing 25,000 points at NSBezierPath might swamp it, or at least run 
very slowly.

Nick___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: instance fails in its own class

2010-11-07 Thread N!K
Success! Your last sentence pointed the way.

On Nov 6, 2010, at 11:25 PM, Greg Guerin wrote:

> N!K wrote:
> 
>> However, exactly the same statement fails when pasted into -init of Class.m.
>> 
>> Build yields "warnings  Class may not respond to -new."
> 
> 
> This message suggests you're calling an instance method, not a class method, 
> or that's the way the compiler is interpreting it.

Yes. I had completely missed the association between +new, which includes 
-init, and my explicit -(id)init, which confused the compiler . My -init of 
course overrides all other inits including those with assignments. This last 
point I knew well.

> Post your actual failing code, in the complete method where it fails.


That was a mess from all the errors in troubleshooting, so I'm not including it 
here. An interesting but frustrating round was the chase of misleading compiler 
errors when my small block of code worked in InstanceAppDelegate as  long as 
Untitled was empty, but got warnings in both places as soon as I put anything 
into Untitled. Instance ran but showed more errors and stalled.

However, in order to not leave you hanging, here is what I wound up with, which 
does work:

#import "Untitled.h"
@implementation Untitled

-(void)alphaObj
{
Untitled *objk;
objk = [Untitled new];
NSLog(@"objk = %@",objk);
//return self;
}
@end 

I also added [obj alphaObj];  to  InstanceAppDelegate.m  to call it.
I had used  -(id)init with my code in it instead of -(void)alphaObj because it 
calls itself, which provides some separation and  is a convenience while 
concentrating on learning some exercises.

> For example, is your class really named Class?  If so, then that won't work.  
> The reason is that Class is already a defined type, and it doesn't descend 
> from NSObject.  See the return type of the NSObject method -class.  Look it 
> up in "The Objective-C Programming Language" reference doc, under the heading 
> "Defined Types", or see the include file "objc/objc.h".

Thanks, I had previously found Class (capitalized) used as the name of a class 
in an Apple guide example, which contrasted it with  class (small initial) 
which is defined, as in @class. To be safe, I'll avoid anything close. I was 
trying to use Class in my email in order to be clear, and it backfired. Sorry.
> 
> Furthermore, since +new is defined as +alloc followed by -init,

This was meant to initialize Class

> calling +new in -init

while this was meant to initialize the new object. I had no idea of redundancy 
here.

> seems a little recursive to me,  but without seeing actual code, it's just a 
> guess.
> 
>  -- GG

What a lot of trouble for such a small item! I'm amazed at the steep learning 
curve in Objective C, Cocoa and Xcode on my own. After exhausting all my own 
thoughts and Google with many trials, I really appreciate having you and this 
group to turn to.

Nick

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


instance fails in its own class

2010-11-06 Thread N!K
This should be an elementary step, just like in  all the examples I've seen, 
but it doesn't work for me.
I'm trying to create an instance of a class, which I can use to access -methods.

Class *obj = [Class new];
 works OK in ProjectAppDelegate.m.



However, exactly the same statement fails when pasted into -init of Class.m. 

Build yields "warnings  Class may not respond to -new."  I have not created any 
-new, and NSObject shows +new.
It doesn't matter if the  Class * declaration is in the .h files instead of .m 
files.

It runs but does nothing. A break point is reached in ProjectAppDelegate.m, but 
none is reached in Class.m

I'm using Xcode 3.2.4, which has GNU gdb 6.3.50-20050815 (Apple version 
gdb-1472) (Wed Jul 21 10:53:12 UTC 2010).
On the chance that Xcode was corrupted, I deleted and installed it again. No 
improvement. 

I couldn't find any leads in Google. Any idea what's going on? 

Thanks,

Nick


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


create multiple Custom Views

2010-10-08 Thread N!K
I know this should be really easy, but I've been unsuccessful finding an 
explanation or tutorial in Apple's documentation or in Google. A couple terse 
examples did show up, but I did not understand them or they didn't seem to 
apply.
In simplest form, I need to put two Custom Views onto the one window in 
Interface Builder along with two buttons to control them. Each button should 
cause a new Bezier line to be drawn on its associated window. The buttons are 
no problem, but controlling the two Custom Views individually is.
Lots of material covers a single Custom View. I have no difficulty creating one 
and using it, although I do not understand specifically what assigns the Custom 
View pointer to in -(void)drawRect:(NSRect)rect or 
–(id)initWithFrame:(NSRect)frameRect. I'm accepting on faith that the system 
“knows” because there is only one Custom View in the one NSView subclass in 
these examples.
However, I think I need to know how to assign the arguments when there is more 
than one Custom View, in order to direct the init and draw to the correct 
Custom View. When I naively drag a second Custom View and AppController onto 
the window, make the connections, and attempt to associate the two Custom Views 
and use two IBOutlets to control them, I fail completely. Maybe I'm barking up 
the wrong tree, trying to do this with only one subclass of NSView for both 
Custom Views.
Questions:
Where can I find out how to assign the init and draw arguments to one Custom 
View or the other? Or is this the wrong approach?
Is one subclass required for each Custom View? This seems cumbersome when there 
are several Custom Views.
Are IBOutlets for each Custom View the right approach?
Is this the place for lockFocus, to draw on only the correct Custom View?
And most important of all, is there a good example with explanation that I can 
follow?


Thanks in advance,

Nick___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com