Test Volume Bar Demo

I'm in the first term of C++ right now in HS and I'm stuck. Ive tried searching for answers on the webs and my teacher also doesn't do the best for helping me. Since there is 3 other language classes in the same room... with only one teacher. He doesn't teach, he gives us packets and expects us to get it. Well this time, he just gave us a demo if everything, of graphics. Making lines and rectangles and etc. Also it shows how to drag something. I actually found the .cpp on the web here... kickstyle.net/~rkick/courses/AdvWebProg/demoCMU.cpp

What my project is to do is make a fake volume bar.

Right now I have the rectangle and a square with constants of the sides beside the side that will move when I click and drag it over to the side of the rectangle.

I copied the code for the dragging example and right now I have the rectangle and the square moves with the mouse movement. I've tried messing with constraints on the dragging code but nothing is working. I don't know where to start either since this is the first project of this type of stuff and we didn't get anything to read, just the examples in the Demo.cpp.

I've pasted all my code at this URL... http://cl1p.net/MyCodeCPlus/

I hate to post it all.. but I have NO idea where to start or what to do..

If someone could help me here, I will be sooo happy!! Ive been stuck on this for 3 days now and getting no where. I've asked for help, but he hasn't helped me in any way I need it...

Any help, please!

Thanks you soo much!
I didn't quite get it.
There is a line testWindow.DrawRectangle(0, 0, testWindow.GetWidth() - 1, testWindow.GetHeight() - 1); which draws a rectangle on the whole screen. There is a line testWindow.DrawRectangle(50, 50, iX, 200); which draws another rectangle. iX is mouse x coordinate I suppose. That line is in no way effected by the value of bDragging. And what square are you talking about?
Anyway, your code should be something like this:
int bar_x, bar_y, bar_w, bar_h, volume, square_w;
while escape is not hit
    if not drag
        if mouse hit and the mouse is over the square
            drag = true
        else
            if mouse released then drag = false
            else
                volume = mousex - bar_x
                if volume < 0 then volume = 0
                if volume > bar_w then volume = bar_w
            endif
        endif
    endif
    draw rectangle (bar_x, bar_y, bar_w, bar_h)
    draw rectangle (bar_x + volume - square_w/2, bar_y, square_w, bar_h)
endwhile
Last edited on
Topic archived. No new replies allowed.