13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//
23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// Magick++ demo to generate a simple text button
33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//
43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2003
53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy//
63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <Magick++.h>
83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <string>
93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <iostream>
103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
113ed852eea50f9d4cd633efb8c2b054b8e33c253cristyusing namespace std;
123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
133ed852eea50f9d4cd633efb8c2b054b8e33c253cristyusing namespace Magick;
143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
153ed852eea50f9d4cd633efb8c2b054b8e33c253cristyint main( int /*argc*/, char ** argv)
163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  // Initialize ImageMagick install location for Windows
193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  InitializeMagick(*argv);
203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  try {
223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    string srcdir("");
243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if(getenv("SRCDIR") != 0)
253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      srcdir = getenv("SRCDIR");
263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    //
283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Options
293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    //
303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    string backGround = "xc:#CCCCCC"; // A solid color
323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Color to use for decorative border
343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Color border = "#D4DCF3";
353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Button size
373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    string buttonSize = "120x20";
383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Button background texture
403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    string buttonTexture = "granite:";
413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Button text
433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    string text = "Button Text";
443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Button text color
463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    string textColor = "red";
473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Font point size
493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    int fontPointSize = 16;
503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    //
523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Magick++ operations
533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    //
543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Image button;
563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Set button size
583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.size( buttonSize );
593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Read background image
613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.read( backGround );
623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Set background to buttonTexture
643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Image backgroundTexture( buttonTexture );
653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.texture( backgroundTexture );
663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Add some text
683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.fillColor( textColor );
693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.fontPointsize( fontPointSize );
703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.annotate( text, CenterGravity );
713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Add a decorative frame
733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.borderColor( border );
743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.frame( "6x6+3+3" );
753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
764a16cd57f82c4fef767eec22bc00e98a065242f0cristy    button.depth( 8 );
774a16cd57f82c4fef767eec22bc00e98a065242f0cristy
783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Quantize to desired colors
793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // button.quantizeTreeDepth(8);
803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.quantizeDither(false);
813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.quantizeColors(64);
823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.quantize();
833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Save to file
853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    cout << "Writing to \"button_out.miff\" ..." << endl;
863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.compressType( RLECompression );
873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    button.write("button_out.miff");
883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // Display on screen
903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    // button.display();
913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  catch( exception &error_ )
943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      cout << "Caught exception: " << error_.what() << endl;
963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return 1;
973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return 0;
1003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
101