src/emu/rendlay.c
| r9411 | r9412 | |
| 4 | 4 | |
| 5 | 5 | Core rendering layout parser and manager. |
| 6 | 6 | |
| 7 | | Copyright Nicola Salmoria and the MAME Team. |
| 8 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 9 | | |
| 10 | 7 | **************************************************************************** |
| 11 | 8 | |
| 12 | | Notes: |
| 9 | Copyright Aaron Giles |
| 10 | All rights reserved. |
| 13 | 11 | |
| 14 | | Unlike the old system, the artwork is not rotated with the game |
| 15 | | orientation. This is to support odd configurations like two |
| 16 | | monitors in different orientations. You can specify an orientation |
| 17 | | for a backdrop/screen/overlay/bezel element, but it only applies |
| 18 | | to the artwork itself, and does not affect coordinates in any way. |
| 12 | Redistribution and use in source and binary forms, with or without |
| 13 | modification, are permitted provided that the following conditions are |
| 14 | met: |
| 19 | 15 | |
| 16 | * Redistributions of source code must retain the above copyright |
| 17 | notice, this list of conditions and the following disclaimer. |
| 18 | * Redistributions in binary form must reproduce the above copyright |
| 19 | notice, this list of conditions and the following disclaimer in |
| 20 | the documentation and/or other materials provided with the |
| 21 | distribution. |
| 22 | * Neither the name 'MAME' nor the names of its contributors may be |
| 23 | used to endorse or promote products derived from this software |
| 24 | without specific prior written permission. |
| 20 | 25 | |
| 26 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 30 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 32 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 33 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 35 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 36 | POSSIBILITY OF SUCH DAMAGE. |
| 37 | |
| 38 | **************************************************************************** |
| 39 | |
| 21 | 40 | Overview of objects: |
| 22 | 41 | |
| 23 | 42 | layout_file -- A layout_file comprises a list of elements and a |
| r9411 | r9412 | |
| 72 | 91 | STANDARD LAYOUTS |
| 73 | 92 | ***************************************************************************/ |
| 74 | 93 | |
| 75 | | /* single screen layouts */ |
| 94 | // single screen layouts |
| 76 | 95 | #include "horizont.lh" |
| 77 | 96 | #include "vertical.lh" |
| 78 | 97 | |
| 79 | | /* dual screen layouts */ |
| 98 | // dual screen layouts |
| 80 | 99 | #include "dualhsxs.lh" |
| 81 | 100 | #include "dualhovu.lh" |
| 82 | 101 | #include "dualhuov.lh" |
| 83 | 102 | |
| 84 | | /* triple screen layouts */ |
| 103 | // triple screen layouts |
| 85 | 104 | #include "triphsxs.lh" |
| 86 | 105 | |
| 87 | | /* generic color overlay layouts */ |
| 106 | // generic color overlay layouts |
| 88 | 107 | #include "ho20ffff.lh" |
| 89 | 108 | #include "ho2eff2e.lh" |
| 90 | 109 | #include "ho4f893d.lh" |
| r9411 | r9412 | |
| 96 | 115 | |
| 97 | 116 | |
| 98 | 117 | |
| 99 | | /*************************************************************************** |
| 100 | | CONSTANTS |
| 101 | | ***************************************************************************/ |
| 118 | //************************************************************************** |
| 119 | // CONSTANTS |
| 120 | //************************************************************************** |
| 102 | 121 | |
| 103 | | #define LAYOUT_VERSION 2 |
| 122 | const int LAYOUT_VERSION = 2; |
| 104 | 123 | |
| 105 | | #define LINE_CAP_NONE 0 |
| 106 | | #define LINE_CAP_START 1 |
| 107 | | #define LINE_CAP_END 2 |
| 108 | | |
| 109 | 124 | enum |
| 110 | 125 | { |
| 111 | | COMPONENT_TYPE_IMAGE = 0, |
| 112 | | COMPONENT_TYPE_RECT, |
| 113 | | COMPONENT_TYPE_DISK, |
| 114 | | COMPONENT_TYPE_TEXT, |
| 115 | | COMPONENT_TYPE_LED7SEG, |
| 116 | | COMPONENT_TYPE_LED14SEG, |
| 117 | | COMPONENT_TYPE_LED16SEG, |
| 118 | | COMPONENT_TYPE_LED14SEGSC, |
| 119 | | COMPONENT_TYPE_LED16SEGSC, |
| 120 | | COMPONENT_TYPE_DOTMATRIX, |
| 121 | | COMPONENT_TYPE_MAX |
| 126 | LINE_CAP_NONE = 0, |
| 127 | LINE_CAP_START = 1, |
| 128 | LINE_CAP_END = 2 |
| 122 | 129 | }; |
| 123 | 130 | |
| 124 | 131 | |
| 125 | | /*************************************************************************** |
| 126 | | TYPE DEFINITIONS |
| 127 | | ***************************************************************************/ |
| 128 | 132 | |
| 129 | | /* an element_component represents an image, rectangle, or disk in an element */ |
| 130 | | struct _element_component |
| 131 | | { |
| 132 | | element_component * next; /* link to next component */ |
| 133 | | int type; /* type of component */ |
| 134 | | int state; /* state where this component is visible (-1 means all states) */ |
| 135 | | render_bounds bounds; /* bounds of the element */ |
| 136 | | render_color color; /* color of the element */ |
| 137 | | const char * string; /* string for text components */ |
| 138 | | bitmap_t * bitmap; /* source bitmap for images */ |
| 139 | | const char * dirname; /* directory name of image file (for lazy loading) */ |
| 140 | | const char * imagefile; /* name of the image file (for lazy loading) */ |
| 141 | | const char * alphafile; /* name of the alpha file (for lazy loading) */ |
| 142 | | int hasalpha; /* is there any alpha component present? */ |
| 143 | | }; |
| 133 | //************************************************************************** |
| 134 | // GLOBAL VARIABLES |
| 135 | //************************************************************************** |
| 144 | 136 | |
| 137 | const render_screen_list render_target::s_empty_screen_list; |
| 145 | 138 | |
| 146 | 139 | |
| 147 | | /*************************************************************************** |
| 148 | | FUNCTION PROTOTYPES |
| 149 | | ***************************************************************************/ |
| 150 | 140 | |
| 151 | | /* layout elements */ |
| 152 | | static void layout_element_scale(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param); |
| 153 | | static void layout_element_draw_rect(bitmap_t &dest, const rectangle &bounds, const render_color &color); |
| 154 | | static void layout_element_draw_disk(bitmap_t &dest, const rectangle &bounds, const render_color &color); |
| 155 | | static void layout_element_draw_text(running_machine &machine, bitmap_t &dest, const rectangle &bounds, const render_color &color, const char *string); |
| 156 | | static void layout_element_draw_led7seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state); |
| 157 | | static void layout_element_draw_led14seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state); |
| 158 | | static void layout_element_draw_led16seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state); |
| 159 | | static void layout_element_draw_led14segsc(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state); |
| 160 | | static void layout_element_draw_led16segsc(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state); |
| 161 | | static void layout_element_draw_dotmatrix(bitmap_t &dest, const rectangle &bounds, const render_color &color, int state); |
| 141 | //************************************************************************** |
| 142 | // INLINE HELPERS |
| 143 | //************************************************************************** |
| 162 | 144 | |
| 163 | | /* layout file parsing */ |
| 164 | | static layout_element *load_layout_element(running_machine &machine, xml_data_node *elemnode, const char *dirname); |
| 165 | | static element_component *load_element_component(running_machine &machine, xml_data_node *compnode, const char *dirname); |
| 166 | | static layout_view *load_layout_view(running_machine &machine, xml_data_node *viewnode, layout_element *elemlist); |
| 167 | | static view_item *load_view_item(running_machine &machine, xml_data_node *itemnode, layout_element *elemlist); |
| 168 | | static bitmap_t *load_component_bitmap(const char *dirname, const char *file, const char *alphafile, int *hasalpha); |
| 169 | | static int load_bounds(running_machine &machine, xml_data_node *boundsnode, render_bounds *bounds); |
| 170 | | static int load_color(running_machine &machine, xml_data_node *colornode, render_color *color); |
| 171 | | static int load_orientation(running_machine &machine, xml_data_node *orientnode, int *orientation); |
| 172 | | static void layout_view_free(layout_view *view); |
| 173 | | static void layout_element_free(layout_element *element); |
| 145 | //------------------------------------------------- |
| 146 | // gcd - compute the greatest common divisor (GCD) |
| 147 | // of two integers using the Euclidean algorithm |
| 148 | //------------------------------------------------- |
| 174 | 149 | |
| 175 | | |
| 176 | | |
| 177 | | /*************************************************************************** |
| 178 | | INLINE FUNCTIONS |
| 179 | | ***************************************************************************/ |
| 180 | | |
| 181 | | /*------------------------------------------------- |
| 182 | | gcd - compute the greatest common divisor (GCD) |
| 183 | | of two integers using the Euclidean algorithm |
| 184 | | -------------------------------------------------*/ |
| 185 | | |
| 186 | | INLINE int gcd(int a, int b) |
| 150 | inline int gcd(int a, int b) |
| 187 | 151 | { |
| 188 | 152 | while (b != 0) |
| 189 | 153 | { |
| r9411 | r9412 | |
| 195 | 159 | } |
| 196 | 160 | |
| 197 | 161 | |
| 198 | | /*------------------------------------------------- |
| 199 | | reduce_fraction - reduce a fraction by |
| 200 | | dividing out common factors |
| 201 | | -------------------------------------------------*/ |
| 162 | //------------------------------------------------- |
| 163 | // reduce_fraction - reduce a fraction by |
| 164 | // dividing out common factors |
| 165 | //------------------------------------------------- |
| 202 | 166 | |
| 203 | | INLINE void reduce_fraction(int *num, int *den) |
| 167 | inline void reduce_fraction(int &num, int &den) |
| 204 | 168 | { |
| 205 | | int div; |
| 169 | // search the greatest common divisor |
| 170 | int div = gcd(num, den); |
| 206 | 171 | |
| 207 | | /* search the greatest common divisor */ |
| 208 | | div = gcd(*num, *den); |
| 209 | | |
| 210 | | /* reduce the fraction if a common divisor has been found */ |
| 172 | // reduce the fraction if a common divisor has been found |
| 211 | 173 | if (div > 1) |
| 212 | 174 | { |
| 213 | | *num /= div; |
| 214 | | *den /= div; |
| 175 | num /= div; |
| 176 | den /= div; |
| 215 | 177 | } |
| 216 | 178 | } |
| 217 | 179 | |
| 218 | 180 | |
| 219 | | /*------------------------------------------------- |
| 220 | | copy_string - make a copy of a string |
| 221 | | -------------------------------------------------*/ |
| 222 | 181 | |
| 223 | | INLINE const char *copy_string(const char *string) |
| 182 | //************************************************************************** |
| 183 | // SHARED PARSING HELPERS |
| 184 | //************************************************************************** |
| 185 | |
| 186 | //------------------------------------------------- |
| 187 | // get_variable_value - compute the value of |
| 188 | // a variable in an XML attribute |
| 189 | //------------------------------------------------- |
| 190 | |
| 191 | static int get_variable_value(running_machine &machine, const char *string, char **outputptr) |
| 224 | 192 | { |
| 225 | | char *newstring = global_alloc_array(char, strlen(string) + 1); |
| 226 | | strcpy(newstring, string); |
| 227 | | return newstring; |
| 193 | char temp[100]; |
| 194 | |
| 195 | // screen 0 parameters |
| 196 | for (const screen_device_config *devconfig = screen_first(machine.m_config); devconfig != NULL; devconfig = screen_next(devconfig)) |
| 197 | { |
| 198 | int scrnum = machine.m_config.m_devicelist.index(SCREEN, devconfig->tag()); |
| 199 | |
| 200 | // native X aspect factor |
| 201 | sprintf(temp, "~scr%dnativexaspect~", scrnum); |
| 202 | if (!strncmp(string, temp, strlen(temp))) |
| 203 | { |
| 204 | int num = devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x; |
| 205 | int den = devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y; |
| 206 | reduce_fraction(num, den); |
| 207 | *outputptr += sprintf(*outputptr, "%d", num); |
| 208 | return strlen(temp); |
| 209 | } |
| 210 | |
| 211 | // native Y aspect factor |
| 212 | sprintf(temp, "~scr%dnativeyaspect~", scrnum); |
| 213 | if (!strncmp(string, temp, strlen(temp))) |
| 214 | { |
| 215 | int num = devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x; |
| 216 | int den = devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y; |
| 217 | reduce_fraction(num, den); |
| 218 | *outputptr += sprintf(*outputptr, "%d", den); |
| 219 | return strlen(temp); |
| 220 | } |
| 221 | |
| 222 | // native width |
| 223 | sprintf(temp, "~scr%dwidth~", scrnum); |
| 224 | if (!strncmp(string, temp, strlen(temp))) |
| 225 | { |
| 226 | *outputptr += sprintf(*outputptr, "%d", devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x); |
| 227 | return strlen(temp); |
| 228 | } |
| 229 | |
| 230 | // native height |
| 231 | sprintf(temp, "~scr%dheight~", scrnum); |
| 232 | if (!strncmp(string, temp, strlen(temp))) |
| 233 | { |
| 234 | *outputptr += sprintf(*outputptr, "%d", devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y); |
| 235 | return strlen(temp); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | // default: copy the first character and continue |
| 240 | **outputptr = *string; |
| 241 | *outputptr += 1; |
| 242 | return 1; |
| 228 | 243 | } |
| 229 | 244 | |
| 230 | 245 | |
| 246 | //------------------------------------------------- |
| 247 | // xml_get_attribute_string_with_subst - analog |
| 248 | // to xml_get_attribute_string but with variable |
| 249 | // substitution |
| 250 | //------------------------------------------------- |
| 231 | 251 | |
| 232 | | /*************************************************************************** |
| 233 | | LAYOUT VIEWS |
| 234 | | ***************************************************************************/ |
| 252 | static const char *xml_get_attribute_string_with_subst(running_machine &machine, xml_data_node &node, const char *attribute, const char *defvalue) |
| 253 | { |
| 254 | const char *str = xml_get_attribute_string(&node, attribute, NULL); |
| 255 | static char buffer[1000]; |
| 235 | 256 | |
| 236 | | /*------------------------------------------------- |
| 237 | | layout_view_recompute - recompute the bounds |
| 238 | | and aspect ratio of a view and all of its |
| 239 | | contained items |
| 240 | | -------------------------------------------------*/ |
| 257 | // if nothing, just return the default |
| 258 | if (str == NULL) |
| 259 | return defvalue; |
| 241 | 260 | |
| 242 | | void layout_view_recompute(layout_view *view, int layerconfig) |
| 261 | // if no tildes, don't worry |
| 262 | if (strchr(str, '~') == NULL) |
| 263 | return str; |
| 264 | |
| 265 | // make a copy of the string, doing substitutions along the way |
| 266 | const char *s; |
| 267 | char *d; |
| 268 | for (s = str, d = buffer; *s != 0; ) |
| 269 | { |
| 270 | // if not a variable, just copy |
| 271 | if (*s != '~') |
| 272 | *d++ = *s++; |
| 273 | |
| 274 | // extract the variable |
| 275 | else |
| 276 | s += get_variable_value(machine, s, &d); |
| 277 | } |
| 278 | *d = 0; |
| 279 | return buffer; |
| 280 | } |
| 281 | |
| 282 | |
| 283 | //------------------------------------------------- |
| 284 | // xml_get_attribute_int_with_subst - analog |
| 285 | // to xml_get_attribute_int but with variable |
| 286 | // substitution |
| 287 | //------------------------------------------------- |
| 288 | |
| 289 | static int xml_get_attribute_int_with_subst(running_machine &machine, xml_data_node &node, const char *attribute, int defvalue) |
| 243 | 290 | { |
| 244 | | render_bounds target_bounds; |
| 245 | | float xscale, yscale; |
| 246 | | float xoffs, yoffs; |
| 247 | | int scrfirst = TRUE; |
| 248 | | int first = TRUE; |
| 249 | | int layer; |
| 291 | const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, NULL); |
| 292 | int value; |
| 250 | 293 | |
| 251 | | /* reset the bounds */ |
| 252 | | view->bounds.x0 = view->bounds.y0 = view->bounds.x1 = view->bounds.y1 = 0.0f; |
| 253 | | view->scrbounds.x0 = view->scrbounds.y0 = view->scrbounds.x1 = view->scrbounds.y1 = 0.0f; |
| 254 | | view->screens = 0; |
| 294 | if (string == NULL) |
| 295 | return defvalue; |
| 296 | if (string[0] == '$') |
| 297 | return (sscanf(&string[1], "%X", &value) == 1) ? value : defvalue; |
| 298 | if (string[0] == '0' && string[1] == 'x') |
| 299 | return (sscanf(&string[2], "%X", &value) == 1) ? value : defvalue; |
| 300 | if (string[0] == '#') |
| 301 | return (sscanf(&string[1], "%d", &value) == 1) ? value : defvalue; |
| 302 | return (sscanf(&string[0], "%d", &value) == 1) ? value : defvalue; |
| 303 | } |
| 255 | 304 | |
| 256 | | /* loop over all layers */ |
| 257 | | for (layer = 0; layer < ITEM_LAYER_MAX; layer++) |
| 305 | |
| 306 | //------------------------------------------------- |
| 307 | // xml_get_attribute_float_with_subst - analog |
| 308 | // to xml_get_attribute_float but with variable |
| 309 | // substitution |
| 310 | //------------------------------------------------- |
| 311 | |
| 312 | static float xml_get_attribute_float_with_subst(running_machine &machine, xml_data_node &node, const char *attribute, float defvalue) |
| 313 | { |
| 314 | const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, NULL); |
| 315 | float value; |
| 316 | |
| 317 | if (string == NULL || sscanf(string, "%f", &value) != 1) |
| 318 | return defvalue; |
| 319 | return value; |
| 320 | } |
| 321 | |
| 322 | |
| 323 | //------------------------------------------------- |
| 324 | // parse_bounds - parse a bounds XML node |
| 325 | //------------------------------------------------- |
| 326 | |
| 327 | void parse_bounds(running_machine &machine, xml_data_node *boundsnode, render_bounds &bounds) |
| 328 | { |
| 329 | // skip if nothing |
| 330 | if (boundsnode == NULL) |
| 258 | 331 | { |
| 259 | | static const int layer_mask[ITEM_LAYER_MAX] = { LAYER_CONFIG_ENABLE_BACKDROP, 0, LAYER_CONFIG_ENABLE_OVERLAY, LAYER_CONFIG_ENABLE_BEZEL }; |
| 332 | bounds.x0 = bounds.y0 = 0.0f; |
| 333 | bounds.x1 = bounds.y1 = 1.0f; |
| 334 | return; |
| 335 | } |
| 260 | 336 | |
| 261 | | /* determine if this layer should be visible */ |
| 262 | | view->layenabled[layer] = (layer_mask[layer] == 0 || (layerconfig & layer_mask[layer])); |
| 337 | // parse out the data |
| 338 | if (xml_get_attribute(boundsnode, "left") != NULL) |
| 339 | { |
| 340 | // left/right/top/bottom format |
| 341 | bounds.x0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "left", 0.0f); |
| 342 | bounds.x1 = xml_get_attribute_float_with_subst(machine, *boundsnode, "right", 1.0f); |
| 343 | bounds.y0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "top", 0.0f); |
| 344 | bounds.y1 = xml_get_attribute_float_with_subst(machine, *boundsnode, "bottom", 1.0f); |
| 345 | } |
| 346 | else if (xml_get_attribute(boundsnode, "x") != NULL) |
| 347 | { |
| 348 | // x/y/width/height format |
| 349 | bounds.x0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "x", 0.0f); |
| 350 | bounds.x1 = bounds.x0 + xml_get_attribute_float_with_subst(machine, *boundsnode, "width", 1.0f); |
| 351 | bounds.y0 = xml_get_attribute_float_with_subst(machine, *boundsnode, "y", 0.0f); |
| 352 | bounds.y1 = bounds.y0 + xml_get_attribute_float_with_subst(machine, *boundsnode, "height", 1.0f); |
| 353 | } |
| 354 | else |
| 355 | throw emu_fatalerror("Illegal bounds value in XML"); |
| 263 | 356 | |
| 264 | | /* only do it if requested */ |
| 265 | | if (view->layenabled[layer]) |
| 266 | | { |
| 267 | | view_item *item; |
| 357 | // check for errors |
| 358 | if (bounds.x0 > bounds.x1 || bounds.y0 > bounds.y1) |
| 359 | throw emu_fatalerror("Illegal bounds value in XML: (%f-%f)-(%f-%f)", bounds.x0, bounds.x1, bounds.y0, bounds.y1); |
| 360 | } |
| 268 | 361 | |
| 269 | | for (item = view->itemlist[layer]; item != NULL; item = item->next) |
| 270 | | { |
| 271 | | /* accumulate bounds */ |
| 272 | | if (first) |
| 273 | | view->bounds = item->rawbounds; |
| 274 | | else |
| 275 | | union_render_bounds(&view->bounds, &item->rawbounds); |
| 276 | | first = FALSE; |
| 277 | 362 | |
| 278 | | /* accumulate screen bounds */ |
| 279 | | if (item->element == NULL) |
| 280 | | { |
| 281 | | if (scrfirst) |
| 282 | | view->scrbounds = item->rawbounds; |
| 283 | | else |
| 284 | | union_render_bounds(&view->scrbounds, &item->rawbounds); |
| 285 | | scrfirst = FALSE; |
| 363 | //------------------------------------------------- |
| 364 | // parse_color - parse a color XML node |
| 365 | //------------------------------------------------- |
| 286 | 366 | |
| 287 | | /* accumulate the screens in use while we're scanning */ |
| 288 | | view->screens |= 1 << item->index; |
| 289 | | } |
| 290 | | } |
| 291 | | } |
| 367 | void parse_color(running_machine &machine, xml_data_node *colornode, render_color &color) |
| 368 | { |
| 369 | // skip if nothing |
| 370 | if (colornode == NULL) |
| 371 | { |
| 372 | color.r = color.g = color.b = color.a = 1.0f; |
| 373 | return; |
| 292 | 374 | } |
| 293 | 375 | |
| 294 | | /* if we have an explicit bounds, override it */ |
| 295 | | if (view->expbounds.x1 > view->expbounds.x0) |
| 296 | | view->bounds = view->expbounds; |
| 376 | // parse out the data |
| 377 | color.r = xml_get_attribute_float_with_subst(machine, *colornode, "red", 1.0); |
| 378 | color.g = xml_get_attribute_float_with_subst(machine, *colornode, "green", 1.0); |
| 379 | color.b = xml_get_attribute_float_with_subst(machine, *colornode, "blue", 1.0); |
| 380 | color.a = xml_get_attribute_float_with_subst(machine, *colornode, "alpha", 1.0); |
| 297 | 381 | |
| 298 | | /* compute the aspect ratio of the view */ |
| 299 | | view->aspect = (view->bounds.x1 - view->bounds.x0) / (view->bounds.y1 - view->bounds.y0); |
| 300 | | view->scraspect = (view->scrbounds.x1 - view->scrbounds.x0) / (view->scrbounds.y1 - view->scrbounds.y0); |
| 382 | // check for errors |
| 383 | if (color.r < 0.0 || color.r > 1.0 || color.g < 0.0 || color.g > 1.0 || |
| 384 | color.b < 0.0 || color.b > 1.0 || color.a < 0.0 || color.a > 1.0) |
| 385 | throw emu_fatalerror("Illegal ARGB color value in XML: %f,%f,%f,%f", color.r, color.g, color.b, color.a); |
| 386 | } |
| 301 | 387 | |
| 302 | | /* if we're handling things normally, the target bounds are (0,0)-(1,1) */ |
| 303 | | if (!(layerconfig & LAYER_CONFIG_ZOOM_TO_SCREEN) || view->screens == 0) |
| 388 | |
| 389 | //------------------------------------------------- |
| 390 | // parse_orientation - parse an orientation XML |
| 391 | // node |
| 392 | //------------------------------------------------- |
| 393 | |
| 394 | static void parse_orientation(running_machine &machine, xml_data_node *orientnode, int &orientation) |
| 395 | { |
| 396 | // skip if nothing |
| 397 | if (orientnode == NULL) |
| 304 | 398 | { |
| 305 | | target_bounds.x0 = target_bounds.y0 = 0.0f; |
| 306 | | target_bounds.x1 = target_bounds.y1 = 1.0f; |
| 399 | orientation = ROT0; |
| 400 | return; |
| 307 | 401 | } |
| 308 | 402 | |
| 309 | | /* if we're cropping, we want the screen area to fill (0,0)-(1,1) */ |
| 310 | | else |
| 403 | // parse out the data |
| 404 | int rotate = xml_get_attribute_int_with_subst(machine, *orientnode, "rotate", 0); |
| 405 | switch (rotate) |
| 311 | 406 | { |
| 312 | | float targwidth = (view->bounds.x1 - view->bounds.x0) / (view->scrbounds.x1 - view->scrbounds.x0); |
| 313 | | float targheight = (view->bounds.y1 - view->bounds.y0) / (view->scrbounds.y1 - view->scrbounds.y0); |
| 314 | | target_bounds.x0 = (view->bounds.x0 - view->scrbounds.x0) / (view->bounds.x1 - view->bounds.x0) * targwidth; |
| 315 | | target_bounds.y0 = (view->bounds.y0 - view->scrbounds.y0) / (view->bounds.y1 - view->bounds.y0) * targheight; |
| 316 | | target_bounds.x1 = target_bounds.x0 + targwidth; |
| 317 | | target_bounds.y1 = target_bounds.y0 + targheight; |
| 407 | case 0: orientation = ROT0; break; |
| 408 | case 90: orientation = ROT90; break; |
| 409 | case 180: orientation = ROT180; break; |
| 410 | case 270: orientation = ROT270; break; |
| 411 | default: throw emu_fatalerror("Invalid rotation in XML orientation node: %d", rotate); break; |
| 318 | 412 | } |
| 413 | if (strcmp("yes", xml_get_attribute_string_with_subst(machine, *orientnode, "swapxy", "no")) == 0) |
| 414 | orientation ^= ORIENTATION_SWAP_XY; |
| 415 | if (strcmp("yes", xml_get_attribute_string_with_subst(machine, *orientnode, "flipx", "no")) == 0) |
| 416 | orientation ^= ORIENTATION_FLIP_X; |
| 417 | if (strcmp("yes", xml_get_attribute_string_with_subst(machine, *orientnode, "flipy", "no")) == 0) |
| 418 | orientation ^= ORIENTATION_FLIP_Y; |
| 419 | } |
| 319 | 420 | |
| 320 | | /* determine the scale/offset for normalization */ |
| 321 | | xoffs = view->bounds.x0; |
| 322 | | yoffs = view->bounds.y0; |
| 323 | | xscale = (target_bounds.x1 - target_bounds.x0) / (view->bounds.x1 - view->bounds.x0); |
| 324 | | yscale = (target_bounds.y1 - target_bounds.y0) / (view->bounds.y1 - view->bounds.y0); |
| 325 | 421 | |
| 326 | | /* normalize all the item bounds */ |
| 327 | | for (layer = 0; layer < ITEM_LAYER_MAX; layer++) |
| 422 | |
| 423 | //************************************************************************** |
| 424 | // LAYOUT ELEMENT |
| 425 | //************************************************************************** |
| 426 | |
| 427 | //------------------------------------------------- |
| 428 | // layout_element - constructor |
| 429 | //------------------------------------------------- |
| 430 | |
| 431 | layout_element::layout_element(running_machine &machine, xml_data_node &elemnode, const char *dirname) |
| 432 | : m_next(NULL), |
| 433 | m_machine(machine), |
| 434 | m_complist(machine.m_respool), |
| 435 | m_defstate(0), |
| 436 | m_maxstate(0), |
| 437 | m_elemtex(NULL) |
| 438 | { |
| 439 | // extract the name |
| 440 | const char *name = xml_get_attribute_string_with_subst(machine, elemnode, "name", NULL); |
| 441 | if (name == NULL) |
| 442 | throw emu_fatalerror("All layout elements must have a name!\n"); |
| 443 | m_name = name; |
| 444 | |
| 445 | // get the default state |
| 446 | m_defstate = xml_get_attribute_int_with_subst(machine, elemnode, "defstate", -1); |
| 447 | |
| 448 | // parse components in order |
| 449 | bool first = true; |
| 450 | render_bounds bounds = { 0 }; |
| 451 | for (xml_data_node *compnode = elemnode.child; compnode != NULL; compnode = compnode->next) |
| 328 | 452 | { |
| 329 | | view_item *item; |
| 453 | // allocate a new component |
| 454 | component &newcomp = m_complist.append(*auto_alloc(&machine, component(machine, *compnode, dirname))); |
| 330 | 455 | |
| 331 | | /* adjust the bounds for each item */ |
| 332 | | for (item = view->itemlist[layer]; item; item = item->next) |
| 333 | | { |
| 334 | | item->bounds.x0 = target_bounds.x0 + (item->rawbounds.x0 - xoffs) * xscale; |
| 335 | | item->bounds.x1 = target_bounds.x0 + (item->rawbounds.x1 - xoffs) * xscale; |
| 336 | | item->bounds.y0 = target_bounds.y0 + (item->rawbounds.y0 - yoffs) * yscale; |
| 337 | | item->bounds.y1 = target_bounds.y0 + (item->rawbounds.y1 - yoffs) * yscale; |
| 338 | | } |
| 456 | // accumulate bounds |
| 457 | if (first) |
| 458 | bounds = newcomp.m_bounds; |
| 459 | else |
| 460 | union_render_bounds(&bounds, &newcomp.m_bounds); |
| 461 | first = false; |
| 462 | |
| 463 | // determine the maximum state |
| 464 | if (newcomp.m_state > m_maxstate) |
| 465 | m_maxstate = newcomp.m_state; |
| 466 | if (newcomp.m_type == component::CTYPE_LED7SEG) |
| 467 | m_maxstate = 255; |
| 468 | if (newcomp.m_type == component::CTYPE_LED14SEG) |
| 469 | m_maxstate = 16383; |
| 470 | if (newcomp.m_type == component::CTYPE_LED14SEGSC || newcomp.m_type == component::CTYPE_LED16SEG) |
| 471 | m_maxstate = 65535; |
| 472 | if (newcomp.m_type == component::CTYPE_LED16SEGSC) |
| 473 | m_maxstate = 262143; |
| 474 | if (newcomp.m_type == component::CTYPE_DOTMATRIX) |
| 475 | m_maxstate = 255; |
| 339 | 476 | } |
| 477 | |
| 478 | // determine the scale/offset for normalization |
| 479 | float xoffs = bounds.x0; |
| 480 | float yoffs = bounds.y0; |
| 481 | float xscale = 1.0f / (bounds.x1 - bounds.x0); |
| 482 | float yscale = 1.0f / (bounds.y1 - bounds.y0); |
| 483 | |
| 484 | // normalize all the component bounds |
| 485 | for (component *curcomp = m_complist.first(); curcomp != NULL; curcomp = curcomp->next()) |
| 486 | { |
| 487 | curcomp->m_bounds.x0 = (curcomp->m_bounds.x0 - xoffs) * xscale; |
| 488 | curcomp->m_bounds.x1 = (curcomp->m_bounds.x1 - xoffs) * xscale; |
| 489 | curcomp->m_bounds.y0 = (curcomp->m_bounds.y0 - yoffs) * yscale; |
| 490 | curcomp->m_bounds.y1 = (curcomp->m_bounds.y1 - yoffs) * yscale; |
| 491 | } |
| 492 | |
| 493 | // allocate an array of element textures for the states |
| 494 | m_elemtex = auto_alloc_array(&machine, texture, m_maxstate + 1); |
| 340 | 495 | } |
| 341 | 496 | |
| 342 | 497 | |
| 498 | //------------------------------------------------- |
| 499 | // ~layout_element - destructor |
| 500 | //------------------------------------------------- |
| 343 | 501 | |
| 344 | | /*************************************************************************** |
| 345 | | LAYOUT ELEMENTS |
| 346 | | ***************************************************************************/ |
| 502 | layout_element::~layout_element() |
| 503 | { |
| 504 | // loop over all states and free their textures |
| 505 | auto_free(&m_machine, m_elemtex); |
| 506 | } |
| 347 | 507 | |
| 348 | | /*------------------------------------------------- |
| 349 | | layout_element_scale - scale an element by |
| 350 | | rendering all the components at the |
| 351 | | appropriate resolution |
| 352 | | -------------------------------------------------*/ |
| 353 | 508 | |
| 354 | | static void layout_element_scale(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param) |
| 509 | //------------------------------------------------- |
| 510 | // state_texture - return a pointer to a |
| 511 | // render_texture for the given state, allocating |
| 512 | // one if needed |
| 513 | //------------------------------------------------- |
| 514 | |
| 515 | render_texture *layout_element::state_texture(int state) |
| 355 | 516 | { |
| 356 | | element_texture *elemtex = (element_texture *)param; |
| 357 | | element_component *component; |
| 517 | assert(state <= m_maxstate); |
| 518 | if (m_elemtex[state].m_texture == NULL) |
| 519 | { |
| 520 | m_elemtex[state].m_element = this; |
| 521 | m_elemtex[state].m_state = state; |
| 522 | m_elemtex[state].m_texture = m_machine.render().texture_alloc(element_scale, &m_elemtex[state]); |
| 523 | } |
| 524 | return m_elemtex[state].m_texture; |
| 525 | } |
| 358 | 526 | |
| 359 | | /* iterate over components that are part of the current state */ |
| 360 | | for (component = elemtex->element->complist; component != NULL; component = component->next) |
| 361 | | if (component->state == -1 || component->state == elemtex->state) |
| 527 | |
| 528 | //------------------------------------------------- |
| 529 | // element_scale - scale an element by rendering |
| 530 | // all the components at the appropriate |
| 531 | // resolution |
| 532 | //------------------------------------------------- |
| 533 | |
| 534 | void layout_element::element_scale(bitmap_t &dest, const bitmap_t &source, const rectangle &sbounds, void *param) |
| 535 | { |
| 536 | texture *elemtex = (texture *)param; |
| 537 | |
| 538 | // iterate over components that are part of the current state |
| 539 | for (component *curcomp = elemtex->m_element->m_complist.first(); curcomp != NULL; curcomp = curcomp->next()) |
| 540 | if (curcomp->m_state == -1 || curcomp->m_state == elemtex->m_state) |
| 362 | 541 | { |
| 542 | // get the local scaled bounds |
| 363 | 543 | rectangle bounds; |
| 544 | bounds.min_x = render_round_nearest(curcomp->bounds().x0 * dest.width); |
| 545 | bounds.min_y = render_round_nearest(curcomp->bounds().y0 * dest.height); |
| 546 | bounds.max_x = render_round_nearest(curcomp->bounds().x1 * dest.width); |
| 547 | bounds.max_y = render_round_nearest(curcomp->bounds().y1 * dest.height); |
| 364 | 548 | |
| 365 | | /* get the local scaled bounds */ |
| 366 | | bounds.min_x = render_round_nearest(component->bounds.x0 * dest.width); |
| 367 | | bounds.min_y = render_round_nearest(component->bounds.y0 * dest.height); |
| 368 | | bounds.max_x = render_round_nearest(component->bounds.x1 * dest.width); |
| 369 | | bounds.max_y = render_round_nearest(component->bounds.y1 * dest.height); |
| 549 | // based on the component type, add to the texture |
| 550 | curcomp->draw(elemtex->m_element->m_machine, dest, bounds, elemtex->m_state); |
| 551 | } |
| 552 | } |
| 370 | 553 | |
| 371 | | /* based on the component type, add to the texture */ |
| 372 | | switch (component->type) |
| 373 | | { |
| 374 | | case COMPONENT_TYPE_IMAGE: |
| 375 | | if (component->bitmap == NULL) |
| 376 | | component->bitmap = load_component_bitmap(component->dirname, component->imagefile, component->alphafile, &component->hasalpha); |
| 377 | | render_resample_argb_bitmap_hq( |
| 378 | | BITMAP_ADDR32(&dest, bounds.min_y, bounds.min_x), |
| 379 | | dest.rowpixels, |
| 380 | | bounds.max_x - bounds.min_x, |
| 381 | | bounds.max_y - bounds.min_y, |
| 382 | | component->bitmap, NULL, &component->color); |
| 383 | | break; |
| 384 | 554 | |
| 385 | | case COMPONENT_TYPE_RECT: |
| 386 | | layout_element_draw_rect(dest, bounds, component->color); |
| 387 | | break; |
| 555 | //************************************************************************** |
| 556 | // LAYOUT ELEMENT TEXTURE |
| 557 | //************************************************************************** |
| 388 | 558 | |
| 389 | | case COMPONENT_TYPE_DISK: |
| 390 | | layout_element_draw_disk(dest, bounds, component->color); |
| 391 | | break; |
| 559 | //------------------------------------------------- |
| 560 | // texture - constructor |
| 561 | //------------------------------------------------- |
| 392 | 562 | |
| 393 | | case COMPONENT_TYPE_TEXT: |
| 394 | | layout_element_draw_text(*elemtex->element->machine, dest, bounds, component->color, component->string); |
| 395 | | break; |
| 563 | layout_element::texture::texture() |
| 564 | : m_element(NULL), |
| 565 | m_texture(NULL), |
| 566 | m_state(0) |
| 567 | { |
| 568 | } |
| 396 | 569 | |
| 397 | | case COMPONENT_TYPE_LED7SEG: |
| 398 | | layout_element_draw_led7seg(dest, bounds, component->color, elemtex->state); |
| 399 | | break; |
| 400 | 570 | |
| 401 | | case COMPONENT_TYPE_LED14SEG: |
| 402 | | layout_element_draw_led14seg(dest, bounds, component->color, elemtex->state); |
| 403 | | break; |
| 571 | //------------------------------------------------- |
| 572 | // ~texture - destructor |
| 573 | //------------------------------------------------- |
| 404 | 574 | |
| 405 | | case COMPONENT_TYPE_LED16SEG: |
| 406 | | layout_element_draw_led16seg(dest, bounds, component->color, elemtex->state); |
| 407 | | break; |
| 575 | layout_element::texture::~texture() |
| 576 | { |
| 577 | if (m_element != NULL) |
| 578 | m_element->m_machine.render().texture_free(m_texture); |
| 579 | } |
| 408 | 580 | |
| 409 | | case COMPONENT_TYPE_LED14SEGSC: |
| 410 | | layout_element_draw_led14segsc(dest, bounds, component->color, elemtex->state); |
| 411 | | break; |
| 412 | 581 | |
| 413 | | case COMPONENT_TYPE_LED16SEGSC: |
| 414 | | layout_element_draw_led16segsc(dest, bounds, component->color, elemtex->state); |
| 415 | | break; |
| 416 | 582 | |
| 417 | | case COMPONENT_TYPE_DOTMATRIX: |
| 418 | | layout_element_draw_dotmatrix(dest, bounds, component->color, elemtex->state); |
| 419 | | break; |
| 420 | | } |
| 421 | | } |
| 583 | //************************************************************************** |
| 584 | // LAYOUT ELEMENT COMPONENT |
| 585 | //************************************************************************** |
| 586 | |
| 587 | //------------------------------------------------- |
| 588 | // component - constructor |
| 589 | //------------------------------------------------- |
| 590 | |
| 591 | layout_element::component::component(running_machine &machine, xml_data_node &compnode, const char *dirname) |
| 592 | : m_next(NULL), |
| 593 | m_type(CTYPE_INVALID), |
| 594 | m_state(0), |
| 595 | m_bitmap(NULL), |
| 596 | m_hasalpha(false) |
| 597 | { |
| 598 | // fetch common data |
| 599 | m_state = xml_get_attribute_int_with_subst(machine, compnode, "state", -1); |
| 600 | parse_bounds(machine, xml_get_sibling(compnode.child, "bounds"), m_bounds); |
| 601 | parse_color(machine, xml_get_sibling(compnode.child, "color"), m_color); |
| 602 | |
| 603 | // image nodes |
| 604 | if (strcmp(compnode.name, "image") == 0) |
| 605 | { |
| 606 | m_type = CTYPE_IMAGE; |
| 607 | m_dirname = dirname; |
| 608 | m_imagefile = xml_get_attribute_string_with_subst(machine, compnode, "file", ""); |
| 609 | m_alphafile = xml_get_attribute_string_with_subst(machine, compnode, "alphafile", ""); |
| 610 | } |
| 611 | |
| 612 | // text nodes |
| 613 | else if (strcmp(compnode.name, "text") == 0) |
| 614 | { |
| 615 | m_type = CTYPE_TEXT; |
| 616 | m_string = xml_get_attribute_string_with_subst(machine, compnode, "string", ""); |
| 617 | } |
| 618 | |
| 619 | // dotmatrix nodes |
| 620 | else if (strcmp(compnode.name, "dotmatrix") == 0) |
| 621 | m_type = CTYPE_DOTMATRIX; |
| 622 | |
| 623 | // led7seg nodes |
| 624 | else if (strcmp(compnode.name, "led7seg") == 0) |
| 625 | m_type = CTYPE_LED7SEG; |
| 626 | |
| 627 | // led14seg nodes |
| 628 | else if (strcmp(compnode.name, "led14seg") == 0) |
| 629 | m_type = CTYPE_LED14SEG; |
| 630 | |
| 631 | // led14segsc nodes |
| 632 | else if (strcmp(compnode.name, "led14segsc") == 0) |
| 633 | m_type = CTYPE_LED14SEGSC; |
| 634 | |
| 635 | // led16seg nodes |
| 636 | else if (strcmp(compnode.name, "led16seg") == 0) |
| 637 | m_type = CTYPE_LED16SEG; |
| 638 | |
| 639 | // led16segsc nodes |
| 640 | else if (strcmp(compnode.name, "led16segsc") == 0) |
| 641 | m_type = CTYPE_LED16SEGSC; |
| 642 | |
| 643 | // rect nodes |
| 644 | else if (strcmp(compnode.name, "rect") == 0) |
| 645 | m_type = CTYPE_RECT; |
| 646 | |
| 647 | // disk nodes |
| 648 | else if (strcmp(compnode.name, "disk") == 0) |
| 649 | m_type = CTYPE_DISK; |
| 650 | |
| 651 | // error otherwise |
| 652 | else |
| 653 | throw emu_fatalerror("Unknown element component: %s", compnode.name); |
| 422 | 654 | } |
| 423 | 655 | |
| 424 | 656 | |
| 425 | | /*------------------------------------------------- |
| 426 | | layout_element_draw_rect - draw a rectangle |
| 427 | | in the specified color |
| 428 | | -------------------------------------------------*/ |
| 657 | //------------------------------------------------- |
| 658 | // ~component - destructor |
| 659 | //------------------------------------------------- |
| 429 | 660 | |
| 430 | | static void layout_element_draw_rect(bitmap_t &dest, const rectangle &bounds, const render_color &color) |
| 661 | layout_element::component::~component() |
| 431 | 662 | { |
| 432 | | UINT32 r, g, b, inva; |
| 433 | | UINT32 x, y; |
| 663 | global_free(m_bitmap); |
| 664 | } |
| 434 | 665 | |
| 435 | | /* compute premultiplied colors */ |
| 436 | | r = color.r * color.a * 255.0; |
| 437 | | g = color.g * color.a * 255.0; |
| 438 | | b = color.b * color.a * 255.0; |
| 439 | | inva = (1.0f - color.a) * 255.0; |
| 440 | 666 | |
| 441 | | /* iterate over X and Y */ |
| 442 | | for (y = bounds.min_y; y < bounds.max_y; y++) |
| 443 | | for (x = bounds.min_x; x < bounds.max_x; x++) |
| 667 | //------------------------------------------------- |
| 668 | // draw - draw a component |
| 669 | //------------------------------------------------- |
| 670 | |
| 671 | void layout_element::component::draw(running_machine &machine, bitmap_t &dest, const rectangle &bounds, int state) |
| 672 | { |
| 673 | switch (m_type) |
| 674 | { |
| 675 | case CTYPE_IMAGE: |
| 676 | if (m_bitmap == NULL) |
| 677 | m_bitmap = load_bitmap(); |
| 678 | render_resample_argb_bitmap_hq( |
| 679 | BITMAP_ADDR32(&dest, bounds.min_y, bounds.min_x), |
| 680 | dest.rowpixels, |
| 681 | bounds.max_x - bounds.min_x, |
| 682 | bounds.max_y - bounds.min_y, |
| 683 | m_bitmap, NULL, &m_color); |
| 684 | break; |
| 685 | |
| 686 | case CTYPE_RECT: |
| 687 | draw_rect(dest, bounds); |
| 688 | break; |
| 689 | |
| 690 | case CTYPE_DISK: |
| 691 | draw_disk(dest, bounds); |
| 692 | break; |
| 693 | |
| 694 | case CTYPE_TEXT: |
| 695 | draw_text(machine, dest, bounds); |
| 696 | break; |
| 697 | |
| 698 | case CTYPE_LED7SEG: |
| 699 | draw_led7seg(dest, bounds, state); |
| 700 | break; |
| 701 | |
| 702 | case CTYPE_LED14SEG: |
| 703 | draw_led14seg(dest, bounds, state); |
| 704 | break; |
| 705 | |
| 706 | case CTYPE_LED16SEG: |
| 707 | draw_led16seg(dest, bounds, state); |
| 708 | break; |
| 709 | |
| 710 | case CTYPE_LED14SEGSC: |
| 711 | draw_led14segsc(dest, bounds, state); |
| 712 | break; |
| 713 | |
| 714 | case CTYPE_LED16SEGSC: |
| 715 | draw_led16segsc(dest, bounds, state); |
| 716 | break; |
| 717 | |
| 718 | case CTYPE_DOTMATRIX: |
| 719 | draw_dotmatrix(dest, bounds, state); |
| 720 | break; |
| 721 | |
| 722 | default: |
| 723 | throw emu_fatalerror("Unknown component type requested draw()"); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | |
| 728 | //------------------------------------------------- |
| 729 | // draw_rect - draw a rectangle in the specified |
| 730 | // color |
| 731 | //------------------------------------------------- |
| 732 | |
| 733 | void layout_element::component::draw_rect(bitmap_t &dest, const rectangle &bounds) |
| 734 | { |
| 735 | // compute premultiplied colors |
| 736 | UINT32 r = m_color.r * m_color.a * 255.0; |
| 737 | UINT32 g = m_color.g * m_color.a * 255.0; |
| 738 | UINT32 b = m_color.b * m_color.a * 255.0; |
| 739 | UINT32 inva = (1.0f - m_color.a) * 255.0; |
| 740 | |
| 741 | // iterate over X and Y |
| 742 | for (UINT32 y = bounds.min_y; y < bounds.max_y; y++) |
| 743 | for (UINT32 x = bounds.min_x; x < bounds.max_x; x++) |
| 444 | 744 | { |
| 445 | 745 | UINT32 finalr = r; |
| 446 | 746 | UINT32 finalg = g; |
| 447 | 747 | UINT32 finalb = b; |
| 448 | 748 | |
| 449 | | /* if we're translucent, add in the destination pixel contribution */ |
| 749 | // if we're translucent, add in the destination pixel contribution |
| 450 | 750 | if (inva > 0) |
| 451 | 751 | { |
| 452 | 752 | UINT32 dpix = *BITMAP_ADDR32(&dest, y, x); |
| r9411 | r9412 | |
| 455 | 755 | finalb += (RGB_BLUE(dpix) * inva) >> 8; |
| 456 | 756 | } |
| 457 | 757 | |
| 458 | | /* store the target pixel, dividing the RGBA values by the overall scale factor */ |
| 758 | // store the target pixel, dividing the RGBA values by the overall scale factor |
| 459 | 759 | *BITMAP_ADDR32(&dest, y, x) = MAKE_ARGB(0xff, finalr, finalg, finalb); |
| 460 | 760 | } |
| 461 | 761 | } |
| 462 | 762 | |
| 463 | 763 | |
| 464 | | /*------------------------------------------------- |
| 465 | | layout_element_draw_disk - draw an ellipse |
| 466 | | in the specified color |
| 467 | | -------------------------------------------------*/ |
| 764 | //------------------------------------------------- |
| 765 | // draw_disk - draw an ellipse in the specified |
| 766 | // color |
| 767 | //------------------------------------------------- |
| 468 | 768 | |
| 469 | | static void layout_element_draw_disk(bitmap_t &dest, const rectangle &bounds, const render_color &color) |
| 769 | void layout_element::component::draw_disk(bitmap_t &dest, const rectangle &bounds) |
| 470 | 770 | { |
| 471 | | float xcenter, ycenter; |
| 472 | | float xradius, yradius, ooyradius2; |
| 473 | | UINT32 r, g, b, inva; |
| 474 | | UINT32 x, y; |
| 771 | // compute premultiplied colors |
| 772 | UINT32 r = m_color.r * m_color.a * 255.0; |
| 773 | UINT32 g = m_color.g * m_color.a * 255.0; |
| 774 | UINT32 b = m_color.b * m_color.a * 255.0; |
| 775 | UINT32 inva = (1.0f - m_color.a) * 255.0; |
| 475 | 776 | |
| 476 | | /* compute premultiplied colors */ |
| 477 | | r = color.r * color.a * 255.0; |
| 478 | | g = color.g * color.a * 255.0; |
| 479 | | b = color.b * color.a * 255.0; |
| 480 | | inva = (1.0f - color.a) * 255.0; |
| 777 | // find the center |
| 778 | float xcenter = (float)(bounds.min_x + bounds.max_x) * 0.5f; |
| 779 | float ycenter = (float)(bounds.min_y + bounds.max_y) * 0.5f; |
| 780 | float xradius = (float)(bounds.max_x - bounds.min_x) * 0.5f; |
| 781 | float yradius = (float)(bounds.max_y - bounds.min_y) * 0.5f; |
| 782 | float ooyradius2 = 1.0f / (yradius * yradius); |
| 481 | 783 | |
| 482 | | /* find the center */ |
| 483 | | xcenter = (float)(bounds.min_x + bounds.max_x) * 0.5f; |
| 484 | | ycenter = (float)(bounds.min_y + bounds.max_y) * 0.5f; |
| 485 | | xradius = (float)(bounds.max_x - bounds.min_x) * 0.5f; |
| 486 | | yradius = (float)(bounds.max_y - bounds.min_y) * 0.5f; |
| 487 | | ooyradius2 = 1.0f / (yradius * yradius); |
| 488 | | |
| 489 | | /* iterate over y */ |
| 490 | | for (y = bounds.min_y; y < bounds.max_y; y++) |
| 784 | // iterate over y |
| 785 | for (UINT32 y = bounds.min_y; y < bounds.max_y; y++) |
| 491 | 786 | { |
| 492 | 787 | float ycoord = ycenter - ((float)y + 0.5f); |
| 493 | 788 | float xval = xradius * sqrt(1.0f - (ycoord * ycoord) * ooyradius2); |
| 494 | | INT32 left, right; |
| 495 | 789 | |
| 496 | | /* compute left/right coordinates */ |
| 497 | | left = (INT32)(xcenter - xval + 0.5f); |
| 498 | | right = (INT32)(xcenter + xval + 0.5f); |
| 790 | // compute left/right coordinates |
| 791 | INT32 left = (INT32)(xcenter - xval + 0.5f); |
| 792 | INT32 right = (INT32)(xcenter + xval + 0.5f); |
| 499 | 793 | |
| 500 | | /* draw this scanline */ |
| 501 | | for (x = left; x < right; x++) |
| 794 | // draw this scanline |
| 795 | for (UINT32 x = left; x < right; x++) |
| 502 | 796 | { |
| 503 | 797 | UINT32 finalr = r; |
| 504 | 798 | UINT32 finalg = g; |
| 505 | 799 | UINT32 finalb = b; |
| 506 | 800 | |
| 507 | | /* if we're translucent, add in the destination pixel contribution */ |
| 801 | // if we're translucent, add in the destination pixel contribution |
| 508 | 802 | if (inva > 0) |
| 509 | 803 | { |
| 510 | 804 | UINT32 dpix = *BITMAP_ADDR32(&dest, y, x); |
| r9411 | r9412 | |
| 513 | 807 | finalb += (RGB_BLUE(dpix) * inva) >> 8; |
| 514 | 808 | } |
| 515 | 809 | |
| 516 | | /* store the target pixel, dividing the RGBA values by the overall scale factor */ |
| 810 | // store the target pixel, dividing the RGBA values by the overall scale factor |
| 517 | 811 | *BITMAP_ADDR32(&dest, y, x) = MAKE_ARGB(0xff, finalr, finalg, finalb); |
| 518 | 812 | } |
| 519 | 813 | } |
| 520 | 814 | } |
| 521 | 815 | |
| 522 | 816 | |
| 523 | | /*------------------------------------------------- |
| 524 | | layout_element_draw_text - draw text in the |
| 525 | | specified color |
| 526 | | -------------------------------------------------*/ |
| 817 | //------------------------------------------------- |
| 818 | // draw_text - draw text in the specified color |
| 819 | //------------------------------------------------- |
| 527 | 820 | |
| 528 | | static void layout_element_draw_text(running_machine &machine, bitmap_t &dest, const rectangle &bounds, const render_color &color, const char *string) |
| 821 | void layout_element::component::draw_text(running_machine &machine, bitmap_t &dest, const rectangle &bounds) |
| 529 | 822 | { |
| 823 | // compute premultiplied colors |
| 824 | UINT32 r = m_color.r * 255.0; |
| 825 | UINT32 g = m_color.g * 255.0; |
| 826 | UINT32 b = m_color.b * 255.0; |
| 827 | UINT32 a = m_color.a * 255.0; |
| 828 | |
| 829 | // get the width of the string |
| 530 | 830 | render_font *font = render_font_alloc(machine, NULL); |
| 531 | | bitmap_t *tempbitmap; |
| 532 | | UINT32 r, g, b, a; |
| 533 | 831 | float aspect = 1.0f; |
| 534 | | INT32 curx, width; |
| 535 | | const char *s; |
| 536 | | |
| 537 | | /* compute premultiplied colors */ |
| 538 | | r = color.r * 255.0; |
| 539 | | g = color.g * 255.0; |
| 540 | | b = color.b * 255.0; |
| 541 | | a = color.a * 255.0; |
| 542 | | |
| 543 | | /* get the width of the string */ |
| 832 | INT32 width; |
| 544 | 833 | while (1) |
| 545 | 834 | { |
| 546 | | width = render_font_get_string_width(font, bounds.max_y - bounds.min_y, aspect, string); |
| 835 | width = render_font_get_string_width(font, bounds.max_y - bounds.min_y, aspect, m_string); |
| 547 | 836 | if (width < bounds.max_x - bounds.min_x) |
| 548 | 837 | break; |
| 549 | 838 | aspect *= 0.9f; |
| 550 | 839 | } |
| 551 | | curx = bounds.min_x + (bounds.max_x - bounds.min_x - width) / 2; |
| 840 | INT32 curx = bounds.min_x + (bounds.max_x - bounds.min_x - width) / 2; |
| 552 | 841 | |
| 553 | | /* allocate a temporary bitmap */ |
| 554 | | tempbitmap = global_alloc(bitmap_t(dest.width, dest.height, BITMAP_FORMAT_ARGB32)); |
| 842 | // allocate a temporary bitmap |
| 843 | bitmap_t *tempbitmap = global_alloc(bitmap_t(dest.width, dest.height, BITMAP_FORMAT_ARGB32)); |
| 555 | 844 | |
| 556 | | /* loop over characters */ |
| 557 | | for (s = string; *s != 0; s++) |
| 845 | // loop over characters |
| 846 | for (const char *s = m_string; *s != 0; s++) |
| 558 | 847 | { |
| 848 | // get the font bitmap |
| 559 | 849 | rectangle chbounds; |
| 560 | | int x, y; |
| 561 | | |
| 562 | | /* get the font bitmap */ |
| 563 | 850 | render_font_get_scaled_bitmap_and_bounds(font, tempbitmap, bounds.max_y - bounds.min_y, aspect, *s, &chbounds); |
| 564 | 851 | |
| 565 | | /* copy the data into the target */ |
| 566 | | for (y = 0; y < chbounds.max_y - chbounds.min_y; y++) |
| 852 | // copy the data into the target |
| 853 | for (int y = 0; y < chbounds.max_y - chbounds.min_y; y++) |
| 567 | 854 | { |
| 568 | 855 | int effy = bounds.min_y + y; |
| 569 | 856 | if (effy >= bounds.min_y && effy <= bounds.max_y) |
| 570 | 857 | { |
| 571 | 858 | UINT32 *src = BITMAP_ADDR32(tempbitmap, y, 0); |
| 572 | 859 | UINT32 *d = BITMAP_ADDR32(&dest, effy, 0); |
| 573 | | for (x = 0; x < chbounds.max_x - chbounds.min_x; x++) |
| 860 | for (int x = 0; x < chbounds.max_x - chbounds.min_x; x++) |
| 574 | 861 | { |
| 575 | 862 | int effx = curx + x + chbounds.min_x; |
| 576 | 863 | if (effx >= bounds.min_x && effx <= bounds.max_x) |
| r9411 | r9412 | |
| 579 | 866 | if (spix != 0) |
| 580 | 867 | { |
| 581 | 868 | UINT32 dpix = d[effx]; |
| 582 | | UINT32 ta, tr, tg, tb; |
| 583 | | |
| 584 | | ta = (a * (spix + 1)) >> 8; |
| 585 | | tr = (r * ta + RGB_RED(dpix) * (0x100 - ta)) >> 8; |
| 586 | | tg = (g * ta + RGB_GREEN(dpix) * (0x100 - ta)) >> 8; |
| 587 | | tb = (b * ta + RGB_BLUE(dpix) * (0x100 - ta)) >> 8; |
| 869 | UINT32 ta = (a * (spix + 1)) >> 8; |
| 870 | UINT32 tr = (r * ta + RGB_RED(dpix) * (0x100 - ta)) >> 8; |
| 871 | UINT32 tg = (g * ta + RGB_GREEN(dpix) * (0x100 - ta)) >> 8; |
| 872 | UINT32 tb = (b * ta + RGB_BLUE(dpix) * (0x100 - ta)) >> 8; |
| 588 | 873 | d[effx] = MAKE_ARGB(0xff, tr, tg, tb); |
| 589 | 874 | } |
| 590 | 875 | } |
| r9411 | r9412 | |
| 592 | 877 | } |
| 593 | 878 | } |
| 594 | 879 | |
| 595 | | /* advance in the X direction */ |
| 880 | // advance in the X direction |
| 596 | 881 | curx += render_font_get_char_width(font, bounds.max_y - bounds.min_y, aspect, *s); |
| 597 | 882 | } |
| 598 | 883 | |
| 599 | | /* free the temporary bitmap and font */ |
| 884 | // free the temporary bitmap and font |
| 600 | 885 | global_free(tempbitmap); |
| 601 | 886 | render_font_free(font); |
| 602 | 887 | } |
| 603 | 888 | |
| 604 | 889 | |
| 605 | | /*------------------------------------------------- |
| 606 | | draw_segment_horizontal_caps - draw a |
| 607 | | horizontal LED segment with definable end |
| 608 | | and start points |
| 609 | | -------------------------------------------------*/ |
| 890 | //------------------------------------------------- |
| 891 | // load_bitmap - load a PNG file with artwork for |
| 892 | // a component |
| 893 | //------------------------------------------------- |
| 610 | 894 | |
| 611 | | static void draw_segment_horizontal_caps(bitmap_t &dest, int minx, int maxx, int midy, int width, int caps, rgb_t color) |
| 895 | bitmap_t *layout_element::component::load_bitmap() |
| 612 | 896 | { |
| 613 | | int x, y; |
| 897 | // load the basic bitmap |
| 898 | bitmap_t *bitmap = render_load_png(OPTION_ARTPATH, m_dirname, m_imagefile, NULL, &m_hasalpha); |
| 899 | if (bitmap != NULL && m_alphafile) |
| 614 | 900 | |
| 615 | | /* loop over the width of the segment */ |
| 616 | | for (y = 0; y < width / 2; y++) |
| 617 | | { |
| 618 | | UINT32 *d0 = BITMAP_ADDR32(&dest, midy - y, 0); |
| 619 | | UINT32 *d1 = BITMAP_ADDR32(&dest, midy + y, 0); |
| 620 | | int ty = (y < width / 8) ? width / 8 : y; |
| 621 | | |
| 622 | | /* loop over the length of the segment */ |
| 623 | | for (x = minx + ((caps & LINE_CAP_START) ? ty : 0); x < maxx - ((caps & LINE_CAP_END) ? ty : 0); x++) |
| 624 | | d0[x] = d1[x] = color; |
| 625 | | } |
| 626 | | } |
| 627 | | |
| 628 | | |
| 629 | | /*------------------------------------------------- |
| 630 | | draw_segment_horizontal - draw a horizontal |
| 631 | | LED segment |
| 632 | | -------------------------------------------------*/ |
| 633 | | |
| 634 | | static void draw_segment_horizontal(bitmap_t &dest, int minx, int maxx, int midy, int width, rgb_t color) |
| 635 | | { |
| 636 | | draw_segment_horizontal_caps(dest, minx, maxx, midy, width, LINE_CAP_START | LINE_CAP_END, color); |
| 637 | | } |
| 638 | | |
| 639 | | |
| 640 | | /*------------------------------------------------- |
| 641 | | draw_segment_vertical_caps - draw a |
| 642 | | vertical LED segment with definable end |
| 643 | | and start points |
| 644 | | -------------------------------------------------*/ |
| 645 | | |
| 646 | | static void draw_segment_vertical_caps(bitmap_t &dest, int miny, int maxy, int midx, int width, int caps, rgb_t color) |
| 647 | | { |
| 648 | | int x, y; |
| 649 | | |
| 650 | | /* loop over the width of the segment */ |
| 651 | | for (x = 0; x < width / 2; x++) |
| 652 | | { |
| 653 | | UINT32 *d0 = BITMAP_ADDR32(&dest, 0, midx - x); |
| 654 | | UINT32 *d1 = BITMAP_ADDR32(&dest, 0, midx + x); |
| 655 | | int tx = (x < width / 8) ? width / 8 : x; |
| 656 | | |
| 657 | | /* loop over the length of the segment */ |
| 658 | | for (y = miny + ((caps & LINE_CAP_START) ? tx : 0); y < maxy - ((caps & LINE_CAP_END) ? tx : 0); y++) |
| 659 | | d0[y * dest.rowpixels] = d1[y * dest.rowpixels] = color; |
| 660 | | } |
| 661 | | } |
| 662 | | |
| 663 | | |
| 664 | | /*------------------------------------------------- |
| 665 | | draw_segment_vertical - draw a vertical |
| 666 | | LED segment |
| 667 | | -------------------------------------------------*/ |
| 668 | | |
| 669 | | static void draw_segment_vertical(bitmap_t &dest, int miny, int maxy, int midx, int width, rgb_t color) |
| 670 | | { |
| 671 | | draw_segment_vertical_caps(dest, miny, maxy, midx, width, LINE_CAP_START | LINE_CAP_END, color); |
| 672 | | } |
| 673 | | |
| 674 | | |
| 675 | | /*------------------------------------------------- |
| 676 | | draw_segment_diagonal_1 - draw a diagonal |
| 677 | | LED segment that looks like this: / |
| 678 | | -------------------------------------------------*/ |
| 679 | | |
| 680 | | static void draw_segment_diagonal_1(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color) |
| 681 | | { |
| 682 | | int x, y; |
| 683 | | float ratio; |
| 684 | | |
| 685 | | /* compute parameters */ |
| 686 | | width *= 1.5; |
| 687 | | ratio = (maxy - miny - width) / (float)(maxx - minx); |
| 688 | | |
| 689 | | /* draw line */ |
| 690 | | for (x = minx; x < maxx; x++) |
| 691 | | if (x >= 0 && x < dest.width) |
| 901 | // load the alpha bitmap if specified |
| 902 | if (render_load_png(OPTION_ARTPATH, m_dirname, m_alphafile, bitmap, &m_hasalpha) == NULL) |
| 692 | 903 | { |
| 693 | | UINT32 *d = BITMAP_ADDR32(&dest, 0, x); |
| 694 | | int step = (x - minx) * ratio; |
| 695 | | |
| 696 | | for (y = maxy - width - step; y < maxy - step; y++) |
| 697 | | if (y >= 0 && y < dest.height) |
| 698 | | { |
| 699 | | d[y * dest.rowpixels] = color; |
| 700 | | } |
| 904 | global_free(bitmap); |
| 905 | bitmap = NULL; |
| 701 | 906 | } |
| 702 | | } |
| 703 | 907 | |
| 704 | | |
| 705 | | /*------------------------------------------------- |
| 706 | | draw_segment_diagonal_2 - draw a diagonal |
| 707 | | LED segment that looks like this: \ |
| 708 | | -------------------------------------------------*/ |
| 709 | | |
| 710 | | static void draw_segment_diagonal_2(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color) |
| 711 | | { |
| 712 | | int x, y; |
| 713 | | float ratio; |
| 714 | | |
| 715 | | /* compute parameters */ |
| 716 | | width *= 1.5; |
| 717 | | ratio = (maxy - miny - width) / (float)(maxx - minx); |
| 718 | | |
| 719 | | /* draw line */ |
| 720 | | for (x = minx; x < maxx; x++) |
| 721 | | if (x >= 0 && x < dest.width) |
| 722 | | { |
| 723 | | UINT32 *d = BITMAP_ADDR32(&dest, 0, x); |
| 724 | | int step = (x - minx) * ratio; |
| 725 | | |
| 726 | | for (y = miny + step; y < miny + step + width; y++) |
| 727 | | if (y >= 0 && y < dest.height) |
| 728 | | { |
| 729 | | d[y * dest.rowpixels] = color; |
| 730 | | } |
| 731 | | } |
| 732 | | } |
| 733 | | |
| 734 | | |
| 735 | | /*------------------------------------------------- |
| 736 | | draw_segment_decimal - draw a decimal point |
| 737 | | -------------------------------------------------*/ |
| 738 | | |
| 739 | | static void draw_segment_decimal(bitmap_t &dest, int midx, int midy, int width, rgb_t color) |
| 740 | | { |
| 741 | | float ooradius2; |
| 742 | | UINT32 x, y; |
| 743 | | |
| 744 | | /* compute parameters */ |
| 745 | | width /= 2; |
| 746 | | ooradius2 = 1.0f / (float)(width * width); |
| 747 | | |
| 748 | | /* iterate over y */ |
| 749 | | for (y = 0; y <= width; y++) |
| 908 | // if we can't load the bitmap, allocate a dummy one and report an error |
| 909 | if (bitmap == NULL) |
| 750 | 910 | { |
| 751 | | UINT32 *d0 = BITMAP_ADDR32(&dest, midy - y, 0); |
| 752 | | UINT32 *d1 = BITMAP_ADDR32(&dest, midy + y, 0); |
| 753 | | float xval = width * sqrt(1.0f - (float)(y * y) * ooradius2); |
| 754 | | INT32 left, right; |
| 911 | // draw some stripes in the bitmap |
| 912 | bitmap = global_alloc(bitmap_t(100, 100, BITMAP_FORMAT_ARGB32)); |
| 913 | bitmap_fill(bitmap, NULL, 0); |
| 914 | for (int step = 0; step < 100; step += 25) |
| 915 | for (int line = 0; line < 100; line++) |
| 916 | *BITMAP_ADDR32(bitmap, (step + line) % 100, line % 100) = MAKE_ARGB(0xff,0xff,0xff,0xff); |
| 755 | 917 | |
| 756 | | /* compute left/right coordinates */ |
| 757 | | left = midx - (INT32)(xval + 0.5f); |
| 758 | | right = midx + (INT32)(xval + 0.5f); |
| 759 | | |
| 760 | | /* draw this scanline */ |
| 761 | | for (x = left; x < right; x++) |
| 762 | | d0[x] = d1[x] = color; |
| 918 | // log an error |
| 919 | if (!m_alphafile) |
| 920 | mame_printf_warning("Unable to load component bitmap '%s'", m_imagefile.cstr()); |
| 921 | else |
| 922 | mame_printf_warning("Unable to load component bitmap '%s'/'%s'", m_imagefile.cstr(), m_alphafile.cstr()); |
| 763 | 923 | } |
| 764 | | } |
| 765 | 924 | |
| 766 | | /*------------------------------------------------- |
| 767 | | draw_segment_comma - draw a comma tail |
| 768 | | -------------------------------------------------*/ |
| 769 | | #if 0 |
| 770 | | static void draw_segment_comma(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color) |
| 771 | | { |
| 772 | | int x, y; |
| 773 | | float ratio; |
| 774 | | |
| 775 | | /* compute parameters */ |
| 776 | | width *= 1.5; |
| 777 | | ratio = (maxy - miny - width) / (float)(maxx - minx); |
| 778 | | |
| 779 | | /* draw line */ |
| 780 | | for (x = minx; x < maxx; x++) |
| 781 | | { |
| 782 | | UINT32 *d = BITMAP_ADDR32(&dest, 0, x); |
| 783 | | int step = (x - minx) * ratio; |
| 784 | | |
| 785 | | for (y = maxy; y < maxy - width - step; y--) |
| 786 | | { |
| 787 | | d[y * dest.rowpixels] = color; |
| 788 | | } |
| 789 | | } |
| 925 | return bitmap; |
| 790 | 926 | } |
| 791 | | #endif |
| 792 | 927 | |
| 793 | 928 | |
| 794 | | /*------------------------------------------------- |
| 795 | | apply_skew - apply skew to a bitmap_t |
| 796 | | -------------------------------------------------*/ |
| 929 | //------------------------------------------------- |
| 930 | // draw_led7seg - draw a 7-segment LCD |
| 931 | //------------------------------------------------- |
| 797 | 932 | |
| 798 | | static void apply_skew(bitmap_t &dest, int skewwidth) |
| 933 | void layout_element::component::draw_led7seg(bitmap_t &dest, const rectangle &bounds, int pattern) |
| 799 | 934 | { |
| 800 | | int x, y; |
| 801 | | |
| 802 | | for (y = 0; y < dest.height; y++) |
| 803 | | { |
| 804 | | UINT32 *destrow = BITMAP_ADDR32(&dest, y, 0); |
| 805 | | int offs = skewwidth * (dest.height - y) / dest.height; |
| 806 | | for (x = dest.width - skewwidth - 1; x >= 0; x--) |
| 807 | | destrow[x + offs] = destrow[x]; |
| 808 | | for (x = 0; x < offs; x++) |
| 809 | | destrow[x] = 0; |
| 810 | | } |
| 811 | | } |
| 812 | | |
| 813 | | |
| 814 | | /*------------------------------------------------- |
| 815 | | layout_element_draw_led7seg - draw a |
| 816 | | 7-segment LCD |
| 817 | | -------------------------------------------------*/ |
| 818 | | |
| 819 | | static void layout_element_draw_led7seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern) |
| 820 | | { |
| 821 | 935 | const rgb_t onpen = MAKE_ARGB(0xff,0xff,0xff,0xff); |
| 822 | 936 | const rgb_t offpen = MAKE_ARGB(0xff,0x20,0x20,0x20); |
| 823 | | int bmwidth, bmheight, segwidth, skewwidth; |
| 824 | | bitmap_t *tempbitmap; |
| 825 | 937 | |
| 826 | | /* sizes for computation */ |
| 827 | | bmwidth = 250; |
| 828 | | bmheight = 400; |
| 829 | | segwidth = 40; |
| 830 | | skewwidth = 40; |
| 938 | // sizes for computation |
| 939 | int bmwidth = 250; |
| 940 | int bmheight = 400; |
| 941 | int segwidth = 40; |
| 942 | int skewwidth = 40; |
| 831 | 943 | |
| 832 | | /* allocate a temporary bitmap for drawing */ |
| 833 | | tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32)); |
| 944 | // allocate a temporary bitmap for drawing |
| 945 | bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32)); |
| 834 | 946 | bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff,0x00,0x00,0x00)); |
| 835 | 947 | |
| 836 | | /* top bar */ |
| 948 | // top bar |
| 837 | 949 | draw_segment_horizontal(*tempbitmap, 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, 0 + segwidth/2, segwidth, (pattern & (1 << 0)) ? onpen : offpen); |
| 838 | 950 | |
| 839 | | /* top-right bar */ |
| 951 | // top-right bar |
| 840 | 952 | draw_segment_vertical(*tempbitmap, 0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2, segwidth, (pattern & (1 << 1)) ? onpen : offpen); |
| 841 | 953 | |
| 842 | | /* bottom-right bar */ |
| 954 | // bottom-right bar |
| 843 | 955 | draw_segment_vertical(*tempbitmap, bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2, segwidth, (pattern & (1 << 2)) ? onpen : offpen); |
| 844 | 956 | |
| 845 | | /* bottom bar */ |
| 957 | // bottom bar |
| 846 | 958 | draw_segment_horizontal(*tempbitmap, 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, bmheight - segwidth/2, segwidth, (pattern & (1 << 3)) ? onpen : offpen); |
| 847 | 959 | |
| 848 | | /* bottom-left bar */ |
| 960 | // bottom-left bar |
| 849 | 961 | draw_segment_vertical(*tempbitmap, bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2, segwidth, (pattern & (1 << 4)) ? onpen : offpen); |
| 850 | 962 | |
| 851 | | /* top-left bar */ |
| 963 | // top-left bar |
| 852 | 964 | draw_segment_vertical(*tempbitmap, 0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2, segwidth, (pattern & (1 << 5)) ? onpen : offpen); |
| 853 | 965 | |
| 854 | | /* middle bar */ |
| 966 | // middle bar |
| 855 | 967 | draw_segment_horizontal(*tempbitmap, 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, bmheight/2, segwidth, (pattern & (1 << 6)) ? onpen : offpen); |
| 856 | 968 | |
| 857 | | /* apply skew */ |
| 969 | // apply skew |
| 858 | 970 | apply_skew(*tempbitmap, 40); |
| 859 | 971 | |
| 860 | | /* decimal point */ |
| 972 | // decimal point |
| 861 | 973 | draw_segment_decimal(*tempbitmap, bmwidth + segwidth/2, bmheight - segwidth/2, segwidth, (pattern & (1 << 7)) ? onpen : offpen); |
| 862 | 974 | |
| 863 | | /* resample to the target size */ |
| 864 | | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color); |
| 975 | // resample to the target size |
| 976 | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color); |
| 865 | 977 | |
| 866 | 978 | global_free(tempbitmap); |
| 867 | 979 | } |
| 868 | 980 | |
| 869 | 981 | |
| 870 | | /*------------------------------------------------- |
| 871 | | layout_element_draw_led14seg - draw a |
| 872 | | 14-segment LCD |
| 873 | | -------------------------------------------------*/ |
| 982 | //------------------------------------------------- |
| 983 | // draw_led14seg - draw a 14-segment LCD |
| 984 | //------------------------------------------------- |
| 874 | 985 | |
| 875 | | static void layout_element_draw_led14seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern) |
| 986 | void layout_element::component::draw_led14seg(bitmap_t &dest, const rectangle &bounds, int pattern) |
| 876 | 987 | { |
| 877 | 988 | const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff); |
| 878 | 989 | const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20); |
| 879 | | int bmwidth, bmheight, segwidth, skewwidth; |
| 880 | | bitmap_t *tempbitmap; |
| 881 | 990 | |
| 882 | | /* sizes for computation */ |
| 883 | | bmwidth = 250; |
| 884 | | bmheight = 400; |
| 885 | | segwidth = 40; |
| 886 | | skewwidth = 40; |
| 991 | // sizes for computation |
| 992 | int bmwidth = 250; |
| 993 | int bmheight = 400; |
| 994 | int segwidth = 40; |
| 995 | int skewwidth = 40; |
| 887 | 996 | |
| 888 | | /* allocate a temporary bitmap for drawing */ |
| 889 | | tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32)); |
| 997 | // allocate a temporary bitmap for drawing |
| 998 | bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32)); |
| 890 | 999 | bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00)); |
| 891 | 1000 | |
| 892 | | /* top bar */ |
| 1001 | // top bar |
| 893 | 1002 | draw_segment_horizontal(*tempbitmap, |
| 894 | 1003 | 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, 0 + segwidth/2, |
| 895 | 1004 | segwidth, (pattern & (1 << 0)) ? onpen : offpen); |
| 896 | 1005 | |
| 897 | | /* right-top bar */ |
| 1006 | // right-top bar |
| 898 | 1007 | draw_segment_vertical(*tempbitmap, |
| 899 | 1008 | 0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2, |
| 900 | 1009 | segwidth, (pattern & (1 << 1)) ? onpen : offpen); |
| 901 | 1010 | |
| 902 | | /* right-bottom bar */ |
| 1011 | // right-bottom bar |
| 903 | 1012 | draw_segment_vertical(*tempbitmap, |
| 904 | 1013 | bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2, |
| 905 | 1014 | segwidth, (pattern & (1 << 2)) ? onpen : offpen); |
| 906 | 1015 | |
| 907 | | /* bottom bar */ |
| 1016 | // bottom bar |
| 908 | 1017 | draw_segment_horizontal(*tempbitmap, |
| 909 | 1018 | 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, bmheight - segwidth/2, |
| 910 | 1019 | segwidth, (pattern & (1 << 3)) ? onpen : offpen); |
| 911 | 1020 | |
| 912 | | /* left-bottom bar */ |
| 1021 | // left-bottom bar |
| 913 | 1022 | draw_segment_vertical(*tempbitmap, |
| 914 | 1023 | bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2, |
| 915 | 1024 | segwidth, (pattern & (1 << 4)) ? onpen : offpen); |
| 916 | 1025 | |
| 917 | | /* left-top bar */ |
| 1026 | // left-top bar |
| 918 | 1027 | draw_segment_vertical(*tempbitmap, |
| 919 | 1028 | 0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2, |
| 920 | 1029 | segwidth, (pattern & (1 << 5)) ? onpen : offpen); |
| 921 | 1030 | |
| 922 | | /* horizontal-middle-left bar */ |
| 1031 | // horizontal-middle-left bar |
| 923 | 1032 | draw_segment_horizontal_caps(*tempbitmap, |
| 924 | 1033 | 0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight/2, |
| 925 | 1034 | segwidth, LINE_CAP_START, (pattern & (1 << 6)) ? onpen : offpen); |
| 926 | 1035 | |
| 927 | | /* horizontal-middle-right bar */ |
| 1036 | // horizontal-middle-right bar |
| 928 | 1037 | draw_segment_horizontal_caps(*tempbitmap, |
| 929 | 1038 | 0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight/2, |
| 930 | 1039 | segwidth, LINE_CAP_END, (pattern & (1 << 7)) ? onpen : offpen); |
| 931 | 1040 | |
| 932 | | /* vertical-middle-top bar */ |
| 1041 | // vertical-middle-top bar |
| 933 | 1042 | draw_segment_vertical_caps(*tempbitmap, |
| 934 | 1043 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, bmwidth/2, |
| 935 | 1044 | segwidth, LINE_CAP_NONE, (pattern & (1 << 8)) ? onpen : offpen); |
| 936 | 1045 | |
| 937 | | /* vertical-middle-bottom bar */ |
| 1046 | // vertical-middle-bottom bar |
| 938 | 1047 | draw_segment_vertical_caps(*tempbitmap, |
| 939 | 1048 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, bmwidth/2, |
| 940 | 1049 | segwidth, LINE_CAP_NONE, (pattern & (1 << 9)) ? onpen : offpen); |
| 941 | 1050 | |
| 942 | | /* diagonal-left-bottom bar */ |
| 1051 | // diagonal-left-bottom bar |
| 943 | 1052 | draw_segment_diagonal_1(*tempbitmap, |
| 944 | 1053 | 0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5, |
| 945 | 1054 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, |
| 946 | 1055 | segwidth, (pattern & (1 << 10)) ? onpen : offpen); |
| 947 | 1056 | |
| 948 | | /* diagonal-left-top bar */ |
| 1057 | // diagonal-left-top bar |
| 949 | 1058 | draw_segment_diagonal_2(*tempbitmap, |
| 950 | 1059 | 0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5, |
| 951 | 1060 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, |
| 952 | 1061 | segwidth, (pattern & (1 << 11)) ? onpen : offpen); |
| 953 | 1062 | |
| 954 | | /* diagonal-right-top bar */ |
| 1063 | // diagonal-right-top bar |
| 955 | 1064 | draw_segment_diagonal_1(*tempbitmap, |
| 956 | 1065 | bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5, |
| 957 | 1066 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, |
| 958 | 1067 | segwidth, (pattern & (1 << 12)) ? onpen : offpen); |
| 959 | 1068 | |
| 960 | | /* diagonal-right-bottom bar */ |
| 1069 | // diagonal-right-bottom bar |
| 961 | 1070 | draw_segment_diagonal_2(*tempbitmap, |
| 962 | 1071 | bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5, |
| 963 | 1072 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, |
| 964 | 1073 | segwidth, (pattern & (1 << 13)) ? onpen : offpen); |
| 965 | 1074 | |
| 966 | | /* apply skew */ |
| 1075 | // apply skew |
| 967 | 1076 | apply_skew(*tempbitmap, 40); |
| 968 | 1077 | |
| 969 | | /* resample to the target size */ |
| 970 | | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color); |
| 1078 | // resample to the target size |
| 1079 | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color); |
| 971 | 1080 | |
| 972 | 1081 | global_free(tempbitmap); |
| 973 | 1082 | } |
| 974 | 1083 | |
| 975 | 1084 | |
| 976 | | /*------------------------------------------------- |
| 977 | | layout_element_draw_led14segsc - draw a |
| 978 | | 14-segment LCD with semicolon (2 extra segments) |
| 979 | | -------------------------------------------------*/ |
| 1085 | //------------------------------------------------- |
| 1086 | // draw_led14segsc - draw a 14-segment LCD with |
| 1087 | // semicolon (2 extra segments) |
| 1088 | //------------------------------------------------- |
| 980 | 1089 | |
| 981 | | static void layout_element_draw_led14segsc(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern) |
| 1090 | void layout_element::component::draw_led14segsc(bitmap_t &dest, const rectangle &bounds, int pattern) |
| 982 | 1091 | { |
| 983 | 1092 | const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff); |
| 984 | 1093 | const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20); |
| 985 | | int bmwidth, bmheight, segwidth, skewwidth; |
| 986 | | bitmap_t *tempbitmap; |
| 987 | 1094 | |
| 988 | | /* sizes for computation */ |
| 989 | | bmwidth = 250; |
| 990 | | bmheight = 400; |
| 991 | | segwidth = 40; |
| 992 | | skewwidth = 40; |
| 1095 | // sizes for computation |
| 1096 | int bmwidth = 250; |
| 1097 | int bmheight = 400; |
| 1098 | int segwidth = 40; |
| 1099 | int skewwidth = 40; |
| 993 | 1100 | |
| 994 | | /* allocate a temporary bitmap for drawing, adding some extra space for the tail */ |
| 995 | | tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight + segwidth, BITMAP_FORMAT_ARGB32)); |
| 1101 | // allocate a temporary bitmap for drawing, adding some extra space for the tail |
| 1102 | bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight + segwidth, BITMAP_FORMAT_ARGB32)); |
| 996 | 1103 | bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00)); |
| 997 | 1104 | |
| 998 | | /* top bar */ |
| 1105 | // top bar |
| 999 | 1106 | draw_segment_horizontal(*tempbitmap, |
| 1000 | 1107 | 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, 0 + segwidth/2, |
| 1001 | 1108 | segwidth, (pattern & (1 << 0)) ? onpen : offpen); |
| 1002 | 1109 | |
| 1003 | | /* right-top bar */ |
| 1110 | // right-top bar |
| 1004 | 1111 | draw_segment_vertical(*tempbitmap, |
| 1005 | 1112 | 0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2, |
| 1006 | 1113 | segwidth, (pattern & (1 << 1)) ? onpen : offpen); |
| 1007 | 1114 | |
| 1008 | | /* right-bottom bar */ |
| 1115 | // right-bottom bar |
| 1009 | 1116 | draw_segment_vertical(*tempbitmap, |
| 1010 | 1117 | bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2, |
| 1011 | 1118 | segwidth, (pattern & (1 << 2)) ? onpen : offpen); |
| 1012 | 1119 | |
| 1013 | | /* bottom bar */ |
| 1120 | // bottom bar |
| 1014 | 1121 | draw_segment_horizontal(*tempbitmap, |
| 1015 | 1122 | 0 + 2*segwidth/3, bmwidth - 2*segwidth/3, bmheight - segwidth/2, |
| 1016 | 1123 | segwidth, (pattern & (1 << 3)) ? onpen : offpen); |
| 1017 | 1124 | |
| 1018 | | /* left-bottom bar */ |
| 1125 | // left-bottom bar |
| 1019 | 1126 | draw_segment_vertical(*tempbitmap, |
| 1020 | 1127 | bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2, |
| 1021 | 1128 | segwidth, (pattern & (1 << 4)) ? onpen : offpen); |
| 1022 | 1129 | |
| 1023 | | /* left-top bar */ |
| 1130 | // left-top bar |
| 1024 | 1131 | draw_segment_vertical(*tempbitmap, |
| 1025 | 1132 | 0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2, |
| 1026 | 1133 | segwidth, (pattern & (1 << 5)) ? onpen : offpen); |
| 1027 | 1134 | |
| 1028 | | /* horizontal-middle-left bar */ |
| 1135 | // horizontal-middle-left bar |
| 1029 | 1136 | draw_segment_horizontal_caps(*tempbitmap, |
| 1030 | 1137 | 0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight/2, |
| 1031 | 1138 | segwidth, LINE_CAP_START, (pattern & (1 << 6)) ? onpen : offpen); |
| 1032 | 1139 | |
| 1033 | | /* horizontal-middle-right bar */ |
| 1140 | // horizontal-middle-right bar |
| 1034 | 1141 | draw_segment_horizontal_caps(*tempbitmap, |
| 1035 | 1142 | 0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight/2, |
| 1036 | 1143 | segwidth, LINE_CAP_END, (pattern & (1 << 7)) ? onpen : offpen); |
| 1037 | 1144 | |
| 1038 | | /* vertical-middle-top bar */ |
| 1145 | // vertical-middle-top bar |
| 1039 | 1146 | draw_segment_vertical_caps(*tempbitmap, |
| 1040 | 1147 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, bmwidth/2, |
| 1041 | 1148 | segwidth, LINE_CAP_NONE, (pattern & (1 << 8)) ? onpen : offpen); |
| 1042 | 1149 | |
| 1043 | | /* vertical-middle-bottom bar */ |
| 1150 | // vertical-middle-bottom bar |
| 1044 | 1151 | draw_segment_vertical_caps(*tempbitmap, |
| 1045 | 1152 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, bmwidth/2, |
| 1046 | 1153 | segwidth, LINE_CAP_NONE, (pattern & (1 << 9)) ? onpen : offpen); |
| 1047 | 1154 | |
| 1048 | | /* diagonal-left-bottom bar */ |
| 1155 | // diagonal-left-bottom bar |
| 1049 | 1156 | draw_segment_diagonal_1(*tempbitmap, |
| 1050 | 1157 | 0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5, |
| 1051 | 1158 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, |
| 1052 | 1159 | segwidth, (pattern & (1 << 10)) ? onpen : offpen); |
| 1053 | 1160 | |
| 1054 | | /* diagonal-left-top bar */ |
| 1161 | // diagonal-left-top bar |
| 1055 | 1162 | draw_segment_diagonal_2(*tempbitmap, |
| 1056 | 1163 | 0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5, |
| 1057 | 1164 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, |
| 1058 | 1165 | segwidth, (pattern & (1 << 11)) ? onpen : offpen); |
| 1059 | 1166 | |
| 1060 | | /* diagonal-right-top bar */ |
| 1167 | // diagonal-right-top bar |
| 1061 | 1168 | draw_segment_diagonal_1(*tempbitmap, |
| 1062 | 1169 | bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5, |
| 1063 | 1170 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, |
| 1064 | 1171 | segwidth, (pattern & (1 << 12)) ? onpen : offpen); |
| 1065 | 1172 | |
| 1066 | | /* diagonal-right-bottom bar */ |
| 1173 | // diagonal-right-bottom bar |
| 1067 | 1174 | draw_segment_diagonal_2(*tempbitmap, |
| 1068 | 1175 | bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5, |
| 1069 | 1176 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, |
| 1070 | 1177 | segwidth, (pattern & (1 << 13)) ? onpen : offpen); |
| 1071 | 1178 | |
| 1072 | | /* apply skew */ |
| 1179 | // apply skew |
| 1073 | 1180 | apply_skew(*tempbitmap, 40); |
| 1074 | 1181 | |
| 1075 | | /* decimal point */ |
| 1182 | // decimal point |
| 1076 | 1183 | draw_segment_decimal(*tempbitmap, bmwidth + segwidth/2, bmheight - segwidth/2, segwidth, (pattern & (1 << 14)) ? onpen : offpen); |
| 1077 | 1184 | |
| 1078 | | /* comma tail */ |
| 1185 | // comma tail |
| 1079 | 1186 | draw_segment_diagonal_1(*tempbitmap, |
| 1080 | 1187 | bmwidth - (segwidth/2), bmwidth + segwidth, |
| 1081 | 1188 | bmheight - (segwidth), bmheight + segwidth*1.5, |
| 1082 | 1189 | segwidth/2, (pattern & (1 << 15)) ? onpen : offpen); |
| 1083 | 1190 | |
| 1084 | | /* resample to the target size */ |
| 1085 | | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color); |
| 1191 | // resample to the target size |
| 1192 | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color); |
| 1086 | 1193 | |
| 1087 | 1194 | global_free(tempbitmap); |
| 1088 | 1195 | } |
| 1089 | 1196 | |
| 1090 | 1197 | |
| 1091 | | /*------------------------------------------------- |
| 1092 | | layout_element_draw_led16seg - draw a |
| 1093 | | 16-segment LCD |
| 1094 | | -------------------------------------------------*/ |
| 1198 | //------------------------------------------------- |
| 1199 | // draw_led16seg - draw a 16-segment LCD |
| 1200 | //------------------------------------------------- |
| 1095 | 1201 | |
| 1096 | | static void layout_element_draw_led16seg(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern) |
| 1202 | void layout_element::component::draw_led16seg(bitmap_t &dest, const rectangle &bounds, int pattern) |
| 1097 | 1203 | { |
| 1098 | 1204 | const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff); |
| 1099 | 1205 | const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20); |
| 1100 | | int bmwidth, bmheight, segwidth, skewwidth; |
| 1101 | | bitmap_t *tempbitmap; |
| 1102 | 1206 | |
| 1103 | | /* sizes for computation */ |
| 1104 | | bmwidth = 250; |
| 1105 | | bmheight = 400; |
| 1106 | | segwidth = 40; |
| 1107 | | skewwidth = 40; |
| 1207 | // sizes for computation |
| 1208 | int bmwidth = 250; |
| 1209 | int bmheight = 400; |
| 1210 | int segwidth = 40; |
| 1211 | int skewwidth = 40; |
| 1108 | 1212 | |
| 1109 | | /* allocate a temporary bitmap for drawing */ |
| 1110 | | tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32)); |
| 1213 | // allocate a temporary bitmap for drawing |
| 1214 | bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight, BITMAP_FORMAT_ARGB32)); |
| 1111 | 1215 | bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00)); |
| 1112 | 1216 | |
| 1113 | | /* top-left bar */ |
| 1217 | // top-left bar |
| 1114 | 1218 | draw_segment_horizontal_caps(*tempbitmap, |
| 1115 | 1219 | 0 + 2*segwidth/3, bmwidth/2 - segwidth/10, 0 + segwidth/2, |
| 1116 | 1220 | segwidth, LINE_CAP_START, (pattern & (1 << 0)) ? onpen : offpen); |
| 1117 | 1221 | |
| 1118 | | /* top-right bar */ |
| 1222 | // top-right bar |
| 1119 | 1223 | draw_segment_horizontal_caps(*tempbitmap, |
| 1120 | 1224 | 0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, 0 + segwidth/2, |
| 1121 | 1225 | segwidth, LINE_CAP_END, (pattern & (1 << 1)) ? onpen : offpen); |
| 1122 | 1226 | |
| 1123 | | /* right-top bar */ |
| 1227 | // right-top bar |
| 1124 | 1228 | draw_segment_vertical(*tempbitmap, |
| 1125 | 1229 | 0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2, |
| 1126 | 1230 | segwidth, (pattern & (1 << 2)) ? onpen : offpen); |
| 1127 | 1231 | |
| 1128 | | /* right-bottom bar */ |
| 1232 | // right-bottom bar |
| 1129 | 1233 | draw_segment_vertical(*tempbitmap, |
| 1130 | 1234 | bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2, |
| 1131 | 1235 | segwidth, (pattern & (1 << 3)) ? onpen : offpen); |
| 1132 | 1236 | |
| 1133 | | /* bottom-right bar */ |
| 1237 | // bottom-right bar |
| 1134 | 1238 | draw_segment_horizontal_caps(*tempbitmap, |
| 1135 | 1239 | 0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight - segwidth/2, |
| 1136 | 1240 | segwidth, LINE_CAP_END, (pattern & (1 << 4)) ? onpen : offpen); |
| 1137 | 1241 | |
| 1138 | | /* bottom-left bar */ |
| 1242 | // bottom-left bar |
| 1139 | 1243 | draw_segment_horizontal_caps(*tempbitmap, |
| 1140 | 1244 | 0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight - segwidth/2, |
| 1141 | 1245 | segwidth, LINE_CAP_START, (pattern & (1 << 5)) ? onpen : offpen); |
| 1142 | 1246 | |
| 1143 | | /* left-bottom bar */ |
| 1247 | // left-bottom bar |
| 1144 | 1248 | draw_segment_vertical(*tempbitmap, |
| 1145 | 1249 | bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2, |
| 1146 | 1250 | segwidth, (pattern & (1 << 6)) ? onpen : offpen); |
| 1147 | 1251 | |
| 1148 | | /* left-top bar */ |
| 1252 | // left-top bar |
| 1149 | 1253 | draw_segment_vertical(*tempbitmap, |
| 1150 | 1254 | 0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2, |
| 1151 | 1255 | segwidth, (pattern & (1 << 7)) ? onpen : offpen); |
| 1152 | 1256 | |
| 1153 | | /* horizontal-middle-left bar */ |
| 1257 | // horizontal-middle-left bar |
| 1154 | 1258 | draw_segment_horizontal_caps(*tempbitmap, |
| 1155 | 1259 | 0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight/2, |
| 1156 | 1260 | segwidth, LINE_CAP_START, (pattern & (1 << 8)) ? onpen : offpen); |
| 1157 | 1261 | |
| 1158 | | /* horizontal-middle-right bar */ |
| 1262 | // horizontal-middle-right bar |
| 1159 | 1263 | draw_segment_horizontal_caps(*tempbitmap, |
| 1160 | 1264 | 0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight/2, |
| 1161 | 1265 | segwidth, LINE_CAP_END, (pattern & (1 << 9)) ? onpen : offpen); |
| 1162 | 1266 | |
| 1163 | | /* vertical-middle-top bar */ |
| 1267 | // vertical-middle-top bar |
| 1164 | 1268 | draw_segment_vertical_caps(*tempbitmap, |
| 1165 | 1269 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, bmwidth/2, |
| 1166 | 1270 | segwidth, LINE_CAP_NONE, (pattern & (1 << 10)) ? onpen : offpen); |
| 1167 | 1271 | |
| 1168 | | /* vertical-middle-bottom bar */ |
| 1272 | // vertical-middle-bottom bar |
| 1169 | 1273 | draw_segment_vertical_caps(*tempbitmap, |
| 1170 | 1274 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, bmwidth/2, |
| 1171 | 1275 | segwidth, LINE_CAP_NONE, (pattern & (1 << 11)) ? onpen : offpen); |
| 1172 | 1276 | |
| 1173 | | /* diagonal-left-bottom bar */ |
| 1277 | // diagonal-left-bottom bar |
| 1174 | 1278 | draw_segment_diagonal_1(*tempbitmap, |
| 1175 | 1279 | 0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5, |
| 1176 | 1280 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, |
| 1177 | 1281 | segwidth, (pattern & (1 << 12)) ? onpen : offpen); |
| 1178 | 1282 | |
| 1179 | | /* diagonal-left-top bar */ |
| 1283 | // diagonal-left-top bar |
| 1180 | 1284 | draw_segment_diagonal_2(*tempbitmap, |
| 1181 | 1285 | 0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5, |
| 1182 | 1286 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, |
| 1183 | 1287 | segwidth, (pattern & (1 << 13)) ? onpen : offpen); |
| 1184 | 1288 | |
| 1185 | | /* diagonal-right-top bar */ |
| 1289 | // diagonal-right-top bar |
| 1186 | 1290 | draw_segment_diagonal_1(*tempbitmap, |
| 1187 | 1291 | bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5, |
| 1188 | 1292 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, |
| 1189 | 1293 | segwidth, (pattern & (1 << 14)) ? onpen : offpen); |
| 1190 | 1294 | |
| 1191 | | /* diagonal-right-bottom bar */ |
| 1295 | // diagonal-right-bottom bar |
| 1192 | 1296 | draw_segment_diagonal_2(*tempbitmap, |
| 1193 | 1297 | bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5, |
| 1194 | 1298 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, |
| 1195 | 1299 | segwidth, (pattern & (1 << 15)) ? onpen : offpen); |
| 1196 | 1300 | |
| 1197 | | /* apply skew */ |
| 1301 | // apply skew |
| 1198 | 1302 | apply_skew(*tempbitmap, 40); |
| 1199 | 1303 | |
| 1200 | | /* resample to the target size */ |
| 1201 | | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color); |
| 1304 | // resample to the target size |
| 1305 | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color); |
| 1202 | 1306 | |
| 1203 | 1307 | global_free(tempbitmap); |
| 1204 | 1308 | } |
| 1205 | 1309 | |
| 1206 | 1310 | |
| 1207 | | /*------------------------------------------------- |
| 1208 | | layout_element_draw_led16segsc - draw a |
| 1209 | | 16-segment LCD with semicolon (2 extra segments) |
| 1210 | | -------------------------------------------------*/ |
| 1311 | //------------------------------------------------- |
| 1312 | // draw_led16segsc - draw a 16-segment LCD with |
| 1313 | // semicolon (2 extra segments) |
| 1314 | //------------------------------------------------- |
| 1211 | 1315 | |
| 1212 | | static void layout_element_draw_led16segsc(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern) |
| 1316 | void layout_element::component::draw_led16segsc(bitmap_t &dest, const rectangle &bounds, int pattern) |
| 1213 | 1317 | { |
| 1214 | 1318 | const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff); |
| 1215 | 1319 | const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20); |
| 1216 | | int bmwidth, bmheight, segwidth, skewwidth; |
| 1217 | | bitmap_t *tempbitmap; |
| 1218 | 1320 | |
| 1219 | | /* sizes for computation */ |
| 1220 | | bmwidth = 250; |
| 1221 | | bmheight = 400; |
| 1222 | | segwidth = 40; |
| 1223 | | skewwidth = 40; |
| 1321 | // sizes for computation |
| 1322 | int bmwidth = 250; |
| 1323 | int bmheight = 400; |
| 1324 | int segwidth = 40; |
| 1325 | int skewwidth = 40; |
| 1224 | 1326 | |
| 1225 | | /* allocate a temporary bitmap for drawing */ |
| 1226 | | tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight + segwidth, BITMAP_FORMAT_ARGB32)); |
| 1327 | // allocate a temporary bitmap for drawing |
| 1328 | bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth + skewwidth, bmheight + segwidth, BITMAP_FORMAT_ARGB32)); |
| 1227 | 1329 | bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00)); |
| 1228 | 1330 | |
| 1229 | | /* top-left bar */ |
| 1331 | // top-left bar |
| 1230 | 1332 | draw_segment_horizontal_caps(*tempbitmap, |
| 1231 | 1333 | 0 + 2*segwidth/3, bmwidth/2 - segwidth/10, 0 + segwidth/2, |
| 1232 | 1334 | segwidth, LINE_CAP_START, (pattern & (1 << 0)) ? onpen : offpen); |
| 1233 | 1335 | |
| 1234 | | /* top-right bar */ |
| 1336 | // top-right bar |
| 1235 | 1337 | draw_segment_horizontal_caps(*tempbitmap, |
| 1236 | 1338 | 0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, 0 + segwidth/2, |
| 1237 | 1339 | segwidth, LINE_CAP_END, (pattern & (1 << 1)) ? onpen : offpen); |
| 1238 | 1340 | |
| 1239 | | /* right-top bar */ |
| 1341 | // right-top bar |
| 1240 | 1342 | draw_segment_vertical(*tempbitmap, |
| 1241 | 1343 | 0 + 2*segwidth/3, bmheight/2 - segwidth/3, bmwidth - segwidth/2, |
| 1242 | 1344 | segwidth, (pattern & (1 << 2)) ? onpen : offpen); |
| 1243 | 1345 | |
| 1244 | | /* right-bottom bar */ |
| 1346 | // right-bottom bar |
| 1245 | 1347 | draw_segment_vertical(*tempbitmap, |
| 1246 | 1348 | bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, bmwidth - segwidth/2, |
| 1247 | 1349 | segwidth, (pattern & (1 << 3)) ? onpen : offpen); |
| 1248 | 1350 | |
| 1249 | | /* bottom-right bar */ |
| 1351 | // bottom-right bar |
| 1250 | 1352 | draw_segment_horizontal_caps(*tempbitmap, |
| 1251 | 1353 | 0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight - segwidth/2, |
| 1252 | 1354 | segwidth, LINE_CAP_END, (pattern & (1 << 4)) ? onpen : offpen); |
| 1253 | 1355 | |
| 1254 | | /* bottom-left bar */ |
| 1356 | // bottom-left bar |
| 1255 | 1357 | draw_segment_horizontal_caps(*tempbitmap, |
| 1256 | 1358 | 0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight - segwidth/2, |
| 1257 | 1359 | segwidth, LINE_CAP_START, (pattern & (1 << 5)) ? onpen : offpen); |
| 1258 | 1360 | |
| 1259 | | /* left-bottom bar */ |
| 1361 | // left-bottom bar |
| 1260 | 1362 | draw_segment_vertical(*tempbitmap, |
| 1261 | 1363 | bmheight/2 + segwidth/3, bmheight - 2*segwidth/3, 0 + segwidth/2, |
| 1262 | 1364 | segwidth, (pattern & (1 << 6)) ? onpen : offpen); |
| 1263 | 1365 | |
| 1264 | | /* left-top bar */ |
| 1366 | // left-top bar |
| 1265 | 1367 | draw_segment_vertical(*tempbitmap, |
| 1266 | 1368 | 0 + 2*segwidth/3, bmheight/2 - segwidth/3, 0 + segwidth/2, |
| 1267 | 1369 | segwidth, (pattern & (1 << 7)) ? onpen : offpen); |
| 1268 | 1370 | |
| 1269 | | /* horizontal-middle-left bar */ |
| 1371 | // horizontal-middle-left bar |
| 1270 | 1372 | draw_segment_horizontal_caps(*tempbitmap, |
| 1271 | 1373 | 0 + 2*segwidth/3, bmwidth/2 - segwidth/10, bmheight/2, |
| 1272 | 1374 | segwidth, LINE_CAP_START, (pattern & (1 << 8)) ? onpen : offpen); |
| 1273 | 1375 | |
| 1274 | | /* horizontal-middle-right bar */ |
| 1376 | // horizontal-middle-right bar |
| 1275 | 1377 | draw_segment_horizontal_caps(*tempbitmap, |
| 1276 | 1378 | 0 + bmwidth/2 + segwidth/10, bmwidth - 2*segwidth/3, bmheight/2, |
| 1277 | 1379 | segwidth, LINE_CAP_END, (pattern & (1 << 9)) ? onpen : offpen); |
| 1278 | 1380 | |
| 1279 | | /* vertical-middle-top bar */ |
| 1381 | // vertical-middle-top bar |
| 1280 | 1382 | draw_segment_vertical_caps(*tempbitmap, |
| 1281 | 1383 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, bmwidth/2, |
| 1282 | 1384 | segwidth, LINE_CAP_NONE, (pattern & (1 << 10)) ? onpen : offpen); |
| 1283 | 1385 | |
| 1284 | | /* vertical-middle-bottom bar */ |
| 1386 | // vertical-middle-bottom bar |
| 1285 | 1387 | draw_segment_vertical_caps(*tempbitmap, |
| 1286 | 1388 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, bmwidth/2, |
| 1287 | 1389 | segwidth, LINE_CAP_NONE, (pattern & (1 << 11)) ? onpen : offpen); |
| 1288 | 1390 | |
| 1289 | | /* diagonal-left-bottom bar */ |
| 1391 | // diagonal-left-bottom bar |
| 1290 | 1392 | draw_segment_diagonal_1(*tempbitmap, |
| 1291 | 1393 | 0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5, |
| 1292 | 1394 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, |
| 1293 | 1395 | segwidth, (pattern & (1 << 12)) ? onpen : offpen); |
| 1294 | 1396 | |
| 1295 | | /* diagonal-left-top bar */ |
| 1397 | // diagonal-left-top bar |
| 1296 | 1398 | draw_segment_diagonal_2(*tempbitmap, |
| 1297 | 1399 | 0 + segwidth + segwidth/5, bmwidth/2 - segwidth/2 - segwidth/5, |
| 1298 | 1400 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, |
| 1299 | 1401 | segwidth, (pattern & (1 << 13)) ? onpen : offpen); |
| 1300 | 1402 | |
| 1301 | | /* diagonal-right-top bar */ |
| 1403 | // diagonal-right-top bar |
| 1302 | 1404 | draw_segment_diagonal_1(*tempbitmap, |
| 1303 | 1405 | bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5, |
| 1304 | 1406 | 0 + segwidth + segwidth/3, bmheight/2 - segwidth/2 - segwidth/3, |
| 1305 | 1407 | segwidth, (pattern & (1 << 14)) ? onpen : offpen); |
| 1306 | 1408 | |
| 1307 | | /* diagonal-right-bottom bar */ |
| 1409 | // diagonal-right-bottom bar |
| 1308 | 1410 | draw_segment_diagonal_2(*tempbitmap, |
| 1309 | 1411 | bmwidth/2 + segwidth/2 + segwidth/5, bmwidth - segwidth - segwidth/5, |
| 1310 | 1412 | bmheight/2 + segwidth/2 + segwidth/3, bmheight - segwidth - segwidth/3, |
| 1311 | 1413 | segwidth, (pattern & (1 << 15)) ? onpen : offpen); |
| 1312 | 1414 | |
| 1313 | | /* decimal point */ |
| 1415 | // decimal point |
| 1314 | 1416 | draw_segment_decimal(*tempbitmap, bmwidth + segwidth/2, bmheight - segwidth/2, segwidth, (pattern & (1 << 16)) ? onpen : offpen); |
| 1315 | 1417 | |
| 1316 | | /* comma tail */ |
| 1418 | // comma tail |
| 1317 | 1419 | draw_segment_diagonal_1(*tempbitmap, |
| 1318 | 1420 | bmwidth - (segwidth/2), bmwidth + segwidth, |
| 1319 | 1421 | bmheight - (segwidth), bmheight + segwidth*1.5, |
| 1320 | 1422 | segwidth/2, (pattern & (1 << 17)) ? onpen : offpen); |
| 1321 | 1423 | |
| 1322 | | /* apply skew */ |
| 1424 | // apply skew |
| 1323 | 1425 | apply_skew(*tempbitmap, 40); |
| 1324 | 1426 | |
| 1325 | | /* resample to the target size */ |
| 1326 | | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color); |
| 1427 | // resample to the target size |
| 1428 | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color); |
| 1327 | 1429 | |
| 1328 | 1430 | global_free(tempbitmap); |
| 1329 | 1431 | } |
| 1330 | 1432 | |
| 1331 | | /*------------------------------------------------- |
| 1332 | | layout_element_draw_dotmatrix - draw a |
| 1333 | | row of 8 dots for a dotmatrix |
| 1334 | | -------------------------------------------------*/ |
| 1335 | 1433 | |
| 1336 | | static void layout_element_draw_dotmatrix(bitmap_t &dest, const rectangle &bounds, const render_color &color, int pattern) |
| 1434 | //------------------------------------------------- |
| 1435 | // draw_dotmatrix - draw a row of 8 dots for a |
| 1436 | // dotmatrix |
| 1437 | //------------------------------------------------- |
| 1438 | |
| 1439 | void layout_element::component::draw_dotmatrix(bitmap_t &dest, const rectangle &bounds, int pattern) |
| 1337 | 1440 | { |
| 1338 | 1441 | const rgb_t onpen = MAKE_ARGB(0xff, 0xff, 0xff, 0xff); |
| 1339 | 1442 | const rgb_t offpen = MAKE_ARGB(0xff, 0x20, 0x20, 0x20); |
| 1340 | | int bmwidth, bmheight, dotwidth, i; |
| 1341 | | bitmap_t *tempbitmap; |
| 1342 | 1443 | |
| 1343 | | /* sizes for computation */ |
| 1344 | | bmwidth = 2000; |
| 1345 | | bmheight = 300; |
| 1346 | | dotwidth = 250; |
| 1444 | // sizes for computation |
| 1445 | int bmwidth = 2000; |
| 1446 | int bmheight = 300; |
| 1447 | int dotwidth = 250; |
| 1347 | 1448 | |
| 1348 | | /* allocate a temporary bitmap for drawing */ |
| 1349 | | tempbitmap = global_alloc(bitmap_t(bmwidth, bmheight, BITMAP_FORMAT_ARGB32)); |
| 1449 | // allocate a temporary bitmap for drawing |
| 1450 | bitmap_t *tempbitmap = global_alloc(bitmap_t(bmwidth, bmheight, BITMAP_FORMAT_ARGB32)); |
| 1350 | 1451 | bitmap_fill(tempbitmap, NULL, MAKE_ARGB(0xff, 0x00, 0x00, 0x00)); |
| 1351 | 1452 | |
| 1352 | | for (i = 0; i < 8; i++) |
| 1353 | | {// height |
| 1453 | for (int i = 0; i < 8; i++) |
| 1354 | 1454 | draw_segment_decimal(*tempbitmap, ((dotwidth/2 )+ (i * dotwidth)), bmheight/2, dotwidth, (pattern & (1 << i))?onpen:offpen); |
| 1355 | | } |
| 1356 | 1455 | |
| 1357 | | /* resample to the target size */ |
| 1358 | | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &color); |
| 1456 | // resample to the target size |
| 1457 | render_resample_argb_bitmap_hq(dest.base, dest.rowpixels, dest.width, dest.height, tempbitmap, NULL, &m_color); |
| 1359 | 1458 | |
| 1360 | 1459 | global_free(tempbitmap); |
| 1361 | 1460 | } |
| 1362 | 1461 | |
| 1363 | 1462 | |
| 1364 | | /*************************************************************************** |
| 1365 | | LAYOUT FILE PARSING |
| 1366 | | ***************************************************************************/ |
| 1463 | //------------------------------------------------- |
| 1464 | // draw_segment_horizontal_caps - draw a |
| 1465 | // horizontal LED segment with definable end |
| 1466 | // and start points |
| 1467 | //------------------------------------------------- |
| 1367 | 1468 | |
| 1368 | | /*------------------------------------------------- |
| 1369 | | get_variable_value - compute the value of |
| 1370 | | a variable in an XML attribute |
| 1371 | | -------------------------------------------------*/ |
| 1372 | | |
| 1373 | | static int get_variable_value(running_machine &machine, const char *string, char **outputptr) |
| 1469 | void layout_element::component::draw_segment_horizontal_caps(bitmap_t &dest, int minx, int maxx, int midy, int width, int caps, rgb_t color) |
| 1374 | 1470 | { |
| 1375 | | const screen_device_config *devconfig; |
| 1376 | | int num, den; |
| 1377 | | char temp[100]; |
| 1378 | | |
| 1379 | | /* screen 0 parameters */ |
| 1380 | | for (devconfig = screen_first(machine.m_config); devconfig != NULL; devconfig = screen_next(devconfig)) |
| 1471 | // loop over the width of the segment |
| 1472 | for (int y = 0; y < width / 2; y++) |
| 1381 | 1473 | { |
| 1382 | | int scrnum = machine.m_config.m_devicelist.index(SCREEN, devconfig->tag()); |
| 1474 | UINT32 *d0 = BITMAP_ADDR32(&dest, midy - y, 0); |
| 1475 | UINT32 *d1 = BITMAP_ADDR32(&dest, midy + y, 0); |
| 1476 | int ty = (y < width / 8) ? width / 8 : y; |
| 1383 | 1477 | |
| 1384 | | /* native X aspect factor */ |
| 1385 | | sprintf(temp, "~scr%dnativexaspect~", scrnum); |
| 1386 | | if (!strncmp(string, temp, strlen(temp))) |
| 1387 | | { |
| 1388 | | num = devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x; |
| 1389 | | den = devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y; |
| 1390 | | reduce_fraction(&num, &den); |
| 1391 | | *outputptr += sprintf(*outputptr, "%d", num); |
| 1392 | | return strlen(temp); |
| 1393 | | } |
| 1394 | | |
| 1395 | | /* native Y aspect factor */ |
| 1396 | | sprintf(temp, "~scr%dnativeyaspect~", scrnum); |
| 1397 | | if (!strncmp(string, temp, strlen(temp))) |
| 1398 | | { |
| 1399 | | num = devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x; |
| 1400 | | den = devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y; |
| 1401 | | reduce_fraction(&num, &den); |
| 1402 | | *outputptr += sprintf(*outputptr, "%d", den); |
| 1403 | | return strlen(temp); |
| 1404 | | } |
| 1405 | | |
| 1406 | | /* native width */ |
| 1407 | | sprintf(temp, "~scr%dwidth~", scrnum); |
| 1408 | | if (!strncmp(string, temp, strlen(temp))) |
| 1409 | | { |
| 1410 | | *outputptr += sprintf(*outputptr, "%d", devconfig->visible_area().max_x + 1 - devconfig->visible_area().min_x); |
| 1411 | | return strlen(temp); |
| 1412 | | } |
| 1413 | | |
| 1414 | | /* native height */ |
| 1415 | | sprintf(temp, "~scr%dheight~", scrnum); |
| 1416 | | if (!strncmp(string, temp, strlen(temp))) |
| 1417 | | { |
| 1418 | | *outputptr += sprintf(*outputptr, "%d", devconfig->visible_area().max_y + 1 - devconfig->visible_area().min_y); |
| 1419 | | return strlen(temp); |
| 1420 | | } |
| 1478 | // loop over the length of the segment |
| 1479 | for (int x = minx + ((caps & LINE_CAP_START) ? ty : 0); x < maxx - ((caps & LINE_CAP_END) ? ty : 0); x++) |
| 1480 | d0[x] = d1[x] = color; |
| 1421 | 1481 | } |
| 1422 | | |
| 1423 | | /* default: copy the first character and continue */ |
| 1424 | | **outputptr = *string; |
| 1425 | | *outputptr += 1; |
| 1426 | | return 1; |
| 1427 | 1482 | } |
| 1428 | 1483 | |
| 1429 | 1484 | |
| 1430 | | /*------------------------------------------------- |
| 1431 | | xml_get_attribute_string_with_subst - analog |
| 1432 | | to xml_get_attribute_string but with variable |
| 1433 | | substitution |
| 1434 | | -------------------------------------------------*/ |
| 1485 | //------------------------------------------------- |
| 1486 | // draw_segment_horizontal - draw a horizontal |
| 1487 | // LED segment |
| 1488 | //------------------------------------------------- |
| 1435 | 1489 | |
| 1436 | | static const char *xml_get_attribute_string_with_subst(running_machine &machine, xml_data_node *node, const char *attribute, const char *defvalue) |
| 1490 | void layout_element::component::draw_segment_horizontal(bitmap_t &dest, int minx, int maxx, int midy, int width, rgb_t color) |
| 1437 | 1491 | { |
| 1438 | | const char *str = xml_get_attribute_string(node, attribute, NULL); |
| 1439 | | static char buffer[1000]; |
| 1440 | | const char *s; |
| 1441 | | char *d; |
| 1492 | draw_segment_horizontal_caps(dest, minx, maxx, midy, width, LINE_CAP_START | LINE_CAP_END, color); |
| 1493 | } |
| 1442 | 1494 | |
| 1443 | | /* if nothing, just return the default */ |
| 1444 | | if (str == NULL) |
| 1445 | | return defvalue; |
| 1446 | 1495 | |
| 1447 | | /* if no tildes, don't worry */ |
| 1448 | | if (strchr(str, '~') == NULL) |
| 1449 | | return str; |
| 1496 | //------------------------------------------------- |
| 1497 | // draw_segment_vertical_caps - draw a |
| 1498 | // vertical LED segment with definable end |
| 1499 | // and start points |
| 1500 | //------------------------------------------------- |
| 1450 | 1501 | |
| 1451 | | /* make a copy of the string, doing substitutions along the way */ |
| 1452 | | for (s = str, d = buffer; *s != 0; ) |
| 1502 | void layout_element::component::draw_segment_vertical_caps(bitmap_t &dest, int miny, int maxy, int midx, int width, int caps, rgb_t color) |
| 1503 | { |
| 1504 | // loop over the width of the segment |
| 1505 | for (int x = 0; x < width / 2; x++) |
| 1453 | 1506 | { |
| 1454 | | /* if not a variable, just copy */ |
| 1455 | | if (*s != '~') |
| 1456 | | *d++ = *s++; |
| 1507 | UINT32 *d0 = BITMAP_ADDR32(&dest, 0, midx - x); |
| 1508 | UINT32 *d1 = BITMAP_ADDR32(&dest, 0, midx + x); |
| 1509 | int tx = (x < width / 8) ? width / 8 : x; |
| 1457 | 1510 | |
| 1458 | | /* extract the variable */ |
| 1459 | | else |
| 1460 | | s += get_variable_value(machine, s, &d); |
| 1511 | // loop over the length of the segment |
| 1512 | for (int y = miny + ((caps & LINE_CAP_START) ? tx : 0); y < maxy - ((caps & LINE_CAP_END) ? tx : 0); y++) |
| 1513 | d0[y * dest.rowpixels] = d1[y * dest.rowpixels] = color; |
| 1461 | 1514 | } |
| 1462 | | *d = 0; |
| 1463 | | return buffer; |
| 1464 | 1515 | } |
| 1465 | 1516 | |
| 1466 | 1517 | |
| 1467 | | /*------------------------------------------------- |
| 1468 | | xml_get_attribute_int_with_subst - analog |
| 1469 | | to xml_get_attribute_int but with variable |
| 1470 | | substitution |
| 1471 | | -------------------------------------------------*/ |
| 1518 | //------------------------------------------------- |
| 1519 | // draw_segment_vertical - draw a vertical |
| 1520 | // LED segment |
| 1521 | //------------------------------------------------- |
| 1472 | 1522 | |
| 1473 | | static int xml_get_attribute_int_with_subst(running_machine &machine, xml_data_node *node, const char *attribute, int defvalue) |
| 1523 | void layout_element::component::draw_segment_vertical(bitmap_t &dest, int miny, int maxy, int midx, int width, rgb_t color) |
| 1474 | 1524 | { |
| 1475 | | const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, NULL); |
| 1476 | | int value; |
| 1477 | | |
| 1478 | | if (string == NULL) |
| 1479 | | return defvalue; |
| 1480 | | if (string[0] == '$') |
| 1481 | | return (sscanf(&string[1], "%X", &value) == 1) ? value : defvalue; |
| 1482 | | if (string[0] == '0' && string[1] == 'x') |
| 1483 | | return (sscanf(&string[2], "%X", &value) == 1) ? value : defvalue; |
| 1484 | | if (string[0] == '#') |
| 1485 | | return (sscanf(&string[1], "%d", &value) == 1) ? value : defvalue; |
| 1486 | | return (sscanf(&string[0], "%d", &value) == 1) ? value : defvalue; |
| 1525 | draw_segment_vertical_caps(dest, miny, maxy, midx, width, LINE_CAP_START | LINE_CAP_END, color); |
| 1487 | 1526 | } |
| 1488 | 1527 | |
| 1489 | 1528 | |
| 1490 | | /*------------------------------------------------- |
| 1491 | | xml_get_attribute_float_with_subst - analog |
| 1492 | | to xml_get_attribute_float but with variable |
| 1493 | | substitution |
| 1494 | | -------------------------------------------------*/ |
| 1529 | //------------------------------------------------- |
| 1530 | // draw_segment_diagonal_1 - draw a diagonal |
| 1531 | // LED segment that looks like this: / |
| 1532 | //------------------------------------------------- |
| 1495 | 1533 | |
| 1496 | | static float xml_get_attribute_float_with_subst(running_machine &machine, xml_data_node *node, const char *attribute, float defvalue) |
| 1534 | void layout_element::component::draw_segment_diagonal_1(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color) |
| 1497 | 1535 | { |
| 1498 | | const char *string = xml_get_attribute_string_with_subst(machine, node, attribute, NULL); |
| 1499 | | float value; |
| 1536 | // compute parameters |
| 1537 | width *= 1.5; |
| 1538 | float ratio = (maxy - miny - width) / (float)(maxx - minx); |
| 1500 | 1539 | |
| 1501 | | if (!string || sscanf(string, "%f", &value) != 1) |
| 1502 | | return defvalue; |
| 1503 | | return value; |
| 1540 | // draw line |
| 1541 | for (int x = minx; x < maxx; x++) |
| 1542 | if (x >= 0 && x < dest.width) |
| 1543 | { |
| 1544 | UINT32 *d = BITMAP_ADDR32(&dest, 0, x); |
| 1545 | int step = (x - minx) * ratio; |
| 1546 | |
| 1547 | for (int y = maxy - width - step; y < maxy - step; y++) |
| 1548 | if (y >= 0 && y < dest.height) |
| 1549 | d[y * dest.rowpixels] = color; |
| 1550 | } |
| 1504 | 1551 | } |
| 1505 | 1552 | |
| 1506 | 1553 | |
| 1507 | | /*------------------------------------------------- |
| 1508 | | layout_file_load - parse a layout XML file |
| 1509 | | into a layout_file |
| 1510 | | -------------------------------------------------*/ |
| 1554 | //------------------------------------------------- |
| 1555 | // draw_segment_diagonal_2 - draw a diagonal |
| 1556 | // LED segment that looks like this: |
| 1557 | //------------------------------------------------- |
| 1511 | 1558 | |
| 1512 | | layout_file *layout_file_load(running_machine &machine, const char *dirname, const char *filename) |
| 1559 | void layout_element::component::draw_segment_diagonal_2(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color) |
| 1513 | 1560 | { |
| 1514 | | xml_data_node *rootnode, *mamelayoutnode, *elemnode, *viewnode; |
| 1515 | | layout_element **elemnext; |
| 1516 | | layout_view **viewnext; |
| 1517 | | layout_file *file; |
| 1518 | | int version; |
| 1561 | // compute parameters |
| 1562 | width *= 1.5; |
| 1563 | float ratio = (maxy - miny - width) / (float)(maxx - minx); |
| 1519 | 1564 | |
| 1520 | | /* if the first character of the "file" is an open brace, assume it is an XML string */ |
| 1521 | | if (filename[0] == '<') |
| 1522 | | rootnode = xml_string_read(filename, NULL); |
| 1565 | // draw line |
| 1566 | for (int x = minx; x < maxx; x++) |
| 1567 | if (x >= 0 && x < dest.width) |
| 1568 | { |
| 1569 | UINT32 *d = BITMAP_ADDR32(&dest, 0, x); |
| 1570 | int step = (x - minx) * ratio; |
| 1523 | 1571 | |
| 1524 | | /* otherwise, assume it is a file */ |
| 1525 | | else |
| 1526 | | { |
| 1527 | | file_error filerr; |
| 1528 | | mame_file *layoutfile; |
| 1572 | for (int y = miny + step; y < miny + step + width; y++) |
| 1573 | if (y >= 0 && y < dest.height) |
| 1574 | d[y * dest.rowpixels] = color; |
| 1575 | } |
| 1576 | } |
| 1529 | 1577 | |
| 1530 | | astring fname(filename, ".lay"); |
| 1531 | | if (dirname != NULL) |
| 1532 | | fname.ins(0, PATH_SEPARATOR).ins(0, dirname); |
| 1533 | 1578 | |
| 1534 | | filerr = mame_fopen(SEARCHPATH_ARTWORK, fname, OPEN_FLAG_READ, &layoutfile); |
| 1579 | //------------------------------------------------- |
| 1580 | // draw_segment_decimal - draw a decimal point |
| 1581 | //------------------------------------------------- |
| 1535 | 1582 | |
| 1536 | | if (filerr != FILERR_NONE) |
| 1537 | | return NULL; |
| 1538 | | rootnode = xml_file_read(mame_core_file(layoutfile), NULL); |
| 1539 | | mame_fclose(layoutfile); |
| 1540 | | } |
| 1583 | void layout_element::component::draw_segment_decimal(bitmap_t &dest, int midx, int midy, int width, rgb_t color) |
| 1584 | { |
| 1585 | // compute parameters |
| 1586 | width /= 2; |
| 1587 | float ooradius2 = 1.0f / (float)(width * width); |
| 1541 | 1588 | |
| 1542 | | /* if unable to parse the file, just bail */ |
| 1543 | | if (rootnode == NULL) |
| 1544 | | return NULL; |
| 1545 | | |
| 1546 | | /* allocate the layout group object first */ |
| 1547 | | file = global_alloc_clear(layout_file); |
| 1548 | | |
| 1549 | | /* find the layout node */ |
| 1550 | | mamelayoutnode = xml_get_sibling(rootnode->child, "mamelayout"); |
| 1551 | | if (mamelayoutnode == NULL) |
| 1552 | | fatalerror("Invalid XML file: missing mamelayout node"); |
| 1553 | | |
| 1554 | | /* validate the config data version */ |
| 1555 | | version = xml_get_attribute_int(mamelayoutnode, "version", 0); |
| 1556 | | if (version != LAYOUT_VERSION) |
| 1557 | | fatalerror("Invalid XML file: unsupported version"); |
| 1558 | | |
| 1559 | | /* parse all the elements */ |
| 1560 | | file->elemlist = NULL; |
| 1561 | | elemnext = &file->elemlist; |
| 1562 | | for (elemnode = xml_get_sibling(mamelayoutnode->child, "element"); elemnode; elemnode = xml_get_sibling(elemnode->next, "element")) |
| 1589 | // iterate over y |
| 1590 | for (UINT32 y = 0; y <= width; y++) |
| 1563 | 1591 | { |
| 1564 | | layout_element *element = load_layout_element(machine, elemnode, dirname); |
| 1565 | | if (element == NULL) |
| 1566 | | goto error; |
| 1592 | UINT32 *d0 = BITMAP_ADDR32(&dest, midy - y, 0); |
| 1593 | UINT32 *d1 = BITMAP_ADDR32(&dest, midy + y, 0); |
| 1594 | float xval = width * sqrt(1.0f - (float)(y * y) * ooradius2); |
| 1595 | INT32 left, right; |
| 1567 | 1596 | |
| 1568 | | /* add to the end of the list */ |
| 1569 | | *elemnext = element; |
| 1570 | | elemnext = &element->next; |
| 1571 | | } |
| 1597 | // compute left/right coordinates |
| 1598 | left = midx - (INT32)(xval + 0.5f); |
| 1599 | right = midx + (INT32)(xval + 0.5f); |
| 1572 | 1600 | |
| 1573 | | /* parse all the views */ |
| 1574 | | file->viewlist = NULL; |
| 1575 | | viewnext = &file->viewlist; |
| 1576 | | for (viewnode = xml_get_sibling(mamelayoutnode->child, "view"); viewnode; viewnode = xml_get_sibling(viewnode->next, "view")) |
| 1577 | | { |
| 1578 | | layout_view *view = load_layout_view(machine, viewnode, file->elemlist); |
| 1579 | | if (view == NULL) |
| 1580 | | goto error; |
| 1581 | | |
| 1582 | | /* add to the end of the list */ |
| 1583 | | *viewnext = view; |
| 1584 | | viewnext = &view->next; |
| 1601 | // draw this scanline |
| 1602 | for (UINT32 x = left; x < right; x++) |
| 1603 | d0[x] = d1[x] = color; |
| 1585 | 1604 | } |
| 1586 | | |
| 1587 | | xml_file_free(rootnode); |
| 1588 | | return file; |
| 1589 | | |
| 1590 | | error: |
| 1591 | | layout_file_free(file); |
| 1592 | | xml_file_free(rootnode); |
| 1593 | | return NULL; |
| 1594 | 1605 | } |
| 1595 | 1606 | |
| 1596 | 1607 | |
| 1597 | | /*------------------------------------------------- |
| 1598 | | load_layout_element - parse an element XML |
| 1599 | | node from the layout file |
| 1600 | | -------------------------------------------------*/ |
| 1608 | //------------------------------------------------- |
| 1609 | // draw_segment_comma - draw a comma tail |
| 1610 | //------------------------------------------------- |
| 1601 | 1611 | |
| 1602 | | static layout_element *load_layout_element(running_machine &machine, xml_data_node *elemnode, const char *dirname) |
| 1612 | void layout_element::component::draw_segment_comma(bitmap_t &dest, int minx, int maxx, int miny, int maxy, int width, rgb_t color) |
| 1603 | 1613 | { |
| 1604 | | render_bounds bounds = { 0 }; |
| 1605 | | element_component **nextcomp; |
| 1606 | | element_component *component; |
| 1607 | | xml_data_node *compnode; |
| 1608 | | layout_element *element; |
| 1609 | | float xscale, yscale; |
| 1610 | | float xoffs, yoffs; |
| 1611 | | const char *name; |
| 1612 | | int state; |
| 1613 | | int first; |
| 1614 | // compute parameters |
| 1615 | width *= 1.5; |
| 1616 | float ratio = (maxy - miny - width) / (float)(maxx - minx); |
| 1614 | 1617 | |
| 1615 | | /* allocate a new element */ |
| 1616 | | element = global_alloc_clear(layout_element); |
| 1617 | | |
| 1618 | | /* extract the name */ |
| 1619 | | name = xml_get_attribute_string_with_subst(machine, elemnode, "name", NULL); |
| 1620 | | if (name == NULL) |
| 1618 | // draw line |
| 1619 | for (int x = minx; x < maxx; x++) |
| 1621 | 1620 | { |
| 1622 | | logerror("All layout elements must have a name!\n"); |
| 1623 | | goto error; |
| 1624 | | } |
| 1625 | | element->machine = &machine; |
| 1626 | | element->name = copy_string(name); |
| 1627 | | element->defstate = xml_get_attribute_int_with_subst(machine, elemnode, "defstate", -1); |
| 1621 | UINT32 *d = BITMAP_ADDR32(&dest, 0, x); |
| 1622 | int step = (x - minx) * ratio; |
| 1628 | 1623 | |
| 1629 | | /* parse components in order */ |
| 1630 | | first = TRUE; |
| 1631 | | nextcomp = &element->complist; |
| 1632 | | for (compnode = elemnode->child; compnode; compnode = compnode->next) |
| 1633 | | { |
| 1634 | | /* allocate a new component */ |
| 1635 | | element_component *new_component = load_element_component(machine, compnode, dirname); |
| 1636 | | if (new_component == NULL) |
| 1637 | | goto error; |
| 1638 | | |
| 1639 | | /* link it into the list */ |
| 1640 | | *nextcomp = new_component; |
| 1641 | | nextcomp = &new_component->next; |
| 1642 | | |
| 1643 | | /* accumulate bounds */ |
| 1644 | | if (first) |
| 1645 | | bounds = new_component->bounds; |
| 1646 | | else |
| 1647 | | union_render_bounds(&bounds, &new_component->bounds); |
| 1648 | | first = FALSE; |
| 1649 | | |
| 1650 | | /* determine the maximum state */ |
| 1651 | | if (new_component->state > element->maxstate) |
| 1652 | | element->maxstate = new_component->state; |
| 1653 | | if (new_component->type == COMPONENT_TYPE_LED7SEG) |
| 1654 | | element->maxstate = 255; |
| 1655 | | if (new_component->type == COMPONENT_TYPE_LED14SEG) |
| 1656 | | element->maxstate = 16383; |
| 1657 | | if (new_component->type == COMPONENT_TYPE_LED14SEGSC || new_component->type == COMPONENT_TYPE_LED16SEG) |
| 1658 | | element->maxstate = 65535; |
| 1659 | | if (new_component->type == COMPONENT_TYPE_LED16SEGSC) |
| 1660 | | element->maxstate = 262143; |
| 1661 | | if (new_component->type == COMPONENT_TYPE_DOTMATRIX) |
| 1662 | | element->maxstate = 255; |
| 1624 | for (int y = maxy; y < maxy - width - step; y--) |
| 1625 | d[y * dest.rowpixels] = color; |
| 1663 | 1626 | } |
| 1664 | | /* determine the scale/offset for normalization */ |
| 1665 | | xoffs = bounds.x0; |
| 1666 | | yoffs = bounds.y0; |
| 1667 | | xscale = 1.0f / (bounds.x1 - bounds.x0); |
| 1668 | | yscale = 1.0f / (bounds.y1 - bounds.y0); |
| 1669 | | |
| 1670 | | /* normalize all the component bounds */ |
| 1671 | | for (component = element->complist; component != NULL; component = component->next) |
| 1672 | | { |
| 1673 | | component->bounds.x0 = (component->bounds.x0 - xoffs) * xscale; |
| 1674 | | component->bounds.x1 = (component->bounds.x1 - xoffs) * xscale; |
| 1675 | | component->bounds.y0 = (component->bounds.y0 - yoffs) * yscale; |
| 1676 | | component->bounds.y1 = (component->bounds.y1 - yoffs) * yscale; |
| 1677 | | } |
| 1678 | | |
| 1679 | | /* allocate an array of element textures for the states */ |
| 1680 | | element->elemtex = global_alloc_array(element_texture, element->maxstate + 1); |
| 1681 | | for (state = 0; state <= element->maxstate; state++) |
| 1682 | | { |
| 1683 | | element->elemtex[state].element = element; |
| 1684 | | element->elemtex[state].state = state; |
| 1685 | | element->elemtex[state].texture = machine.render().texture_alloc(layout_element_scale, &element->elemtex[state]); |
| 1686 | | } |
| 1687 | | |
| 1688 | | return element; |
| 1689 | | |
| 1690 | | error: |
| 1691 | | layout_element_free(element); |
| 1692 | | return NULL; |
| 1693 | 1627 | } |
| 1694 | 1628 | |
| 1695 | 1629 | |
| 1696 | | /*------------------------------------------------- |
| 1697 | | load_element_component - parse a component |
| 1698 | | XML node (image/rect/disk) |
| 1699 | | -------------------------------------------------*/ |
| 1630 | //------------------------------------------------- |
| 1631 | // apply_skew - apply skew to a bitmap_t |
| 1632 | //------------------------------------------------- |
| 1700 | 1633 | |
| 1701 | | static element_component *load_element_component(running_machine &machine, xml_data_node *compnode, const char *dirname) |
| 1634 | void layout_element::component::apply_skew(bitmap_t &dest, int skewwidth) |
| 1702 | 1635 | { |
| 1703 | | element_component *component; |
| 1704 | | |
| 1705 | | /* allocate memory for the component */ |
| 1706 | | component = global_alloc_clear(element_component); |
| 1707 | | |
| 1708 | | /* fetch common data */ |
| 1709 | | component->state = xml_get_attribute_int_with_subst(machine, compnode, "state", -1); |
| 1710 | | if (load_bounds(machine, xml_get_sibling(compnode->child, "bounds"), &component->bounds)) |
| 1711 | | goto error; |
| 1712 | | if (load_color(machine, xml_get_sibling(compnode->child, "color"), &component->color)) |
| 1713 | | goto error; |
| 1714 | | |
| 1715 | | /* image nodes */ |
| 1716 | | if (strcmp(compnode->name, "image") == 0) |
| 1636 | for (int y = 0; y < dest.height; y++) |
| 1717 | 1637 | { |
| 1718 | | const char *file = xml_get_attribute_string_with_subst(machine, compnode, "file", NULL); |
| 1719 | | const char *afile = xml_get_attribute_string_with_subst(machine, compnode, "alphafile", NULL); |
| 1720 | | |
| 1721 | | /* load and allocate the bitmap */ |
| 1722 | | component->type = COMPONENT_TYPE_IMAGE; |
| 1723 | | component->dirname = (dirname == NULL) ? NULL : copy_string(dirname); |
| 1724 | | component->imagefile = (file == NULL) ? NULL : copy_string(file); |
| 1725 | | component->alphafile = (afile == NULL) ? NULL : copy_string(afile); |
| 1638 | UINT32 *destrow = BITMAP_ADDR32(&dest, y, 0); |
| 1639 | int offs = skewwidth * (dest.height - y) / dest.height; |
| 1640 | for (int x = dest.width - skewwidth - 1; x >= 0; x--) |
| 1641 | destrow[x + offs] = destrow[x]; |
| 1642 | for (int x = 0; x < offs; x++) |
| 1643 | destrow[x] = 0; |
| 1726 | 1644 | } |
| 1645 | } |
| 1727 | 1646 | |
| 1728 | | /* text nodes */ |
| 1729 | | else if (strcmp(compnode->name, "text") == 0) |
| 1730 | | { |
| 1731 | | const char *text = xml_get_attribute_string_with_subst(machine, compnode, "string", ""); |
| 1732 | | char *string; |
| 1733 | 1647 | |
| 1734 | | /* allocate a copy of the string */ |
| 1735 | | component->type = COMPONENT_TYPE_TEXT; |
| 1736 | | string = global_alloc_array(char, strlen(text) + 1); |
| 1737 | | strcpy(string, text); |
| 1738 | | component->string = string; |
| 1739 | | } |
| 1740 | 1648 | |
| 1741 | | /* dotmatrix nodes */ |
| 1742 | | else if (strcmp(compnode->name, "dotmatrix") == 0) |
| 1743 | | component->type = COMPONENT_TYPE_DOTMATRIX; |
| 1649 | //************************************************************************** |
| 1650 | // LAYOUT VIEW |
| 1651 | //************************************************************************** |
| 1744 | 1652 | |
| 1745 | | /* led7seg nodes */ |
| 1746 | | else if (strcmp(compnode->name, "led7seg") == 0) |
| 1747 | | component->type = COMPONENT_TYPE_LED7SEG; |
| 1653 | //------------------------------------------------- |
| 1654 | // layout_view - constructor |
| 1655 | //------------------------------------------------- |
| 1748 | 1656 | |
| 1749 | | /* led14seg nodes */ |
| 1750 | | else if (strcmp(compnode->name, "led14seg") == 0) |
| 1751 | | component->type = COMPONENT_TYPE_LED14SEG; |
| 1657 | layout_view::layout_view(running_machine &machine, xml_data_node &viewnode, simple_list<layout_element> &elemlist) |
| 1658 | : m_next(NULL), |
| 1659 | m_aspect(1.0f), |
| 1660 | m_scraspect(1.0f), |
| 1661 | m_screens(machine.m_respool), |
| 1662 | m_backdrop_list(machine.m_respool), |
| 1663 | m_screen_list(machine.m_respool), |
| 1664 | m_overlay_list(machine.m_respool), |
| 1665 | m_bezel_list(machine.m_respool) |
| 1666 | { |
| 1667 | // allocate a copy of the name |
| 1668 | m_name = xml_get_attribute_string_with_subst(machine, viewnode, "name", ""); |
| 1752 | 1669 | |
| 1753 | | /* led14segsc nodes */ |
| 1754 | | else if (strcmp(compnode->name, "led14segsc") == 0) |
| 1755 | | component->type = COMPONENT_TYPE_LED14SEGSC; |
| 1670 | // if we have a bounds item, load it |
| 1671 | xml_data_node *boundsnode = xml_get_sibling(viewnode.child, "bounds"); |
| 1672 | m_expbounds.x0 = m_expbounds.y0 = m_expbounds.x1 = m_expbounds.y1 = 0; |
| 1673 | if (boundsnode != NULL) |
| 1674 | parse_bounds(machine, xml_get_sibling(boundsnode, "bounds"), m_expbounds); |
| 1756 | 1675 | |
| 1757 | | /* led16seg nodes */ |
| 1758 | | else if (strcmp(compnode->name, "led16seg") == 0) |
| 1759 | | component->type = COMPONENT_TYPE_LED16SEG; |
| 1676 | // load backdrop items |
| 1677 | for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "backdrop"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "backdrop")) |
| 1678 | m_backdrop_list.append(*auto_alloc(&machine, item(machine, *itemnode, elemlist))); |
| 1760 | 1679 | |
| 1761 | | /* led16segsc nodes */ |
| 1762 | | else if (strcmp(compnode->name, "led16segsc") == 0) |
| 1763 | | component->type = COMPONENT_TYPE_LED16SEGSC; |
| 1680 | // load screen items |
| 1681 | for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "screen"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "screen")) |
| 1682 | m_screen_list.append(*auto_alloc(&machine, item(machine, *itemnode, elemlist))); |
| 1764 | 1683 | |
| 1765 | | /* rect nodes */ |
| 1766 | | else if (strcmp(compnode->name, "rect") == 0) |
| 1767 | | component->type = COMPONENT_TYPE_RECT; |
| 1684 | // load overlay items |
| 1685 | for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "overlay"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "overlay")) |
| 1686 | m_overlay_list.append(*auto_alloc(&machine, item(machine, *itemnode, elemlist))); |
| 1768 | 1687 | |
| 1769 | | /* disk nodes */ |
| 1770 | | else if (strcmp(compnode->name, "disk") == 0) |
| 1771 | | component->type = COMPONENT_TYPE_DISK; |
| 1688 | // load bezel items |
| 1689 | for (xml_data_node *itemnode = xml_get_sibling(viewnode.child, "bezel"); itemnode != NULL; itemnode = xml_get_sibling(itemnode->next, "bezel")) |
| 1690 | m_bezel_list.append(*auto_alloc(&machine, item(machine, *itemnode, elemlist))); |
| 1772 | 1691 | |
| 1773 | | /* error otherwise */ |
| 1774 | | else |
| 1775 | | fatalerror("Unknown element component: %s", compnode->name); |
| 1776 | | |
| 1777 | | return component; |
| 1778 | | |
| 1779 | | error: |
| 1780 | | global_free(component); |
| 1781 | | return NULL; |
| 1692 | // recompute the data for the view based on a default layer config |
| 1693 | recompute(render_layer_config()); |
| 1782 | 1694 | } |
| 1783 | 1695 | |
| 1784 | 1696 | |
| 1785 | | /*------------------------------------------------- |
| 1786 | | load_layout_view - parse a view XML node |
| 1787 | | -------------------------------------------------*/ |
| 1697 | //------------------------------------------------- |
| 1698 | // layout_view - destructor |
| 1699 | //------------------------------------------------- |
| 1788 | 1700 | |
| 1789 | | static layout_view *load_layout_view(running_machine &machine, xml_data_node *viewnode, layout_element *elemlist) |
| 1701 | layout_view::~layout_view() |
| 1790 | 1702 | { |
| 1791 | | xml_data_node *boundsnode; |
| 1792 | | view_item **itemnext; |
| 1793 | | layout_view *view; |
| 1794 | | int layer; |
| 1703 | } |
| 1795 | 1704 | |
| 1796 | | /* first allocate memory */ |
| 1797 | | view = global_alloc_clear(layout_view); |
| 1798 | 1705 | |
| 1799 | | /* allocate a copy of the name */ |
| 1800 | | view->name = copy_string(xml_get_attribute_string_with_subst(machine, viewnode, "name", "")); |
| 1706 | //------------------------------------------------- |
| 1707 | // first_item - return the first item in the |
| 1708 | // appropriate list |
| 1709 | //------------------------------------------------- |
| 1801 | 1710 | |
| 1802 | | /* if we have a bounds item, load it */ |
| 1803 | | boundsnode = xml_get_sibling(viewnode->child, "bounds"); |
| 1804 | | if (boundsnode != NULL && load_bounds(machine, xml_get_sibling(boundsnode, "bounds"), &view->expbounds)) |
| 1805 | | goto error; |
| 1806 | | |
| 1807 | | /* loop over all the layer types we support */ |
| 1808 | | for (layer = 0; layer < ITEM_LAYER_MAX; layer++) |
| 1711 | layout_view::item *layout_view::first_item(item_layer layer) const |
| 1712 | { |
| 1713 | switch (layer) |
| 1809 | 1714 | { |
| 1810 | | static const char *const layer_node_name[ITEM_LAYER_MAX] = { "backdrop", "screen", "overlay", "bezel" }; |
| 1811 | | xml_data_node *itemnode; |
| 1812 | | |
| 1813 | | /* initialize the list */ |
| 1814 | | view->itemlist[layer] = NULL; |
| 1815 | | itemnext = &view->itemlist[layer]; |
| 1816 | | |
| 1817 | | /* parse all of the elements of that type */ |
| 1818 | | for (itemnode = xml_get_sibling(viewnode->child, layer_node_name[layer]); itemnode; itemnode = xml_get_sibling(itemnode->next, layer_node_name[layer])) |
| 1819 | | { |
| 1820 | | view_item *item = load_view_item(machine, itemnode, elemlist); |
| 1821 | | if (!item) |
| 1822 | | goto error; |
| 1823 | | |
| 1824 | | /* add to the end of the list */ |
| 1825 | | *itemnext = item; |
| 1826 | | itemnext = &item->next; |
| 1827 | | } |
| 1715 | case ITEM_LAYER_BACKDROP: return m_backdrop_list.first(); |
| 1716 | case ITEM_LAYER_SCREEN: return m_screen_list.first(); |
| 1717 | case ITEM_LAYER_OVERLAY: return m_overlay_list.first(); |
| 1718 | case ITEM_LAYER_BEZEL: return m_bezel_list.first(); |
| 1719 | default: return NULL; |
| 1828 | 1720 | } |
| 1829 | | |
| 1830 | | /* recompute the data for the view */ |
| 1831 | | layout_view_recompute(view, ~0); |
| 1832 | | return view; |
| 1833 | | |
| 1834 | | error: |
| 1835 | | layout_view_free(view); |
| 1836 | | return NULL; |
| 1837 | 1721 | } |
| 1838 | 1722 | |
| 1839 | 1723 | |
| 1840 | | /*------------------------------------------------- |
| 1841 | | load_view_item - parse an item XML node |
| 1842 | | -------------------------------------------------*/ |
| 1724 | //------------------------------------------------- |
| 1725 | // recompute - recompute the bounds and aspect |
| 1726 | // ratio of a view and all of its contained items |
| 1727 | //------------------------------------------------- |
| 1843 | 1728 | |
| 1844 | | static view_item *load_view_item(running_machine &machine, xml_data_node *itemnode, layout_element *elemlist) |
| 1729 | void layout_view::recompute(render_layer_config layerconfig) |
| 1845 | 1730 | { |
| 1846 | | view_item *item; |
| 1847 | | const char *name; |
| 1731 | // reset the bounds |
| 1732 | m_bounds.x0 = m_bounds.y0 = m_bounds.x1 = m_bounds.y1 = 0.0f; |
| 1733 | m_scrbounds.x0 = m_scrbounds.y0 = m_scrbounds.x1 = m_scrbounds.y1 = 0.0f; |
| 1734 | m_screens.reset(); |
| 1848 | 1735 | |
| 1849 | | /* allocate a new item */ |
| 1850 | | item = global_alloc_clear(view_item); |
| 1851 | | |
| 1852 | | /* allocate a copy of the output name */ |
| 1853 | | item->output_name = copy_string(xml_get_attribute_string_with_subst(machine, itemnode, "name", "")); |
| 1854 | | |
| 1855 | | /* allocate a copy of the input tag */ |
| 1856 | | item->input_tag = copy_string(xml_get_attribute_string_with_subst(machine, itemnode, "inputtag", "")); |
| 1857 | | |
| 1858 | | /* find the associated element */ |
| 1859 | | name = xml_get_attribute_string_with_subst(machine, itemnode, "element", NULL); |
| 1860 | | if (name != NULL) |
| 1736 | // loop over all layers |
| 1737 | bool first = true; |
| 1738 | bool scrfirst = true; |
| 1739 | for (item_layer layer = ITEM_LAYER_FIRST; layer < ITEM_LAYER_MAX; layer++) |
| 1861 | 1740 | { |
| 1862 | | layout_element *element; |
| 1741 | // determine if this layer should be visible |
| 1742 | switch (layer) |
| 1743 | { |
| 1744 | case ITEM_LAYER_BACKDROP: m_layenabled[layer] = layerconfig.backdrops_enabled(); break; |
| 1745 | case ITEM_LAYER_OVERLAY: m_layenabled[layer] = layerconfig.overlays_enabled(); break; |
| 1746 | case ITEM_LAYER_BEZEL: m_layenabled[layer] = layerconfig.bezels_enabled(); break; |
| 1747 | default: m_layenabled[layer] = true; break; |
| 1748 | } |
| 1863 | 1749 | |
| 1864 | | /* search the list of elements for a match */ |
| 1865 | | for (element = elemlist; element; element = element->next) |
| 1866 | | if (strcmp(name, element->name) == 0) |
| 1867 | | break; |
| 1750 | // only do it if requested |
| 1751 | if (m_layenabled[layer]) |
| 1752 | for (item *curitem = first_item(layer); curitem != NULL; curitem = curitem->next()) |
| 1753 | { |
| 1754 | // accumulate bounds |
| 1755 | if (first) |
| 1756 | m_bounds = curitem->m_rawbounds; |
| 1757 | else |
| 1758 | union_render_bounds(&m_bounds, &curitem->m_rawbounds); |
| 1759 | first = false; |
| 1868 | 1760 | |
| 1869 | | /* error if not found */ |
| 1870 | | if (element == NULL) |
| 1871 | | fatalerror("Unable to find layout element %s", name); |
| 1872 | | item->element = element; |
| 1761 | // accumulate screen bounds |
| 1762 | if (curitem->m_screen != NULL) |
| 1763 | { |
| 1764 | if (scrfirst) |
| 1765 | m_scrbounds = curitem->m_rawbounds; |
| 1766 | else |
| 1767 | union_render_bounds(&m_scrbounds, &curitem->m_rawbounds); |
| 1768 | scrfirst = false; |
| 1769 | |
| 1770 | // accumulate the screens in use while we're scanning |
| 1771 | m_screens.add(*curitem->m_screen); |
| 1772 | } |
| 1773 | } |
| 1873 | 1774 | } |
| 1874 | 1775 | |
| 1875 | | /* fetch common data */ |
| 1876 | | item->index = xml_get_attribute_int_with_subst(machine, itemnode, "index", -1); |
| 1877 | | item->input_mask = xml_get_attribute_int_with_subst(machine, itemnode, "inputmask", 0); |
| 1878 | | if (item->output_name[0] != 0 && item->element != 0) |
| 1879 | | output_set_value(item->output_name, item->element->defstate); |
| 1880 | | if (load_bounds(machine, xml_get_sibling(itemnode->child, "bounds"), &item->rawbounds)) |
| 1881 | | goto error; |
| 1882 | | if (load_color(machine, xml_get_sibling(itemnode->child, "color"), &item->color)) |
| 1883 | | goto error; |
| 1884 | | if (load_orientation(machine, xml_get_sibling(itemnode->child, "orientation"), &item->orientation)) |
| 1885 | | goto error; |
| 1776 | // if we have an explicit bounds, override it |
| 1777 | if (m_expbounds.x1 > m_expbounds.x0) |
| 1778 | m_bounds = m_expbounds; |
| 1886 | 1779 | |
| 1887 | | /* sanity checks */ |
| 1888 | | if (strcmp(itemnode->name, "screen") == 0) |
| 1780 | // compute the aspect ratio of the view |
| 1781 | m_aspect = (m_bounds.x1 - m_bounds.x0) / (m_bounds.y1 - m_bounds.y0); |
| 1782 | m_scraspect = (m_scrbounds.x1 - m_scrbounds.x0) / (m_scrbounds.y1 - m_scrbounds.y0); |
| 1783 | |
| 1784 | // if we're handling things normally, the target bounds are (0,0)-(1,1) |
| 1785 | render_bounds target_bounds; |
| 1786 | if (!layerconfig.zoom_to_screen() || m_screens.count() == 0) |
| 1889 | 1787 | { |
| 1890 | | if (item->index < 0) |
| 1891 | | fatalerror("Layout references invalid screen index %d", item->index); |
| 1788 | target_bounds.x0 = target_bounds.y0 = 0.0f; |
| 1789 | target_bounds.x1 = target_bounds.y1 = 1.0f; |
| 1892 | 1790 | } |
| 1791 | |
| 1792 | // if we're cropping, we want the screen area to fill (0,0)-(1,1) |
| 1893 | 1793 | else |
| 1894 | 1794 | { |
| 1895 | | if (item->element == NULL) |
| 1896 | | fatalerror("Layout item of type %s require an element tag", itemnode->name); |
| 1795 | float targwidth = (m_bounds.x1 - m_bounds.x0) / (m_scrbounds.x1 - m_scrbounds.x0); |
| 1796 | float targheight = (m_bounds.y1 - m_bounds.y0) / (m_scrbounds.y1 - m_scrbounds.y0); |
| 1797 | target_bounds.x0 = (m_bounds.x0 - m_scrbounds.x0) / (m_bounds.x1 - m_bounds.x0) * targwidth; |
| 1798 | target_bounds.y0 = (m_bounds.y0 - m_scrbounds.y0) / (m_bounds.y1 - m_bounds.y0) * targheight; |
| 1799 | target_bounds.x1 = target_bounds.x0 + targwidth; |
| 1800 | target_bounds.y1 = target_bounds.y0 + targheight; |
| 1897 | 1801 | } |
| 1898 | 1802 | |
| 1899 | | return item; |
| 1803 | // determine the scale/offset for normalization |
| 1804 | float xoffs = m_bounds.x0; |
| 1805 | float yoffs = m_bounds.y0; |
| 1806 | float xscale = (target_bounds.x1 - target_bounds.x0) / (m_bounds.x1 - m_bounds.x0); |
| 1807 | float yscale = (target_bounds.y1 - target_bounds.y0) / (m_bounds.y1 - m_bounds.y0); |
| 1900 | 1808 | |
| 1901 | | error: |
| 1902 | | if (item->output_name != NULL) |
| 1903 | | global_free(item->output_name); |
| 1904 | | if (item->input_tag != NULL) |
| 1905 | | global_free(item->input_tag); |
| 1906 | | global_free(item); |
| 1907 | | return NULL; |
| 1809 | // normalize all the item bounds |
| 1810 | for (item_layer layer = ITEM_LAYER_FIRST; layer < ITEM_LAYER_MAX; layer++) |
| 1811 | for (item *curitem = first_item(layer); curitem != NULL; curitem = curitem->next()) |
| 1812 | { |
| 1813 | curitem->m_bounds.x0 = target_bounds.x0 + (curitem->m_rawbounds.x0 - xoffs) * xscale; |
| 1814 | curitem->m_bounds.x1 = target_bounds.x0 + (curitem->m_rawbounds.x1 - xoffs) * xscale; |
| 1815 | curitem->m_bounds.y0 = target_bounds.y0 + (curitem->m_rawbounds.y0 - yoffs) * yscale; |
| 1816 | curitem->m_bounds.y1 = target_bounds.y0 + (curitem->m_rawbounds.y1 - yoffs) * yscale; |
| 1817 | } |
| 1908 | 1818 | } |
| 1909 | 1819 | |
| 1910 | 1820 | |
| 1911 | | /*------------------------------------------------- |
| 1912 | | load_component_bitmap - load a PNG file |
| 1913 | | with artwork for a component |
| 1914 | | -------------------------------------------------*/ |
| 1915 | 1821 | |
| 1916 | | static bitmap_t *load_component_bitmap(const char *dirname, const char *file, const char *alphafile, int *hasalpha) |
| 1917 | | { |
| 1918 | | bitmap_t *bitmap; |
| 1822 | //************************************************************************** |
| 1823 | // LAYOUT VIEW ITEM |
| 1824 | //************************************************************************** |
| 1919 | 1825 | |
| 1920 | | /* load the basic bitmap */ |
| 1921 | | bitmap = render_load_png(OPTION_ARTPATH, dirname, file, NULL, hasalpha); |
| 1922 | | if (bitmap != NULL && alphafile != NULL) |
| 1826 | //------------------------------------------------- |
| 1827 | // item - constructor |
| 1828 | //------------------------------------------------- |
| 1923 | 1829 | |
| 1924 | | /* load the alpha bitmap if specified */ |
| 1925 | | if (render_load_png(OPTION_ARTPATH, dirname, alphafile, bitmap, hasalpha) == NULL) |
| 1926 | | { |
| 1927 | | global_free(bitmap); |
| 1928 | | bitmap = NULL; |
| 1929 | | } |
| 1830 | layout_view::item::item(running_machine &machine, xml_data_node &itemnode, simple_list<layout_element> &elemlist) |
| 1831 | : m_next(NULL), |
| 1832 | m_element(NULL), |
| 1833 | m_input_mask(0), |
| 1834 | m_screen(NULL), |
| 1835 | m_orientation(ROT0) |
| 1836 | { |
| 1837 | // allocate a copy of the output name |
| 1838 | m_output_name = xml_get_attribute_string_with_subst(machine, itemnode, "name", ""); |
| 1930 | 1839 | |
| 1931 | | /* if we can't load the bitmap, allocate a dummy one and report an error */ |
| 1932 | | if (bitmap == NULL) |
| 1840 | // allocate a copy of the input tag |
| 1841 | m_input_tag = xml_get_attribute_string_with_subst(machine, itemnode, "inputtag", ""); |
| 1842 | |
| 1843 | // find the associated element |
| 1844 | const char *name = xml_get_attribute_string_with_subst(machine, itemnode, "element", NULL); |
| 1845 | if (name != NULL) |
| 1933 | 1846 | { |
| 1934 | | int step, line; |
| 1847 | // search the list of elements for a match |
| 1848 | for (m_element = elemlist.first(); m_element != NULL; m_element = m_element->next()) |
| 1849 | if (strcmp(name, m_element->name()) == 0) |
| 1850 | break; |
| 1935 | 1851 | |
| 1936 | | /* draw some stripes in the bitmap */ |
| 1937 | | bitmap = global_alloc(bitmap_t(100, 100, BITMAP_FORMAT_ARGB32)); |
| 1938 | | bitmap_fill(bitmap, NULL, 0); |
| 1939 | | for (step = 0; step < 100; step += 25) |
| 1940 | | for (line = 0; line < 100; line++) |
| 1941 | | *BITMAP_ADDR32(bitmap, (step + line) % 100, line % 100) = MAKE_ARGB(0xff,0xff,0xff,0xff); |
| 1942 | | |
| 1943 | | /* log an error */ |
| 1944 | | if (alphafile == NULL) |
| 1945 | | logerror("Unable to load component bitmap '%s'", file); |
| 1946 | | else |
| 1947 | | logerror("Unable to load component bitmap '%s'/'%s'", file, alphafile); |
| 1852 | // error if not found |
| 1853 | if (m_element == NULL) |
| 1854 | throw emu_fatalerror("Unable to find layout element %s", name); |
| 1948 | 1855 | } |
| 1949 | 1856 | |
| 1950 | | return bitmap; |
| 1951 | | } |
| 1857 | // fetch common data |
| 1858 | int index = xml_get_attribute_int_with_subst(machine, itemnode, "index", -1); |
| 1859 | if (index != -1) |
| 1860 | m_screen = downcast<screen_device *>(machine.m_devicelist.find(SCREEN, index)); |
| 1861 | m_input_mask = xml_get_attribute_int_with_subst(machine, itemnode, "inputmask", 0); |
| 1862 | if (m_output_name[0] != 0 && m_element != NULL) |
| 1863 | output_set_value(m_output_name, m_element->default_state()); |
| 1864 | parse_bounds(machine, xml_get_sibling(itemnode.child, "bounds"), m_rawbounds); |
| 1865 | parse_color(machine, xml_get_sibling(itemnode.child, "color"), m_color); |
| 1866 | parse_orientation(machine, xml_get_sibling(itemnode.child, "orientation"), m_orientation); |
| 1952 | 1867 | |
| 1953 | | |
| 1954 | | /*------------------------------------------------- |
| 1955 | | load_bounds - parse a bounds XML node |
| 1956 | | -------------------------------------------------*/ |
| 1957 | | |
| 1958 | | static int load_bounds(running_machine &machine, xml_data_node *boundsnode, render_bounds *bounds) |
| 1959 | | { |
| 1960 | | /* skip if nothing */ |
| 1961 | | if (boundsnode == NULL) |
| 1868 | // sanity checks |
| 1869 | if (strcmp(itemnode.name, "screen") == 0) |
| 1962 | 1870 | { |
| 1963 | | bounds->x0 = bounds->y0 = 0.0f; |
| 1964 | | bounds->x1 = bounds->y1 = 1.0f; |
| 1965 | | return 0; |
| 1871 | if (m_screen == NULL) |
| 1872 | throw emu_fatalerror("Layout references invalid screen index %d", index); |
| 1966 | 1873 | } |
| 1967 | | |
| 1968 | | /* parse out the data */ |
| 1969 | | if (xml_get_attribute(boundsnode, "left") != NULL) |
| 1970 | | { |
| 1971 | | /* left/right/top/bottom format */ |
| 1972 | | bounds->x0 = xml_get_attribute_float_with_subst(machine, boundsnode, "left", 0.0f); |
| 1973 | | bounds->x1 = xml_get_attribute_float_with_subst(machine, boundsnode, "right", 1.0f); |
| 1974 | | bounds->y0 = xml_get_attribute_float_with_subst(machine, boundsnode, "top", 0.0f); |
| 1975 | | bounds->y1 = xml_get_attribute_float_with_subst(machine, boundsnode, "bottom", 1.0f); |
| 1976 | | } |
| 1977 | | else if (xml_get_attribute(boundsnode, "x") != NULL) |
| 1978 | | { |
| 1979 | | /* x/y/width/height format */ |
| 1980 | | bounds->x0 = xml_get_attribute_float_with_subst(machine, boundsnode, "x", 0.0f); |
| 1981 | | bounds->x1 = bounds->x0 + xml_get_attribute_float_with_subst(machine, boundsnode, "width", 1.0f); |
| 1982 | | bounds->y0 = xml_get_attribute_float_with_subst(machine, boundsnode, "y", 0.0f); |
| 1983 | | bounds->y1 = bounds->y0 + xml_get_attribute_float_with_subst(machine, boundsnode, "height", 1.0f); |
| 1984 | | } |
| 1985 | 1874 | else |
| 1986 | 1875 | { |
| 1987 | | fatalerror("Illegal bounds value in XML"); |
| 1988 | | return 1; |
| 1876 | if (m_element == NULL) |
| 1877 | throw emu_fatalerror("Layout item of type %s require an element tag", itemnode.name); |
| 1989 | 1878 | } |
| 1990 | | |
| 1991 | | /* check for errors */ |
| 1992 | | if (bounds->x0 > bounds->x1 || bounds->y0 > bounds->y1) |
| 1993 | | { |
| 1994 | | fatalerror("Illegal bounds value in XML: (%f-%f)-(%f-%f)", bounds->x0, bounds->x1, bounds->y0, bounds->y1); |
| 1995 | | return 1; |
| 1996 | | } |
| 1997 | | return 0; |
| 1998 | 1879 | } |
| 1999 | 1880 | |
| 2000 | 1881 | |
| 2001 | | /*------------------------------------------------- |
| 2002 | | load_color - parse a color XML node |
| 2003 | | -------------------------------------------------*/ |
| 1882 | //------------------------------------------------- |
| 1883 | // item - destructor |
| 1884 | //------------------------------------------------- |
| 2004 | 1885 | |
| 2005 | | static int load_color(running_machine &machine, xml_data_node *colornode, render_color *color) |
| 1886 | layout_view::item::~item() |
| 2006 | 1887 | { |
| 2007 | | /* skip if nothing */ |
| 2008 | | if (colornode == NULL) |
| 2009 | | { |
| 2010 | | color->r = color->g = color->b = color->a = 1.0f; |
| 2011 | | return 0; |
| 2012 | | } |
| 2013 | | |
| 2014 | | /* parse out the data */ |
| 2015 | | color->r = xml_get_attribute_float_with_subst(machine, colornode, "red", 1.0); |
| 2016 | | color->g = xml_get_attribute_float_with_subst(machine, colornode, "green", 1.0); |
| 2017 | | color->b = xml_get_attribute_float_with_subst(machine, colornode, "blue", 1.0); |
| 2018 | | color->a = xml_get_attribute_float_with_subst(machine, colornode, "alpha", 1.0); |
| 2019 | | |
| 2020 | | /* check for errors */ |
| 2021 | | if (color->r < 0.0 || color->r > 1.0 || color->g < 0.0 || color->g > 1.0 || |
| 2022 | | color->b < 0.0 || color->b > 1.0 || color->a < 0.0 || color->a > 1.0) |
| 2023 | | { |
| 2024 | | fatalerror("Illegal ARGB color value in XML: %f,%f,%f,%f", color->r, color->g, color->b, color->a); |
| 2025 | | return 1; |
| 2026 | | } |
| 2027 | | return 0; |
| 2028 | 1888 | } |
| 2029 | 1889 | |
| 2030 | 1890 | |
| 2031 | | /*------------------------------------------------- |
| 2032 | | load_orientation - parse an orientation XML |
| 2033 | | node |
| 2034 | | -------------------------------------------------*/ |
| 1891 | //------------------------------------------------- |
| 1892 | // state - fetch state based on configured source |
| 1893 | //------------------------------------------------- |
| 2035 | 1894 | |
| 2036 | | static int load_orientation(running_machine &machine, xml_data_node *orientnode, int *orientation) |
| 1895 | int layout_view::item::state() const |
| 2037 | 1896 | { |
| 2038 | | int rotate; |
| 2039 | | |
| 2040 | | /* skip if nothing */ |
| 2041 | | if (orientnode == NULL) |
| 1897 | int state = 0; |
| 1898 | |
| 1899 | assert(m_element != NULL); |
| 1900 | |
| 1901 | // if configured to an output, fetch the output value |
| 1902 | if (m_output_name[0] != 0) |
| 1903 | state = output_get_value(m_output_name); |
| 1904 | |
| 1905 | // if configured to an input, fetch the input value |
| 1906 | else if (m_input_tag[0] != 0) |
| 2042 | 1907 | { |
| 2043 | | *orientation = ROT0; |
| 2044 | | return 0; |
| 1908 | const input_field_config *field = input_field_by_tag_and_mask(m_element->machine().m_portlist, m_input_tag, m_input_mask); |
| 1909 | if (field != NULL) |
| 1910 | state = ((input_port_read_safe(&m_element->machine(), m_input_tag, 0) ^ field->defvalue) & m_input_mask) ? 1 : 0; |
| 2045 | 1911 | } |
| 2046 | | |
| 2047 | | /* parse out the data */ |
| 2048 | | rotate = xml_get_attribute_int_with_subst(machine, orientnode, "rotate", 0); |
| 2049 | | switch (rotate) |
| 2050 | | { |
| 2051 | | case 0: *orientation = ROT0; break; |
| 2052 | | case 90: *orientation = ROT90; break; |
| 2053 | | case 180: *orientation = ROT180; break; |
| 2054 | | case 270: *orientation = ROT270; break; |
| 2055 | | default: |
| 2056 | | fatalerror("Invalid rotation in XML orientation node: %d", rotate); |
| 2057 | | return 1; |
| 2058 | | } |
| 2059 | | if (strcmp("yes", xml_get_attribute_string_with_subst(machine, orientnode, "swapxy", "no")) == 0) |
| 2060 | | *orientation ^= ORIENTATION_SWAP_XY; |
| 2061 | | if (strcmp("yes", xml_get_attribute_string_with_subst(machine, orientnode, "flipx", "no")) == 0) |
| 2062 | | *orientation ^= ORIENTATION_FLIP_X; |
| 2063 | | if (strcmp("yes", xml_get_attribute_string_with_subst(machine, orientnode, "flipy", "no")) == 0) |
| 2064 | | *orientation ^= ORIENTATION_FLIP_Y; |
| 2065 | | return 0; |
| 1912 | return state; |
| 2066 | 1913 | } |
| 2067 | 1914 | |
| 2068 | 1915 | |
| 2069 | | /*------------------------------------------------- |
| 2070 | | layout_file_free - free memory for a |
| 2071 | | layout_file and all of its subelements |
| 2072 | | -------------------------------------------------*/ |
| 2073 | 1916 | |
| 2074 | | void layout_file_free(layout_file *file) |
| 2075 | | { |
| 2076 | | /* free each element in the list */ |
| 2077 | | while (file->elemlist != NULL) |
| 2078 | | { |
| 2079 | | layout_element *temp = file->elemlist; |
| 2080 | | file->elemlist = temp->next; |
| 2081 | | layout_element_free(temp); |
| 2082 | | } |
| 1917 | //************************************************************************** |
| 1918 | // LAYOUT FILE |
| 1919 | //************************************************************************** |
| 2083 | 1920 | |
| 2084 | | /* free each layout */ |
| 2085 | | while (file->viewlist != NULL) |
| 2086 | | { |
| 2087 | | layout_view *temp = file->viewlist; |
| 2088 | | file->viewlist = temp->next; |
| 2089 | | layout_view_free(temp); |
| 2090 | | } |
| 1921 | //------------------------------------------------- |
| 1922 | // layout_file - constructor |
| 1923 | //------------------------------------------------- |
| 2091 | 1924 | |
| 2092 | | /* free the file itself */ |
| 2093 | | global_free(file); |
| 2094 | | } |
| 2095 | | |
| 2096 | | |
| 2097 | | /*------------------------------------------------- |
| 2098 | | layout_view_free - free memory for a |
| 2099 | | layout_view and all of its subelements |
| 2100 | | -------------------------------------------------*/ |
| 2101 | | |
| 2102 | | static void layout_view_free(layout_view *view) |
| 1925 | layout_file::layout_file(running_machine &machine, xml_data_node &rootnode, const char *dirname) |
| 1926 | : m_next(NULL), |
| 1927 | m_elemlist(machine.m_respool), |
| 1928 | m_viewlist(machine.m_respool) |
| 2103 | 1929 | { |
| 2104 | | int layer; |
| 1930 | // find the layout node |
| 1931 | xml_data_node *mamelayoutnode = xml_get_sibling(rootnode.child, "mamelayout"); |
| 1932 | if (mamelayoutnode == NULL) |
| 1933 | throw emu_fatalerror("Invalid XML file: missing mamelayout node"); |
| 2105 | 1934 | |
| 2106 | | /* for each layer, free each item in that layer */ |
| 2107 | | for (layer = 0; layer < ITEM_LAYER_MAX; layer++) |
| 2108 | | while (view->itemlist[layer] != NULL) |
| 2109 | | { |
| 2110 | | view_item *temp = view->itemlist[layer]; |
| 2111 | | view->itemlist[layer] = temp->next; |
| 2112 | | if (temp->output_name != NULL) |
| 2113 | | global_free(temp->output_name); |
| 2114 | | if (temp->input_tag != NULL) |
| 2115 | | global_free(temp->input_tag); |
| 2116 | | global_free(temp); |
| 2117 | | } |
| 1935 | // validate the config data version |
| 1936 | int version = xml_get_attribute_int(mamelayoutnode, "version", 0); |
| 1937 | if (version != LAYOUT_VERSION) |
| 1938 | throw emu_fatalerror("Invalid XML file: unsupported version"); |
| 2118 | 1939 | |
| 2119 | | /* free the view itself */ |
| 2120 | | if (view->name != NULL) |
| 2121 | | global_free((void *)view->name); |
| 2122 | | global_free(view); |
| 1940 | // parse all the elements |
| 1941 | for (xml_data_node *elemnode = xml_get_sibling(mamelayoutnode->child, "element"); elemnode != NULL; elemnode = xml_get_sibling(elemnode->next, "element")) |
| 1942 | m_elemlist.append(*auto_alloc(&machine, layout_element(machine, *elemnode, dirname))); |
| 1943 | |
| 1944 | // parse all the views |
| 1945 | for (xml_data_node *viewnode = xml_get_sibling(mamelayoutnode->child, "view"); viewnode != NULL; viewnode = xml_get_sibling(viewnode->next, "view")) |
| 1946 | m_viewlist.append(*auto_alloc(&machine, layout_view(machine, *viewnode, m_elemlist))); |
| 2123 | 1947 | } |
| 2124 | 1948 | |
| 2125 | 1949 | |
| 2126 | | /*------------------------------------------------- |
| 2127 | | layout_element_free - free memory for a |
| 2128 | | layout_element and its components |
| 2129 | | -------------------------------------------------*/ |
| 1950 | //------------------------------------------------- |
| 1951 | // ~layout_file - destructor |
| 1952 | //------------------------------------------------- |
| 2130 | 1953 | |
| 2131 | | static void layout_element_free(layout_element *element) |
| 1954 | layout_file::~layout_file() |
| 2132 | 1955 | { |
| 2133 | | /* free all allocated components */ |
| 2134 | | while (element->complist != NULL) |
| 2135 | | { |
| 2136 | | element_component *temp = element->complist; |
| 2137 | | element->complist = temp->next; |
| 2138 | | if (temp->string != NULL) |
| 2139 | | global_free(temp->string); |
| 2140 | | if (temp->dirname != NULL) |
| 2141 | | global_free(temp->dirname); |
| 2142 | | if (temp->imagefile != NULL) |
| 2143 | | global_free(temp->imagefile); |
| 2144 | | if (temp->alphafile != NULL) |
| 2145 | | global_free(temp->alphafile); |
| 2146 | | global_free(temp->bitmap); |
| 2147 | | global_free(temp); |
| 2148 | | } |
| 2149 | | |
| 2150 | | /* free all textures */ |
| 2151 | | if (element->elemtex != NULL) |
| 2152 | | { |
| 2153 | | int state; |
| 2154 | | |
| 2155 | | /* loop over all states and free their textures */ |
| 2156 | | for (state = 0; state <= element->maxstate; state++) |
| 2157 | | element->machine->render().texture_free(element->elemtex[state].texture); |
| 2158 | | |
| 2159 | | global_free(element->elemtex); |
| 2160 | | } |
| 2161 | | |
| 2162 | | /* free the element itself */ |
| 2163 | | if (element->name != NULL) |
| 2164 | | global_free(element->name); |
| 2165 | | global_free(element); |
| 2166 | 1956 | } |