티스토리 뷰


MFC 그래픽에 손을 대본지 4년만이라 감이 잘 안 선다...

일단 해보려고 했던 것이 여러 개의 선을 이이서 하는 거였지..

//이을 점들..
float x[i],y[i]

for(int loop = 0 ; loop < i - 1 ; loop++)
{
  line(x[loop] , y[loop] , x[loop+1] , y[loop + 1]);
}


뭐 이런식으로 하면 줄줄이 이어지긴 하니깐...

그런데 아침에 우연히 CDC::Polyline 이란게 눈에 들어왔다.

원래부터 꺽은선이 존재하는거였군! ㅠㅠ

뭐, 위의 단계를 몇 줄 줄이는 것 뿐이긴 하지만 나름 더 편하게 할 수 있을 것 같다..

이놈에 대해서 살펴보면... msdn에서는 아래와 같이 정의하고 있지..


MFC Library Reference 
CDC::Polyline 

Draws a set of line segments connecting the points specified by lpPoints.

BOOL Polyline(
   LPPOINT lpPoints,
   int nCount 
);

Parameters

lpPoints

Points to an array of POINT structures or CPoint objects to be connected.

nCount

Specifies the number of points in the array. This value must be at least 2.

Nonzero if the function is successful; otherwise 0.

The lines are drawn from the first point through subsequent points using the current pen. Unlike the LineTo member function, the Polyline function neither uses nor updates the current position.

For more information, see PolyLine in the Platform SDK.

LPPOINT 랑 nCount 의 인자를 받으니

POINT의 배열을 넘겨주면 되겠군..

아직 사용해본적이 없는 CArray를 한번 활용해서 하면 편할 것 같기도 하다..

써본적이 없으니 스펙을 알아봐야지...

역시 msdn에 있는 내용..

CArray Class 

Supports arrays that are similar to C arrays, but can dynamically shrink and grow as necessary.

template < class TYPE, class ARG_TYPE = const TYPE& > 
class CArray : 
   public CObject

Parameters

TYPE

Template parameter specifying the type of objects stored in the array. TYPE is a parameter that is returned by CArray.

ARG _ TYPE

Template parameter specifying the argument type used to access objects stored in the array. Often a reference to TYPE. ARG_TYPE is a parameter that is passed to CArray.

Array indexes always start at position 0. You can decide whether to fix the upper bound or allow the array to expand when you add elements past the current bound. Memory is allocated contiguously to the upper bound, even if some elements are null.

As with a C array, the access time for a CArray indexed element is constant and is independent of the array size.

NoteTip

Before using an array, use SetSize to establish its size and allocate memory for it. If you do not use SetSize, adding elements to your array causes it to be frequently reallocated and copied. Frequent reallocation and copying are inefficient and can fragment memory.

If you need a dump of individual elements in an array, you must set the depth of the CDumpContext object to 1 or greater.

Certain member functions of this class call global helper functions that must be customized for most uses of the CArray class. See the topic Collection Class Helpers in the MFC Macros and Globals section.

Array class derivation is similar to list derivation.

For more information on using CArray, see the article Collections.

Header: afxtempl.h



vector랑 비슷한것 같다.. 템플릿을 쓰는 배열.. 주의할게 헤더를 요구하네..기본 헤더인지 알아봐야겠다..

동적으로 그래프를 그리려면 쉽게쉽게 맨앞의 값을 제거하고 뒤의 값을 추가할 수 있어야하므로 멤버의 내용도 살펴봐야할 것 같다..



CArray Members 

Base Class Members

CObject Members

Construction

CArray

Constructs an empty array.

Attributes

GetCount

Gets the number of elements in this array.

GetSize

Gets the number of elements in this array.

GetUpperBound

Returns the largest valid index.

IsEmpty

Determines whether the array is empty.

SetSize

Sets the number of elements to be contained in this array.

Operations

FreeExtra

Frees all unused memory above the current upper bound.

RemoveAll

Removes all the elements from this array.

RelocateElements

Relocates data to a new buffer when the array should grow or shrink.

Element Access

ElementAt

Returns a temporary reference to the element pointer within the array.

GetAt

Returns the value at a given index.

GetData

Allows access to elements in the array. Can be NULL.

SetAt

Sets the value for a given index; array not allowed to grow.

Growing the Array

Add

Adds an element to the end of the array; grows the array if necessary.

Append

Appends another array to the array; grows the array if necessary

Copy

Copies another array to the array; grows the array if necessary.

SetAtGrow

Sets the value for a given index; grows the array if necessary.

Insertion/Removal

InsertAt

Inserts an element (or all the elements in another array) at a specified index.

RemoveAt

Removes an element at a specific index.

Operators

operator []

Sets or gets the element at the specified index.




뭐 있을 건 다 있다. RemoveAt[0]이랑 Add()로 사용하면 될 것 같다.

그렇다면 이제

CArray<CPoint> arrPoint; 를 활용해서 그래프를 그리면 될 것 같다..

CDC::Polyline(arrPoint.GetData() , arrPoint.GetSize());

한 줄로 처리 가능하겠지..

//////////////////////////////////////////////////////////////////////

문제는 (값이)동적인 그래프를 동적으로(숫자 변동..) 그려야한다는 것...

동적으로 그리려면 클래스를 만들어야겠다..

고려해야할 것들이 Rect의 범위를 고려, 데이터 값에서 CPoint를 변환하는 작업..

Min, Max 값을 설정하는 것이 문제가 될 수 있을 것 같기도 하다..


공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함