Firefox problem with custom image buttons

52 views
Skip to first unread message

Elias

unread,
Dec 16, 2009, 7:30:35 AM12/16/09
to Cappuccino & Objective-J
Hi,

I create buttons with custom images like this

var myButton = [[CPButton alloc] initWithFrame:CGRectMake(10, 10, 20,
20)];
[myButton setPosition:CGPointMake(10, 10)];
[self addSubview: myButton];

[myButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle
mainBundle] pathForResource:@"myButton_normal.png"]]];
[self setAlternateImage:[[CPImage alloc] initWithContentsOfFile:
[[CPBundle mainBundle] pathForResource:@"myButton_active.png"]]];
[self setImagePosition:CGPointMake(0, 0)];
[self setBordered:NO];

Now I got the problem that the custom image isn't shown in Firefox
until I click on the button. After that the active image is shown and
when I release the mouse button the normal image is shown also.

This problem only appears in Firefox. No problem in Safari or Chrome.

Elias

unread,
Dec 30, 2009, 6:45:14 PM12/30/09
to Cappuccino & Objective-J
Am I the only one with this problem?

> This problem only appears inFirefox. No problem in Safari or Chrome.

Ross Boucher

unread,
Dec 30, 2009, 7:05:50 PM12/30/09
to objec...@googlegroups.com
The first problem I notice is that there's no method called
setPosition: You should try taking that out.
-Ross

> --
>
> You received this message because you are subscribed to the Google
> Groups "Cappuccino & Objective-J" group.
> To post to this group, send email to objec...@googlegroups.com.
> To unsubscribe from this group, send email to objectivej+...@googlegroups.com
> .
> For more options, visit this group at http://groups.google.com/group/objectivej?hl=en
> .
>
>

samdev

unread,
Dec 30, 2009, 7:10:07 PM12/30/09
to objec...@googlegroups.com
In my case (Safari 4.2, jake branch, OS X 10.6.2) image is positioned wrongly unless I click the button. At first, it is 50% shifted down.

Elias

unread,
Dec 31, 2009, 4:09:29 AM12/31/09
to Cappuccino & Objective-J
@Ross Yeah I forgot that because I made a subclass for the custom
buttons. But I forgot to delete it when I edited this example code. So
in my case, there IS this method ;)

So the code should be like this:

var myButton = [[CPButton alloc] initWithFrame:CGRectMake(10, 10, 20,
20)];

[myButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle
mainBundle] pathForResource:@"myButton_normal.png"]]];

[myButton setAlternateImage:[[CPImage alloc] initWithContentsOfFile:


[[CPBundle mainBundle] pathForResource:@"myButton_active.png"]]];

[myButton setImagePosition:CGPointMake(0, 0)];
[myButton setBordered:NO];
[contentView addSubview: myButton];

Elias

unread,
Dec 31, 2009, 4:26:40 AM12/31/09
to Cappuccino & Objective-J
I also made a short video which shows how it looks like.
Keep in mind this is only in Firefox. Safari and Chrome just work
fine.

http://thisagree.com/files/custom_button_fail.mov

Elias

Elias

unread,
Jan 3, 2010, 3:40:19 PM1/3/10
to Cappuccino & Objective-J
Allright now I made a custom button subclass which now also works in
Firefox seamless.

https://gist.github.com/cbc2179ec48d6c041c42

But I have a question here. The normal button behaviour is that when
you click on it and drag the mouse away from the button not performing
a mouseUp the button should be in an initial state.
At my solution the button is beeing pressed although the mouse is
outside of the button rect.

I took a look into the CPControl.j and there is something I thought it
would help.

[self trackMouse:anEvent];

But that didn't change the problem.


Du you have any idea about it?

Ross Boucher

unread,
Jan 3, 2010, 3:59:15 PM1/3/10
to objec...@googlegroups.com
You definitely don't want to create a subclass here. For one, you are redoing work, and some of it potentially slightly broken ways (like the problem you are describing here).

Going back to your original code, here's another problem line:

> [myButton setImagePosition:CGPointMake(0, 0)];

setImagePosition doesn't take a point, it takes a constant. One of the following:

CPNoImage;
CPImageOnly;
CPImageLeft;
CPImageRight;
CPImageBelow;
CPImageAbove;
CPImageOverlaps;

You should try updating your original code and see if that works for you.

-Ross

Elias

unread,
Jan 3, 2010, 4:18:46 PM1/3/10
to Cappuccino & Objective-J
Thanks for that Ross! I figured out that [myButton
setImagePosition:CPImageOverlaps] sets the correct position of the
image on the button.
But it again fails in Firefox... :( I really don't know what to do
here..

Joel Norvell

unread,
Jan 3, 2010, 8:19:21 PM1/3/10
to Cappuccino & Objective-J
Elias,

I posted a ticket yesterday (01-02-2010) on the button state problem
you described in this thread.

http://github.com/280north/cappuccino/issues#issue/392

CPButton state toggles when it should not

The test case referenced in my ticket is:

http://dl.dropbox.com/u/2248/ToggleButtonTest.zip

Sincerely,
Joel

Elias

unread,
Jan 4, 2010, 4:21:05 AM1/4/10
to Cappuccino & Objective-J
@Joel I don't think that it's the same problem here. My problem is
that the CPButton's setImage: method may be partially broken in
Firefox.

Joel Norvell

unread,
Jan 4, 2010, 2:30:14 PM1/4/10
to Cappuccino & Objective-J
Dear Elias,

> But I have a question here. The normal button behaviour is that
> when you click on it and drag the mouse away from the button
> not performing a mouseUp the button should be in an initial state.
> At my solution the button is beeing pressed although the mouse is
> outside of the button rect.

I thought you were talking about the problem I'd reported, that
CPButton state toggles when it should not.

Sorry if I misinterpreted your comment!

Sincerely,
Joel

Ross Boucher

unread,
Jan 7, 2010, 7:11:02 PM1/7/10
to objec...@googlegroups.com
Elias (and anyone else experiencing this problem),

Can you send me your code? I'm not sure I am able to reproduce the problem myself, and I want to make sure we track this down.

-Ross

Elias

unread,
Jan 8, 2010, 7:17:35 AM1/8/10
to Cappuccino & Objective-J

Ross Boucher

unread,
Jan 8, 2010, 12:38:13 PM1/8/10
to objec...@googlegroups.com
This is now fixed in the jake branch.

Elias

unread,
Jan 8, 2010, 2:31:31 PM1/8/10
to Cappuccino & Objective-J
Cool thanks! Will it be also merged in the next Atlas version?

Qiushi (Billy) He

unread,
Jan 14, 2010, 6:36:59 PM1/14/10
to Cappuccino & Objective-J
Hi Ross,

If possible please post a patch or describe how the problem was fixed.
I'm working on a project and I can't exactly wait indefinitely for the
next release.

Also, where is the "jake" branch? Do you mind post the URL to that
github project please?

Without Wax
Billy

> >>>>> But it again fails inFirefox... :( I really don't know what to do

> >>>>>>>> Keep in mind this is only inFirefox. Safari and Chrome just work

Randy Luecke

unread,
Jan 14, 2010, 7:09:53 PM1/14/10
to Cappuccino & Objective-J
Reply all
Reply to author
Forward
0 new messages