Author Topic: ProgressBar without using many images  (Read 2832 times)

m4unot

  • Guest
ProgressBar without using many images
« on: June 25, 2012, 09:39:21 pm »
I have seen many people using 50-100 images to animate a progress bar, but here i'm using only 3 images and some math:



Code: [Select]
#include "DragonFireSDK.h"

bool stop = false;


void loading(int p , int MyView,  int end_view, int width, int height, int x, int y){

ViewSetVisible(MyView, true);

// p = percent

if(p > 100|| p ==  100){

 
  ViewSetxy(MyView,  x-(((p-1)*2)-1), y);

  ViewSetSize(MyView, width*(p-1), height);

  ViewSetVisible(end_view, true);

  stop = true;
    }

else{

if(p > 50|| p ==  50){

   ViewSetxy(MyView,   x-((p*2)-1), y);


     ViewSetSize(MyView, width*(p)+1, height);


else{


if(p == 25|| p ==  29|| p == 31|| p ==  41|| p == 43|| p ==  47|| p ==  49){

  ViewSetxy(MyView,   x-((p*2)-1), y);


      ViewSetSize(MyView, width*p, height);

else{

   ViewSetxy(MyView,   x-((p*2)-2), y);


   ViewSetSize(MyView, width*p, height);
    }


}

}


}






int Font, text;

char str[100];
int p;

int x  , y ;

int height, width;

int MyView, end_view;



void AppMain()

{


    x = 25 , y =  25;

Font = FontAdd("Arial","Regular",12,0xFF0000);

    text = TextAdd((x*5)+5, y-2, "Waiting the touch data", Font);


    int skin = ImageAdd("Images/prog_menu.png");

    ViewAdd(skin, x, y);



int end = ImageAdd("Images/prog_end.png");

    end_view = ViewAdd(end, x, y);

ViewSetVisible(end_view, false);



    int MyImage = ImageAdd("Images/prog_load.png");

    MyView = ViewAdd(MyImage,0, 0);

ViewSetVisible(MyView, false);


height = ImageGetHeight(MyImage), width = ImageGetWidth(MyImage);




}

 

void AppExit()

{

 

}

 

void OnTimer()

{


if(stop == false){

p  +=1;

sprintf(str, "%d%%\n", p);

TextSetText(text, str);

    }


loading(p ,  MyView,   end_view,  width,  height,  x,  y);

 

}





PS: Download the attachments down below and place them inside your folder: " Images "

Shelbyp67

  • Guest
Re: ProgressBar without using many images
« Reply #1 on: November 21, 2012, 09:07:00 pm »
Cool! but how would I slow it down?

ciuffolo

  • Guest
Re: ProgressBar without using many images
« Reply #2 on: December 26, 2012, 03:19:09 am »
I think you have to make p float and implement it in OnTimer for 0.5,0.3,0.1 ecc...

nednones

  • Guest
Re: ProgressBar without using many images
« Reply #3 on: December 26, 2012, 08:07:27 am »
You just need to set a value to the if statement within the OnTimer method, e.g.


int Counter = 0;

void OnTimer()
{
   Counter++;

   if(Counter == 2)   //Could be 3 for 1/sec or 6 1/2 secs e.t.c
  {
        Counter = 0;
        UpdateProgressBar(vars...);
   }
}