Rebol Talk Forum  |  Getting Started  |  Code Examples, Tips & Advice  |  Topic: How to set time interval for insert-event-func ?
Pages: [1] Print
Author Topic: How to set time interval for insert-event-func ?  (Read 948 times)
PopMilo
Newbie
*
Offline Offline

Posts: 6


View Profile
How to set time interval for insert-event-func ?
« on: October 02, 2007, 08:08:45 AM »

Here is a begining of a small graphic editor...

I have trouble timing events. How can I time event processing so that my routine gets called two times a second or something like that.
Now it is to fast. I would like to slow it down.

Source:
----------

rebol [Title: "Editor..."]

paleta: [   0.0.0         255.255.255   104.55.43      112.164.178   111.61.134   88.141.67      53.40.121      184.199.111
            111.79.37   67.57.0         154.103.89   68.68.68      108.108.108   154.210.132   108.94.181   149.149.149 ]

pixel_size: 20x20
grid_size: 24x21
panel-width: 100
panel_size: as-pair panel-width ((grid_size/y + 2) * pixel_size/y)
window_size: as-pair (((grid_size/x + 2) * pixel_size/x) + panel_size/x) panel_size/y
screen_size: system/view/screen-face/size

cursor_x: 10
cursor_y: 10
cursor_color: 1

pixel_face: make face [
    size: pixel_size
    edge: none
   color: black
    data: 0
]

sprite-colors: copy []

repeat y grid_size/y [
   line: copy []
   repeat x grid_size/x [
      append line reduce [:y + x // 16]
   ]
   append sprite-colors reduce [:line]
]

pane-func: func [face index] [
    index: (index - 1)
    either integer? index [
        if index < ((grid_size/x) * (grid_size/y)) [
           xx: (index // (grid_size/x)) + 1
           yy: to-integer ((index / (grid_size/x)) + 1)
            pixel_face/data: index
            pixel_face/offset/y: ((yy - 1) * (pixel_size/y))
            pixel_face/offset/x: ((xx - 1) * (pixel_size/x))
            pixel_face/color: pick paleta sprite-colors/:yy/:xx
            return pixel_face
        ]
    ][
 ;       return to-integer index/y / 20 + 1
    ]
]

key-event: func [face event] [
    if event/type = 'key [
               switch event/key [
                        up [cursor_y: cursor_y - 1]
                   down [cursor_y: cursor_y + 1]
                        left [cursor_x: cursor_x - 1]
                        right [cursor_x: cursor_x + 1]
                       ]
                sprite-colors/:cursor_y/:cursor_x: 2
               show grid
            ]
    if event/type = 'time [
       cursor_color: (3 - cursor_color)
         sprite-colors/:cursor_y/:cursor_x: :cursor_color
        show grid
   ]
    event
]
 
insert-event-func :key-event

grid: make face [
    offset: ((screen_size - window_size) / 2)
    size: window_size
    color: blue
    effect: [gradient] rate: 1
    pane: :pane-func
]

view/new grid
do-events
Logged
btiffin
Jr. Member
**
Offline Offline

Posts: 54


View Profile
Re: How to set time interval for insert-event-func ?
« Reply #1 on: October 03, 2007, 02:10:56 AM »

Hi,

   faces have a rate element.  rate: 2  will set to fire a timer twice a second.

rate: integer!  sets it to attempt to fire that many times a second
rate: time!  sets it to fire every elapsed time.  rate: 00:00:05  every 5 seconds.

Experiment with adding  rate:  to your grid face.
Check out more deets at http://rebol.com/docs/view-system.html#section-5.8

Cheers,
Brian
Logged
PopMilo
Newbie
*
Offline Offline

Posts: 6


View Profile
Re: How to set time interval for insert-event-func ?
« Reply #2 on: October 03, 2007, 04:07:08 AM »

Thank you for your answer!

I red documentation and it doesn't help... I already tried to put rate value in every piece of display that I have and it doesnt help... Sad

Rate works if I dont use insert-event-func...
And I need it to get keyboard respons from my iterated pane...

What can I do?
Logged
btiffin
Jr. Member
**
Offline Offline

Posts: 54


View Profile
Re: How to set time interval for insert-event-func ?
« Reply #3 on: October 03, 2007, 04:21:04 PM »

I'm just adding this post for completeness.

Solution was worked out on Altme.

The solution was to keep the key event handler in insert-event-func and along with the rate, move the timer to the engage feel function.  Not great, but functional.

Cheers everyone,
Brian
Logged
DefiantPc
Administrator
Jr. Member
*
Offline Offline

Posts: 69


View Profile
Re: How to set time interval for insert-event-func ?
« Reply #4 on: October 04, 2007, 07:16:39 AM »

Thanks for the update!
Logged
Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Code Examples, Tips & Advice  |  Topic: How to set time interval for insert-event-func ?
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 20, 2008, 04:34:27 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2190 Posts in 579 Topics by 1632 Members
Latest Member: Apodeptackked

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc