branches/micko/src/emu/guiengine.c
| r23990 | r23991 | |
| 86 | 86 | /// Called by Rocket when it wants to render geometry that it does not wish to optimise. |
| 87 | 87 | virtual void RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation) |
| 88 | 88 | { |
| 89 | bitmap_rgb32 *bitmap = ((bitmap_rgb32 *)texture); |
| 90 | for (int i = 0; i < num_indices/6; i++) |
| 91 | { |
| 92 | int p1 = indices[i*6+0]; |
| 93 | int p2 = indices[i*6+5]; |
| 94 | if (bitmap!=0) |
| 95 | { |
| 96 | render_texture *hilight_texture = machine().render().texture_alloc(); |
| 97 | rectangle bit = bitmap->cliprect(); |
| 98 | rectangle myrect = bitmap->cliprect(); |
| 89 | 99 | |
| 90 | | for (int i = 0; i < num_indices/6; i++) |
| 91 | | { |
| 92 | | render_texture *hilight_texture = machine().render().texture_alloc(); |
| 93 | | rectangle bit = ((bitmap_rgb32 *)texture)->cliprect(); |
| 94 | | rectangle myrect = ((bitmap_rgb32 *)texture)->cliprect(); |
| 95 | | int p1 = indices[i*6+0]; |
| 96 | | int p2 = indices[i*6+5]; |
| 100 | myrect.min_x = bit.max_x * vertices[p1].tex_coord.x; |
| 101 | myrect.min_y = bit.max_y * vertices[p1].tex_coord.y; |
| 102 | myrect.max_x = bit.max_x * vertices[p2].tex_coord.x; |
| 103 | myrect.max_y = bit.max_y * vertices[p2].tex_coord.y; |
| 104 | if (myrect.min_x > myrect.max_x) { int t = myrect.max_x; myrect.max_x = myrect.min_x; myrect.min_x = t; } // this should be flipping |
| 105 | if (myrect.min_y > myrect.max_y) { int t = myrect.max_y; myrect.max_y = myrect.min_y; myrect.min_y = t; } |
| 97 | 106 | |
| 98 | | myrect.min_x = bit.max_x * vertices[p1].tex_coord.x; |
| 99 | | myrect.min_y = bit.max_y * vertices[p1].tex_coord.y; |
| 100 | | myrect.max_x = bit.max_x * vertices[p2].tex_coord.x; |
| 101 | | myrect.max_y = bit.max_y * vertices[p2].tex_coord.y; |
| 102 | | if (myrect.min_x > myrect.max_x) { int t = myrect.max_x; myrect.max_x = myrect.min_x; myrect.min_x = t; } // this should be flipping |
| 103 | | if (myrect.min_y > myrect.max_y) { int t = myrect.max_y; myrect.max_y = myrect.min_y; myrect.min_y = t; } |
| 107 | hilight_texture->set_bitmap(*((bitmap_rgb32 *)texture), myrect, TEXFORMAT_ARGB32); |
| 108 | rgb_t col = MAKE_ARGB(vertices[p1].colour.alpha, vertices[p1].colour.red, vertices[p1].colour.green, vertices[p1].colour.blue); |
| 109 | machine().render().ui_container().add_quad((vertices[p1].position.x+translation.x)/1280,(vertices[p1].position.y+translation.y)/960, (vertices[p2].position.x+translation.x)/1280,(vertices[p2].position.y+translation.y)/960, col, hilight_texture,PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 110 | //machine().render().texture_free(hilight_texture); |
| 111 | } else { |
| 112 | rgb_t col = MAKE_ARGB(vertices[p1].colour.alpha, vertices[p1].colour.red, vertices[p1].colour.green, vertices[p1].colour.blue); |
| 113 | int x1 = MIN(vertices[p1].position.x,vertices[p2].position.x); |
| 114 | int x2 = MAX(vertices[p1].position.x,vertices[p2].position.x); |
| 115 | int y1 = MIN(vertices[p1].position.y,vertices[p2].position.y); |
| 116 | int y2 = MAX(vertices[p1].position.y,vertices[p2].position.y); |
| 117 | machine().render().ui_container().add_quad((x1+translation.x)/1280,(y1+translation.y)/960, (x2+translation.x)/1280,(y2+translation.y)/960, col, NULL,PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 118 | } |
| 104 | 119 | |
| 105 | | hilight_texture->set_bitmap(*((bitmap_rgb32 *)texture), myrect, TEXFORMAT_ARGB32); |
| 106 | | |
| 107 | | machine().render().ui_container().add_quad((vertices[p1].position.x+translation.x)/1280,(vertices[p1].position.y+translation.y)/960, (vertices[p2].position.x+translation.x)/1280,(vertices[p2].position.y+translation.y)/960, UI_BORDER_COLOR, hilight_texture,PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); |
| 108 | | //machine().render().texture_free(hilight_texture); |
| 109 | | } |
| 110 | | |
| 120 | } |
| 111 | 121 | } |
| 112 | 122 | |
| 113 | 123 | /// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future. |
| r23990 | r23991 | |
| 160 | 170 | virtual bool LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source) |
| 161 | 171 | { |
| 162 | 172 | |
| 163 | | |
| 164 | | emu_file file("", OPEN_FLAG_READ); |
| 165 | | file_error filerr = file.open(source.CString()); |
| 173 | core_file *file = NULL; |
| 174 | file_error filerr = core_fopen(source.CString(), OPEN_FLAG_READ, &file); |
| 166 | 175 | if(filerr != FILERR_NONE) |
| 167 | 176 | { |
| 168 | 177 | return false; |
| r23990 | r23991 | |
| 173 | 182 | { |
| 174 | 183 | bitmap_argb32 bitmap; |
| 175 | 184 | png_read_bitmap(file, bitmap); |
| 176 | | bitmap_rgb32 *hilight_bitmap = auto_bitmap_rgb32_alloc(machine(), bitmap.width(), bitmap.height()); |
| 177 | | for (int y = 0; y < bitmap.height(); ++y) |
| 185 | int image_size = bitmap.width() * bitmap.height() * 4; // We always make 32bit textures |
| 186 | unsigned char* image_dest = new unsigned char[image_size]; |
| 187 | |
| 188 | // Targa is BGR, swap to RGB and flip Y axis |
| 189 | for (long y = 0; y < bitmap.height(); y++) |
| 178 | 190 | { |
| 179 | | for (int x = 0; x < bitmap.width(); ++x) |
| 191 | long write_index = y * bitmap.width() * 4; |
| 192 | for (long x = 0; x < bitmap.width(); x++) |
| 180 | 193 | { |
| 181 | | hilight_bitmap->pix32(y, x) = bitmap.pix32(y,x); |
| 194 | image_dest[write_index] = (bitmap.pix32(y,x) >> 16) & 0xff; |
| 195 | image_dest[write_index+1] = (bitmap.pix32(y,x) >> 8) & 0xff; |
| 196 | image_dest[write_index+2] = (bitmap.pix32(y,x) >> 0) & 0xff; |
| 197 | image_dest[write_index+3] = (bitmap.pix32(y,x) >> 24) & 0xff; |
| 198 | |
| 199 | write_index += 4; |
| 182 | 200 | } |
| 183 | 201 | } |
| 202 | |
| 184 | 203 | |
| 185 | | texture_handle = (Rocket::Core::TextureHandle)hilight_bitmap; |
| 186 | 204 | texture_dimensions.x = bitmap.width(); |
| 187 | 205 | texture_dimensions.y = bitmap.height(); |
| 188 | | return true; |
| 206 | bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions); |
| 207 | |
| 208 | delete [] image_dest; |
| 209 | |
| 210 | return success; |
| 189 | 211 | } |
| 190 | 212 | else |
| 191 | 213 | { |
| 192 | 214 | |
| 193 | | file.seek(0, SEEK_END); |
| 194 | | size_t buffer_size = file.tell(); |
| 195 | | file.seek(0, SEEK_SET); |
| 196 | 215 | |
| 216 | size_t buffer_size = core_fsize(file); |
| 217 | |
| 197 | 218 | char* buffer = new char[buffer_size]; |
| 198 | | file.read(buffer, buffer_size); |
| 199 | | file.close(); |
| 219 | core_fread(file, buffer, buffer_size); |
| 220 | core_fclose(file); |
| 200 | 221 | |
| 201 | 222 | TGAHeader header; |
| 202 | 223 | memcpy(&header, buffer, sizeof(TGAHeader)); |