diff --git a/artpaint/tools/AirBrushTool.cpp b/artpaint/tools/AirBrushTool.cpp index e252d940..e083c815 100644 --- a/artpaint/tools/AirBrushTool.cpp +++ b/artpaint/tools/AirBrushTool.cpp @@ -74,24 +74,24 @@ AirBrushTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) while (LastUpdatedRect().IsValid()) snooze(50000); - coordinate_queue = new (std::nothrow) CoordinateQueue(); - if (coordinate_queue == NULL) - return NULL; - image_view = view; - thread_id coordinate_reader - = spawn_thread(CoordinateReader, "read coordinates", B_NORMAL_PRIORITY, this); - resume_thread(coordinate_reader); + CoordinateReader* coordinate_reader + = new (std::nothrow) CoordinateReader(view, NO_INTERPOLATION, false); + if (coordinate_reader == NULL) + return NULL; reading_coordinates = true; BPoint prev_point; BBitmap* bitmap = view->ReturnImage()->ReturnActiveBitmap(); BBitmap* srcBuffer = new (std::nothrow) BBitmap(bitmap); - if (srcBuffer == NULL) + if (srcBuffer == NULL) { + delete coordinate_reader; return NULL; + } BBitmap* tmpBuffer = new (std::nothrow) BBitmap(bitmap); if (tmpBuffer == NULL) { delete srcBuffer; + delete coordinate_reader; return NULL; } @@ -125,140 +125,134 @@ AirBrushTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) prev_point = point - BPoint(1, 1); SetLastUpdatedRect(BRect(point, point)); // while (buttons) { - while (((status_of_read = coordinate_queue->Get(point)) == B_OK) - || (reading_coordinates == true)) { - if ((status_of_read == B_OK)) { - the_script->AddPoint(point); - - float half_size = fToolSettings.size / 2; - // we should only consider points that are inside this rectangle - rc = BRect(point.x - half_size, point.y - half_size, point.x + half_size, - point.y + half_size); - rc = rc & bounds; - rc = rc & selection->GetBoundingRect(); - - if (rc.IsValid() == true) { - int32 height = rc.IntegerHeight(); - int32 width = rc.IntegerWidth(); - int32 left = (int32)rc.left; - int32 top = (int32)rc.top; - - for (int32 y = 0; y <= height; y++) { - int32 y_sqr = (int32)((point.y - rc.top - y) * (point.y - rc.top - y)); - for (int32 x = 0; x <= width; x++) { - int32 dx = (int32)(point.x - rc.left - x); - float distance = sqrt_table[dx * dx + y_sqr]; - if ((distance <= half_size) - && (selection->IsEmpty() - || selection->ContainsPoint(left + x, top + y))) { - float change = (half_size - distance) / half_size; - change *= ((float)fToolSettings.pressure) / 100.0; - - // This is experimental for doing a real transparency - // Seems to work quite well - union { - uint8 bytes[4]; - uint32 word; - } color; - color.word = drawer->GetPixel(left + x, top + y); - if (color.bytes[3] != 0x00) { - drawer->SetPixel(left + x, top + y, - mix_2_pixels_fixed( - target_color, color.word, (uint32)(32768 * change)), - selection, NULL); - } else { - color.word = target_color; - color.bytes[3] = 0x00; - drawer->SetPixel(left + x, top + y, - mix_2_pixels_fixed( - target_color, color.word, (uint32)(32768 * change)), - selection, NULL); - } + while (coordinate_reader->GetPoint(point) == B_OK) { + the_script->AddPoint(point); + + float half_size = fToolSettings.size / 2; + // we should only consider points that are inside this rectangle + rc = BRect(point.x - half_size, point.y - half_size, point.x + half_size, + point.y + half_size); + rc = rc & bounds; + rc = rc & selection->GetBoundingRect(); + + if (rc.IsValid() == true) { + int32 height = rc.IntegerHeight(); + int32 width = rc.IntegerWidth(); + int32 left = (int32)rc.left; + int32 top = (int32)rc.top; + + for (int32 y = 0; y <= height; y++) { + int32 y_sqr = (int32)((point.y - rc.top - y) * (point.y - rc.top - y)); + for (int32 x = 0; x <= width; x++) { + int32 dx = (int32)(point.x - rc.left - x); + float distance = sqrt_table[dx * dx + y_sqr]; + if ((distance <= half_size) + && (selection->IsEmpty() + || selection->ContainsPoint(left + x, top + y))) { + float change = (half_size - distance) / half_size; + change *= ((float)fToolSettings.pressure) / 100.0; + + // This is experimental for doing a real transparency + // Seems to work quite well + union { + uint8 bytes[4]; + uint32 word; + } color; + color.word = drawer->GetPixel(left + x, top + y); + if (color.bytes[3] != 0x00) { + drawer->SetPixel(left + x, top + y, + mix_2_pixels_fixed( + target_color, color.word, (uint32)(32768 * change)), + selection, NULL); + } else { + color.word = target_color; + color.bytes[3] = 0x00; + drawer->SetPixel(left + x, top + y, + mix_2_pixels_fixed( + target_color, color.word, (uint32)(32768 * change)), + selection, NULL); } } } } + } - imageUpdater->AddRect(rc); - SetLastUpdatedRect(LastUpdatedRect() | rc); - BitmapUtilities::CompositeBitmapOnSource(bitmap, srcBuffer, tmpBuffer, rc); + imageUpdater->AddRect(rc); + SetLastUpdatedRect(LastUpdatedRect() | rc); + BitmapUtilities::CompositeBitmapOnSource(bitmap, srcBuffer, tmpBuffer, rc); - snooze(20 * 1000); - } + snooze(20 * 1000); } } else if (fToolSettings.mode == HS_SPRAY_MODE) { // Do the spray RandomNumberGenerator* generator = new RandomNumberGenerator(0, 10000); prev_point = point; - while (((status_of_read = coordinate_queue->Get(point)) == B_OK) - || (reading_coordinates == true)) { - if ((status_of_read == B_OK)) { - int32 flow = fToolSettings.pressure + 1; - float width = fToolSettings.size; - float angle; - float opacity = 0.4; - - BRect rc(point, point); - - if (point == prev_point) { - for (int32 i = 0; i < flow; i++) { - float x = generator->UniformDistribution(0, width * .5); - float y = generator->UniformDistribution( - 0, sqrt((width * .5) * (width * .5) - x * x)); - - angle = generator->UniformDistribution(0, 1.0) * 2 * M_PI; - float old_x = x; - x = cos(angle) * x - sin(angle) * y; - y = sin(angle) * old_x + cos(angle) * y; - BPoint new_point = point + BPoint(x, y); - new_point.x = round(new_point.x); - new_point.y = round(new_point.y); - rc = rc | BRect(new_point, new_point); - - if (selection->IsEmpty() || selection->ContainsPoint(new_point)) { - drawer->SetPixel(new_point, - mix_2_pixels_fixed(target_color, drawer->GetPixel(new_point), - (uint32)(32768 * opacity)), - selection, NULL); - } + while (coordinate_reader->GetPoint(point) == B_OK) { + int32 flow = fToolSettings.pressure + 1; + float width = fToolSettings.size; + float angle; + float opacity = 0.4; + + BRect rc(point, point); + + if (point == prev_point) { + for (int32 i = 0; i < flow; i++) { + float x = generator->UniformDistribution(0, width * .5); + float y = generator->UniformDistribution( + 0, sqrt((width * .5) * (width * .5) - x * x)); + + angle = generator->UniformDistribution(0, 1.0) * 2 * M_PI; + float old_x = x; + x = cos(angle) * x - sin(angle) * y; + y = sin(angle) * old_x + cos(angle) * y; + BPoint new_point = point + BPoint(x, y); + new_point.x = round(new_point.x); + new_point.y = round(new_point.y); + rc = rc | BRect(new_point, new_point); + + if (selection->IsEmpty() || selection->ContainsPoint(new_point)) { + drawer->SetPixel(new_point, + mix_2_pixels_fixed(target_color, drawer->GetPixel(new_point), + (uint32)(32768 * opacity)), + selection, NULL); } - } else { - BPoint center; - for (int32 i = 0; i < flow; i++) { - float x = generator->UniformDistribution(0, width * .5); - float y = generator->UniformDistribution( - 0, sqrt((width * .5) * (width * .5) - x * x)); - - // Select center randomly from the line between prev_point and point. - // This is done by doing a linear interpolation between the - // two points and rounding the result to nearest integer. - float a = generator->UniformDistribution(0, 1.0); - center.x = round(a * prev_point.x + (1.0 - a) * point.x); - center.y = round(a * prev_point.y + (1.0 - a) * point.y); - - angle = generator->UniformDistribution(0, 1.0) * 2 * M_PI; - float old_x = x; - x = cos(angle) * x - sin(angle) * y; - y = sin(angle) * old_x + cos(angle) * y; - BPoint new_point = center + BPoint(x, y); - new_point.x = round(new_point.x); - new_point.y = round(new_point.y); - rc = rc | BRect(new_point, new_point); - - if (selection->IsEmpty() || selection->ContainsPoint(new_point)) { - drawer->SetPixel(new_point, - mix_2_pixels_fixed(target_color, drawer->GetPixel(new_point), - (uint32)(32768 * opacity)), - selection, NULL); - } + } + } else { + BPoint center; + for (int32 i = 0; i < flow; i++) { + float x = generator->UniformDistribution(0, width * .5); + float y = generator->UniformDistribution( + 0, sqrt((width * .5) * (width * .5) - x * x)); + + // Select center randomly from the line between prev_point and point. + // This is done by doing a linear interpolation between the + // two points and rounding the result to nearest integer. + float a = generator->UniformDistribution(0, 1.0); + center.x = round(a * prev_point.x + (1.0 - a) * point.x); + center.y = round(a * prev_point.y + (1.0 - a) * point.y); + + angle = generator->UniformDistribution(0, 1.0) * 2 * M_PI; + float old_x = x; + x = cos(angle) * x - sin(angle) * y; + y = sin(angle) * old_x + cos(angle) * y; + BPoint new_point = center + BPoint(x, y); + new_point.x = round(new_point.x); + new_point.y = round(new_point.y); + rc = rc | BRect(new_point, new_point); + + if (selection->IsEmpty() || selection->ContainsPoint(new_point)) { + drawer->SetPixel(new_point, + mix_2_pixels_fixed(target_color, drawer->GetPixel(new_point), + (uint32)(32768 * opacity)), + selection, NULL); } } - prev_point = point; - - imageUpdater->AddRect(rc); - SetLastUpdatedRect(LastUpdatedRect() | rc); - BitmapUtilities::CompositeBitmapOnSource(bitmap, srcBuffer, tmpBuffer, rc); } + prev_point = point; + + imageUpdater->AddRect(rc); + SetLastUpdatedRect(LastUpdatedRect() | rc); + BitmapUtilities::CompositeBitmapOnSource(bitmap, srcBuffer, tmpBuffer, rc); } delete generator; @@ -266,7 +260,7 @@ AirBrushTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) imageUpdater->ForceUpdate(); delete imageUpdater; - delete coordinate_queue; + delete coordinate_reader; delete drawer; delete srcBuffer; @@ -304,42 +298,6 @@ AirBrushTool::HelpString(bool isInUse) const } -int32 -AirBrushTool::CoordinateReader(void* data) -{ - AirBrushTool* this_pointer = (AirBrushTool*)data; - return this_pointer->read_coordinates(); -} - - -int32 -AirBrushTool::read_coordinates() -{ - reading_coordinates = true; - uint32 buttons; - BPoint point, prev_point; - BPoint view_point; - image_view->Window()->Lock(); - image_view->getCoords(&point, &buttons, &view_point); - image_view->MovePenTo(view_point); - image_view->Window()->Unlock(); - prev_point = point + BPoint(1, 1); - - while (buttons) { - image_view->Window()->Lock(); - if (point != prev_point || fToolSettings.mode == HS_SPRAY_MODE) { - coordinate_queue->Put(point); - prev_point = point; - } - image_view->getCoords(&point, &buttons, &view_point); - image_view->Window()->Unlock(); - snooze(20 * 1000); - } - - reading_coordinates = false; - return B_OK; -} - // #pragma mark -- AirBrushToolConfigView diff --git a/artpaint/tools/AirBrushTool.h b/artpaint/tools/AirBrushTool.h index 36fe7178..05f9ace6 100644 --- a/artpaint/tools/AirBrushTool.h +++ b/artpaint/tools/AirBrushTool.h @@ -40,9 +40,6 @@ class AirBrushTool : public DrawingTool { const char* HelpString(bool isInUse) const; private: - int32 read_coordinates(); - static int32 CoordinateReader(void*); - bool reading_coordinates; ImageView* image_view; diff --git a/artpaint/tools/EraserTool.cpp b/artpaint/tools/EraserTool.cpp index 971fb762..995312d0 100644 --- a/artpaint/tools/EraserTool.cpp +++ b/artpaint/tools/EraserTool.cpp @@ -16,6 +16,7 @@ #include "BitmapUtilities.h" #include "Brush.h" #include "CoordinateQueue.h" +#include "CoordinateReader.h" #include "Cursors.h" #include "Image.h" #include "ImageUpdater.h" @@ -69,30 +70,30 @@ EraserTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) while (LastUpdatedRect().IsValid()) snooze(50000); - coordinate_queue = new CoordinateQueue(); image_view = view; - thread_id coordinate_reader - = spawn_thread(CoordinateReader, "read coordinates", B_NORMAL_PRIORITY, this); - resume_thread(coordinate_reader); + CoordinateReader* coordinate_reader + = new (std::nothrow) CoordinateReader(view, NO_INTERPOLATION, false); + if (coordinate_reader == NULL) + return NULL; reading_coordinates = true; ToolScript* the_script = new ToolScript(Type(), fToolSettings, ((PaintApplication*)be_app)->Color(true)); if (the_script == NULL) { - delete coordinate_queue; + delete coordinate_reader; return NULL; } BBitmap* buffer = view->ReturnImage()->ReturnActiveBitmap(); if (buffer == NULL) { - delete coordinate_queue; + delete coordinate_reader; delete the_script; return NULL; } BBitmap* srcBuffer = new (std::nothrow) BBitmap(buffer); if (srcBuffer == NULL) { - delete coordinate_queue; + delete coordinate_reader; delete the_script; return NULL; } @@ -114,7 +115,7 @@ EraserTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) Selection* selection = view->GetSelection(); BitmapDrawer* drawer = new BitmapDrawer(tmpBuffer); if (drawer == NULL) { - delete coordinate_queue; + delete coordinate_reader; delete the_script; return NULL; @@ -187,9 +188,8 @@ EraserTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) ImageUpdater* imageUpdater = new ImageUpdater(view, 2000); imageUpdater->AddRect(updated_rect); - while (((status_of_read = coordinate_queue->Get(point)) == B_OK) - || (reading_coordinates == true)) { - if ((status_of_read == B_OK) && (prev_point != point)) { + while (coordinate_reader->GetPoint(point) == B_OK) { + if (prev_point != point) { the_script->AddPoint(point); if (fToolSettings.use_current_brush == true && brush != NULL) { brush->draw(tmpBuffer, @@ -235,7 +235,7 @@ EraserTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) delete tmpBuffer; delete drawer; - delete coordinate_queue; + delete coordinate_reader; return the_script; } @@ -268,44 +268,6 @@ EraserTool::HelpString(bool isInUse) const } -int32 -EraserTool::CoordinateReader(void* data) -{ - EraserTool* this_pointer = (EraserTool*)data; - return this_pointer->read_coordinates(); -} - - -int32 -EraserTool::read_coordinates() -{ - reading_coordinates = true; - uint32 buttons; - BPoint point, prev_point; - BPoint view_point; - image_view->Window()->Lock(); - image_view->getCoords(&point, &buttons, &view_point); - image_view->MovePenTo(view_point); - image_view->Window()->Unlock(); - prev_point = point + BPoint(1, 1); - - while (buttons) { - image_view->Window()->Lock(); - if (point != prev_point) { - coordinate_queue->Put(point); - image_view->StrokeLine(view_point); - prev_point = point; - } - image_view->getCoords(&point, &buttons, &view_point); - image_view->Window()->Unlock(); - snooze(20 * 1000); - } - - reading_coordinates = false; - return B_OK; -} - - // #pragma mark -- EraserToolConfigView diff --git a/artpaint/tools/EraserTool.h b/artpaint/tools/EraserTool.h index 9b886b4c..dbeaec7c 100644 --- a/artpaint/tools/EraserTool.h +++ b/artpaint/tools/EraserTool.h @@ -40,11 +40,6 @@ class EraserTool : public DrawingTool { const void* ToolCursor() const; const char* HelpString(bool isInUse) const; -private: - - int32 read_coordinates(); - static int32 CoordinateReader(void* data); - private: bool reading_coordinates; diff --git a/artpaint/tools/FreeLineTool.cpp b/artpaint/tools/FreeLineTool.cpp index d04b4983..75694ad4 100644 --- a/artpaint/tools/FreeLineTool.cpp +++ b/artpaint/tools/FreeLineTool.cpp @@ -16,6 +16,7 @@ #include "BitmapUtilities.h" #include "Brush.h" #include "CoordinateQueue.h" +#include "CoordinateReader.h" #include "Cursors.h" #include "Image.h" #include "ImageUpdater.h" @@ -63,40 +64,36 @@ FreeLineTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) while (LastUpdatedRect().IsValid()) snooze(50000); - coordinate_queue = new (std::nothrow) CoordinateQueue(); - if (coordinate_queue == NULL) - return NULL; - image_view = view; - thread_id coordinate_reader - = spawn_thread(CoordinateReader, "read coordinates", B_NORMAL_PRIORITY, this); - resume_thread(coordinate_reader); - reading_coordinates = true; + CoordinateReader* coordinate_reader + = new (std::nothrow) CoordinateReader(view, LINEAR_INTERPOLATION, false); + if (coordinate_reader == NULL) + return NULL; ToolScript* the_script = new (std::nothrow) ToolScript(Type(), fToolSettings, ((PaintApplication*)be_app)->Color(true)); if (the_script == NULL) { - delete coordinate_queue; + delete coordinate_reader; return NULL; } BBitmap* buffer = view->ReturnImage()->ReturnActiveBitmap(); if (buffer == NULL) { - delete coordinate_queue; + delete coordinate_reader; delete the_script; return NULL; } BBitmap* srcBuffer = new (std::nothrow) BBitmap(buffer); if (srcBuffer == NULL) { - delete coordinate_queue; + delete coordinate_reader; delete the_script; return NULL; } BBitmap* tmpBuffer = new (std::nothrow) BBitmap(buffer); if (tmpBuffer == NULL) { - delete coordinate_queue; + delete coordinate_reader; delete the_script; delete srcBuffer; return NULL; @@ -111,7 +108,7 @@ FreeLineTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) Selection* selection = view->GetSelection(); BitmapDrawer* drawer = new (std::nothrow) BitmapDrawer(tmpBuffer); if (drawer == NULL) { - delete coordinate_queue; + delete coordinate_reader; delete the_script; delete srcBuffer; delete tmpBuffer; @@ -126,7 +123,6 @@ FreeLineTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) prev_point = point; BRect updated_rect; - status_t status_of_read; Brush* brush; bool delete_brush = false; @@ -177,9 +173,8 @@ FreeLineTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) ImageUpdater* imageUpdater = new ImageUpdater(view, 2000); imageUpdater->AddRect(updated_rect); - while (((status_of_read = coordinate_queue->Get(point)) == B_OK) - || (reading_coordinates == true)) { - if ((status_of_read == B_OK) && (prev_point != point)) { + while (coordinate_reader->GetPoint(point) == B_OK) { + if (prev_point != point) { the_script->AddPoint(point); brush->draw(tmpBuffer, BPoint(point.x - brush_width_per_2, point.y - brush_height_per_2), selection); @@ -214,7 +209,7 @@ FreeLineTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) delete tmpBuffer; delete drawer; - delete coordinate_queue; + delete coordinate_reader; if (delete_brush == true) delete brush; @@ -251,44 +246,6 @@ FreeLineTool::HelpString(bool isInUse) const } -int32 -FreeLineTool::CoordinateReader(void* data) -{ - FreeLineTool* this_pointer = (FreeLineTool*)data; - return this_pointer->read_coordinates(); -} - - -int32 -FreeLineTool::read_coordinates() -{ - reading_coordinates = true; - uint32 buttons; - BPoint point, prev_point; - BPoint view_point; - image_view->Window()->Lock(); - image_view->getCoords(&point, &buttons, &view_point); - image_view->MovePenTo(view_point); - image_view->Window()->Unlock(); - prev_point = point + BPoint(1, 1); - - while (buttons) { - image_view->Window()->Lock(); - if (point != prev_point) { - coordinate_queue->Put(point); - image_view->StrokeLine(view_point); - prev_point = point; - } - image_view->getCoords(&point, &buttons, &view_point); - image_view->Window()->Unlock(); - snooze(20 * 1000); - } - - reading_coordinates = false; - return B_OK; -} - - // #pragma mark -- FreeLineToolConfigView diff --git a/artpaint/tools/FreeLineTool.h b/artpaint/tools/FreeLineTool.h index ee8a17d0..f5521c7c 100644 --- a/artpaint/tools/FreeLineTool.h +++ b/artpaint/tools/FreeLineTool.h @@ -40,9 +40,6 @@ class FreeLineTool : public DrawingTool { BView* ConfigView(); const void* ToolCursor() const; const char* HelpString(bool isInUse) const; -private: - int32 read_coordinates(); - static int32 CoordinateReader(void*); private: bool reading_coordinates; diff --git a/artpaint/tools/TransparencyTool.cpp b/artpaint/tools/TransparencyTool.cpp index 924a770a..494fa5e9 100644 --- a/artpaint/tools/TransparencyTool.cpp +++ b/artpaint/tools/TransparencyTool.cpp @@ -14,6 +14,7 @@ #include "Brush.h" #include "CoordinateQueue.h" +#include "CoordinateReader.h" #include "Cursors.h" #include "Image.h" #include "ImageUpdater.h" @@ -63,14 +64,11 @@ TransparencyTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) while (LastUpdatedRect().IsValid()) snooze(50000); - coordinate_queue = new (std::nothrow) CoordinateQueue(); - if (coordinate_queue == NULL) - return NULL; - image_view = view; - thread_id coordinate_reader - = spawn_thread(CoordinateReader, "read coordinates", B_NORMAL_PRIORITY, this); - resume_thread(coordinate_reader); + CoordinateReader* coordinate_reader + = new (std::nothrow) CoordinateReader(view, NO_INTERPOLATION, false); + if (coordinate_reader == NULL) + return NULL; reading_coordinates = true; BBitmap* bitmap = view->ReturnImage()->ReturnActiveBitmap(); @@ -126,77 +124,74 @@ TransparencyTool::UseTool(ImageView* view, uint32 buttons, BPoint point, BPoint) status_t status_of_read; - while (((status_of_read = coordinate_queue->Get(point)) == B_OK) - || (reading_coordinates == true)) { - if ((status_of_read == B_OK)) { - if (selection == NULL || selection->IsEmpty() == true - || selection->ContainsPoint(point)) { + while (coordinate_reader->GetPoint(point) == B_OK) { + if (selection == NULL || selection->IsEmpty() == true + || selection->ContainsPoint(point)) { - the_script->AddPoint(point); + the_script->AddPoint(point); - int32 x_dist, y_sqr; + int32 x_dist, y_sqr; - rc = BRect(floor(point.x - half_width), floor(point.y - half_height), - ceil(point.x + half_width), ceil(point.y + half_height)); - rc = rc & bounds; + rc = BRect(floor(point.x - half_width), floor(point.y - half_height), + ceil(point.x + half_width), ceil(point.y + half_height)); + rc = rc & bounds; - int32 width = rc.IntegerWidth(); - int32 height = rc.IntegerHeight(); - if (fToolSettings.use_current_brush == true) { - width -= 1; - height -= 1; - } + int32 width = rc.IntegerWidth(); + int32 height = rc.IntegerHeight(); + if (fToolSettings.use_current_brush == true) { + width -= 1; + height -= 1; + } - for (int32 y = 0; y < height + 1; y++) { - y_sqr = (int32)(point.y - rc.top - y); - y_sqr *= y_sqr; - int32 real_y = (int32)(rc.top + y); - int32 real_x; - for (int32 x = 0; x < width + 1; x++) { - x_dist = (int32)(point.x - rc.left - x); - real_x = (int32)(rc.left + x); - float brush_val = 1.0; - if (fToolSettings.use_current_brush == true) { - union color_conversion brush_color; - brush_color.word = *(brush_bits + x + y * brush_bpr); - brush_val = brush_color.bytes[3]; - } - if ((fToolSettings.use_current_brush == true && brush_val > 0.0) - || (fToolSettings.use_current_brush == false - && sqrt_table[x_dist * x_dist + y_sqr] <= half_width)) { - color.word = *(bits_origin + real_y * bpr + real_x); - if (selection == NULL || selection->IsEmpty() == true - || selection->ContainsPoint(real_x, real_y)) { - - uint8 diff = fabs(color.bytes[3] - transparency_value); - uint8 step = (uint8)(ceil(diff * pressure * brush_val / 2)); - - if (color.bytes[3] < transparency_value) { - color.bytes[3] - = (uint8)min_c(color.bytes[3] + step, transparency_value); - *(bits_origin + real_y * bpr + real_x) = color.word; - } else if (color.bytes[3] > transparency_value) { - color.bytes[3] - = (uint8)max_c(color.bytes[3] - step, transparency_value); - *(bits_origin + real_y * bpr + real_x) = color.word; - } + for (int32 y = 0; y < height + 1; y++) { + y_sqr = (int32)(point.y - rc.top - y); + y_sqr *= y_sqr; + int32 real_y = (int32)(rc.top + y); + int32 real_x; + for (int32 x = 0; x < width + 1; x++) { + x_dist = (int32)(point.x - rc.left - x); + real_x = (int32)(rc.left + x); + float brush_val = 1.0; + if (fToolSettings.use_current_brush == true) { + union color_conversion brush_color; + brush_color.word = *(brush_bits + x + y * brush_bpr); + brush_val = brush_color.bytes[3]; + } + if ((fToolSettings.use_current_brush == true && brush_val > 0.0) + || (fToolSettings.use_current_brush == false + && sqrt_table[x_dist * x_dist + y_sqr] <= half_width)) { + color.word = *(bits_origin + real_y * bpr + real_x); + if (selection == NULL || selection->IsEmpty() == true + || selection->ContainsPoint(real_x, real_y)) { + + uint8 diff = fabs(color.bytes[3] - transparency_value); + uint8 step = (uint8)(ceil(diff * pressure * brush_val / 2)); + + if (color.bytes[3] < transparency_value) { + color.bytes[3] + = (uint8)min_c(color.bytes[3] + step, transparency_value); + *(bits_origin + real_y * bpr + real_x) = color.word; + } else if (color.bytes[3] > transparency_value) { + color.bytes[3] + = (uint8)max_c(color.bytes[3] - step, transparency_value); + *(bits_origin + real_y * bpr + real_x) = color.word; } } } } + } - imageUpdater->AddRect(rc); + imageUpdater->AddRect(rc); - SetLastUpdatedRect(LastUpdatedRect() | rc); - snooze(20 * 1000); - } + SetLastUpdatedRect(LastUpdatedRect() | rc); + snooze(20 * 1000); } } imageUpdater->ForceUpdate(); delete imageUpdater; - delete coordinate_queue; + delete coordinate_reader; return the_script; } @@ -231,42 +226,6 @@ TransparencyTool::HelpString(bool isInUse) const } -int32 -TransparencyTool::CoordinateReader(void* data) -{ - TransparencyTool* this_pointer = (TransparencyTool*)data; - return this_pointer->read_coordinates(); -} - - -int32 -TransparencyTool::read_coordinates() -{ - reading_coordinates = true; - uint32 buttons; - BPoint point, prev_point; - BPoint view_point; - image_view->Window()->Lock(); - image_view->getCoords(&point, &buttons, &view_point); - image_view->MovePenTo(view_point); - image_view->Window()->Unlock(); - prev_point = point + BPoint(1, 1); - - while (buttons) { - image_view->Window()->Lock(); - if (point != prev_point) { - coordinate_queue->Put(point); - prev_point = point; - } - image_view->getCoords(&point, &buttons, &view_point); - image_view->Window()->Unlock(); - snooze(20 * 1000); - } - - reading_coordinates = false; - return B_OK; -} - // #pragma mark -- TransparencyToolConfigView diff --git a/artpaint/tools/TransparencyTool.h b/artpaint/tools/TransparencyTool.h index 843fe2f4..7c734a37 100644 --- a/artpaint/tools/TransparencyTool.h +++ b/artpaint/tools/TransparencyTool.h @@ -40,9 +40,6 @@ class TransparencyTool : public DrawingTool { const void* ToolCursor() const; const char* HelpString(bool isInUse) const; private: - int32 read_coordinates(); - static int32 CoordinateReader(void*); - bool reading_coordinates; ImageView* image_view;