|
Pages: [1]
|
 |
|
Author
|
Topic: How to set time interval for insert-event-func ? (Read 948 times)
|
|
PopMilo
|
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
|
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.8Cheers, Brian
|
|
|
|
|
Logged
|
|
|
|
|
PopMilo
|
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...  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
|
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
Posts: 69
|
Thanks for the update!
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |