1 // license: public domain 2 // authors: jonas.sundstrom@kirilla.com 3 4 #include <ZipOMaticActivity.h> 5 6 Activity::Activity (BRect a_rect, const char * a_name, uint32 a_resizing_mode, uint32 a_flags) 7 : BBox (a_rect, a_name, a_resizing_mode, a_flags), 8 m_is_running (false), 9 m_barberpole_bitmap (NULL) 10 { 11 m_pattern.data[0] = 0x0f; 12 m_pattern.data[1] = 0x1e; 13 m_pattern.data[2] = 0x3c; 14 m_pattern.data[3] = 0x78; 15 m_pattern.data[4] = 0xf0; 16 m_pattern.data[5] = 0xe1; 17 m_pattern.data[6] = 0xc3; 18 m_pattern.data[7] = 0x87; 19 20 CreateBitmap(); 21 }; 22 23 Activity::~Activity() 24 { 25 // subviews are deleted by superclass 26 27 delete m_barberpole_bitmap; 28 } 29 30 void 31 Activity::Start() 32 { 33 m_is_running = true; 34 Window()->SetPulseRate(100000); 35 SetFlags(Flags() | B_PULSE_NEEDED); 36 SetViewColor(B_TRANSPARENT_COLOR); 37 Invalidate(); 38 } 39 40 void 41 Activity::Pause() 42 { 43 Window()->SetPulseRate(500000); 44 SetFlags(Flags() & (~ B_PULSE_NEEDED)); 45 Invalidate(); 46 } 47 48 void 49 Activity::Stop() 50 { 51 m_is_running = false; 52 Window()->SetPulseRate(500000); 53 SetFlags(Flags() & (~ B_PULSE_NEEDED)); 54 SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 55 Invalidate(); 56 } 57 58 bool 59 Activity::IsRunning() 60 { 61 return m_is_running; 62 } 63 64 void 65 Activity::Pulse() 66 { 67 uchar tmp = m_pattern.data[7]; 68 69 for (int j = 7; j > 0; --j) 70 { 71 m_pattern.data[j] = m_pattern.data[j-1]; 72 } 73 74 m_pattern.data[0] = tmp; 75 76 DrawIntoBitmap(); 77 78 Invalidate(); 79 } 80 81 void 82 Activity::Draw(BRect a_rect) 83 { 84 if (IsRunning()) 85 { 86 // draw BBox outline 87 BBox::Draw(a_rect); 88 SetDrawingMode(B_OP_COPY); 89 DrawBitmap(m_barberpole_bitmap); 90 } 91 else 92 { 93 BBox::Draw(a_rect); 94 95 float string_width = StringWidth("Drop files to zip."); 96 float view_width = Bounds().Width(); 97 98 MovePenTo ((view_width/2)-(string_width/2),12); 99 DrawString("Drop files to zip."); 100 } 101 } 102 103 void Activity::DrawIntoBitmap (void) 104 { 105 if (m_barberpole_bitmap->Lock()) 106 { 107 BRect a_rect = m_barberpole_bitmap->Bounds(); 108 109 m_barberpole_bitmap_view->SetDrawingMode(B_OP_COPY); 110 111 rgb_color color; 112 color.red = 0; 113 color.green = 0; 114 color.blue = 200; 115 color.alpha = 255; 116 m_barberpole_bitmap_view->SetHighColor(color); 117 118 // draw the pole 119 a_rect.InsetBy(2,2); 120 m_barberpole_bitmap_view->FillRect(a_rect, m_pattern); 121 122 // draw frame 123 124 // left 125 color.red = 150; 126 color.green = 150; 127 color.blue = 150; 128 m_barberpole_bitmap_view->SetHighColor(color); 129 BPoint point_a = m_barberpole_bitmap->Bounds().LeftTop(); 130 BPoint point_b = m_barberpole_bitmap->Bounds().LeftBottom(); 131 point_b.y -= 1; 132 m_barberpole_bitmap_view->StrokeLine(point_a, point_b); 133 point_a.x += 1; 134 point_b.x += 1; 135 point_b.y -= 1; 136 m_barberpole_bitmap_view->StrokeLine(point_a, point_b); 137 138 // top 139 m_barberpole_bitmap_view->SetDrawingMode(B_OP_OVER); 140 m_barberpole_bitmap_view->SetHighColor(color); 141 point_a = m_barberpole_bitmap->Bounds().LeftTop(); 142 point_b = m_barberpole_bitmap->Bounds().RightTop(); 143 point_b.x -= 1; 144 m_barberpole_bitmap_view->StrokeLine(point_a, point_b); 145 point_a.y += 1; 146 point_b.y += 1; 147 point_b.x -= 1; 148 m_barberpole_bitmap_view->StrokeLine(point_a, point_b); 149 150 // right 151 color.red = 255; 152 color.green = 255; 153 color.blue = 255; 154 m_barberpole_bitmap_view->SetHighColor(color); 155 point_a = m_barberpole_bitmap->Bounds().RightTop(); 156 point_b = m_barberpole_bitmap->Bounds().RightBottom(); 157 m_barberpole_bitmap_view->StrokeLine(point_a, point_b); 158 point_a.y += 1; 159 point_a.x -= 1; 160 point_b.x -= 1; 161 m_barberpole_bitmap_view->StrokeLine(point_a, point_b); 162 163 // bottom 164 m_barberpole_bitmap_view->SetHighColor(color); 165 point_a = m_barberpole_bitmap->Bounds().LeftBottom(); 166 point_b = m_barberpole_bitmap->Bounds().RightBottom(); 167 m_barberpole_bitmap_view->StrokeLine(point_a, point_b); 168 point_a.x += 1; 169 point_a.y -= 1; 170 point_b.y -= 1; 171 m_barberpole_bitmap_view->StrokeLine(point_a, point_b); 172 173 // some blending 174 color.red = 150; 175 color.green = 150; 176 color.blue = 150; 177 m_barberpole_bitmap_view->SetHighColor(color); 178 m_barberpole_bitmap_view->SetDrawingMode(B_OP_SUBTRACT); 179 m_barberpole_bitmap_view->StrokeRect(a_rect); 180 181 a_rect.InsetBy(1,1); 182 LightenBitmapHighColor(& color); 183 m_barberpole_bitmap_view->StrokeRect(a_rect); 184 185 a_rect.InsetBy(1,1); 186 LightenBitmapHighColor(& color); 187 m_barberpole_bitmap_view->StrokeRect(a_rect); 188 189 a_rect.InsetBy(1,1); 190 LightenBitmapHighColor(& color); 191 m_barberpole_bitmap_view->StrokeRect(a_rect); 192 193 a_rect.InsetBy(1,1); 194 LightenBitmapHighColor(& color); 195 m_barberpole_bitmap_view->StrokeRect(a_rect); 196 197 m_barberpole_bitmap_view->Flush(); 198 } 199 200 m_barberpole_bitmap->Unlock(); 201 } 202 203 void Activity::LightenBitmapHighColor (rgb_color * a_color) 204 { 205 a_color->red -= 30; 206 a_color->green -= 30; 207 a_color->blue -= 30; 208 209 m_barberpole_bitmap_view->SetHighColor(* a_color); 210 } 211 212 void Activity::CreateBitmap (void) 213 { 214 BRect barberpole_rect = Bounds(); 215 m_barberpole_bitmap = new BBitmap(barberpole_rect, B_CMAP8, true); 216 m_barberpole_bitmap_view = new BView(Bounds(), "buffer", B_FOLLOW_NONE, 0); 217 m_barberpole_bitmap->AddChild(m_barberpole_bitmap_view); 218 } 219 220 void Activity::FrameMoved (BPoint a_point) 221 { 222 delete m_barberpole_bitmap; 223 CreateBitmap(); 224 Invalidate(); 225 } 226 227 void Activity::FrameResized (float a_width, float a_height) 228 { 229 delete m_barberpole_bitmap; 230 CreateBitmap(); 231 Invalidate(); 232 } 233