Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

OHELP_IF.CPP Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

OHELP_IF.CPP

Go to the documentation of this file.
00001 // Filename    : OHELP_IF.CPP
00002 // Description : The screen of help topic and help desc.
00003 // owner                        : Kevin(Ho)
00004 // Notes:       Steps to introduce a new class of user interface
00005 //                              1.      construct the new class
00006 //                              2.      in sys.h, add the new MODE, e.g. MODE_ADMISSIONS_AND_FINANCIAL_OFFICE
00007 //                              3.      include the new header file in cc.cpp, osysdisp.cpp, osysdet.cpp
00008 //                              4.      in cc.cpp, declare a global object of the new class, with the name matching the 'extern' statement in the header file
00009 //                              5.      in osysdisp.cpp, under switch(view_mode), add the redirection to the display function
00010 //                              6.      in osysdet.cpp, under Sys::detect_view, add the redirection to the detect function
00011 //                              7.      in osysdet.cpp, under Sys::process_key, add the new hot key (optional)
00012 //                              8.      in osysdet.cpp, under Sys::detect_button, modify if necessary (see the comments there)
00013 //                              9.      the deinit function (AdmOffice::deinit()) can be called when the view_mode in 'sys' object is switched
00014 //                                      the function frees memory occupied by this object
00015 //                                      the report function would re-allocate memory when it is called (note the report_init_flag)
00016 //                                      notice the beginning section of Sys::disp_frame()
00017 // Kevin 0723
00018 
00019 #include <OSYS.H>
00020 #include <OSTR.H>
00021 #include <OMISC.H>
00022 #include <OGAMESET.H>
00023 #include <OWORLDMT.H>
00024 #include <OVGA.H>
00025 #include <OIFACE.H>
00026 #include <OINFO.H>
00027 #include <COLOR.H>
00028 #include <OFONT.H>
00029 #include <OGAMESTR.H>
00030 #include <OMOUSE.H>
00031 #include <OBUTTON.H>
00032 #include <OFINANCE.H>
00033 //#include <OTXTBOX.H>
00034 #include <OTXTLIST.H>
00035 #include  <OHELPIF.H>
00036 
00037 enum {                                            // screen coordinates
00038     REPORT_X1 = ZOOM_X1+15,
00039     REPORT_Y1 = ZOOM_Y1+25,
00040     REPORT_X2 = ZOOM_X2-15,
00041     REPORT_Y2 = ZOOM_Y2-55
00042 };
00043 
00044 enum {
00045     BOTTOM_BUTTON_X0 = REPORT_X1+70,
00046     BOTTOM_BUTTON_X1 = REPORT_X1+170,
00047     BOTTOM_BUTTON_Y1 = REPORT_Y2+15,
00048     BOTTOM_BUTTON_X2 = REPORT_X2-20,
00049     BOTTOM_BUTTON_Y2 = REPORT_Y2+40
00050 };
00051 
00052 enum {
00053     BOTTOM_BUTTON_WIDTH = 125,
00054     BOTTOM_BUTTON_HEIGHT = 25,
00055     HELP_BUTTON_COUNT = 3,
00056     BOTTOM_BUTTON_DISTANCE
00057     = (BOTTOM_BUTTON_X2-BOTTOM_BUTTON_X1-BOTTOM_BUTTON_WIDTH*2)/3
00058 };
00059 
00060 enum {                                            // the bg image id
00061     BG_PIC_ID = 2
00062 };
00063 
00064 static ButtonGroup help_topic_bottom_button_group(2);
00065 static ButtonGroup help_desc_bottom_button_group(3);
00066 static short *bottom_button_up_bitmap[HELP_BUTTON_COUNT];
00067 static short *bottom_button_down_bitmap[HELP_BUTTON_COUNT];
00068 static char *help_desc_bottom_button_label[] = {
00069     "Help Topics","Back","Close"
00070 };
00071 static char *help_topic_bottom_button_label[] = {
00072     "Open","Cancel"
00073 };
00074 static int help_topic_report_init_flag;
00075 static int help_desc_report_init_flag;
00076 
00077 static int help_topic_current_mode=-1;
00078 static int help_desc_current_mode=-1;
00079 //------- Begin of function HelpIf::HelpIf -----------//
00081 HelpIf::HelpIf() {
00082     init();
00083 }
00084 
00085 //--------- End of function HelpIf::HelpIf -----------//
00086 
00087 //------- Begin of function HelpIf::~HelpIf -----------//
00089 HelpIf::~HelpIf() {
00090     deinit();
00091 }
00092 
00093 //--------- End of function HelpIf::~HelpIf -----------//
00094 
00095 //------- Begin of function HelpIf::deinit ---------------//
00097 void HelpIf::deinit() {
00098     //--------- deallocate memory -------------//
00099     for (int i = 0; i < HELP_BUTTON_COUNT; i++) {
00100         if (bottom_button_up_bitmap[i]) {
00101             mem_del(bottom_button_up_bitmap[i]);
00102             mem_del(bottom_button_down_bitmap[i]);
00103             bottom_button_up_bitmap[i] = NULL;
00104             bottom_button_down_bitmap[i] = NULL;
00105         }
00106     }
00107     help_textlist.deinit();
00108     help_topic_report_init_flag = 0;
00109     help_desc_report_init_flag = 0;
00110 }
00111 
00112 //--------- End of function HelpIf::deinit ---------------//
00113 
00114 //------- Begin of function HelpIf::init -----------------//
00116 void HelpIf::init() {
00117     memset(this,0,sizeof(HelpIf));
00118     for (int i = 0; i < HELP_BUTTON_COUNT; i++) {
00119         bottom_button_up_bitmap[i] = NULL;
00120         bottom_button_down_bitmap[i] = NULL;
00121     }
00122 
00123     help_topic_report_init_flag = 0;
00124     help_desc_report_init_flag = 0;
00125 }
00126 
00127 //--------- End of function HelpIf::init -----------------//
00128 
00129 //------- Begin of function HelpIf::help_topic_report ---------------//
00131 void HelpIf::help_topic_report(int refreshFlag) {
00132     vga.use_back();
00133 
00134     if (refreshFlag == INFO_REPAINT) {
00135         if(help_topic_report_init_flag )
00136             // deinit it first if it has already been initialized
00137             deinit();
00138         help_topic_current_mode=-1;
00139         //------------- paint the background ----------------//
00140         user_interface.bg_img(BG_PIC_ID, &vga_back);
00141 
00142         //----- initialize the bottom sub-menus buttons -----//
00143         if (!help_topic_report_init_flag) {
00144             short x = BOTTOM_BUTTON_X1;
00145             for (int i = 0; i < 2; i++, x+=BOTTOM_BUTTON_WIDTH+BOTTOM_BUTTON_DISTANCE) {
00146                 user_interface.create_button_bitmap(x, BOTTOM_BUTTON_Y1,
00147                                                     x+BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_Y1+BOTTOM_BUTTON_HEIGHT,
00148                                                     help_topic_bottom_button_label[i], &bottom_button_up_bitmap[i],
00149                                                     &bottom_button_down_bitmap[i], &vga_back);
00150 
00151                 help_topic_bottom_button_group[i].create_bitmapW(x, BOTTOM_BUTTON_Y1,
00152                                                                  x+BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_Y1+BOTTOM_BUTTON_HEIGHT,
00153                                                                  ((i == help_topic_current_mode) ? bottom_button_down_bitmap[i] :
00154                                                                   bottom_button_up_bitmap[i])+4);
00155             }
00156 
00157             help_topic_report_init_flag = 1;
00158             font_charts.put(REPORT_X1+300,REPORT_Y1-15,"Help Topics");
00159 
00160             String str;
00161             str  = DIR_RES;
00162             str += "SCORE";
00163             help_textlist.init(REPORT_X1,REPORT_Y1+5,REPORT_X2,REPORT_Y2,str);
00164             help_textlist.init_list(REPORT_X1,REPORT_Y1+5,REPORT_X2,REPORT_Y2);
00165         }
00166         //----------- paint the bottom button group ---------//
00167         help_topic_bottom_button_group.paint(help_topic_current_mode);
00168     }
00169 
00170     help_textlist.disp(refreshFlag,help_textlist.topic_id); {
00171 
00172         //      if (refreshFlag == INFO_REPAINT)
00173         //------- blt the back buffer to front buffer -------//
00174         vga.blt_buf(ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2);
00175     }
00176     vga.use_front();
00177 }
00178 
00179 //---------- End of function HelpIf::help_topic_report ------------//
00180 
00181 //---------- Begin of function HelpIf::help_desc_report ------------//
00183 void HelpIf::help_desc_report(int refreshFlag) {
00184     vga.use_back();
00185 
00186     if (refreshFlag == INFO_REPAINT) {
00187         if(help_desc_report_init_flag )
00188             // deinit it first if it has already been initialized
00189             deinit();
00190 
00191         //------------- paint the background ----------------//
00192         user_interface.bg_img(BG_PIC_ID, &vga_back);
00193 
00194         //----- initialize the bottom sub-menus buttons -----//
00195         if (!help_desc_report_init_flag) {
00196             short x = BOTTOM_BUTTON_X0;
00197             help_desc_current_mode=-1;
00198             for (int i = 0; i < 3; i++, x+=BOTTOM_BUTTON_WIDTH+BOTTOM_BUTTON_DISTANCE) {
00199                 user_interface.create_button_bitmap(x, BOTTOM_BUTTON_Y1,
00200                                                     x+BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_Y1+BOTTOM_BUTTON_HEIGHT,
00201                                                     help_desc_bottom_button_label[i], &bottom_button_up_bitmap[i],
00202                                                     &bottom_button_down_bitmap[i], &vga_back);
00203 
00204                 help_desc_bottom_button_group[i].create_bitmapW(x, BOTTOM_BUTTON_Y1,
00205                                                                 x+BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_Y1+BOTTOM_BUTTON_HEIGHT,
00206                                                                 ( ((i==1)&&(!help_textlist.can_back))||
00207                                                                   (i == help_desc_current_mode) ? bottom_button_down_bitmap[i] :
00208                                                                   bottom_button_up_bitmap[i])+4);
00209             }
00210 
00211             help_desc_bottom_button_group[1].enable_flag=help_textlist.can_back;
00212             if(!help_textlist.can_back) {
00213                 //help_desc_bottom_button_group[1].is_pushed=1;
00214                 //help_desc_bottom_button_group[1].enable_flag=0;
00215                 help_desc_bottom_button_group[1].body_ptr = (void *) (bottom_button_down_bitmap[1] + 4);
00216             }
00217 
00218             help_desc_report_init_flag = 1;
00219             String str;
00220             str  = DIR_RES;
00221             str += "SCORE";
00222             //                  if(!help_textlist.init_flag)
00223             help_textlist.init(REPORT_X1,REPORT_Y1+5,REPORT_X2,REPORT_Y2,str);
00224             help_textlist.init_list_flag=0;
00225         }
00226 
00227         String help_title;
00228         help_title=help_textlist.res_txt.get_title(help_textlist.topic_id);
00229         int ww=help_title.len()*(font_charts.width()+3);
00230         int wx=(REPORT_X2+REPORT_X1-ww)/2;
00231         user_interface.brighten(wx-20,REPORT_Y1-25,wx+ww+10,REPORT_Y1+font_charts.height()-18);
00232         user_interface.rect(wx-20,REPORT_Y1-25,wx+ww+10,REPORT_Y1+font_charts.height()-18,2);
00233         font_charts.put((wx>0)?wx:0,REPORT_Y1-18,help_title);
00234 
00235         //----------- paint the bottom button group ---------//
00236         help_desc_bottom_button_group.paint(help_desc_current_mode);
00237         //              help_textlist.back_history();
00238         if(!help_textlist.can_back) {
00239             short x=BOTTOM_BUTTON_X0+BOTTOM_BUTTON_WIDTH+BOTTOM_BUTTON_DISTANCE;
00240             user_interface.darken(x, BOTTOM_BUTTON_Y1,
00241                                   x+BOTTOM_BUTTON_WIDTH, BOTTOM_BUTTON_Y1+BOTTOM_BUTTON_HEIGHT);
00242         }
00243     }
00244 
00245     help_textlist.disp(refreshFlag,help_textlist.topic_id);
00246 
00247     if (refreshFlag == INFO_REPAINT) {
00248         //------- blt the back buffer to front buffer -------//
00249         vga.blt_buf(ZOOM_X1, ZOOM_Y1, ZOOM_X2, ZOOM_Y2);
00250         sys.blt_virtual_buf();
00251     }
00252     vga.use_front();
00253 }
00254 
00255 //---------- End of function Development::help_desc_report ------------//
00256 
00257 int HelpIf::help_topic_detect() {
00258     if (!help_topic_report_init_flag)
00259         return 0;
00260 
00261     int help_topic_bottomButtonGroupDetect;
00262 
00263     if ((help_topic_bottomButtonGroupDetect = help_topic_bottom_button_group.detect()) >= 0) {
00264         //-------- change display mode ------------//
00265         if(help_topic_current_mode>=0)
00266             help_topic_bottom_button_group[help_topic_current_mode].body_ptr = (void *) (bottom_button_up_bitmap[help_topic_current_mode] + 4);
00267         else
00268             for(int i=0;i<2;i++)
00269                 help_topic_bottom_button_group[i].body_ptr = (void *) (bottom_button_up_bitmap[i] + 4);
00270 
00271         help_topic_current_mode = help_topic_bottomButtonGroupDetect;
00272         help_topic_bottom_button_group[help_topic_current_mode].body_ptr = (void *) (bottom_button_down_bitmap[help_topic_current_mode] + 4);
00273 
00274         //-------- post display redraw flag -------//
00275         if(help_topic_bottomButtonGroupDetect==0) {
00276             // add current topic id to the history
00277             help_textlist.add_history(help_textlist.topic_id);
00278             sys.set_view_mode(MODE_HELP_DESC);
00279         }
00280         if((sys.back_view_mode==MODE_HELP_TOPIC)||
00281            (sys.back_view_mode==MODE_HELP_DESC))
00282             sys.back_view_mode=MODE_NORMAL;
00283 
00284         if(help_topic_bottomButtonGroupDetect==1)
00285             sys.set_view_mode(sys.back_view_mode);
00286         sys.redraw_all_flag = 1;
00287 
00288         return 1;
00289     }
00290 
00291     vga.use_front();
00292     help_textlist.detect();
00293     if(help_textlist.double_clicked) {
00294         // add current topic id to the history
00295         help_textlist.add_history(help_textlist.topic_id);
00296         sys.set_view_mode(MODE_HELP_DESC);
00297         help_textlist.double_clicked=0;
00298     }
00299 
00300     return 0;
00301 }
00302 
00304 
00305 int HelpIf::help_desc_detect() {
00306     if (!help_desc_report_init_flag)
00307         return 0;
00308 
00309     int help_desc_bottomButtonGroupDetect;
00310 
00311     if ((help_desc_bottomButtonGroupDetect = help_desc_bottom_button_group.detect()) >= 0) {
00312         if((!help_textlist.can_back)&&(help_desc_bottomButtonGroupDetect==1))return 0;
00313 
00314         if(help_desc_current_mode>=0)
00315             //-------- change display mode ------------//
00316             help_desc_bottom_button_group[help_desc_current_mode].body_ptr = (void *) (bottom_button_up_bitmap[help_desc_current_mode] + 4);
00317         else
00318             for(int i=0;i<3;i++)
00319                 help_desc_bottom_button_group[i].body_ptr = (void *) (bottom_button_up_bitmap[i] + 4);
00320 
00321         help_desc_current_mode = help_desc_bottomButtonGroupDetect;
00322         help_desc_bottom_button_group[help_desc_current_mode].body_ptr = (void *) (bottom_button_down_bitmap[help_desc_current_mode] + 4);
00323 
00324         //-------- post display redraw flag -------//
00325         if(help_desc_bottomButtonGroupDetect==0)sys.set_view_mode(MODE_HELP_TOPIC);
00326         if(help_desc_bottomButtonGroupDetect==1)help_textlist.back_history();
00327         if(help_desc_bottomButtonGroupDetect==2) {
00328             if((sys.back_view_mode==MODE_HELP_TOPIC)||
00329                (sys.back_view_mode==MODE_HELP_DESC))
00330                 sys.back_view_mode=MODE_NORMAL;
00331             sys.set_view_mode(sys.back_view_mode);
00332         }
00333         if(help_desc_bottomButtonGroupDetect==0 ||
00334            help_desc_bottomButtonGroupDetect==1 ||
00335            help_desc_bottomButtonGroupDetect==2)help_textlist.top_line=1;
00336 
00337         sys.redraw_all_flag = 1;
00338         return 1;
00339     }
00340     help_textlist.detect();
00341     return 0;
00342 }
00343 

Generated on Fri Aug 23 01:37:58 2002 for VirtualU by doxygen1.2.17