|
3 | 3 | license:CC0-1.0
|
4 | 4 | -->
|
5 | 5 | <mamelayout version="2">
|
| 6 | + <element name="card" /> |
| 7 | + |
6 | 8 | <element name="pencursor">
|
7 | 9 | <image state="1">
|
8 | 10 | <data><![CDATA[
|
@@ -51,77 +53,140 @@ license:CC0-1.0
|
51 | 53 | </element>
|
52 | 54 | </view>
|
53 | 55 |
|
| 56 | + <view name="Storyware and Card View"> |
| 57 | + <screen index="0"> |
| 58 | + <bounds x="0" y="0" width="4" height="3" /> |
| 59 | + </screen> |
| 60 | + |
| 61 | + <element id="leftpage" ref="leftpage"> |
| 62 | + <bounds x="0" y="3.1" width="2" height="2.8" /> |
| 63 | + </element> |
| 64 | + <element id="rightpage" ref="rightpage"> |
| 65 | + <bounds x="2" y="3.1" width="2" height="2.8" /> |
| 66 | + </element> |
| 67 | + |
| 68 | + <element id="pencursor" ref="pencursor"> |
| 69 | + <!-- will be positioned by script --> |
| 70 | + <bounds x="0" y="3.1" width="0.2" height="0.2" /> |
| 71 | + <color alpha="0.7" /> |
| 72 | + </element> |
| 73 | + |
| 74 | + <element ref="card"> |
| 75 | + <bounds x="0" y="6" width="4" height="2.65" /> |
| 76 | + </element> |
| 77 | + </view> |
| 78 | + |
54 | 79 | <script><![CDATA[
|
55 |
| - file:set_resolve_tags_callback( |
56 |
| - function () |
57 |
| - -- get memory regions for page scans |
58 |
| - local pages = { } |
59 |
| - for i = 1, 12 do |
60 |
| - local page = file.device:memregion(string.format('cartslot:page%u', i)) |
61 |
| - if page ~= nil then |
62 |
| - pages[i] = page |
63 |
| - else |
64 |
| - break |
65 |
| - end |
66 |
| - end |
| 80 | + local function init_storyware(view) |
| 81 | + -- get memory regions for page scans |
| 82 | + local pages = { } |
| 83 | + for i = 1, 12 do |
| 84 | + local page = file.device:memregion(string.format('cartslot:page%u', i)) |
| 85 | + if page ~= nil then |
| 86 | + pages[i] = page |
| 87 | + else |
| 88 | + break |
| 89 | + end |
| 90 | + end |
| 91 | +
|
| 92 | + -- left/right page items are needed on-the-fly |
| 93 | + local leftpage = file.views[view].items['leftpage'] |
| 94 | + local rightpage = file.views[view].items['rightpage'] |
| 95 | +
|
| 96 | + -- recompute target pen cursor size and area when necessary |
| 97 | + local curxoffs, curyoffs, curxscale, curyscale, curwidth, curheight |
| 98 | + file.views[view]:set_recomputed_callback( |
| 99 | + function () |
| 100 | + local lbounds = leftpage.bounds |
| 101 | + local rbounds = rightpage.bounds |
| 102 | + curwidth = lbounds.width / 10 |
| 103 | + curheight = lbounds.height / 14 |
| 104 | + curxoffs = lbounds.x0 - (curwidth * 0.5) |
| 105 | + curyoffs = lbounds.y0 - (curheight * 0.5) |
| 106 | + curxscale = (rbounds.x1 - lbounds.x0) / 255 |
| 107 | + curyscale = lbounds.height / 255 |
| 108 | + end) |
| 109 | +
|
| 110 | + -- make page display respond to page selection input |
| 111 | + local pagectrl = file.device:ioport('PAGE') |
| 112 | + local function get_page() return pagectrl:read() end |
| 113 | + leftpage:set_element_state_callback(get_page) |
| 114 | + rightpage:set_element_state_callback(get_page) |
67 | 115 |
|
68 |
| - -- left/right page items are needed on-the-fly |
69 |
| - local leftpage = file.views['Default View'].items['leftpage'] |
70 |
| - local rightpage = file.views['Default View'].items['rightpage'] |
71 |
| -
|
72 |
| - -- recompute target pen cursor size and area when necessary |
73 |
| - local curxoffs, curyoffs, curxscale, curyscale, curwidth, curheight |
74 |
| - file.views['Default View']:set_recomputed_callback( |
75 |
| - function () |
76 |
| - local lbounds = leftpage.bounds |
77 |
| - local rbounds = rightpage.bounds |
78 |
| - curwidth = lbounds.width / 10 |
79 |
| - curheight = lbounds.height / 14 |
80 |
| - curxoffs = lbounds.x0 - (curwidth * 0.5) |
81 |
| - curyoffs = lbounds.y0 - (curheight * 0.5) |
82 |
| - curxscale = (rbounds.x1 - lbounds.x0) / 255 |
83 |
| - curyscale = lbounds.height / 255 |
84 |
| - end) |
85 |
| -
|
86 |
| - -- make page display respond to page selection input |
87 |
| - local pagectrl = file.device:ioport('PAGE') |
88 |
| - local function get_page() return pagectrl:read() end |
89 |
| - leftpage:set_element_state_callback(get_page) |
90 |
| - rightpage:set_element_state_callback(get_page) |
91 |
| -
|
92 |
| - -- render even pages on the left, odd pages on the right |
93 |
| - local function draw_page(n, dest) |
94 |
| - local page = pages[n] |
95 |
| - if page ~= nil then |
| 116 | + -- render even pages on the left, odd pages on the right |
| 117 | + local function draw_page(n, dest) |
| 118 | + local page = pages[n] |
| 119 | + if page ~= nil then |
| 120 | + -- TODO: reduce temporary memory usage when I/O classes are exposed to Lua |
| 121 | + local data = page:read(0, page.size) |
| 122 | + local image = emu.bitmap_argb32.load(data) |
| 123 | + image:resample(dest) |
| 124 | + end |
| 125 | + end |
| 126 | + file.elements['leftpage']:set_draw_callback( |
| 127 | + function (state, bitmap) |
| 128 | + draw_page(state * 2, bitmap) |
| 129 | + end) |
| 130 | + file.elements['rightpage']:set_draw_callback( |
| 131 | + function (state, bitmap) |
| 132 | + draw_page((state * 2) + 1, bitmap) |
| 133 | + end) |
| 134 | +
|
| 135 | + -- animate the position of the pen cursor |
| 136 | + local penctrl = file.device:ioport('PEN_LEFT') |
| 137 | + local penx = file.device:ioport('PENX') |
| 138 | + local peny = file.device:ioport('PENY') |
| 139 | + file.views[view].items['pencursor']:set_element_state_callback( |
| 140 | + function () |
| 141 | + return (penctrl:read() & 2) >> 1 |
| 142 | + end) |
| 143 | + file.views[view].items['pencursor']:set_bounds_callback( |
| 144 | + function () |
| 145 | + local x = curxoffs + (penx:read() * curxscale) |
| 146 | + local y = curyoffs + (peny:read() * curyscale) |
| 147 | + return emu.render_bounds(x, y, x + curwidth, y + curheight) |
| 148 | + end) |
| 149 | + end |
| 150 | +
|
| 151 | + local sub -- keep this here to avoid it being garbage collected prematurely |
| 152 | +
|
| 153 | + local function init_card() |
| 154 | + -- get card slot device and card display element |
| 155 | + local card_device = emu.image_enumerator(file.device)['card'] |
| 156 | + local card_element = file.elements['card'] |
| 157 | +
|
| 158 | + -- invalidate the card display on media change |
| 159 | + local card_data = card_device.device:memregion('card') |
| 160 | + sub = card_device:add_media_change_notifier( |
| 161 | + function (event) |
| 162 | + card_data = card_device.device:memregion('card') |
| 163 | + card_element:invalidate() |
| 164 | + end) |
| 165 | +
|
| 166 | + -- draw the card image |
| 167 | + card_element:set_draw_callback( |
| 168 | + function (state, bitmap) |
| 169 | + if card_data ~= nil then |
96 | 170 | -- TODO: reduce temporary memory usage when I/O classes are exposed to Lua
|
97 |
| - local data = page:read(0, page.size) |
| 171 | + local data = card_data:read(0, card_data.size) |
98 | 172 | local image = emu.bitmap_argb32.load(data)
|
99 |
| - image:resample(dest) |
| 173 | + image:resample(bitmap) |
100 | 174 | end
|
| 175 | + end) |
| 176 | + end |
| 177 | +
|
| 178 | + file:set_resolve_tags_callback( |
| 179 | + function () |
| 180 | + local barcode_device = emu.device_enumerator(file.device, 3)[':card:rd'] |
| 181 | + if barcode_device == nil then |
| 182 | + barcode_device = emu.device_enumerator(file.device, 3)[':card:rd2061'] |
| 183 | + end |
| 184 | + if barcode_device == nil then |
| 185 | + init_storyware('Default View') |
| 186 | + else |
| 187 | + init_storyware('Storyware and Card View') |
| 188 | + init_card() |
101 | 189 | end
|
102 |
| - file.elements['leftpage']:set_draw_callback( |
103 |
| - function (state, bitmap) |
104 |
| - draw_page(state * 2, bitmap) |
105 |
| - end) |
106 |
| - file.elements['rightpage']:set_draw_callback( |
107 |
| - function (state, bitmap) |
108 |
| - draw_page((state * 2) + 1, bitmap) |
109 |
| - end) |
110 |
| -
|
111 |
| - -- animate the position of the pen cursor |
112 |
| - local penctrl = file.device:ioport('PEN_LEFT') |
113 |
| - local penx = file.device:ioport('PENX') |
114 |
| - local peny = file.device:ioport('PENY') |
115 |
| - file.views['Default View'].items['pencursor']:set_element_state_callback( |
116 |
| - function () |
117 |
| - return (penctrl:read() & 2) >> 1 |
118 |
| - end) |
119 |
| - file.views['Default View'].items['pencursor']:set_bounds_callback( |
120 |
| - function () |
121 |
| - local x = curxoffs + (penx:read() * curxscale) |
122 |
| - local y = curyoffs + (peny:read() * curyscale) |
123 |
| - return emu.render_bounds(x, y, x + curwidth, y + curheight) |
124 |
| - end) |
125 | 190 | end)
|
126 | 191 | ]]></script>
|
127 | 192 | </mamelayout>
|
0 commit comments