meter.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* $Id$
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. // A function to display onscreen a percentage meter for progress. No
  22. // screen saving is done.
  23. #include "mouse.h"
  24. #include "graphics.h"
  25. #include "window.h"
  26. #include "meter.h"
  27. #include "string.h"
  28. #include <dos.h>
  29. //Calculates the percent from progress and out_of as in (progress/out_of).
  30. void meter(char far *title,unsigned int segment,int progress,int out_of) {
  31. int titlex=40-(str_len(title)>>1);
  32. m_hide();
  33. draw_window_box(5,10,74,12,segment,DI_MAIN,DI_DARK,DI_CORNER);
  34. //Add title
  35. write_string(title,titlex,10,DI_TITLE,segment);
  36. draw_char(' ',DI_TITLE,titlex-1,10,segment);
  37. draw_char(' ',DI_TITLE,titlex+str_len(title),10,segment);
  38. meter_interior(segment,progress,out_of);
  39. m_show();
  40. }
  41. //Draws the meter but only the interior where the percent is. Use for
  42. //speed and no flicker.
  43. void meter_interior(unsigned int segment,int progress,int out_of) {
  44. //The actual meter has 66 spaces, or 132 half spaces, to use, so...
  45. int percent=(int)(((long)progress*132L)/(long)out_of);
  46. //...percent is the number of half spaces to display.
  47. int revcolor=((DI_METER&15)<<4)+(DI_METER>>4);
  48. char percentstr[5]=" %";
  49. //Pointer to % display on video (IE the ###%)
  50. char far *video=(char far *)MK_FP(segment,(37+11*80)*2);
  51. int t1;
  52. //Fill in meter
  53. m_hide();
  54. if(percent>1) {
  55. fill_line(percent>>1,7,11,32+(revcolor<<8),segment);
  56. }
  57. if(percent<131) {
  58. fill_line((133-percent)>>1,7+(percent>>1),11,32+(DI_METER<<8),segment);
  59. }
  60. if(percent&1) {
  61. draw_char('Þ',revcolor,7+(percent>>1),11,segment);
  62. }
  63. //Determine percentage
  64. percent=(int)(((long)progress*100L)/(long)out_of);
  65. percentstr[2]='0'+percent%10;
  66. percent/=10;
  67. if(percent>0) {
  68. percentstr[1]='0'+percent%10;
  69. if(percent>9) percentstr[0]='1';
  70. }
  71. //Draw percentage, directly w/o color changes
  72. for(t1=0;t1<4;t1++) {
  73. if(percentstr[t1]!=' ') video[t1<<1]=percentstr[t1];
  74. }
  75. m_show();
  76. //Done! :)
  77. }