Example #1
0
wxSize  ThemeBase::ImageSize( int iIndex )
{
   wxASSERT( iIndex >= 0 );
   EnsureInitialised();
   wxImage & Image = mImages[iIndex];
   return wxSize( Image.GetWidth(), Image.GetHeight());
}
Example #2
0
wxFont   & ThemeBase::Font( int iIndex )
{
   wxASSERT( iIndex >= 0 );
   EnsureInitialised();
   // Purposeful null deref.  Function is for future use.
   // If anyone tries to use it now they will get an error.
   return *(wxFont*)NULL;
}
Example #3
0
bool RenderBuffer::CreateRenderBuffer(const GLenum& internalformat, const unsigned int& width, const unsigned int& height) {
	EnsureInitialised(); // ensure this render buffer has been set up properly
	mWidth = util::NextPowerOf2(width); // store the width
	mHeight = util::NextPowerOf2(height); // store the height
	
	glBindRenderbuffer(GL_RENDERBUFFER, mRenderBufferID); // bind this render buffer as the current
	OpenGLStates::mCurrentRenderBuffer = mRenderBufferID; // set the current render buffer as this
	glRenderbufferStorage(GL_RENDERBUFFER, internalformat, mWidth, mHeight); // create this render buffer with the supplied data
	
	return true;
}
Example #4
0
File: pbo.cpp Project: dakodun/uair
void PBO::BufferData(const GLenum& target, const GLsizeiptr& size, const GLenum& usage) {
	EnsureInitialised(); // ensure this pbo has been set up properly
	
	if (target == GL_PIXEL_PACK_BUFFER) { // if we're using the pack buffer...
		OpenGLStates::BindPBOPack(mPBOID); // bind the pbo to the pack buffer
	}
	else {
		OpenGLStates::BindPBOUnpack(mPBOID); // otherwise bind the pbo to the unpack buffer
	}
	
	glBufferData(target, size, 0, usage); // assign memory to the pbo
}
Example #5
0
/// This function is called to load the initial Theme images.
/// There are many possible choices for what this function
/// should do, as we have (potentially) four sources of images.
///   - (deprecated) programmed in XPMs.
///   - Programmed in in-built theme.
///   - External image Cache file.
///   - External component files.
///
/// We currently still have the deprecated XPMs, so we have
/// those being used if the user decides not to load themes.
///
/// @param bLookForExternalFiles uses file iff true.
void ThemeBase::LoadThemeAtStartUp( bool bLookForExternalFiles )
{
   EnsureInitialised();

   const bool cbBinaryRead =true;
   const bool cbOkIfNotFound = true;

   // IF not interested in external files, 
   // THEN just use the internal default set.
   if( !bLookForExternalFiles )
   {
      // IF the XPMs have been retired, THEN we'd better use the built-in cache
      // at start up.  
      // ELSE do nothing, we already have XPM based images.
#ifdef XPMS_RETIRED
      ReadThemeInternal();
#endif
      return;
   }
   // ELSE IF can't read the external image cache.
   else if( !ReadImageCache( cbBinaryRead, cbOkIfNotFound ) )
   {
      // THEN get the default set.
      ReadThemeInternal();

      // JKC: Now we could go on and load the individual images
      // on top of the default images using the commented out 
      // code that follows...
      //
      // However, I think it is better to get the user to 
      // build a new image cache, which they can do easily
      // from the Theme preferences tab.
#if 0
      // and now add any available component images.
      LoadComponents( cbOkIfNotFound );

      // JKC: I'm usure about doing this next step automatically.
      // Suppose the disk is write protected?
      // Is having the image cache created automatically 
      // going to confuse users?  Do we need version specific names?
      // and now save the combined image as a cache for later use.
      // We should load the images a little faster in future as a result.
      CreateImageCache();
#endif
   }

   // Next line is not required as we haven't yet built the GUI 
   // when this function is (or should be) called.
   // ApplyUpdatedImages();
}
Example #6
0
/// Writes an html file with an image map of the ImageCache
/// Very handy for seeing what each part is for.
void ThemeBase::WriteImageMap( )
{
   EnsureInitialised();
   wxBusyCursor busy;

   int i;
   mFlow.Init( ImageCacheWidth );
   
   wxFFile File( FileNames::ThemeCacheHtm(), wxT("wb") );// I'll put in new lines explicitly.
   if( !File.IsOpened() )
      return;

   File.Write( wxT("<html>\r\n"));
   File.Write( wxT("<body>\r\n"));
   File.Write( wxT("<img src=\"ImageCache.png\" usemap=\"#map1\">\r\n" ));
   File.Write( wxT("<map name=\"map1\">\r\n") );

   for(i=0;i<(int)mImages.GetCount();i++)
   {
      wxImage &SrcImage = mImages[i];
      mFlow.mFlags = mBitmapFlags[i];
      if( (mBitmapFlags[i] & resFlagInternal)==0)
      {
         mFlow.GetNextPosition( SrcImage.GetWidth(), SrcImage.GetHeight());
         // No href in html.  Uses title not alt.
         wxRect R( mFlow.Rect() );
         File.Write( wxString::Format( 
            wxT("<area title=\"Bitmap:%s\" shape=rect coords=\"%i,%i,%i,%i\">\r\n"),
            mBitmapNames[i].c_str(), 
            R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom()) );
      }
   }
   // Now save the colours.
   mFlow.SetNewGroup(1);
   const int iColSize=10;
   for(i=0;i<(int)mColours.GetCount();i++)
   {
      mFlow.GetNextPosition( iColSize, iColSize );
      // No href in html.  Uses title not alt.
      wxRect R( mFlow.Rect() );
      File.Write( wxString::Format( wxT("<area title=\"Colour:%s\" shape=rect coords=\"%i,%i,%i,%i\">\r\n"),
         mColourNames[i].c_str(), 
         R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom()) );
   }
   File.Write( wxT("</map>\r\n") );
   File.Write( wxT("</body>\r\n"));
   File.Write( wxT("</html>\r\n"));
   // File will be closed automatically.
}
Example #7
0
/// Writes a series of Macro definitions that can be used in the include file.
void ThemeBase::WriteImageDefs( )
{
   EnsureInitialised();
   wxBusyCursor busy;

   int i;
   wxFFile File( FileNames::ThemeImageDefsAsCee(), wxT("wb") );
   if( !File.IsOpened() )
      return;
   teResourceFlags PrevFlags = (teResourceFlags)-1;
   for(i=0;i<(int)mImages.GetCount();i++)
   {
      wxImage &SrcImage = mImages[i];
      // No href in html.  Uses title not alt.
      if( PrevFlags != mBitmapFlags[i] )
      {
         PrevFlags = (teResourceFlags)mBitmapFlags[i];
         int t = (int)PrevFlags;
         wxString Temp;
         if( t==0 ) Temp = wxT(" resFlagNone ");
         if( t & resFlagPaired )   Temp += wxT(" resFlagPaired ");
         if( t & resFlagCursor )   Temp += wxT(" resFlagCursor ");
         if( t & resFlagNewLine )  Temp += wxT(" resFlagNewLine ");
         if( t & resFlagInternal ) Temp += wxT(" resFlagInternal ");
         Temp.Replace( wxT("  "), wxT(" | ") );

         File.Write( wxString::Format( wxT("\r\n   SET_THEME_FLAGS( %s );\r\n"),
            Temp.c_str() ));
      }
      File.Write( wxString::Format( 
         wxT("   DEFINE_IMAGE( bmp%s, wxImage( %i, %i ), wxT(\"%s\"));\r\n"),
         mBitmapNames[i].c_str(), 
         SrcImage.GetWidth(),
         SrcImage.GetHeight(),
         mBitmapNames[i].c_str()
         ));
   }
}
Example #8
0
/// Reads an image cache including images, cursors and colours.
/// @param bBinaryRead if true means read from an external binary file.  
///   otherwise the data is taken from a compiled in block of memory.
/// @param bOkIfNotFound if true means do not report absent file.
/// @return true iff we loaded the images.
bool ThemeBase::ReadImageCache( bool bBinaryRead, bool bOkIfNotFound)
{
   EnsureInitialised();
   wxImage ImageCache;
   wxBusyCursor busy;

   // Ensure we have an alpha channel...
//   if( !ImageCache.HasAlpha() )
//   {
//      ImageCache.InitAlpha();
//   }

   // IF bBinary read THEN a normal read from a PNG file
   if(  bBinaryRead )
   {
      wxString FileName = FileNames::ThemeCachePng();
      if( !wxFileExists( FileName ))
      {  
         if( bOkIfNotFound )
            return false; // did not load the images, so return false.
         wxMessageBox(
            wxString::Format( 
            _("Audacity could not find file:\n  %s.\nTheme not loaded."),
               FileName.c_str() ));
         return false;
      }
      if( !ImageCache.LoadFile( FileName, wxBITMAP_TYPE_PNG ))
      {
         wxMessageBox(
            wxString::Format( 
            _("Audacity could not load file:\n  %s.\nBad png format perhaps?"),
               FileName.c_str() ));
         return false;
      }
   }
   // ELSE we are reading from internal storage.
   else
   {  
      wxMemoryInputStream InternalStream(
         (char *)ImageCacheAsData, sizeof(ImageCacheAsData));
      if( !ImageCache.LoadFile( InternalStream, wxBITMAP_TYPE_PNG ))
      {
         // If we get this message, it means that the data in file
         // was not a valid png image.
         // Most likely someone edited it by mistake, 
         // Or some experiment is being tried with new formats for it.
         wxMessageBox(_("Audacity could not read its default theme.\nPlease report the problem."));
         return false;
      }
   }

   int i;
   mFlow.Init(ImageCacheWidth);
   // Load the bitmaps
   for(i=0;i<(int)mImages.GetCount();i++)
   {
      wxImage &Image = mImages[i];
      mFlow.mFlags = mBitmapFlags[i];
      if( (mBitmapFlags[i] & resFlagInternal)==0)
      {
         mFlow.GetNextPosition( Image.GetWidth(),Image.GetHeight() );
         //      wxLogDebug(wxT("Copy at %i %i (%i,%i)"), mxPos, myPos, xWidth1, yHeight1 );
         Image = GetSubImageWithAlpha( ImageCache, mFlow.Rect());
         mBitmaps[i] = wxBitmap(Image);
      }
   }

//   return true; //To not load colours..
   // Now load the colours.
   int x,y;
   mFlow.SetNewGroup(1);
   wxColour TempColour;
   const int iColSize=10;
   mFlow.myHeight = iColSize+1;
   for(i=0;i<(int)mColours.GetCount();i++)
   {
      mFlow.GetNextPosition( iColSize, iColSize );
      mFlow.RectMid( x, y );
      // Only change the colour if the alpha is opaque.
      // This allows us to add new colours more easily.
      if( ImageCache.GetAlpha(x,y ) > 128 )
      {
         TempColour = wxColour( 
            ImageCache.GetRed( x,y), 
            ImageCache.GetGreen( x,y), 
            ImageCache.GetBlue(x,y));
         /// \todo revisit this hack which makes adding new colours easier
         /// but which prevents a colour of (1,1,1) from being added.
         /// find an alternative way to make adding new colours easier.
         /// e.g. initialise the background to translucent, perhaps.
         if( TempColour != wxColour(1,1,1) )
            mColours[i] = TempColour;
      }
   }
   return true;
}
Example #9
0
void ThemeBase::CreateImageCache( bool bBinarySave )
{
   EnsureInitialised();
   wxBusyCursor busy;

   wxImage ImageCache( ImageCacheWidth, ImageCacheHeight );
   ImageCache.SetRGB( wxRect( 0,0,ImageCacheWidth, ImageCacheHeight), 1,1,1);//Not-quite black.

   // Ensure we have an alpha channel...
   if( !ImageCache.HasAlpha() )
   {
      ImageCache.InitAlpha();
   }

   int i;

   mFlow.Init( ImageCacheWidth );

//#define IMAGE_MAP
#ifdef IMAGE_MAP
   wxLogDebug( wxT("<img src=\"ImageCache.png\" usemap=\"#map1\">" ));
   wxLogDebug( wxT("<map name=\"map1\">") );
#endif

   // Save the bitmaps
   for(i=0;i<(int)mImages.GetCount();i++)
   {
      wxImage &SrcImage = mImages[i];
      mFlow.mFlags = mBitmapFlags[i];
      if( (mBitmapFlags[i] & resFlagInternal)==0)
      {
         mFlow.GetNextPosition( SrcImage.GetWidth(), SrcImage.GetHeight());
         PasteSubImage( &ImageCache, &SrcImage, mFlow.mxPos, mFlow.myPos );
#ifdef IMAGE_MAP
         // No href in html.  Uses title not alt.
         wxRect R( mFlow.Rect() );
         wxLogDebug( wxT("<area title=\"Bitmap:%s\" shape=rect coords=\"%i,%i,%i,%i\">"),
            mBitmapNames[i].c_str(), 
            R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom() );
#endif
      }
   }

   // Now save the colours.
   int x,y;

   mFlow.SetNewGroup(1);
   const int iColSize=10;
   mFlow.myHeight = iColSize+1;
   for(i=0;i<(int)mColours.GetCount();i++)
   {
      mFlow.GetNextPosition( iColSize, iColSize );
      wxColour c = mColours[i];
      ImageCache.SetRGB( mFlow.Rect(), c.Red(), c.Green(), c.Blue() );

      // YUCK!  No function in wxWidgets to set a rectangle of alpha...
      for(x=0;x<iColSize;x++)
      {
         for(y=0;y<iColSize;y++)
         {
            ImageCache.SetAlpha( mFlow.mxPos + x, mFlow.myPos+y, 255);
         }
      }
#ifdef IMAGE_MAP
      // No href in html.  Uses title not alt.
      wxRect R( mFlow.Rect() );
      wxLogDebug( wxT("<area title=\"Colour:%s\" shape=rect coords=\"%i,%i,%i,%i\">"),
         mColourNames[i].c_str(), 
         R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom() );
#endif
   }

#ifdef IMAGE_MAP
   wxLogDebug( "</map>" );
#endif

   // IF nBinarySave, THEN saving to a normal PNG file.
   if( bBinarySave )
   {
      wxString FileName = FileNames::ThemeCachePng();

      // Perhaps we should prompt the user if they are overwriting 
      // an existing theme cache?
#if 0
      if( wxFileExist( FileName ))
      {
         wxMessageBox(
            wxString::Format( 
            wxT("Theme cache file:\n  %s\nalready exists.\nAre you sure you want to replace it?"),
               FileName.c_str() ));
         return;
      }
#endif
      if( !ImageCache.SaveFile( FileName, wxBITMAP_TYPE_PNG ))
      {
         wxMessageBox(
            wxString::Format( 
            _("Audacity could not write file:\n  %s."),
               FileName.c_str() ));
         return;
      }
      wxMessageBox(
         wxString::Format( 
            wxT("Theme written to:\n  %s."),
            FileName.c_str() ));
   }
   // ELSE saving to a C code textual version.
   else
   {
      SourceOutputStream OutStream;
      wxString FileName = FileNames::ThemeCacheAsCee( );
      if( !OutStream.OpenFile( FileName ))
      {
         wxMessageBox(
            wxString::Format( 
            _("Audacity could not open file:\n  %s\nfor writing."),
            FileName.c_str() ));
         return;
      }
      if( !ImageCache.SaveFile(OutStream, wxBITMAP_TYPE_PNG ) )
      {
         wxMessageBox(
            wxString::Format( 
            _("Audacity could not write images to file:\n  %s."),
            FileName.c_str() ));
         return;
      }
      wxMessageBox(
         wxString::Format( 
            wxT("Theme as Cee code written to:\n  %s."),
            FileName.c_str() ));
   }
}
Example #10
0
wxFont   & ThemeBase::Font( int iIndex )
{
   wxASSERT( iIndex >= 0 );
   EnsureInitialised();
   return *(wxFont*)NULL;
}
Example #11
0
wxCursor & ThemeBase::Cursor( int iIndex )
{
   wxASSERT( iIndex >= 0 );
   EnsureInitialised();
   return *(wxCursor*)NULL;
}
Example #12
0
wxImage  & ThemeBase::Image( int iIndex )
{
   wxASSERT( iIndex >= 0 );
   EnsureInitialised();
   return mImages[iIndex];
}
Example #13
0
wxBitmap & ThemeBase::Bitmap( int iIndex )
{
   wxASSERT( iIndex >= 0 );
   EnsureInitialised();
   return mBitmaps[iIndex];
}
Example #14
0
wxColour & ThemeBase::Colour( int iIndex )
{
   wxASSERT( iIndex >= 0 );
   EnsureInitialised();
   return mColours[iIndex];
}