discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: One question about subclass


From: Germán André Arias Santiago
Subject: Re: One question about subclass
Date: Wed, 24 Sep 2008 19:27:03 -0700 (PDT)

I want make an app to solve some physics problems. Then my app have a panel wiht many things (ball, cannon, wall, ....) to represent the problem. When a user do click in some of this things, a NSViewImage is add into the chalckbord (a NSView's subclass). I want let the user to move these things to any position (with a drag operation). But, when I do click in one of this things (NSImageView), the NSView don't get the NSEvent, then I can't move the NSImageView with mouseDragged: method (in the NSView). Even if I add the NSImageView with addSubview: positioned: relativeTo:   with the argument NSWindowBelow. I don't know some method to delegate this event from NSImageView to NSView. I tryed with Drag & Drop, but I only can move an image from one NSImageView to another. Then I think in a subclass of NSImageView to write the mouseDragged: method. I add this subclass in something like this


- (void) addObject: (id)sender
{
  /* insert your code here */
NSImage *icono = [[NSImage alloc] initByReferencingFile: @"Resources/112.tif"] ;

NSImageView *nuevoIcono = [[MIImagen alloc] initWithFrame: NSMakeRect(20,20,90,90)] ;
[nuevoIcono setImage: icono] ;
[nuevoIcono setEditable: NO] ;
[self addSubview: nuevoIcono positioned: NSWindowBelow relativeTo: self] ;
[self setNeedsDisplay: YES] ;
RELEASE(icono) ; 
RELEASE(nuevoIcono) ; 
}
   

MIImagen is my subclass of NSImageVIew. I add the MIImagen.h file in the header of the chalckboar (NSView's subclass). If I write NSImageView instead MIImagen, the image is added.

--- El jue 25-sep-08, Markus Hitter <mah@jump-ing.de> escribió:
De: Markus Hitter <mah@jump-ing.de>
Asunto: Re: One question about subclass
A: "Germán Arias" <germanandre304@yahoo.com>
Cc: discuss-gnustep@gnu..org
Fecha: jueves, 25 septiembre, 2008, 12:12 am

Am 25.09.2008 um 00:44 schrieb Germán Arias:

> For example, I create a subclass of NSImageView, I set its methods
> and all OK.
> But when my app is running and I alloc and init my subclass I don't
> see the
> object's instance. I don't get any error. Can somebody tell me
what
> is the
> problem?

As always, code snippets are great ...

Interesting would be, why you create a subclass. Subclassing is in
Obj-C a lot less in fashion (= rarely used) than in C++, as Obj-C has
categories (extensions to a class) and GNUstep/Cocoa makes a lot of
use of this capability.

Back to your question: Where would you expect to "see" something? If

you mean like appearing on the screen, then you have to connect this
view to a window somehow. Typically as a subview of the window's
contentView. Gorm would do this connection automatically when
dragging an NSImageView from the palette into a window.


MarKus

- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/







Yahoo! MTV Blog & Rock
¡Cuéntanos tu historia, inspira una canción y gánate un viaje a los Premios MTV!
Participa aquí http://mtvla.yahoo.com/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]