Previous 199869 Revisions Next

r23989 Friday 28th June, 2013 at 10:01:53 UTC by Miodrag Milanović
(MickoWIP) make it us PNG as well (nw)
[/branches/micko/src/emu]guiengine.c
[/branches/micko/src/tools]ShellRenderInterfaceOpenGL.cpp
[/branches/micko/test]invader.png* invader.rcss invader.tga

branches/micko/src/tools/ShellRenderInterfaceOpenGL.cpp
r23988r23989
2727
2828#include <ShellRenderInterfaceOpenGL.h>
2929#include <Rocket/Core.h>
30
30#include "png.h"
31#include "corefile.h"
3132#define GL_CLAMP_TO_EDGE 0x812F
3233
3334ShellRenderInterfaceOpenGL::ShellRenderInterfaceOpenGL()
r23988r23989
116117// Called by Rocket when a texture is required by the library.     
117118bool ShellRenderInterfaceOpenGL::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source)
118119{
119   Rocket::Core::FileInterface* file_interface = Rocket::Core::GetFileInterface();
120   Rocket::Core::FileHandle file_handle = file_interface->Open(source);
121   if (!file_handle)
122   {
123      return false;
124   }
125   
126   file_interface->Seek(file_handle, 0, SEEK_END);
127   size_t buffer_size = file_interface->Tell(file_handle);
128   file_interface->Seek(file_handle, 0, SEEK_SET);
129   
130   char* buffer = new char[buffer_size];
131   file_interface->Read(buffer, buffer_size, file_handle);
132   file_interface->Close(file_handle);
120     
121      core_file *file = NULL;
122      file_error filerr = core_fopen(source.CString(), OPEN_FLAG_READ, &file);     
123      if(filerr != FILERR_NONE)
124      {
125         return false;
126      }     
127     
128      astring fname(source.CString());
129      if (fname.find(0, ".png") != -1)
130      {
131         bitmap_argb32 bitmap;
132         png_read_bitmap(file, bitmap);           
133         int image_size = bitmap.width() * bitmap.height() * 4; // We always make 32bit textures
134         unsigned char* image_dest = new unsigned char[image_size];
135         
136         // Targa is BGR, swap to RGB and flip Y axis
137         for (long y = 0; y < bitmap.height(); y++)
138         {
139            long write_index = y * bitmap.width() * 4;
140            for (long x = 0; x < bitmap.width(); x++)
141            {
142               image_dest[write_index] =   (bitmap.pix32(y,x) >> 16) & 0xff;
143               image_dest[write_index+1] = (bitmap.pix32(y,x) >> 8) & 0xff;
144               image_dest[write_index+2] = (bitmap.pix32(y,x) >> 0) & 0xff;
145               image_dest[write_index+3] = (bitmap.pix32(y,x) >> 24) & 0xff;
146               
147               write_index += 4;
148            }
149         }
133150
134   TGAHeader header;
135   memcpy(&header, buffer, sizeof(TGAHeader));
151         
152         texture_dimensions.x = bitmap.width();
153         texture_dimensions.y = bitmap.height();
154         bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions);
155         
156         delete [] image_dest;
157         
158         return success;
159      }
160      else
161      {
136162   
137   int color_mode = header.bitsPerPixel / 8;
138   int image_size = header.width * header.height * 4; // We always make 32bit textures
139   
140   if (header.dataType != 2)
141   {
142      Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24/32bit uncompressed TGAs are supported.");
143      return false;
144   }
145   
146   // Ensure we have at least 3 colors
147   if (color_mode < 3)
148   {
149      Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24 and 32bit textures are supported");
150      return false;
151   }
152   
153   const char* image_src = buffer + sizeof(TGAHeader);
154   unsigned char* image_dest = new unsigned char[image_size];
155   
156   // Targa is BGR, swap to RGB and flip Y axis
157   for (long y = 0; y < header.height; y++)
158   {
159      long read_index = y * header.width * color_mode;
160      long write_index = ((header.imageDescriptor & 32) != 0) ? read_index : (header.height - y - 1) * header.width * color_mode;
161      for (long x = 0; x < header.width; x++)
162      {
163         image_dest[write_index] = image_src[read_index+2];
164         image_dest[write_index+1] = image_src[read_index+1];
165         image_dest[write_index+2] = image_src[read_index];
166         if (color_mode == 4)
167            image_dest[write_index+3] = image_src[read_index+3];
168         else
169            image_dest[write_index+3] = 255;
163         size_t buffer_size = core_fsize(file);
170164         
171         write_index += 4;
172         read_index += color_mode;
165         char* buffer = new char[buffer_size];
166         core_fread(file, buffer, buffer_size);
167         core_fclose(file);
168
169         TGAHeader header;
170         memcpy(&header, buffer, sizeof(TGAHeader));
171         
172         int color_mode = header.bitsPerPixel / 8;
173         int image_size = header.width * header.height * 4; // We always make 32bit textures
174         
175         if (header.dataType != 2)
176         {
177            Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24/32bit uncompressed TGAs are supported.");
178            printf("Only 24/32bit uncompressed TGAs are supported.\n");
179            return false;
180         }
181         
182         // Ensure we have at least 3 colors
183         if (color_mode < 3)
184         {
185            Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24 and 32bit textures are supported");
186            printf("Only 24 and 32bit textures are supported\n");
187            return false;
188         }
189         
190         const char* image_src = buffer + sizeof(TGAHeader);
191         unsigned char* image_dest = new unsigned char[image_size];
192         
193         // Targa is BGR, swap to RGB and flip Y axis
194         for (long y = 0; y < header.height; y++)
195         {
196            long read_index = y * header.width * color_mode;
197            long write_index = ((header.imageDescriptor & 32) != 0) ? read_index : (header.height - y - 1) * header.width * color_mode;
198            for (long x = 0; x < header.width; x++)
199            {
200               image_dest[write_index] = image_src[read_index+2];
201               image_dest[write_index+1] = image_src[read_index+1];
202               image_dest[write_index+2] = image_src[read_index];
203               if (color_mode == 4)
204                  image_dest[write_index+3] = image_src[read_index+3];
205               else
206                  image_dest[write_index+3] = 255;
207               
208               write_index += 4;
209               read_index += color_mode;
210            }
211         }
212
213         texture_dimensions.x = header.width;
214         texture_dimensions.y = header.height;
215         
216         bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions);
217         
218         delete [] image_dest;
219         delete [] buffer;
220         return success;
173221      }
174   }
175
176   texture_dimensions.x = header.width;
177   texture_dimensions.y = header.height;
178   
179   bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions);
180   
181   delete [] image_dest;
182   delete [] buffer;
183   
184   return success;
185222}
186223
187224// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
branches/micko/src/emu/guiengine.c
r23988r23989
4343#include "emu.h"
4444#include "emuopts.h"
4545#include "osdepend.h"
46#include "png.h"
4647
4748
4849class ShellSystemInterface : public Rocket::Core::SystemInterface
r23988r23989
6566   virtual float GetElapsedTime() { return machine().time().as_double(); }
6667};
6768
68#define UI_LINE_WIDTH           (1.0f / 500.0f)
6969#define UI_BORDER_COLOR         MAKE_ARGB(0xff,0xff,0xff,0xff)
7070
7171class ShellRenderInterfaceSystem : public Rocket::Core::RenderInterface
r23988r23989
104104
105105         hilight_texture->set_bitmap(*((bitmap_rgb32 *)texture), myrect, TEXFORMAT_ARGB32);     
106106         
107         machine().render().ui_container().add_quad((vertices[p1].position.x+translation.x)/1024,(vertices[p1].position.y+translation.y)/768, (vertices[p2].position.x+translation.x)/1024,(vertices[p2].position.y+translation.y)/768, UI_BORDER_COLOR, hilight_texture,PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
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));
108108         //machine().render().texture_free(hilight_texture);
109109      }                 
110110     
r23988r23989
159159   /// Called by Rocket when a texture is required by the library.
160160   virtual bool LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source)
161161   {
162     
163     
162164      emu_file file("", OPEN_FLAG_READ);
163165      file_error filerr = file.open(source.CString());   
164166      if(filerr != FILERR_NONE)
165167      {
166168         return false;
167      }
169      }     
168170     
169      file.seek(0, SEEK_END);
170      size_t buffer_size = file.tell();
171      file.seek(0, SEEK_SET);
172     
173      char* buffer = new char[buffer_size];
174      file.read(buffer, buffer_size);
175      file.close();
176
177      TGAHeader header;
178      memcpy(&header, buffer, sizeof(TGAHeader));
179     
180      int color_mode = header.bitsPerPixel / 8;
181      int image_size = header.width * header.height * 4; // We always make 32bit textures
182     
183      if (header.dataType != 2)
171      astring fname(source.CString());
172      if (fname.find(0, ".png") != -1)
184173      {
185         Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24/32bit uncompressed TGAs are supported.");
186         return false;
174         bitmap_argb32 bitmap;
175         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)
178         {
179            for (int x = 0; x < bitmap.width(); ++x)
180            {
181               hilight_bitmap->pix32(y, x) = bitmap.pix32(y,x);
182            }
183         }
184         
185         texture_handle = (Rocket::Core::TextureHandle)hilight_bitmap;         
186         texture_dimensions.x = bitmap.width();
187         texture_dimensions.y = bitmap.height();
188         return true;
187189      }
188     
189      // Ensure we have at least 3 colors
190      if (color_mode < 3)
190      else
191191      {
192         Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24 and 32bit textures are supported");
193         return false;
194      }
195192     
196      const char* image_src = buffer + sizeof(TGAHeader);
197      unsigned char* image_dest = new unsigned char[image_size];
198     
199      // Targa is BGR, swap to RGB and flip Y axis
200      for (long y = 0; y < header.height; y++)
201      {
202         long read_index = y * header.width * color_mode;
203         long write_index = ((header.imageDescriptor & 32) != 0) ? read_index : (header.height - y - 1) * header.width * color_mode;
204         for (long x = 0; x < header.width; x++)
193         file.seek(0, SEEK_END);
194         size_t buffer_size = file.tell();
195         file.seek(0, SEEK_SET);
196         
197         char* buffer = new char[buffer_size];
198         file.read(buffer, buffer_size);
199         file.close();
200
201         TGAHeader header;
202         memcpy(&header, buffer, sizeof(TGAHeader));
203         
204         int color_mode = header.bitsPerPixel / 8;
205         int image_size = header.width * header.height * 4; // We always make 32bit textures
206         
207         if (header.dataType != 2)
205208         {
206            image_dest[write_index] = image_src[read_index+2];
207            image_dest[write_index+1] = image_src[read_index+1];
208            image_dest[write_index+2] = image_src[read_index];
209            if (color_mode == 4)
210               image_dest[write_index+3] = image_src[read_index+3];
211            else
212               image_dest[write_index+3] = 255;
213           
214            write_index += 4;
215            read_index += color_mode;
209            Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24/32bit uncompressed TGAs are supported.");
210            printf("Only 24/32bit uncompressed TGAs are supported.\n");
211            return false;
216212         }
213         
214         // Ensure we have at least 3 colors
215         if (color_mode < 3)
216         {
217            Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24 and 32bit textures are supported");
218            printf("Only 24 and 32bit textures are supported\n");
219            return false;
220         }
221         
222         const char* image_src = buffer + sizeof(TGAHeader);
223         unsigned char* image_dest = new unsigned char[image_size];
224         
225         // Targa is BGR, swap to RGB and flip Y axis
226         for (long y = 0; y < header.height; y++)
227         {
228            long read_index = y * header.width * color_mode;
229            long write_index = ((header.imageDescriptor & 32) != 0) ? read_index : (header.height - y - 1) * header.width * color_mode;
230            for (long x = 0; x < header.width; x++)
231            {
232               image_dest[write_index] = image_src[read_index+2];
233               image_dest[write_index+1] = image_src[read_index+1];
234               image_dest[write_index+2] = image_src[read_index];
235               if (color_mode == 4)
236                  image_dest[write_index+3] = image_src[read_index+3];
237               else
238                  image_dest[write_index+3] = 255;
239               
240               write_index += 4;
241               read_index += color_mode;
242            }
243         }
244
245         texture_dimensions.x = header.width;
246         texture_dimensions.y = header.height;
247         
248         bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions);
249         
250         delete [] image_dest;
251         delete [] buffer;
252         return success;
217253      }
218
219      texture_dimensions.x = header.width;
220      texture_dimensions.y = header.height;
221254     
222      bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions);
223     
224      delete [] image_dest;
225      delete [] buffer;
226     
227      return success;
228255   }
229256   /// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
230257   virtual bool GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const Rocket::Core::byte* source, const Rocket::Core::Vector2i& source_dimensions)
r23988r23989
297324   Rocket::Controls::Initialise();
298325   
299326   // Create the main Rocket context and set it on the shell's input layer.
300   context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768));
327   context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1280, 960));
301328   if (context == NULL)
302329   {
303330      Rocket::Core::Shutdown();
branches/micko/test/invader.tga
branches/micko/test/invader.png
Property changes on: branches/micko/test/invader.png
Added: svn:mime-type
   + image/png
branches/micko/test/invader.rcss
r23988r23989
4242   height: 39px;
4343   
4444   icon-decorator: image;
45   icon-image-src: invader.tga;
45   icon-image-src: invader.png;
4646}
4747
4848div#title_bar span
r23988r23989
6060   outline-color: black;
6161
6262   background-decorator: tiled-horizontal;
63   background-left-image: invader.tga 147px 0px 229px 85px;
64   background-center-image: invader.tga stretch 229px 0px 230px 85px;
65   background-right-image: invader.tga 231px 0px 246px 85px;
63   background-left-image: invader.png 147px 0px 229px 85px;
64   background-center-image: invader.png stretch 229px 0px 230px 85px;
65   background-right-image: invader.png 231px 0px 246px 85px;
6666}
6767
6868
r23988r23989
7373   padding: 10px 15px;
7474
7575   background-decorator: tiled-box;
76   background-top-left-image: invader.tga 0px 0px 133px 140px;
77   background-top-right-image: invader.tga 136px 0px 146px 140px;
78   background-top-image: invader.tga stretch 134px 0px 135px 140px;
79   background-bottom-left-image: invader.tga 0px 140px 11px 151px;
80   background-bottom-right-image: invader.tga 136px 140px 146px 151px;
81   background-bottom-image: invader.tga stretch 11px 140px 12px 151px;
82   background-left-image: invader.tga stretch 0px 139px 10px 140px;
83   background-center-image: invader.tga stretch 11px 139px 12px 140px;
76   background-top-left-image: invader.png 0px 0px 133px 140px;
77   background-top-right-image: invader.png 136px 0px 146px 140px;
78   background-top-image: invader.png stretch 134px 0px 135px 140px;
79   background-bottom-left-image: invader.png 0px 140px 11px 151px;
80   background-bottom-right-image: invader.png 136px 140px 146px 151px;
81   background-bottom-image: invader.png stretch 11px 140px 12px 151px;
82   background-left-image: invader.png stretch 0px 139px 10px 140px;
83   background-center-image: invader.png stretch 11px 139px 12px 140px;
8484}
8585
8686div#content
r23988r23989
149149   tab-index: auto;
150150
151151   background-decorator: image;
152   background-image: invader.tga 247px 0px 406px 45px;
152   background-image: invader.png 247px 0px 406px 45px;
153153}
154154
155155button:focus,
r23988r23989
182182   padding: 10px 10px 0px;
183183
184184   background-decorator: tiled-horizontal;
185   background-left-image: invader.tga 162px 192px 176px 223px;
186   background-center-image: invader.tga stretch 176px 192px 177px 223px;
185   background-left-image: invader.png 162px 192px 176px 223px;
186   background-center-image: invader.png stretch 176px 192px 177px 223px;
187187}
188188
189189input.text,
r23988r23989
229229   padding: 9px 10px 0px 10px;
230230
231231   background-decorator: image;
232   background-image: invader.tga 162px 192px 307px 229px;
232   background-image: invader.png 162px 192px 307px 229px;
233233}
234234
235235select selectvalue:hover,
r23988r23989
245245   height: 37px;
246246   
247247   icon-decorator: image;
248   icon-image: invader.tga 307px 192px 337px 229px;
248   icon-image: invader.png 307px 192px 337px 229px;
249249}
250250
251251select selectarrow:hover,
r23988r23989
276276datagrid datagridbody
277277{
278278   background-decorator: tiled-box;
279   background-top-left-image: invader.tga 281px 275px 292px 284px;
280   background-top-right-image: invader.tga 294px 275px 305px 284px;
281   background-top-image: invader.tga stretch 292px 275px 293px 284px;
282   background-bottom-left-image: invader.tga 281px 285px 292px 296px;
283   background-bottom-right-image: invader.tga 294px 285px 305px 296px;
284   background-bottom-image: invader.tga stretch 292px 285px 293px 296px;
285   background-left-image: invader.tga stretch 281px 283px 292px 284px;
286   background-center-image: invader.tga stretch 292px 283px 293px 284px;
279   background-top-left-image: invader.png 281px 275px 292px 284px;
280   background-top-right-image: invader.png 294px 275px 305px 284px;
281   background-top-image: invader.png stretch 292px 275px 293px 284px;
282   background-bottom-left-image: invader.png 281px 285px 292px 296px;
283   background-bottom-right-image: invader.png 294px 285px 305px 296px;
284   background-bottom-image: invader.png stretch 292px 285px 293px 296px;
285   background-left-image: invader.png stretch 281px 283px 292px 284px;
286   background-center-image: invader.png stretch 292px 283px 293px 284px;
287287}
288288
289289select selectbox option,
r23988r23989
320320input.radio
321321{
322322   icon-decorator: image;
323   icon-image: invader.tga 407px 0px 437px 30px;
323   icon-image: invader.png 407px 0px 437px 30px;
324324}
325325
326326input.radio:hover
r23988r23989
353353input.checkbox
354354{
355355   icon-decorator: image;
356   icon-image: invader.tga 407px 60px 437px 90px;
356   icon-image: invader.png 407px 60px 437px 90px;
357357}
358358
359359input.checkbox:hover
r23988r23989
392392   padding: 5px 10px 0px 10px;
393393
394394   background-decorator: tiled-horizontal;
395   background-left-image: invader.tga 127px 192px 143px 223px;
396   background-center-image: invader.tga stretch 143px 192px 145px 223px;
397   background-right-image: invader.tga 145px 192px 160px 223px;
395   background-left-image: invader.png 127px 192px 143px 223px;
396   background-center-image: invader.png stretch 143px 192px 145px 223px;
397   background-right-image: invader.png 145px 192px 160px 223px;
398398}
399399
400400datagrid datagridbody
r23988r23989
417417   width: 17px;
418418   
419419   icon-decorator: image;
420   icon-image: invader.tga 3px 232px 20px 249px;
420   icon-image: invader.png 3px 232px 20px 249px;
421421}
422422
423423datagridexpand:hover
r23988r23989
448448scrollbarvertical slidertrack
449449{
450450   background-decorator: tiled-vertical;
451   background-top-image: invader.tga 70px 199px 97px 201px;
452   background-center-image: invader.tga stretch 70px 201px 97px 202px;
453   background-bottom-image: invader.tga 70px 203px 97px 204px;
451   background-top-image: invader.png 70px 199px 97px 201px;
452   background-center-image: invader.png stretch 70px 201px 97px 202px;
453   background-bottom-image: invader.png 70px 203px 97px 204px;
454454}
455455
456456scrollbarvertical sliderbar
r23988r23989
460460   min-height: 46px;
461461
462462   background-decorator: tiled-vertical;
463   background-top-image: invader.tga 56px 152px 79px 175px;
464   background-center-image: invader.tga stretch 56px 175px 79px 175px;
465   background-bottom-image: invader.tga 56px 176px 79px 198px;
463   background-top-image: invader.png 56px 152px 79px 175px;
464   background-center-image: invader.png stretch 56px 175px 79px 175px;
465   background-bottom-image: invader.png 56px 176px 79px 198px;
466466}
467467
468468scrollbarvertical sliderbar:hover
r23988r23989
485485   height: 24px;
486486   
487487   icon-decorator: image;
488   icon-image: invader.tga 0px 152px 27px 176px;
488   icon-image: invader.png 0px 152px 27px 176px;
489489}
490490
491491scrollbarvertical sliderarrowdec:hover,
r23988r23989
506506   height: 24px;
507507   
508508   icon-decorator: image;
509   icon-image: invader.tga 28px 152px 55px 176px;
509   icon-image: invader.png 28px 152px 55px 176px;
510510}
511511
512512

Previous 199869 Revisions Next


© 1997-2024 The MAME Team