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

Password:

oiface.cpp Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

oiface.cpp

Go to the documentation of this file.
00001 //Filename    : OIFACE.CPP
00002 //Description : UserInterface class
00003 
00004 // Comments:    general functions for user interface manipulation
00005 //                                      refer to "admissions and financial aid office", <Oadm_off>
00006 // Norris 0714
00007 
00008 #include <ALL.H>
00009 #include <OSYS.H>
00010 #include <OWORLDMT.H>
00011 #include <OIFACE.H>
00012 #include <OVGA.H>
00013 #include <COLOR.H>
00014 #include <OCOLTBL.H>
00015 #include <OIMGRES.H>
00016 #include <OFONT.H>
00017 #include <OINFO.H>
00018 #include <OFILE.H>
00019 #include <ORESX.H>
00020 #include <OBITMAPW.H>
00021 
00022 //--------- define constant ---------//
00023 
00024 #define BG_FILENAME "IFACE"                       // background images filename prefix
00025 #define NUM_BG_IMG  19                            // number of background images
00026 
00027 enum {
00028     BRIGHTENING_IDX = 6,
00029     DARKENING_IDX = -2
00030 };
00031 
00032 //-------- Begin of function UserInterface::UserInterface ------//
00034 UserInterface::UserInterface() {
00035     memset(this, 0, sizeof(UserInterface));
00036     color_table = new ColorTable;
00037     backgd_flag = 1;
00038     cur_img_id = 0;
00039     // ##### begin Gilbert 26/04/2001 ######//
00040     save_area_buffer = NULL;
00041     save_area_buffer_size = 0;;
00042     // ##### end Gilbert 26/04/2001 ######//
00043 }
00044 
00045 //---------- End of function UserInterface::UserInterface ------//
00046 
00047 //-------- Begin of function UserInterface::~UserInterface -----//
00049 UserInterface::~UserInterface() {
00050     // ##### begin Gilbert 26/04/2001 ######//
00051     if( save_area_buffer )
00052         mem_del(save_area_buffer);
00053     save_area_buffer = NULL;
00054     save_area_buffer_size = 0;
00055     // ##### end Gilbert 26/04/2001 ######//
00056     delete color_table;
00057 }
00058 
00059 //---------- End of function UserInterface::~UserInterface -----//
00060 
00061 //-------- Begin of function UserInterface::bg_img ------------//
00067 void UserInterface::bg_img(int imgId, VgaBuf *vgaBufPtr) {
00068     err_when(imgId <= 0 || imgId > NUM_BG_IMG);
00069 
00070     if(backgd_flag==0) {
00071         //              vgaBufPtr->bar(ZOOM_X1, ZOOM_Y1,ZOOM_X2, ZOOM_Y2, V_WHITE);
00072         vgaBufPtr->barW_fast(ZOOM_X1, ZOOM_Y1,ZOOM_X2, ZOOM_Y2,0xFFFF);
00073         //              info.disp_column_bitmap(vgaBufPtr);
00074         return;
00075     }
00076 
00077     String imgName = BG_FILENAME;
00078     imgName += long(imgId);
00079 
00080     int dataSize;
00081     File* filePtr = image_interface.get_file(imgName, dataSize);
00082 
00083     if (imgId != cur_img_id) {
00084         short header = filePtr->file_get_short();
00085 
00086         err_when( header != -1 );                     // must use own color palette
00087 
00088         filePtr->file_read(palette, 256 * 3);
00089 
00090         PalDesc palDesc(palette, 3, 256, 6);
00091         color_table->generate_table_fast(MAX_BRIGHTNESS_ADJUST_DEGREE, palDesc, ColorTable::bright_func);
00092         remap_table = (short *) color_table->get_table(0);
00093 
00094         cur_img_id = imgId;
00095     }
00096     else {
00097         filePtr->file_seek(filePtr->file_pos() + 256 * 3 + sizeof(short));
00098     }
00099 
00100     vgaBufPtr->put_large_bitmap(ZOOM_X1, ZOOM_Y1, filePtr, remap_table);
00101 
00102     info.disp_column_bitmap(vgaBufPtr);
00103 }
00104 
00105 //---------- End of function UserInterface::bg_img ------------//
00106 
00107 /*
00108 //-------- Begin of function UserInterface::construct_palette_brighten ------//
00110 void UserInterface::construct_palette_brighten()
00111 {
00112   double rgbR, rgbG, rgbB;
00113   double yiqY, yiqI, yiqQ;
00114   unsigned char *palettePtr = palette, *paletteBrightenPtr = palette_brighten;
00115   for (int i = 0; i < 256; i++)
00116   {
00117     yiqY = 0.2990*(rgbR=double(*palettePtr++)/63.0);
00118 yiqY += 0.5870*(rgbG=double(*palettePtr++)/63.0);
00119 yiqY += 0.1140*(rgbB=double(*palettePtr++)/63.0) + BRIGHTEN_IDX;
00120 yiqI = 0.5960*rgbR - 0.2750*rgbG - 0.3210*rgbB;
00121 yiqQ = 0.2120*rgbR - 0.5230*rgbG + 0.3110*rgbB;
00122 rgbR = yiqY + 0.9557*yiqI + 0.6199*yiqQ;
00123 rgbG = yiqY - 0.2716*yiqI - 0.6469*yiqQ;
00124 rgbB = yiqY - 1.1082*yiqI + 1.7051*yiqQ;
00125 (*paletteBrightenPtr++) = (rgbR > 1.0) ? 63 : short(rgbR*63.0);
00126 (*paletteBrightenPtr++) = (rgbG > 1.0) ? 63 : short(rgbG*63.0);
00127 (*paletteBrightenPtr++) = (rgbB > 1.0) ? 63 : short(rgbB*63.0);
00128 }
00129 PalDesc palDesc(palette_brighten, 3, 256, 6);
00130 color_table_brighten->generate_table_fast(MAX_BRIGHTNESS_ADJUST_DEGREE, palDesc, ColorTable::bright_func);
00131 remap_table_brighten = (short *) color_table_brighten->get_table(0);
00132 }
00133 //---------- End of function UserInterface::construct_palette_brighten ------//
00134 */
00135 
00136 //-------- Begin of function UserInterface::rect ------------//
00144 void UserInterface::rect(int x1, int y1, int x2, int y2, int width, int borderColor, int shadowColor, VgaBuf *vgaBufPtr) {
00145     //  vgaBufPtr->bar(x1+width, y1+width, x2-width, y1+width+1, shadowColor);
00146     //  vgaBufPtr->bar(x1+width, y1+width+2, x1+width+1, y2-width, shadowColor);
00147     //  vgaBufPtr->bar(x1+1, y2+1, x2+2, y2+2, shadowColor);
00148     //  vgaBufPtr->bar(x2+1, y1+1, x2+2, y2, shadowColor);
00149     //  vgaBufPtr->bar(x1, y1, x2, y1+(--width), borderColor);
00150     //  vgaBufPtr->bar(x1, y1+width+1, x1+width, y2, borderColor);
00151     //  vgaBufPtr->bar(x1+width+1, y2-width, x2, y2, borderColor);
00152     //  vgaBufPtr->bar(x2-width, y1+width+1, x2, y2-width-1, borderColor);
00153     int w=width+1;
00154     if(w<2)w=2;
00155     // - 1
00156     vgaBufPtr->bar(x1+w, y1+w, x2-w, y1+w, shadowColor);
00157     // | 1
00158     vgaBufPtr->bar(x1+w, y1+w+1, x1+w, y2-w+2, shadowColor);
00159     vgaBufPtr->bar(x1, y2+2, x2, y2+2, shadowColor);// - 2
00160     vgaBufPtr->bar(x2, y1, x2, y2+2, shadowColor);  // | 2
00161     w--;
00162     // RGB = 75,60,31, Idx =5 (187,150,75)
00163     // ref to : /ccres/pal/pal.std
00164     vgaBufPtr->bar(x1+w, y1+w, x2-w, y1+w, 5);      // - 1
00165     vgaBufPtr->bar(x1+w, y1+w+1, x1+w, y2-w+1, 5);  // | 1
00166     vgaBufPtr->bar(x1, y2+1, x2-1, y2+1, 5);        // - 2
00167     vgaBufPtr->bar(x2-1, y1, x2-1, y2+1, 5);        // | 2
00168     w--;
00169 
00170 #if(GAME_VERSION>=200)
00171     if ( borderColor == Vga::active_buf->color_up ) {
00172         // RGB = 94,87,69 , Idx = 193 (250,217,173)
00173         vgaBufPtr->bar(x1, y1, x2-2, y1+w, 193);      // - 1
00174         vgaBufPtr->bar(x1, y1+w, x1+w, y2-w, 193);    // | 1
00175         vgaBufPtr->bar(x1, y2-w, x2-2, y2, 193);      // - 2
00176         vgaBufPtr->bar(x2-w-2, y1, x2-2, y2, 193);    // | 2
00177     }
00178     else {
00179         // RGB = 94,87,69 , Idx = 193 (250,217,173)
00180         // - 1
00181         vgaBufPtr->bar(x1, y1, x2-2, y1+w, borderColor);
00182         // | 1
00183         vgaBufPtr->bar(x1, y1+w, x1+w, y2-w, borderColor);
00184         // - 2
00185         vgaBufPtr->bar(x1, y2-w, x2-2, y2, borderColor);
00186         // | 2
00187         vgaBufPtr->bar(x2-w-2, y1, x2-2, y2, borderColor);
00188     }
00189 #else
00190     // RGB = 94,87,69 , Idx = 193 (250,217,173)
00191     vgaBufPtr->bar(x1, y1, x2-2, y1+w, 193);        // - 1
00192     vgaBufPtr->bar(x1, y1+w, x1+w, y2-w, 193);      // | 1
00193     vgaBufPtr->bar(x1, y2-w, x2-2, y2, 193);        // - 2
00194     vgaBufPtr->bar(x2-w-2, y1, x2-2, y2, 193);      // | 2
00195 #endif
00196     //  vgaBufPtr->bar(x1+w, y1+w, x2-1, y1+w, V_BROWN);    // - 1
00197     //  vgaBufPtr->bar(x1+w, y1+w+1, x1+w, y2-1, V_BROWN);       // | 1
00198     //  vgaBufPtr->bar(x1, y2+w, x2+w+1, y2+w, V_BROWN);                 // - 2
00199     //  vgaBufPtr->bar(x2+w, y1, x2+w, y2+w-1, V_BROWN);         // | 2
00200     //  w--;
00201     //  vgaBufPtr->bar(x1, y1, x2, y1+w, V_ORANGE);                     // - 1
00202     //  vgaBufPtr->bar(x1, y1+w, x1+w, y2, V_ORANGE);           // | 1
00203     //  vgaBufPtr->bar(x1, y2, x2+w, y2+w, V_ORANGE);           // - 2
00204     //  vgaBufPtr->bar(x2, y1, x2+w, y2, V_ORANGE);             // | 2
00205 
00206     //  vgaBufPtr->bar(x1+width, y1+width, x2-width, y1+width+1, shadowColor);
00207     //  vgaBufPtr->bar(x1+width, y1+width+2, x1+width+1, y2-width, shadowColor);
00208     //  vgaBufPtr->bar(x1+1, y2+1, x2+2, y2+2, shadowColor);
00209     //  vgaBufPtr->bar(x2+1, y1+1, x2+2, y2, shadowColor);
00210     //  vgaBufPtr->bar(x1, y1, x2, y1+(--width), V_BROWN);
00211     //  vgaBufPtr->bar(x1, y1+width+1, x1+width, y2, V_BROWN);
00212     //  vgaBufPtr->bar(x1+width+1, y2-width, x2, y2, V_BROWN);
00213     //  vgaBufPtr->bar(x2-width, y1+width+1, x2, y2-width-1, V_BROWN);
00214     //  vgaBufPtr->bar(x1, y1, x2, y1+(--width), V_ORANGE);
00215     //  vgaBufPtr->bar(x1, y1+width+1, x1+width, y2, V_ORANGE);
00216     //  vgaBufPtr->bar(x1+width+1, y2-width, x2, y2, V_ORANGE);
00217     //  vgaBufPtr->bar(x2-width, y1+width+1, x2, y2-width-1, V_ORANGE);
00218 }
00219 
00220 //---------- End of function UserInterface::rect ------------//
00221 
00222 //-------- Begin of function UserInterface::h_line ------------//
00231 void UserInterface::h_line(int x1, int y1, int length, int width, int borderColor, int shadowColor, VgaBuf *vgaBufPtr) {
00232     //borderColor);
00233     vgaBufPtr->bar(x1, y1, x1+length-1, y1+width-1, 193);
00234     // shadowColor);
00235     vgaBufPtr->bar(x1+1, y1+width, x1+length+1, y1+width+1,5);
00236     // shadowColor);
00237     vgaBufPtr->bar(x1+length+1, y1+1, x1+length+2, y1+width,5);
00238 }
00239 
00240 //---------- End of function UserInterface::h_line ------------//
00241 
00242 //-------- Begin of function UserInterface::v_line ------------//
00251 void UserInterface::v_line(int x1, int y1, int height, int width, int borderColor, int shadowColor, VgaBuf *vgaBufPtr) {
00252     if (borderColor >0 || shadowColor>0) {
00253         vgaBufPtr->bar(x1, y1, x1+width-1, y1+height-1, borderColor);
00254         vgaBufPtr->bar(x1+width+1, y1+1, x1+width+2, y1+height+1, shadowColor);
00255         vgaBufPtr->bar(x1+1, y1+height, x1+width, y1+height+1, shadowColor);
00256     }
00257     else {
00258         //borderColor);
00259         vgaBufPtr->bar(x1, y1, x1+width-1, y1+height-1, 193);
00260         // shadowColor);
00261         vgaBufPtr->bar(x1+width+1, y1+1, x1+width+2, y1+height+1, 5);
00262         //shadowColor);
00263         vgaBufPtr->bar(x1+1, y1+height, x1+width, y1+height+1, 5);
00264     }
00265 }
00266 
00267 //---------- End of function UserInterface::v_line ------------//
00268 
00269 //-------- Begin of function UserInterface::bar ------------//
00277 void UserInterface::bar(int x1, int y1, int x2, int y2, int barColor, int shadowColor, VgaBuf *vgaBufPtr) {
00278     vgaBufPtr->bar(x1, y1, x2, y2, barColor);
00279     vgaBufPtr->bar(x1, y2+1, x2, y2+2, shadowColor);
00280     vgaBufPtr->bar(x2+1, y1, x2+2, y2+2, shadowColor);
00281 }
00282 
00283 //---------- End of function UserInterface::bar ------------//
00284 
00285 //-------- Begin of function UserInterface::panel ------------//
00293 void UserInterface::panel(int x1, int y1, int x2, int y2, int panelColor, int lightColor, int shadowColor, VgaBuf *vgaBufPtr) {
00294     vgaBufPtr->bar(x1, y1, x2, y1, shadowColor);
00295     vgaBufPtr->bar(x1, y1+1, x1, y2, shadowColor);
00296     vgaBufPtr->bar(x1+1, y2, x2, y2, lightColor);
00297     vgaBufPtr->bar(x2, y1+1, x2, y2-1, lightColor);
00298     vgaBufPtr->bar(x1+1, y1+1, x2-1, y2-1, panelColor);
00299 }
00300 
00301 //---------- End of function UserInterface::panel ------------//
00302 
00303 //-------- Begin of function UserInterface::paint ------------//
00309 void UserInterface::paint(int x1, int y1, int x2, int y2, int paintColor, VgaBuf *vgaBufPtr) {
00310     vgaBufPtr->bar(x1, y1, x2, y2, paintColor);
00311 }
00312 
00313 //---------- End of function UserInterface::paint ------------//
00314 
00315 /*
00316 //-------- Begin of function UserInterface::brighten ----------//
00323 void UserInterface::brighten(short *bufPtr)
00324 {
00325   int bufSize = int(*bufPtr++);
00326 bufSize *= int(*bufPtr++);
00327 
00328 if (cur_img_id <= 0 || cur_img_id > NUM_BG_IMG)
00329 return;
00330 
00331 if (!palette_flag)
00332 {
00333 construct_palette_brighten();
00334 palette_flag = 1;
00335 }
00336 
00337 for (int i = 0; i < bufSize; i++, bufPtr++)
00338 {
00339 for (int j = 0; j < 256; j++)
00340 {
00341 if (*bufPtr == remap_table[j])
00342 {
00343 *bufPtr = remap_table_brighten[j];
00344 break;
00345 }
00346 }
00347 }
00348 }
00349 //---------- End of function UserInterface::brighten ---------//
00350 */
00351 
00352 //--------- Begin of function UserInterface::adjust_brigheness -------//
00354 void UserInterface::adjust_brightness(int x1, int y1, int x2, int y2, int brightness, VgaBuf *vgaBufPtr) {
00355 #if( MAX_BRIGHTNESS_ADJUST_DEGREE > 10 )
00356     brightness *= MAX_BRIGHTNESS_ADJUST_DEGREE / 10;
00357 #endif
00358 
00359     err_when( brightness < -MAX_BRIGHTNESS_ADJUST_DEGREE ||
00360               brightness >  MAX_BRIGHTNESS_ADJUST_DEGREE );
00361 
00362     IMGbrightBar( vgaBufPtr->buf_ptr(), vgaBufPtr->buf_true_pitch(), x1, y1, x2, y2, brightness);
00363 
00364     /*
00365       if ((x2 - x1 + 1) * (y2 - y1 + 1) > COMMON_DATA_BUF_SIZE)
00366       {
00367       for (short i = y1; i <= y2; i++)
00368       {
00369       vgaBufPtr->save_area_common_buf(x1, i, x2, i);
00370       IMGcopyWbright( vgaBufPtr->buf_ptr(), vgaBufPtr->buf_true_pitch(),
00371       ((short*)sys.common_data_buf)+6, *((short*)sys.common_data_buf),
00372       x1, i, x2, i, brightness);
00373       }
00374       }
00375       else
00376       {
00377       vgaBufPtr->save_area_common_buf(x1, y1, x2, y2);
00378       IMGcopyWbright( vgaBufPtr->buf_ptr(), vgaBufPtr->buf_true_pitch(),
00379       ((short*)sys.common_data_buf)+6, *((short*)sys.common_data_buf),
00380       x1, y1, x2, y2, brightness);
00381       }
00382     */
00383 }
00384 
00385 //----------- End of function UserInterface::adjust_brightness -------//
00386 
00387 //--------- Begin of function UserInterface::brighten -------//
00389 void UserInterface::brighten(int x1, int y1, int x2, int y2, VgaBuf *vgaBufPtr) {
00390     if(backgd_flag==0)return;
00391     adjust_brightness(x1, y1, x2, y2, BRIGHTENING_IDX, vgaBufPtr);
00392 }
00393 
00394 //----------- End of function UserInterface::brighten -------//
00395 
00396 //--------- Begin of function UserInterface::darken -------//
00398 void UserInterface::darken(int x1, int y1, int x2, int y2, VgaBuf *vgaBufPtr) {
00399     adjust_brightness(x1, y1, x2, y2, DARKENING_IDX, vgaBufPtr);
00400 }
00401 
00402 //----------- End of function UserInterface::darken -------//
00403 
00404 //---------- Begin of funcion UserInterface::create_button_bitmap -------//
00405 //
00406 //      <int>                   x1, y1, x2, y2                  coordinates of the button
00407 // <char*>              label                                           text label of the button
00408 // <short**>    upBitmapPtr                             ptr to button-up bitmap (to use: upBitmapPtr+4)
00409 // <short**>    downBitmapPtr                   ptr to button-down bitmap (to use: downBitmapPtr+4)
00410 //      [VgaBuf*]       vgaBufPtr                               ptr to VgaBuf (default = Vga::active_buf)
00411 // [Font*]              fontPtr                                 ptr to font to be used (default = &font_san)
00412 //
00413 void UserInterface::create_button_bitmap(int x1, int y1, int x2, int y2, char *label, short **upBitmapPtr, short **downBitmapPtr, VgaBuf *vgaBufPtr, Font *fontPtr) {
00414     x1++;
00415     y1++;
00416     x2--;
00417     y2--;
00418 
00419     // ##### begin Gilbert 26/04/2001 ######//
00420     // reduce mem_add/mem_del
00421     // short *saveAreaBuf = vgaBufPtr->save_area(x1, y1, x2+2, y2+2);  //## chea 070999 BUGHERE if the button is @ the bottom of the screen
00422     int saveAreaSize = BitmapW::size(x2+2-x1+1, y2+2-y1+1);
00423     if( saveAreaSize > save_area_buffer_size ) {
00424         save_area_buffer_size = saveAreaSize + 0x1000;// allocate 1K byte more
00425         save_area_buffer = (short *)mem_resize( save_area_buffer, save_area_buffer_size );
00426     }
00427     vgaBufPtr->read_bitmapW(x1, y1, x2+2, y2+2, save_area_buffer );
00428     // ##### end Gilbert 26/04/2001 ######//
00429 
00430     rect(x1, y1, x2+2, y2,1);
00431 #if(GAME_VERSION>=200)
00432     short lineCount = 1;
00433     char labelLocal[123];
00434     strcpy( labelLocal, label );
00435     short breakPos[2]= {                            // Assume can divide into 3 rows
00436         strlen(label),strlen(label)
00437     };
00438     for ( int i=0; i<strlen(label)-1; i++ ) {
00439         if ( label[i] == '\n' ) {                     // there should be a line break
00440             breakPos[lineCount-1] = i-1;                // will copy strings till i
00441             lineCount++;
00442         }
00443     }
00444     char oneRowLabel[123]="\0";
00445     char* tail = "\0";
00446     int  startY,endY;
00447     for ( i=0; i<lineCount; i++ ) {
00448         strcpy ( oneRowLabel, "" );
00449         // copy the text need to display
00450         strncpy( oneRowLabel, labelLocal, breakPos[i]+1 );
00451         strcpy( oneRowLabel+breakPos[i]+1, tail );
00452         startY = ((y2+1-(y1+2))/lineCount)*i+(y1+2);
00453         endY   = ((y2+1-(y1+2))/lineCount)*(i+1)+(y1+2);
00454         fontPtr->center_put( x1+2, startY, x2, endY, oneRowLabel );
00455         // Shorten the label
00456         strcpy( labelLocal, label+breakPos[i]+1 );
00457     }
00458 #else
00459     fontPtr->center_put(x1+2, y1+2, x2, y2+1, label);
00460 #endif
00461     *downBitmapPtr = vgaBufPtr->save_area(x1-1, y1-1, x2+2, y2+2, *downBitmapPtr);
00462     // ##### begin Gilbert 26/04/2001 ######//
00463     // vgaBufPtr->rest_area(saveAreaBuf, 0);
00464     vgaBufPtr->put_bitmapW( x1,y1, save_area_buffer );
00465     // ##### end Gilbert 26/04/2001 ######//
00466     brighten(x1, y1, x2+2, y2);
00467     rect(x1, y1, x2+2, y2,1);
00468 #if(GAME_VERSION>=200)
00469     strcpy( labelLocal, label );
00470     strcpy(oneRowLabel,"\0");
00471     tail = "\0";
00472     startY,endY;
00473     for ( i=0; i<lineCount; i++ ) {
00474         strcpy( oneRowLabel, "" );
00475         // copy the text need to display
00476         strncpy( oneRowLabel, labelLocal, breakPos[i]+1 );
00477         strcpy( oneRowLabel+breakPos[i]+1, tail );
00478         startY = ((y2+1-(y1+2))/lineCount)*i+(y1+2);
00479         endY   = ((y2+1-(y1+2))/lineCount)*(i+1)+(y1+2);
00480         fontPtr->center_put( x1+2, startY, x2, endY, oneRowLabel );
00481         // Shorten the label
00482         strcpy( labelLocal, label+breakPos[i]+1 );
00483     }
00484 #else
00485     fontPtr->center_put(x1+2, y1+2, x2, y2+1, label);
00486 #endif
00487     *upBitmapPtr = vgaBufPtr->save_area(x1-1, y1-1, x2+2, y2+2, *upBitmapPtr);
00488     // ##### begin Gilbert 26/04/2001 ######//
00489     // vgaBufPtr->rest_area(saveAreaBuf, 1);
00490     vgaBufPtr->put_bitmapW( x1,y1, save_area_buffer );
00491     // ##### end Gilbert 26/04/2001 ######//
00492 }
00493 
00494 //----------- End of function UserInterface::create_button_bitmap -------//

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