Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5326120
  • 博文数量: 671
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 7310
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-14 09:56
文章分类

全部博文(671)

文章存档

2011年(1)

2010年(2)

2009年(24)

2008年(271)

2007年(319)

2006年(54)

我的朋友

分类: C/C++

2008-09-02 09:56:04

Introduction

In VC++ we have a class CRectTracker which helps drawing the trackers and also there is function a DrawFocusRect() with which tracker behavior can be achieved. In C# I did not find any kind of such functionality (if there is then I am unaware at the moment.). So I decided to make program which draw box with tracker and allows manipulation with the box with the help of trackers.

Key features

  • Drawing trackers
  • Moving the boxes having trackers attached to it.
  • Resizing the box with the help of trackers.
  • Selection is made in Z Order.

I tried to avoid Form’s Invalidate() function as it generates flickering effects and drawing is not smooth. I designed the program in a way to maximize the usage of double buffering to avoid flickering effect.

Using the code

Class CRectTracker

Methods Functionality
DrawSelectionGhostRect() Draws the given ghost rectangle on the specified bitmap
InitTrackerRects() Initializes the eight rectangle of the tracker.
DrawSelectionTrackers() Draws the already initialized tracker rectangles
CursorCheck() Checks the position of the cursor and changes the form cursor with appropriate cursor and returns the border of the rectangle for the resizing purpose.

In the main program there are three modes of the program. First is the “None mode” which indicates that user is not drawing, second mode is the “Drawing mode” and it is invoked when user selects the Box icon from the toolbar and third is the “selection mode” it is invoked when user selects a box for changing the positioning or size.  

There is main bitmap which holds the current drawing. Whenever a change is required like drawing rubber band selection or drawing tracker a copy of the main bitmap is made and saved in TrackerImage bitmap and all the changes are made in it and in the end it is assigned to the main bitmap. Even when repaint is required then RePaintForm() function is called instead of calling paint() function of the form to avoid the flickering effect.

Conclusion

A simple program that demonstrates double buffering & tracker drawing is included. OnPaint() generates flickering effects so it is recommended to draw first on the bitmap and then on the form.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found

阅读(1473) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~