1 // WorkView.cpp 2 3 #include <Application.h> 4 #include <TranslationUtils.h> 5 #include <Bitmap.h> 6 #include <stdio.h> 7 #include <Path.h> 8 #include "MultiTest.h" 9 #include "WorkView.h" 10 11 const char *kPath1 = "../data/images/image.jpg"; 12 const char *kPath2 = "../data/images/image.gif"; 13 WorkView(BRect rect)14WorkView::WorkView(BRect rect) 15 : BView(rect, "Work View", B_FOLLOW_ALL, B_WILL_DRAW | B_PULSE_NEEDED) 16 { 17 fbImage = true; 18 fPath = kPath1; 19 } 20 21 void AttachedToWindow()22WorkView::AttachedToWindow() 23 { 24 BTranslatorRoster *pRoster = NULL; 25 BBitmap *pBitmap; 26 27 //pRoster = ((MultiTestApplication *) be_app)->GetTranslatorRoster(); 28 29 pBitmap = BTranslationUtils::GetBitmap(fPath, pRoster); 30 if (pBitmap) { 31 SetViewBitmap(pBitmap); 32 delete pBitmap; 33 } 34 } 35 36 void Pulse()37WorkView::Pulse() 38 { 39 if (fbImage) { 40 ClearViewBitmap(); 41 fbImage = false; 42 if (fPath == kPath1) 43 fPath = kPath2; 44 else 45 fPath = kPath1; 46 } else { 47 //BTranslatorRoster *pRoster = NULL; 48 BBitmap *pBitmap = BTranslationUtils::GetBitmapFile(fPath); 49 if (pBitmap) { 50 ClearViewBitmap(); 51 SetViewBitmap(pBitmap); 52 delete pBitmap; 53 } else { 54 BPath Path(fPath); 55 printf("-- failed to get bitmap (%s)!\n", Path.Path()); 56 } 57 fbImage = true; 58 } 59 60 Invalidate(); 61 } 62