PrjName = 'swGuiEngine' UID = '0x02222228' use_engine('ShapeListMgr', eng_uid = '0x02222229') resource.menu = [['Shape', [['Circle', 'iAppView->SetBrushShapeType( C$PrjName$AppView::ECircle );' ], ['Rectangle', 'iAppView->SetBrushShapeType( C$PrjName$AppView::ERectangle );' ], ]], ['Clear', 'iAppView->Clear();' ], ['Exit', 'Exit();' ], ] resource.libraries += [ 'ws32' ] resource.eng_libs += [ 'euser' ] appview.keyevents( [[ "EKeyLeftArrow", 'if (iPosition.iX > (Rect().iTl.iX + 10)) --iPosition.iX;' ], [ "EKeyRightArrow", 'if (iPosition.iX < (Rect().iBr.iX - 10)) ++iPosition.iX;' ], [ "EKeyUpArrow", 'if (iPosition.iY > (Rect().iTl.iY + 10)) --iPosition.iY;' ], [ "EKeyDownArrow", 'if (iPosition.iY < (Rect().iBr.iY - 10)) ++iPosition.iY;' ], [ "EKeyDevice3", """\ TShape* newShape = NULL; // Update the co-ordinates in the model to the position at which the // pointer event occurred. switch (iBrushShapeType) { case ECircle : newShape = new (ELeave) TCircle(iPosition, KBrushRadius); iDocument->Model()->AddShapeL(newShape); // Takes ownership break; case ERectangle : newShape = new (ELeave) TRectangle(iPosition, KBrushHeight, KBrushWidth); iDocument->Model()->AddShapeL(newShape); // Takes ownership break; default : User::Panic(_L("$PrjName$"), E$PrjName$Ui); }""" ], ] ) appview.inc_src += [ '"Circle.h"', '"Rectangle.h"', '"$PrjName$.pan"' ] appview.intro_src = r""" using namespace NShapes; static const TInt KBlackPointer = 1; static const TInt KBrushRadius = 5; static const TInt KBrushHeight = 10; static const TInt KBrushWidth = 10; """ appview.add_public( Method( 'void', ('Clear', 'Clear the view / model'), [], """\ iDocument->Model()->Clear(); DrawNow();""" ) ) appview.add_public( Method( 'void', ('SetBrushShapeType', 'Set the type of shape that will be added next'), [Arg('TBrushShapeType', 'aShapeType', 'the shape of the brush')], 'iBrushShapeType = aShapeType;' ) ) appview.add_public( Method( ('$CLASS$::TBrushShapeType', 'Returns the type of shape that will be added'), ('BrushShapeType', 'Get the type of shape that will be added next'), [], 'return iBrushShapeType;', is_const = True ) ) appview.add_public( Enum( ('TBrushShapeType', 'The shape type to be drawn'), [['ECircle', 'user last drew a circle'], ['ERectangle', 'user last drew a rectangle']] ) ) appview.add_private( Var( 'TBrushShapeType', 'iBrushShapeType', 'The current shape type' ) ) appview.add_private( Var( 'TPoint', 'iPosition', "The current 'cursor' position" ) ) appview.members['Draw'].code = """\ CWindowGc& graphicsContext = SystemGc(); // Clear the application view graphicsContext.Clear(); // Draw the 'cursor' crosshair, size 10 pixels by 10 pixels graphicsContext.SetPenSize(TSize(1,1)); graphicsContext.SetPenColor(KRgbBlack); graphicsContext.DrawLine ( TPoint(iPosition.iX - 10, iPosition.iY), TPoint(iPosition.iX + 10, iPosition.iY)); graphicsContext.DrawLine ( TPoint(iPosition.iX, iPosition.iY - 10), TPoint(iPosition.iX, iPosition.iY + 10)); // Draw all the current shapes TShape* shape = iDocument->Model()->GetNextShape(); while (shape) { shape->Draw(graphicsContext); shape = iDocument->Model()->GetNextShape(); }""" appview.members['$CLASS$'].construct_init += [ 'iPosition(10,10)' ] # the engine is in this case a list of shapes engine.inc_inc = [ '"shape.h"' ] engine.inc_src = [ '"rectangle.h"', '"circle.h"' ] engine.intro_src = 'using namespace NShapes;' engine.members['~$CLASS$'].code += ' iShapeList.ResetAndDestroy();' engine.add_public( Method( 'void', ('AddShapeL', 'Add a shape to the list'), [Arg('NShapes::TShape*', 'aShape', 'the object to add to the list')], """\ User::LeaveIfError(iShapeList.Append(aShape));""" ) ) engine.add_public( Method( ('NShapes::TShape*', 'If there is no such shape, then it returns NULL and resets'), ('GetNextShape', 'Get the next shape in the list and increment the next shape index'), [], """ if (iShapeList.Count() > 0) { if (iNextShapeIndex < iShapeList.Count()) { TShape* shape = iShapeList[iNextShapeIndex]; ++iNextShapeIndex; return shape; } // Gone past the end, so reset the index iNextShapeIndex = 0; } return NULL;""" ) ) engine.members['Clear'].code = """ iNextShapeIndex = 0; // The first shape in the list iShapeList.ResetAndDestroy();""" engine.add_private( Var( 'TInt', 'iNextShapeIndex', 'The index of the next shape' ) ) engine.add_private( Var( 'RPointerArray', 'iShapeList', 'The list of shapes' ) ) shape = CClass( ('Shape', 'Abstract class for shapes'), 'T' ) shape.is_dll = True shape.inc_inc = [ '', '' ] shape.namespace = 'NShapes' shape.namespace_consts = Enum( ('TShapeType', 'Shape constants'), [['KRectangle = 1', 'represents a rectangle'], ['KCircle', 'represents a circle']] ).declaration() shape.add_public( Method( '', ('$CLASS$', 'Create the shape at a specified point'), [Arg('TShapeType', 'aShapeType', 'the type of the actual shape'), Arg('const TPoint&', 'aOrigin', 'where the center of the shape is located') ], '', 'iShapeType(aShapeType), iOrigin(aOrigin)' ) ) shape.add_public( Method( 'void', ('Draw', 'Pure virtual method that draws the shape to the specified graphics context' ), [Arg('CWindowGc&', 'aActiveGraphicsContext', 'the active context to draw the shape to')], '', is_pure_virtual = True, is_const = True ) ) shape.add_public( Method( ('TRect', 'The shape'), ('GetRect', 'Pure virtual method: return the smallest bounding shape' ), [], '', is_pure_virtual = True, is_const = True ) ) shape.add_protected( Var( 'const TShapeType', 'iShapeType', 'The type of the actual shape' ) ) shape.add_protected( Var( 'TPoint', 'iOrigin', 'The origin of the shape' ) ) circle = CClass( 'Circle', 'T' ) circle.is_dll = True circle.parent = ': public TShape' circle.inc_inc = [ '"shape.h"' ] circle.namespace = 'NShapes' circle.add_public( Method( '', ('$CLASS$', 'Create an instance of $CLASS$ at a specified location and radius' ), [Arg('const TPoint&', 'aCenter', 'where the center of the circle is located'), Arg('TInt', 'aRadius', 'The circle radius')], '', 'TShape(KCircle, aCenter - TSize(aRadius, aRadius)), iRadius(aRadius)' ) ) circle.add_public( Method( '', ('$CLASS$', 'Create an instance of $CLASS$' ), [], '', 'TShape(KCircle, TPoint(0,0)), iRadius(0)' ) ) circle.add_public( Method( 'void', ('Draw', 'Virtual method that draws the shape to the specified graphics context' ), [Arg('CWindowGc&', 'aActiveGraphicsContext', 'the active context to draw the shape to')], """\ aActiveGraphicsContext.DrawEllipse( GetRect() );""", is_const = True ) ) circle.add_public( Method( ('TRect', 'The rectangle'), ('GetRect', 'Return the smallest bounding rectangle' ), [], 'return TRect(iOrigin, TSize(iRadius * 2, iRadius * 2));', is_const = True ) ) circle.add_private( Var( 'TInt', 'iRadius', 'The radius of the circle' ) ) rectangle = CClass( 'Rectangle', 'T' ) rectangle.is_dll = True rectangle.parent = ': public TShape' rectangle.inc_inc = [ '"shape.h"' ] rectangle.namespace = 'NShapes' rectangle.add_public( Method( '', ('$CLASS$', 'Create an instance of $CLASS$ at a specified location and size' ), [Arg('const TPoint&', 'aOrigin', 'where the center of the rectangle is located'), Arg('TInt', 'aWidth', 'The rectangle width'), Arg('TInt', 'aHeight', 'The rectangle height') ], '', 'TShape(KRectangle, aOrigin), iWidth(aWidth), iHeight(aHeight)' ) ) rectangle.add_public( Method( '', ('$CLASS$', 'Create an instance of $CLASS$' ), [], '', 'TShape(KRectangle, TPoint(0,0)), iWidth(0), iHeight(0)' ) ) rectangle.add_public( Method( 'void', ('Draw', 'Virtual method that draws the shape to the specified graphics context' ), [Arg('CWindowGc&', 'aActiveGraphicsContext', 'the active context to draw the shape to')], """\ aActiveGraphicsContext.DrawRect( GetRect() );""", is_const = True ) ) rectangle.add_public( Method( ('TRect', 'The rectangle'), ('GetRect', 'Return the smallest bounding rectangle' ), [], 'return TRect(iOrigin, TSize(iWidth, iHeight));', is_const = True ) ) rectangle.add_private( Var( 'TInt', 'iWidth', 'The width of the rectangle' ) ) rectangle.add_private( Var( 'TInt', 'iHeight', 'The height of the rectangle' ) )