Re: [Factor-talk] Newbie question on customizing gadgets

2010-01-22 Thread Matt Gushee
Hello--

On Fri, 22 Jan 2010 02:33 +1300, Slava Pestov sl...@factorcode.org
wrote:

  First post, sort of (I made an attempt to learn Factor early last year,
  and didn't get very far, but now I'm trying again--maybe this time I'll
  reach escape velocity).
 
 Sorry for the late reply, I've been stuck doing VM hacking :-)

No need to apologize for improving the project. Now if you had been,
say,
drinking beer with your friends, *that* would require an apology :-)

Haven't had time to get back to this yet, but I appreciate your
suggestions
and Jon's, and I'll give them a try.

-- 
Matt Gushee
m...@gushee.net

--
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Newbie question on customizing gadgets

2010-01-21 Thread Slava Pestov
On Sun, Jan 17, 2010 at 11:41 AM, Matt Gushee m...@gushee.net wrote:
 Hello, folks--

 First post, sort of (I made an attempt to learn Factor early last year,
 and didn't get very far, but now I'm trying again--maybe this time I'll
 reach escape velocity).

Sorry for the late reply, I've been stuck doing VM hacking :-)

 As a learning exercise (and maybe an excuse to have a game on my laptop,
 which thus far has been free of such distractions ;-) I am trying to
 implement the classic Minesweeper game. So, for each cell in the grid, I
 need a gadget with the following characteristics:

  * At least 2 visual states, clicked and un-clicked, typically shown
  with a raised or flat appearance

  * Left-click and right-click event handlers

  * The ability to display an icon or a character, and to change the icon
  at runtime

 It doesn't appear that there is any existing gadget that has all these
 characteristics, and I'm not sure what would be the best one to
 customize,

In this case I'd suggest making your own gadget from scratch. Have it
respond to button-down or button-up gestures, and use the hand-loc
variable to get the mouse location. Render the board in a method on
the draw-gadget* generic word. The extra/tetris demo provides a good
example of how to do basic UI tasks such as these. Bear in mind that
it was one of the first demos we had, and some of the code in there
could be written better with newer Factor idioms.

 but in other GUI toolkits I've worked with, button widgets
 work pretty well for this kind of thing, so I thought I would start by
 taking the border-button gadget and giving it a raised appearance. I
 created 3 TIFF images the same sizes as those used by the plain tile pen
 of the button pen of the border-button gadget. Then I created a new
 tile-pen using those images and new BG and FG colors, and assigned them
 to the plain slot of the button-pen.

Factor's button, slider and labelled gadgets -- all the ones that use
.tiff images to render borders, etc -- are not really skinnable like
that. They're not designed to be used with any images other than the
default theme. However, note that you can reuse button gadgets, with
your own button-pen.

Slava

--
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Newbie question on customizing gadgets

2010-01-20 Thread Jon Harper
Ok, I think I found a way to do what you want. I don't think you
really need tile-pens. Here's the pen I used :
: my-pen ( -- pen )
vocab:demineur/flat.tiff vocab:demineur/pressed.tiff
[ image-name image-pen ] bi@
dupd dup dup button-pen ;

Then I created a button with it :
: my-button ( -- button )
Click it [ Clicked.. replace-text ] button my-pen interior ;

The problem with this is with the text's transparency. The default
implementation sets it to
M: gadget gadget-background dup interior pen-background ;
and for the image-pen that we use, it defaults to :
M: object pen-background 2drop f ;
which means no transparency

So you have to change this method either for the pen or the button; I
did it for the button :
TUPLE: my-button  button ;
M: my-button gadget-background drop transparent ;

and my-button becomes
: my-button ( -- button )
Click it [ Clicked.. replace-text ] \ my-button new-button my-pen
interior ;

Hope this helps :)

Jon Harper



On Wed, Jan 20, 2010 at 3:01 AM, Matt Gushee m...@gushee.net wrote:
 Hi, Jon--

 On Tue, 19 Jan 2010 18:22 +0100, Jon Harper jon.harpe...@gmail.com
 wrote:

 Hi,
 did you get any help with your problem ? Here's what I could come up with..


 You're the first respondent ... thanks for the tips! I'd still like to hear
 something
 about the graphics.

 PS: Does nobody watch this list on weekends? If so, too bad for me, since
 that's
 about the only time I can experiment with Factor.

 --
 Matt Gushee
 m...@gushee.net

 --
 Throughout its 18-year history, RSA Conference consistently attracts the
 world's best and brightest in the field, creating opportunities for
 Conference
 attendees to learn about information security's most important issues
 through
 interactions with peers, luminaries and emerging and established companies.
 http://p.sf.net/sfu/rsaconf-dev2dev
 ___
 Factor-talk mailing list
 Factor-talk@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/factor-talk



--
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Newbie question on customizing gadgets

2010-01-19 Thread Jon Harper
Hi,
did you get any help with your problem ? Here's what I could come up with..

