renddlg.cpp

Go to the documentation of this file.
00001 // $Id: renddlg.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // A simple Dialog That does some Gavin Rendering into itself
00099 
00100 /*
00101 */
00102 
00103 #include "camtypes.h"
00104 #include "renddlg.h"
00105 
00106 //#include "mario.h"
00107 //#include "rikdlg.h"
00108 //#include "rik.h"
00109 #include "menuops.h"
00110 
00111 #include "ccdc.h"       // specific #includes needed for kernel-rendered dialogues
00112 #include "dlgcol.h"
00113 //#include "fillval.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 #include "grnddib.h"
00115 
00116 // This is not compulsory, but you may as well put it in so that the correct version
00117 // of your file can be registered in the .exe
00118 DECLARE_SOURCE("$Revision: 1282 $");
00119 
00120 // An implement to match the Declare in the .h file.
00121 // If you have many classes, it is recommended to place them all together, here at the start of the file
00122 CC_IMPLEMENT_DYNCREATE(RenderDemoDlg, DialogOp)
00123 
00124 // This will get Camelot to display the filename and linenumber of any memory allocations
00125 // that are not released at program exit
00126 #define new CAM_DEBUG_NEW
00127 
00128 
00129 // Set the static vars of the render dialog
00130 const CDlgMode RenderDemoDlg::Mode = MODELESS;
00131 const UINT32 RenderDemoDlg::IDD = _R(IDD_RENDERDEMO);
00132 
00133 
00134 
00135 
00136 /*******************************************************************************************
00137 
00138 >   RenderDemoDlg::RenderDemoDlg() : DialogOp(RenderDlg::IDD, RenderDlg::Mode) 
00139 
00140     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00141     Created:    6/10/94
00142     Purpose:    Constructs a Render Dialog
00143 
00144 *******************************************************************************************/
00145 
00146 RenderDemoDlg::RenderDemoDlg() : DialogOp(RenderDemoDlg::IDD, RenderDemoDlg::Mode) 
00147 {
00148     // Set the 2 colours that we can toggle between
00149     First = DocColour(255,0,250);
00150     Second = DocColour(0,255,255);
00151     ShowFirst = TRUE;
00152 }       
00153 
00154 
00155 
00156 /*******************************************************************************************
00157 
00158 >   RenderDemoDlg::~RenderDemoDlg()
00159 
00160     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00161     Created:    6/10/94
00162     Purpose:    Destructor, does nothing
00163 
00164 *******************************************************************************************/
00165 
00166 RenderDemoDlg::~RenderDemoDlg()
00167 {
00168 } 
00169 
00170 
00171 
00172 /*******************************************************************************************
00173 
00174 >   MsgResult RenderDemoDlg::Message(Msg* Message)
00175 
00176     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00177     Created:    6/10/94
00178     Purpose:    Handles all the Render dialog's messages 
00179 
00180 *******************************************************************************************/
00181 
00182 MsgResult RenderDemoDlg::Message(Msg* Message)
00183 {
00184     // See if it is for us
00185     if (IS_OUR_DIALOG_MSG(Message))
00186     {
00187         // it is
00188         DialogMsg* Msg = (DialogMsg*)Message;
00189 
00190         // decide what to do
00191         switch (Msg->DlgMsg)
00192         {
00193             // Create message
00194             case DIM_CREATE :
00195                 break;
00196 
00197             // Close and destroy the dialog 
00198             case DIM_COMMIT :
00199             case DIM_CANCEL :
00200             {
00201                 Close();
00202                 End();
00203                 break;
00204             }
00205 
00206             case DIM_LFT_BN_CLICKED :
00207             {
00208                 // See which button was pressed
00209                 if (Msg->GadgetID == _R(IDC_REDRAWBTN))
00210                 {
00211                     // Toggle the colour
00212                     ShowFirst = ShowFirst ? FALSE : TRUE;
00213 
00214                     // invalidate the gadget with the picture in it
00215                     InvalidateGadget(_R(IDC_REDRAW_ME));
00216                 }
00217                 break;
00218             }
00219 
00220             case DIM_REDRAW :
00221             {
00222                 // This is where all the redrawing is done
00223                 // Which control in the window is sending the redraw message (if there are many
00224                 // grdraw controls you can tell which is which from the Gadget ID
00225                 if (Msg->GadgetID == _R(IDC_REDRAW_ME))
00226                 {
00227                     // Draw the redraw_me control in here
00228                     // Render this control
00229                     RenderControl((ReDrawInfoType*) Msg->DlgMsgParam);
00230                 }
00231                 else
00232                 // there are no other controls that should get a redraw message ever
00233                 {
00234                     // give out an error in debug builds, ignore in retail builds
00235                     ERROR3("Got a redraw message for a control I don't know about");
00236                     break;
00237                 }
00238 
00239                 break;
00240             }
00241             default:
00242                 break;
00243         }
00244         
00245         // Return
00246         return (DLG_EAT_IF_HUNGRY(Msg));
00247     }
00248 
00249     return OK;  
00250 }  
00251 
00252 
00253 
00254 
00255 /********************************************************************************************
00256 
00257 >   void RenderDemoDlg::RenderControl(ReDrawInfoType* ExtraInfo)
00258 
00259     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00260     Created:    11/10/94
00261     Inputs:     ExtraInfo - The structure that has the extra data we need to start rendering
00262     Purpose:    Renders a grad fill into the main control in this dialog.
00263 
00264 ********************************************************************************************/
00265 
00266 void RenderDemoDlg::RenderControl(ReDrawInfoType* ExtraInfo)
00267 {
00268     // Go get a render region
00269     DocRect VirtualSize(-ExtraInfo->dx/2, -ExtraInfo->dy/2, ExtraInfo->dx/2, ExtraInfo->dy/2);
00270     RenderRegion* pRender = CreateGRenderRegion(&VirtualSize, ExtraInfo);
00271     if (pRender!=NULL)
00272     {
00273         DialogColourInfo RedrawColours;     // Get a supplier for default dlg colours
00274 
00275         // Render stuff in here
00276         // Build a Linear fill attribute
00277         LinearFillAttribute MyGradFill;
00278         MyGradFill.Colour = DocColour(255, 255, 0);
00279         MyGradFill.EndColour = DocColour(0, 255, 255);
00280         MyGradFill.StartPoint = DocCoord(0, ExtraInfo->dy);
00281         MyGradFill.EndPoint = DocCoord(ExtraInfo->dx, 0);
00282 
00283         // Build a path
00284         Path InkPath;
00285         InkPath.Initialise(12,12);
00286         InkPath.FindStartOfPath();
00287 
00288         // Get the coords used to build a shape
00289         INT32 dx = ExtraInfo->dx / 2;
00290         INT32 dy = ExtraInfo->dy / 2;
00291         INT32 Midx = ExtraInfo->dx / 4;
00292         INT32 Midy = ExtraInfo->dy / 4;
00293 
00294         // build a circle in the middle of the control
00295         InkPath.InsertMoveTo(DocCoord(Midx, dy));
00296         InkPath.InsertCurveTo(DocCoord(Midx+Midx/2, dy), DocCoord(dx, Midy+Midy/2), DocCoord(dx, Midy));
00297         InkPath.InsertCurveTo(DocCoord(dx, Midy-Midy/2), DocCoord(Midx+Midx/2, 0), DocCoord(Midx, 0));
00298         InkPath.InsertCurveTo(DocCoord(Midx-Midx/2, 0), DocCoord(0, Midy-Midy/2), DocCoord(0, Midy));
00299         InkPath.InsertCurveTo(DocCoord(0, Midy+Midy/2), DocCoord(Midx-Midx/2, dy), DocCoord(Midx, dy));
00300         InkPath.IsFilled = TRUE;
00301         
00302         // A Grey colour [...hmmm, it's not a very grey grey any more... oragnge more like]
00303         DocColour Grey(255,200,0);
00304 
00305         // Render the attributes and the a rectangle
00306         pRender->SaveContext();
00307         pRender->SetLineColour(Grey);
00308 
00309         // Draw a rectangle to fill in the background - Fill with Dialogue Background colour
00310         DocRect DrawMe(0, 0, ExtraInfo->dx, ExtraInfo->dy);
00311         pRender->SetFillColour(RedrawColours.DialogBack());
00312         pRender->DrawRect(&VirtualSize);
00313 
00314         // Draw some shapes and stuff
00315         pRender->SetFillGeometry(&MyGradFill, FALSE);
00316         pRender->DrawPath(&InkPath);
00317 
00318         // Build a path
00319         Path TriPath;
00320         TriPath.Initialise(12,12);
00321         TriPath.FindStartOfPath();
00322 
00323         // build a circle in the middle of the control
00324         TriPath.InsertMoveTo(VirtualSize.lo);
00325         TriPath.InsertLineTo(DocCoord(VirtualSize.hi.x, VirtualSize.lo.y));
00326         TriPath.InsertLineTo(DocCoord(0, VirtualSize.hi.y));
00327         TriPath.InsertLineTo(VirtualSize.lo);
00328         TriPath.IsFilled = TRUE;
00329 
00330         LinearFillAttribute MyTriFill;
00331         MyTriFill.Colour = ShowFirst ? First : Second;
00332         MyTriFill.EndColour = DocColour(0,0,0);
00333         MyTriFill.StartPoint = DocCoord(ExtraInfo->dx, 0);
00334         MyTriFill.EndPoint = DocCoord(0, ExtraInfo->dy);
00335 
00336         pRender->SetFillGeometry(&MyTriFill, FALSE);
00337         pRender->DrawPath(&TriPath);
00338 
00339         pRender->RestoreContext();
00340 
00341         // Get rid of the render region
00342         DestroyGRenderRegion(pRender);
00343     }
00344 
00345     // and animate it!
00346     if (ShowFirst)
00347     {
00348         INT32 Red, Green, Blue;
00349         First.GetRGBValue(&Red, &Green, &Blue);
00350 
00351         if (Blue>0)
00352         {
00353             // Set the colour back again
00354             Blue -= 10;
00355             First.SetRGBValue(Red, Green, Blue);
00356 
00357             // redraw it
00358             InvalidateGadget(_R(IDC_REDRAW_ME));
00359         }
00360     }
00361     else
00362     {
00363         // Set the colour back to how it was
00364         First.SetRGBValue(255, 0, 250);
00365     }
00366 }
00367 
00368 
00369 
00370 /*******************************************************************************************
00371 
00372 >   OpState RenderDemoDlg::GetState(String_256*, OpDescriptor*)
00373 
00374     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00375     Created:    6/10/94
00376     Purpose:    Returns the OpState of the Render dialogue operation
00377 
00378 *******************************************************************************************/
00379 
00380 OpState RenderDemoDlg::GetState(String_256*, OpDescriptor*)
00381 {
00382     return OpState(FALSE, FALSE);
00383 }
00384 
00385          
00386 
00387 /*******************************************************************************************
00388 
00389 >   BOOL RenderDemoDlg::Init()
00390 
00391     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00392     Created:    6/10/94
00393     Returns:    FALSE if it fails (due to lack of memory)
00394     Purpose:    Creates an OpDescriptor for a Render Dialog
00395 
00396 *******************************************************************************************/
00397 BOOL RenderDemoDlg::Init()
00398 {  
00399     return RegisterOpDescriptor(0,                              // Tool ID
00400                                 _R(IDS_RENDERDEMO),                 // String resouirce ID
00401                                 CC_RUNTIME_CLASS(RenderDemoDlg),// Runtime class
00402                                 OPTOKEN_RENDERDEMODLG,          // Token string
00403                                 RenderDemoDlg::GetState,        // GetState function
00404                                 0,                              // Help ID
00405                                 0,                              // Bubble ID
00406                                 0,                              // Resource ID
00407                                 0,                              // Control ID
00408                                 SYSTEMBAR_ILLEGAL,              // Bar ID
00409                                 FALSE,                          // Recieve system messages
00410                                 FALSE,                          // Smart duplicate operation
00411                                 TRUE,                           // Clean operation
00412                                 0,                              // No vertical counterpart
00413                                 0);                             // String for one copy only
00414 }   
00415  
00416 
00417          
00418 
00419 /*******************************************************************************************
00420 
00421 >   void RenderDemoDlg::Do(OpDescriptor*)
00422 
00423     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
00424     Created:    6/10/94
00425     Purpose:    Creates and shows a Render Demo dialog
00426 
00427 *******************************************************************************************/
00428 void RenderDemoDlg::Do(OpDescriptor*)
00429 {
00430     // if we can create the dialog, then open it
00431     if (Create())
00432         Open();
00433     else
00434         TRACE( _T("Failed to create Render Demo Dialog\n"));
00435 }
00436 
00437 

Generated on Sat Nov 10 03:46:43 2007 for Camelot by  doxygen 1.4.4