Chapter 9:
Object Alignment Functions
 

The alignment functions make it easy to align objects on the screen.

 

AlignInsideEdges(); Align Inside Edges of a selection list

 

AlignSelList_Bottom(); Align Selection List Bottom

 

AlignSelList_Center(); Align Selection List Center

 

AlignSelList_Left(); Align Selection List Left

 

AlignSelList_Right(); Align Selection List Right

 

AlignSelList_Top(); Align Selection List Top

 

CenterOnPage(); Center objects in selection list

 

JoinHoriz(); Join movable objects in the selection list horizontally

 

JoinToFirst(); Join movable objects in the selection list to first

 

JoinVert(); Join movable objects in the selection list vertically

 

MakeSameSize(); Make all items in the selection list the same size as the first item.

 

SizeToPicture(); Resize and relocate all items in the selection list

   

AlignInsideEdges()

 

This function aligns the right edge of all moveable objects (e.g., graph title, subtitle, footnote, etc.) in the selection list (pSelList).

Syntax:

INT16 PUBLIC AlignInsideEdges (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 alignH,
     INT16 alignV
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnvPtr()

 

pGraph: Pointer to the graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

alignH: 0/1

 

0=

don't align horizontally

 

1=

align horizontally

 

alignV: 0/1

 

0=

don't align vertically

 

1=

align vertically

Return:

INT16

 

E00_OK = Alignment successful

 

E00_RANGE_ERROR = Alignment not successful

Notes:

This and other alignment functions align the edges of the bounding box in which the selected, moveable objects reside. This bounding box is specified by the A_LOCATE_... attributes. Depending on the size/location of the box, aligned objects may overlap.

Example:

INT16 hAlign = 1;
INT16 vAlign = 0;
case IDM_REDRAW:
{
// When user redraws graph,
// align selected objs with first object
AlignInsideEdges (gpDrawEnv, gpGraph, gpList,
     hAlign,vAlign);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
} break;

Also See:

AlignSelList_Bottom(), AlignSelList_Center, AlignSelList_Left(), AlignSelList_Right(), AlignSelList_Top

AlignSelList_Bottom()

 

This function aligns the bottom edges of all moveable objects (e.g., graph title, subtitle, footnote, etc.) in the selection list (identified by pSelList) to the bottom-most edge of either the first selected objects (the first thing in the selection list) or to the bottom-most item in the list.

Syntax:

INT16 PUBLIC
AlignSelList_Bottom (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 alignToFirst
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnvPtr()

 

pGraph: Pointer to the graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

alignToFirst: 0/1

 

0=

align to the bottom-most object

 

1=

align the list to the first object

Return:

INT16

 

E00_OK = Alignment successful

 

E00_RANGE_ERROR = Alignment not successful

Notes:

This and other alignment functions align the edges of the bounding box in which the selected, moveable objects reside. This bounding box is specified by the A_LOCATE_... attributes. Depending on the size/location of the box, aligned objects may overlap.

Example:

INT16 TopAlign = 1;
case IDM_REDRAW:
{
// When user redraws graph,
// align all selected objects with first object
AlignSelList_Bottom (gpDrawEnv, gpGraph,
     gpList, TopAlign);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
} break;

Also See:

AlignSelList_Center(), AlignSelList_Left(), AlignSelList_Right(), AlignSelList_Top

AlignSelList_Center()

 

This function aligns the center of all moveable objects (e.g., graph title, subtitle, footnote, etc.) in the selection list. The objects are centered based on the first object in the selection list. The horiz and vert parameters can be used to align object horizontally and/or vertically.

Syntax:

INT16 PUBLIC AlignSelList_Center (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 horiz,
     INT16 vert);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnvPtr()

 

pGraph: Pointer to the graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

horiz: 0/1

 

0=

don't align horizontally

 

1=

Align horizontally

 

vert: 0/1

 

0=

don't align vertically

 

1=

align vertically

Return:

INT16

 

E00_OK = Alignment successful

 

E00_RANGE_ERROR = Alignment not successful

Notes:

This and other alignment functions align the edges of the bounding box in which the selected, moveable objects reside. This bounding box is specified by the A_LOCATE_... attributes. Depending on the size/location of the box, aligned objects may overlap.

Example:

INT16 hAlign = 1;
INT16 vAlign = 0;
case IDM_REDRAW:
{
// When user redraws graph, align
// all selected object to center
AlignSelList_Center (gpDrawEnv, gpGraph,
     gpList, hAlign,vAlign);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
} break;

Also See:

AlignSelList_Bottom(), AlignSelList_Left(), AlignSelList_Right(), AlignSelList_Top

AlignSelList_Left()

 

This function aligns the left edges of all movable objects (e.g., graph title, subtitle, footnote, etc.) in the selection list (pSelList). Objects are aligned to the left-most edge of either the first selected object (the first thing in the selection list) or to the left-most item in the list.

Syntax:

INT16 PUBLIC
AlignSelList_Left (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 alignToFirst
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnvPtr()

 

pGraph: Pointer to the graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

alignToFirst: 0/1

 

0=

align to the left-most object

 

1=

align the list to the first object

Return:

INT16

 

E00_OK = Alignment successful

 

E00_RANGE_ERROR = Alignment not successful

Notes:

This and other alignment functions align the edges of the bounding box in which the selected, moveable objects reside. This bounding box is specified by the A_LOCATE_... attributes. Depending on the size/location of the box, aligned objects may overlap.

Example:

INT16 AFirst = 1;
case IDM_REDRAW:
{
// When user redraws graph,
// align all selected objects
// with first object
AlignSelList_Left (gpDrawEnv, gpGraph,
     gpList, AFirst);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
} break;

Also See:

AlignSelList_Bottom(), AlignSelList_Center(), AlignSelList_Right(), AlignSelList_Top

AlignSelList_Right()

 

This function aligns the right edges of all movable objects (e.g., graph title, subtitle, footnote, etc.) in the selection list (pSelList). Objects are aligned to the right-most edge of either the first selected object (the first thing in the selection list) or to the right-most item in the list.

Syntax:

INT16 PUBLIC
AlignSelList_Right (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 alignToFirst
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnvPtr()

 

pGraph: Pointer to the graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

alignToFirst: 0/1

 

0=

align to the right-most object

 

1=

align the list to the first object

Return:

INT16

 

E00_OK = Alignment successful

 

E00_RANGE_ERROR = Alignment not successful

Notes:

This and other alignment functions align the edges of the bounding box in which the selected, moveable objects reside. This bounding box is specified by the A_LOCATE_... attributes. Depending on the size/location of the box, aligned objects may overlap.

Example:

INT16 AFirst = 1;
case IDM_REDRAW:
{
// When user redraws graph,
// align all selected object with first
AlignSelList_Right (gpDrawEnv, gpGraph,
     gpList, AFirst);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
} break;

Also See:

AlignSelList_Bottom(), AlignSelList_Center(), AlignSelList_Left(), AlignSelList_Top

AlignSelList_Top()

 

This function aligns the top edges of all movable objects (e.g., graph title, subtitle, footnote, etc.) in the selection list (pSelList). Objects are aligned to the top-most edge of either the first selected object (the first thing in the selection list) or to the top-most item in the list.

Syntax:

INT16 PUBLIC
AlignSelList_Top (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 alignToFirst
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnvPtr()

 

pGraph: Pointer to the graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

alignToFirst: 0/1

 

0=

align to the top-most object

 

1=

align the list to the first object

Return:

INT16

 

E00_OK = Alignment successful

 

E00_RANGE_ERROR = Alignment not successful

Notes:

This and other alignment functions align the edges of the bounding box in which the selected, moveable objects reside. This bounding box is specified by the A_LOCATE_... attributes. Depending on the size/location of the box, aligned objects may overlap.

Example:

INT16 AFirst = 1;
AlignSelList_Top (gpDrawEnv, gpGraph,
     gpList, AFirst);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
} break;

Also See:

AlignSelList_Bottom(), AlignSelList_Center(), AlignSelList_Left(), AlignSelList_Right()

   

CenterOnPage()

 

This function calculates new boundaries and centers all objects in the selection list identified by pSelList. The centerH and centerV flags allow you to specify horizontal centering, vertical centering, or both.

Syntax:

INT16 PUBLIC
CenterOnPage (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 centerH,
     INT16 centerV
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnvPtr()

 

pGraph: Pointer to a graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

centerH: 0/1

 

0=

do not center horizontally

 

1=

center horizontally

 

centerV: 0/1

 

0=

do not center vertically

 

1=

center vertically

Return:

INT16

 

Zero = Centering successful

 

E00_RANGE_ERROR = Centering Unsuccessful

Notes:

This function centers the bounding box in which the selected, movable objects reside. This bounding box is specified by the A_LOCATE_... attributes. Depending on the size/location of the box, objects may not appear to be centered.

Example:

INT16 hAlign = 0;
INT16 vAlign = 1;
case IDM_REDRAW:
{
// When user redraws graph,
// align all selected object with first
CenterOnPage (gpDrawEnv, gpGraph,
     gpList, hAlign,vAlign);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
} break;

   

JoinHoriz()

 

This function joins movable objects in the selection list (pSelItem) horizontally. If stretchVert is set (1), selected items are moved vertically to attach to the first item in the list. If stretchVert is not set (0), selected items are simply aligned horizontally with the first item/object in the list.

Syntax:

INT16 PUBLIC
JoinHoriz (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 stretchVert
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnv()

 

pGraph: Pointer to a graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

stretchVert: 0/1

 

0=

don't move vertically

 

1=

move vertically to attach objects

Return:

INT16

 

E00_OK =

Alignment successful

 

E00_RANGE_ERROR =

Alignment not successful

Example:

JoinHoriz(gpDrawEnv,gpGraph,gpList,nSV);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
} break;

Notes:

Selected objects must fit inside the chart frame horizontally in order to be joined. Otherwise, the location of selected objects is not changed.

Also See:

JoinToFirst(), JoinVert()

JoinToFirst()

 

This function snaps selected objects to the closest side of the first item in the list (pSelList).

Syntax:

INT16 PUBLIC
JoinToFirst (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnvPtr()

 

pGraph: Pointer to the graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList().See the SelListRec in Appendix A.

Return:

INT16

 

E00_OK =

Alignment successful

 

E00_RANGE_ERROR =

Alignment not successful

Example:

/* Add to selection list and draw handles */
gpSelItem = Select_AddItem(gpGraph,
     gpList,gpDetNode);
Select_CalcHandlesItem (
     gpDrawEnv,gpSelItem);
Select_DrawXorItem(
     gpDrawEnv,gpSelItem);
}
} break;
case IDM_REDRAW:
{
/* When user redraws the graph,
join to first object selected */
JointToFirst (
     gpDrawEnv, gpGraph, gpList);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
}
break;

Notes:

JoinToFirst() is an intuitive routine that attempts to snap selected objects (Graph objects and annotations) to the closest side of the first selected object. Example: If you select the graph frame, the legend frame, and the main title and call JoinToFirst(), the legend might snap to the right side of the graph (if that is closest) and the title might snap to the top of the graph (again, if it is the closest side).

Also See:

JoinHoriz(), JoinVert()

JoinVert()

 

This function joins moveable objects in the selection list (identified by pSelItem) next to the first selected item in a vertical direction. If stretchHoriz is set (1), selected items are moved horizontally to attach to the first item in the list. If stretchHoriz is not set (0), selected items are simply aligned vertically with the first item/object in the list.

Syntax:

INT16 PUBLIC
JoinVert (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 stretchHoriz
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnv()

 

pGraph: Pointer to a graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

stretchHoriz: 0/1

 

0=

don't change horizontal placement

 

1=

move horizontally to attach objects

Return:

INT16

 

E00_OK =

Alignment successful

 

E00_RANGE_ERROR =

Alignment not successful

Example:

/* Add to selection list and draw handles */
gpSelItem = Select_AddItem(
     gpGraph,gpList,gpDetNode);
Select_CalcHandlesItem (gpDrawEnv,gpSelItem);
Select_DrawXorItem(gpDrawEnv,gpSelItem);
case IDM_REDRAW:
{
/* When user redraws the graph, join horizontally */
JoinVert(gpDrawEnv,gpGraph,gpList,nSH);
InvalidateRect (hWnd, &rOld, TRUE);
UpdateWindow(hWnd);
} break;

Notes:

Selected objects must fit inside the chart frame vertically in order to be joined. Otherwise, the location of selected objects is not changed.

Also See:

JoinHoriz(), JoinToFirst()

MakeSameSize()

 

This function makes all items in the selection list (identified by pSelList) the same size as the first one in the horizontal, vertical or both directions.

Syntax:

INT16 PUBLIC
MakeSameSize (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList,
     INT16 horiz,
     INT16 vert
);

Input:

pDE: Pointer to a graph environment created by AllocGraphEnv()

 

pGraph: Pointer to a graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list .allocated by Select_AllocList(). See the SelListRec in Appendix A.

 

horiz: 0/1

 

0=

don't use first item in horizontal direction

 

1=

use first item in horizontal direction

 

vert: 0/1

 

0=

don't use first item in vertical direction

 

1=

use first item in vertical direction

Return:

INT16

 

E00_OK = Alignment successful

 

E00_RANGE_ERROR = Alignment not successful

   

SizeToPicture()

 

This function resizes and relocates all items in the selection list (pSelList). It determines the current center of each object and the boundary of the picture (in destination coordinates), calculates the virtual height and width of the picture, constructs new boundaries for the object, and moves the object. It designed for use with annotation objects.

Syntax:

INT16 PUBLIC
SizeToPicture (
     DrawEnvPtr pDE,
     GraphPtr pGraph,
     SelListPtr pSelList
);

Input:

pDE: Pointer to a draw environment created by AllocDrawEnvPtr()

 

pGraph: Pointer to the graph object created by AllocGraphPtr()

 

pSelList: Pointer to a selection list allocated by Select_AllocList(). See the SelListRec in Appendix A.

Return:

INT16:

 

Possible Values

Description

 

E00_OK =

Alignment successful

 

E00_RANGE_ERROR =

Alignment not successful

Example:

void CGraph::SizeToPicture( CDrawEnv& de )
{
     ::SizeToPicture((DrawEnvPtr)de.GetDrawEnv(),
     (GraphPtr) m_pGraph,
     (SelListPtr) m_SelList.GetList() );
}