On Sat, Jan 16, 2010 at 11:41 PM, Matt Gushee m...@gushee.net wrote:

 Hello, folks--

 First post, sort of (I made an attempt to learn Factor early last year,
 and didn't get very far, but now I'm trying again--maybe this time I'll
 reach escape velocity).

 As a learning exercise (and maybe an excuse to have a game on my laptop,
 which thus far has been free of such distractions ;-) I am trying to
 implement the classic Minesweeper game. So, for each cell in the grid, I
 need a gadget with the following characteristics:

  * At least 2 visual states, clicked and un-clicked, typically shown
  with a raised or flat appearance


  * Left-click and right-click event handlers

buttons handle all clicks the same way : (from button.factor)
button H{
{ T{ button-up } [ button-clicked ] }
{ T{ button-down } [ button-update ] }
{ mouse-leave [ button-leave ] }
{ mouse-enter [ button-enter ] }
} set-gestures
T{ button-down } handles any click (it's like T{ button-down f f f } ).
Left clicks are T{ button-down f f 1 } and right clicks T{ button-down f f 3
}.
I'm not sure on how to go from there;  Maybe subclass button and copy/paste
it's gestures and add a line that handles the right click...?


  * The ability to display an icon or a character, and to change the icon
  at runtime

you can change a button's text with the following word
: replace-text ( button text -- )
 [ drop children pop drop ]
 [ label add-gadget drop ] 2bi ;
I'm not sure if buttons are always supposed to have 1 child or not though..

It doesn't appear that there is any existing gadget that has all these
 characteristics, and I'm not sure what would be the best one to
 customize, but in other GUI toolkits I've worked with, button widgets
 work pretty well for this kind of thing, so I thought I would start by
 taking the border-button gadget and giving it a raised appearance. I
 created 3 TIFF images the same sizes as those used by the plain tile pen
 of the button pen of the border-button gadget. Then I created a new
 tile-pen using those images and new BG and FG colors, and assigned them
 to the plain slot of the button-pen.

 The result does indeed look different from the default, but it also
 looks different from what I expected, and quite ugly. I thought I would
 keep looking through the docs for an answer, but I'm just getting lost.
 I can post my code if people want to see it, but I think the real
 problem is not really a programming error, but rather that I don't
 understand how the various images and colors are used in constructing
 the button.

 So can someone explain how border-buttons are rendered (noting that,
 while I am reasonably familiar with 2D graphics terminology, I do *not*
 understand OpenGL [I've tried to learn it, failed, maybe try again
 someday, but not today, please])? Or perhaps provide a working example
 of gadget customization?

 Thanks for any  all info!

 --
 Matt Gushee
 m...@gushee.net


 --
 Throughout its 18-year history, RSA Conference consistently attracts the
 world's best and brightest in the field, creating opportunities for
 Conference
 attendees to learn about information security's most important issues
 through
 interactions with peers, luminaries and emerging and established companies.
 http://p.sf.net/sfu/rsaconf-dev2dev
 ___
 Factor-talk mailing list
 Factor-talk@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/factor-talk

--
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Newbie question on customizing gadgets

2010-01-19 Thread Matt Gushee
Hi, Jon--

On Tue, 19 Jan 2010 18:22 +0100, Jon Harper
jon.harpe...@gmail.com wrote:

  Hi,
  did you get any help with your problem ? Here's what I could
  come up with..


You're the first respondent ... thanks for the tips! I'd still
like to hear something
about the graphics.

PS: Does nobody watch this list on weekends? If so, too bad for
me, since that's
about the only time I can experiment with Factor.
--
Matt Gushee
m...@gushee.net
--
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] Newbie question on customizing gadgets

2010-01-16 Thread Matt Gushee
Hello, folks--

First post, sort of (I made an attempt to learn Factor early last year,
and didn't get very far, but now I'm trying again--maybe this time I'll
reach escape velocity).

As a learning exercise (and maybe an excuse to have a game on my laptop,
which thus far has been free of such distractions ;-) I am trying to
implement the classic Minesweeper game. So, for each cell in the grid, I
need a gadget with the following characteristics:

 * At least 2 visual states, clicked and un-clicked, typically shown
 with a raised or flat appearance

 * Left-click and right-click event handlers

 * The ability to display an icon or a character, and to change the icon
 at runtime

It doesn't appear that there is any existing gadget that has all these
characteristics, and I'm not sure what would be the best one to
customize, but in other GUI toolkits I've worked with, button widgets
work pretty well for this kind of thing, so I thought I would start by
taking the border-button gadget and giving it a raised appearance. I
created 3 TIFF images the same sizes as those used by the plain tile pen
of the button pen of the border-button gadget. Then I created a new
tile-pen using those images and new BG and FG colors, and assigned them
to the plain slot of the button-pen.

The result does indeed look different from the default, but it also
looks different from what I expected, and quite ugly. I thought I would
keep looking through the docs for an answer, but I'm just getting lost.
I can post my code if people want to see it, but I think the real
problem is not really a programming error, but rather that I don't
understand how the various images and colors are used in constructing
the button.

So can someone explain how border-buttons are rendered (noting that,
while I am reasonably familiar with 2D graphics terminology, I do *not*
understand OpenGL [I've tried to learn it, failed, maybe try again
someday, but not today, please])? Or perhaps provide a working example
of gadget customization?

Thanks for any  all info!

-- 
Matt Gushee
m...@gushee.net

--
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk