Progress bar creation principle

Source: Internet
Author: User

The progress bar is as easy to develop as a static control, because they only receive a few messages.

Basically, you need to do two things for the progress bar-you need to tell it the Maximum/minimum range and step size. for example, I want to create a loading progress bar because I want to load 100 different game resources. I will create a progress bar with a range of 0 to 100. I will initially set the progress bar to 0. Then, when I load a resource, I will use the unit length to move the progress bar forward to a step. when the progress bar advances, it will re-draw itself. The graph uses a long bar proportional to the drawing area to show how long it is.

The progress bar is like a scroll bar. In fact, you can use the scroll bar method to develop the progress bar. I separate the progress bar and scroll bar for development because I want them to have very different appearances and slightly different behaviors-your needs may be different.

Slide and scroll bar

Draw a slide or scroll bar is very similar to the draw progress bar, which is displayed in the percentage of the rectangle to be drawn using the slide bar. It provides the information of the slide location to show its current position. you need to make some minor changes for the vertical and horizontal controls-I first made a base class, gui_slider, which contains all the publicCodeAnd all member variables, and then develop two different Derived classes, gui_slider_horz and gui_slider_vert. They process different draw and click logics.

Just like processing mouse clicks, I chose a simple method for the slide bar. if the mouse clicks in the scroll bar area, it will automatically scroll to that position. in my slide bar, you cannot click and move the position on the axis at the same time-directly jump to the place you click. this is mainly because it is very simple and I do not like the default Windows method.

You know that the logic of the scroll bar/slide bar is the same as that of the progress bar-minimum, maximum, and current position. However, unlike the progress bar, you can click on the control to change the current position.

Now let's look at the scroll bar. in my gui, the scroll bar is a slide with a button on each side. the two buttons (up/down or left/right arrow) Move the slide unit distance. this method eliminates code duplication between a large number of Button classes and the scroll bar. I strongly recommend that you look at similar things.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.