Click here to Skip to main content
15,897,891 members
Articles / Desktop Programming / MFC

2D LUA Based Robot Simulator

Rate me:
Please Sign up or sign in to vote.
4.89/5 (26 votes)
14 Apr 2014Public Domain9 min read 131.2K   7.9K   119  
An article on designing your own robot simulator
#pragma once

#include <math.h>
#include <list>

enum
{
	TOOL_RECTANGLE,
	TOOL_CIRCLE,
	TOOL_LINE,
	TOOL_DELETE,
	TOOL_SELECT,
};

class CCanvas
{
public:
	typedef struct
	{
		int		objectName;
		CPoint	point[2]; // Stores coordinate points
		bool	isSelected;
	} OBJECT;

	CCanvas(void);
	~CCanvas(void);

	void drawGrid(CDC *dc, HWND hwnd, int gridsizeX, int gridsizeY);
	bool loadFile(char *fileName);
	bool saveFile(char *fileName);
	void clearAll();
	void setSnapToGrid(bool setting, int gridsizeX, int gridsizeY);
	void set(CPoint ptStart, CPoint ptEnd);
	void set(int tool);
	void selectAll();
	int  update(CDC *dc);
	void store();
	void setMessage(char message[128]);

	// Define storage and its iterator
	std::list<OBJECT *>	m_object;
	std::list<OBJECT *>::iterator m_iterator;

private:
	void swapLong(LONG *a, LONG *b);
	bool isAnObjectSelected(CPoint pt);
	bool isTooSmall();
	void drawHitMark(CDC *dc, int flag);
	void moveSelectedObject();
	void deselectObjects();
	int  deleteObject();
	void initPoints();
	void setResize();
	void resizeObject();

	bool m_isResizing;
	bool m_isSelecting;
	bool m_isSelectAll;
	bool m_isMoving;

	int  m_cursorType;

	int  m_resizeDirection;

	bool m_isSnapToGrid;
	int  m_gridsizeX;
	int  m_gridsizeY;

	char m_message[128];

	// Remember origin location if we are doing mouse drag
	CPoint m_ptStart;
	CPoint m_ptEnd;
	CPoint m_ptEnd0;

	// For drawing hit mark
	CPoint	m_centerL;
	CPoint	m_centerR;
	CPoint	m_centerT;
	CPoint	m_centerB;
	CPoint	m_topLCorner;
	CPoint	m_bottomLCorner;
	CPoint	m_topRCorner;
	CPoint	m_bottomRCorner;
};

#define LEFT_CENTER					7
#define RIGHT_CENTER				3
#define TOP_CENTER					1
#define BOTTOM_CENTER				5
#define TOP_LEFT_CORNER				0
#define BOTTOM_LEFT_CORNER			6
#define TOP_RIGHT_CORNER			2
#define BOTTOM_RIGHT_CORNER			4
#define NONE						100

/*

  0------1------2
  |             |
  |             |
  7             3
  |             |
  |             |
  6------5------4
*/

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Student
Indonesia Indonesia
http://kataauralius.com/

Comments and Discussions