Professional Web Applications Themes

Making custom widgets? - Mac Programming

Me again with another I-know-next-to-nothing-about-mac-programming question. Suppose I want to make a GUI with a custom widget. (In this case I want to make an on-screen piano keyboard that generates some sort of keypress event for each click on a key where the event says what key is pressed.) I played around with Inteface Builder a bit but couldn't find any facilities for just drawing freeform shapes. What's the right way to approach this? -Peter -- Peter Seibel com Lisp is the red pill. -- John Fraser, comp.lang.lisp...

  1. #1

    Default Making custom widgets?

    Me again with another I-know-next-to-nothing-about-mac-programming
    question. Suppose I want to make a GUI with a custom widget. (In this
    case I want to make an on-screen piano keyboard that generates some
    sort of keypress event for each click on a key where the event says
    what key is pressed.) I played around with Inteface Builder a bit but
    couldn't find any facilities for just drawing freeform shapes. What's
    the right way to approach this?

    -Peter

    --
    Peter Seibel com

    Lisp is the red pill. -- John Fraser, comp.lang.lisp
    Peter Guest

  2. #2

    Default Re: Making custom widgets?

    Peter Seibel wrote: 

    there's no way interface builder could let you do something like that.
    you'd have to write it in code.

    the cocoa approach would be to create a subclass of nsview or nscontrol
    and start writing code to draw on it. i don't know enough about carbon
    to say how you'd even start over there.
    Jhnny Guest

  3. #3

    Default Re: Making custom widgets?

    In article <nashville.comcast.net>,
    Jhnny Fvrt (it means "halo, then resonate") <com> wrote:
     

    The Carbon approach is to subclass HIView and start writing code to draw on it
    :-)

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  4. #4

    Default Re: Making custom widgets?

    Jhnny Fvrt (it means "halo, then resonate") <com> writes:
     
    >
    > there's no way interface builder could let you do something like that.
    > you'd have to write it in code.
    >
    > the cocoa approach would be to create a subclass of nsview or nscontrol
    > and start writing code to draw on it. i don't know enough about carbon
    > to say how you'd even start over there.[/ref]

    And do I use NSActionCells to make parts of the view capable of
    responding to mouse clicks or do I just capture the clicks at the
    NSView level and then figure out where in the view the click was and
    thus what key of my drawn piano it was in?

    -Peter

    --
    Peter Seibel com

    Lisp is the red pill. -- John Fraser, comp.lang.lisp
    Peter Guest

  5. #5

    Default Re: Making custom widgets?

    In article <nashville.comcast.net>,
    Jhnny Fvrt (it means "halo, then resonate") <com>
    wrote:
     
    >
    > there's no way interface builder could let you do something like that.
    > you'd have to write it in code.[/ref]

    Perhaps you just don't know how to use IB. It took me 10 seconds to
    mock up a piano keyboard using square buttons (you could stick the white
    keys in a big matrix) and then putting smaller buttons on top of and
    between them. If you actually need them to appear black and white, you
    could make the actual buttons transparent and simply draw the visuals
    underneath.
    Doc Guest

  6. #6

    Default Re: Making custom widgets?

    Miro Jurisic wrote: 

    how do you "subclass" in carbon? isn't it a C api?
    Jhnny Guest

  7. Moderated Post

    Default Re: Making custom widgets?

    Removed by Administrator
    Jhnny Guest
    Moderated Post

  8. #8

    Default Re: Making custom widgets?

    In article <com>,
    Peter Seibel <com> wrote:
     

    You could subclass NSControl if you wanted. Or you could just use your
    NSView to respond to click events, and use the coordinates to figure out
    which key is pressed and animate that event.

    --
    |\/| /| |2 |<
    mehaase(at)sas(dot)upenn(dot)edu
    Mark Guest

  9. #9

    Default Re: Making custom widgets?

    In article <nashville.comcast.net>,
    Jhnny Fvrt (it means "halo, then resonate") <com> wrote:
     
    >
    > how do you "subclass" in carbon? isn't it a C api?[/ref]

    Using HIObjectRegisterSubclass. Yes, it is a C API, but that's irrelevant -- C
    is a Turing complete language, just as Obj-C is. Anything you can do in one, you
    can do in the other. In this case, Carbon events are used as a message passing
    algorithm, and Carbon event handler hierarchy is used for inheritance.

    meeroh

    --
    If this message helped you, consider buying an item
    from my wish list: <http://web.meeroh.org/wishlist>

    Miro Guest

  10. #10

    Default Re: Making custom widgets?

    Doc O'Leary <com> writes:
     
    > >
    > > there's no way interface builder could let you do something like that.
    > > you'd have to write it in code.[/ref]
    >
    > Perhaps you just don't know how to use IB.[/ref]

    That's almost certainly true.
     

    So just to make sure I understand, any actual drawing would have to be
    done in code, right? I.e. there's no way to use IB to draw arbitrary
    stuff in my interface.

    -Peter

    --
    Peter Seibel com

    Lisp is the red pill. -- John Fraser, comp.lang.lisp
    Peter Guest

  11. #11

    Default Re: Making custom widgets?

    In article <com>,
    Peter Seibel <com> wrote:
     

    That depends. If you want to do it in a very simple way, you could
    probably draw an image of each kind of key (with Photoshop, or Sketch,
    or whatever), use a borderless NSButton to draw each one, arrange them
    together and set their actions to call methods that actually play the
    sound you want them to.

    But IMHO the cleaner approach would be to write your own NSView
    subclass that draws the entire piano, does hit-testing and then calls an
    appropriate action method. That way, if you needed a similar keyboard
    somewhere else in your application, you could use that view again
    without copying oodles of buttons around. Not to mention that,
    technically, having lots of views in a window will slow things down.

    HTH,
    -- Uli
    http://www.zathras.de
    Uli Guest

  12. Moderated Post

    Default Re: Making custom widgets?

    Removed by Administrator
    Uli Guest
    Moderated Post

  13. #13

    Default Re: Making custom widgets?

    In article <com>,
    Peter Seibel <com> wrote:
     

    Yeah, IB is not designed to do that.

    --
    |\/| /| |2 |<
    mehaase(at)sas(dot)upenn(dot)edu
    Mark Guest

  14. #14

    Default Re: Making custom widgets?

    In article <com>,
    Peter Seibel <com> wrote:
     

    IB has no drawing tools, if that's what you mean. But you can do your
    drawings in an image file and then display them on an NSButton or in an
    NSImageView, and for both of these views, you can turn off the border
    and background so all that is drawn is your image, and that's done for
    you automagically.

    HTH,
    -- Uli
    http://www.zathras.de
    Uli Guest

  15. #15

    Default Re: Making custom widgets?

    Uli Kusterer wrote: 

    i haven't written enough cocoa code to know one way or the other. i'm
    from beos, and views there are almost free, and there aren't many
    alternatives even if you wanted to do something else. i tend to use
    views. so i'll take your word for this, since i don't know any better.
     

    now this i really disagree with. hit-testing *sounds* easy, and it is
    in theory, then in actual practice i always end up with these
    ridiculously complicated statements where you're subtracting the left
    edge of this thing from the right edge of that thing starting at some
    base edge and subtracting one to avoid an off-by-one error, etc. even
    when you get it right, you can't eyeball the statements and *know* it's
    right. if there's any way to let the gui system itself do the
    hit-testing, i will.
     

    personally, if i ever see a good "seam" where i can break an object up
    into smaller objects, i'll probably take that opportunity. i like nice,
    short functions and modules. they are easier to read, and easier to
    eyeball-verify as correct.
    Jhnny Guest

Similar Threads

  1. Widgets
    By Les Matthews in forum Macromedia Dreamweaver
    Replies: 2
    Last Post: July 1st, 01:40 PM
  2. Making custom Flash CS3 component bindable in flex
    By slaingod in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: April 3rd, 07:32 PM
  3. Making Custom Control Properties Visible in Visual Studio's Properties Palette
    By Nathan Sokalski in forum ASP.NET Building Controls
    Replies: 0
    Last Post: October 17th, 02:05 AM
  4. Making a custom control with TD tags show in the designer
    By groups@ygrah.com in forum ASP.NET Building Controls
    Replies: 0
    Last Post: March 16th, 04:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139