Review IdleRegister
(#4892)
This turns `IdleRegister::add()` into a template function to make the provided function pointers type safe. It also adds a `delete_data` parameter to manage the provided data pointer even in `destroy()`.
This commit is contained in:
@@ -44,11 +44,11 @@ HistogramPanel::HistogramPanel ()
|
||||
|
||||
histogramArea = Gtk::manage (new HistogramArea (this));
|
||||
setExpandAlignProperties(histogramArea, true, true, Gtk::ALIGN_FILL, Gtk::ALIGN_FILL);
|
||||
|
||||
|
||||
histogramRGBArea = Gtk::manage (new HistogramRGBArea ());
|
||||
setExpandAlignProperties(histogramRGBArea, true, false, Gtk::ALIGN_FILL, Gtk::ALIGN_END);
|
||||
histogramRGBArea->show();
|
||||
|
||||
|
||||
// connecting the two childs
|
||||
histogramArea->signal_factor_changed().connect( sigc::mem_fun(*histogramRGBArea, &HistogramRGBArea::factorChanged) );
|
||||
|
||||
@@ -78,7 +78,7 @@ HistogramPanel::HistogramPanel ()
|
||||
chroImage_g = new RTImage ("histogram-gold-off-small.png");
|
||||
rawImage_g = new RTImage ("histogram-bayer-off-small.png");
|
||||
barImage_g = new RTImage ("histogram-bar-off-small.png");
|
||||
|
||||
|
||||
mode0Image = new RTImage ("histogram-mode-linear-small.png");
|
||||
mode1Image = new RTImage ("histogram-mode-logx-small.png");
|
||||
mode2Image = new RTImage ("histogram-mode-logxy-small.png");
|
||||
@@ -226,9 +226,9 @@ void HistogramPanel::resized (Gtk::Allocation& req)
|
||||
histogramRGBArea->updateBackBuffer(-1, -1, -1);
|
||||
histogramRGBArea->queue_draw ();
|
||||
|
||||
// Store current height of the histogram
|
||||
// Store current height of the histogram
|
||||
options.histogramHeight = get_height();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void HistogramPanel::red_toggled ()
|
||||
@@ -346,7 +346,7 @@ void HistogramPanel::reorder (Gtk::PositionType align)
|
||||
|
||||
// DrawModeListener interface:
|
||||
void HistogramPanel::toggleButtonMode ()
|
||||
{
|
||||
{
|
||||
if (options.histogramDrawMode == 0)
|
||||
showMode->set_image(*mode0Image);
|
||||
else if (options.histogramDrawMode == 1)
|
||||
@@ -562,28 +562,28 @@ void HistogramRGBArea::update (int valh, int rh, int gh, int bh)
|
||||
|
||||
harih->pending++;
|
||||
|
||||
const auto func = [](gpointer data) -> gboolean {
|
||||
HistogramRGBAreaIdleHelper* const harih = static_cast<HistogramRGBAreaIdleHelper*>(data);
|
||||
const auto func =
|
||||
[](HistogramRGBAreaIdleHelper* harih) -> bool
|
||||
{
|
||||
if (harih->destroyed) {
|
||||
if (harih->pending == 1) {
|
||||
delete harih;
|
||||
} else {
|
||||
harih->pending--;
|
||||
}
|
||||
|
||||
if (harih->destroyed) {
|
||||
if (harih->pending == 1) {
|
||||
delete harih;
|
||||
} else {
|
||||
harih->pending--;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
harih->harea->updateBackBuffer(-1, -1, -1);
|
||||
harih->harea->queue_draw ();
|
||||
|
||||
harih->harea->updateBackBuffer(-1, -1, -1);
|
||||
harih->harea->queue_draw ();
|
||||
harih->pending--;
|
||||
|
||||
harih->pending--;
|
||||
return false;
|
||||
};
|
||||
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
idle_register.add(func, harih);
|
||||
idle_register.add<HistogramRGBAreaIdleHelper>(func, harih, false);
|
||||
}
|
||||
|
||||
void HistogramRGBArea::updateOptions (bool r, bool g, bool b, bool l, bool c, bool raw, bool bar)
|
||||
@@ -655,7 +655,7 @@ void HistogramRGBArea::factorChanged (double newFactor)
|
||||
//
|
||||
//
|
||||
// HistogramArea
|
||||
HistogramArea::HistogramArea (DrawModeListener *fml) :
|
||||
HistogramArea::HistogramArea (DrawModeListener *fml) :
|
||||
valid(false), drawMode(options.histogramDrawMode), myDrawModeListener(fml),
|
||||
oldwidth(-1), oldheight(-1),
|
||||
needRed(options.histogramRed), needGreen(options.histogramGreen), needBlue(options.histogramBlue),
|
||||
@@ -703,14 +703,14 @@ void HistogramArea::get_preferred_height_vfunc (int &minimum_height, int &natura
|
||||
|
||||
void HistogramArea::get_preferred_width_vfunc (int &minimum_width, int &natural_width) const
|
||||
{
|
||||
|
||||
|
||||
minimum_width = 200;
|
||||
natural_width = 400;
|
||||
}
|
||||
|
||||
void HistogramArea::get_preferred_height_for_width_vfunc (int width, int &minimum_height, int &natural_height) const
|
||||
{
|
||||
|
||||
|
||||
minimum_height = 0;
|
||||
natural_height = 0;
|
||||
}
|
||||
@@ -722,7 +722,7 @@ void HistogramArea::get_preferred_width_for_height_vfunc (int height, int &minim
|
||||
|
||||
void HistogramArea::updateOptions (bool r, bool g, bool b, bool l, bool c, bool raw, int mode)
|
||||
{
|
||||
|
||||
|
||||
options.histogramRed = needRed = r;
|
||||
options.histogramGreen = needGreen = g;
|
||||
options.histogramBlue = needBlue = b;
|
||||
@@ -761,29 +761,29 @@ void HistogramArea::update(
|
||||
|
||||
haih->pending++;
|
||||
// Can be done outside of the GUI thread
|
||||
const auto func = [](gpointer data) -> gboolean {
|
||||
HistogramAreaIdleHelper* const haih = static_cast<HistogramAreaIdleHelper*>(data);
|
||||
const auto func =
|
||||
[](HistogramAreaIdleHelper* haih) -> bool
|
||||
{
|
||||
if (haih->destroyed) {
|
||||
if (haih->pending == 1) {
|
||||
delete haih;
|
||||
} else {
|
||||
haih->pending--;
|
||||
}
|
||||
|
||||
if (haih->destroyed) {
|
||||
if (haih->pending == 1) {
|
||||
delete haih;
|
||||
} else {
|
||||
haih->pending--;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
haih->harea->setDirty (true);
|
||||
haih->harea->updateBackBuffer ();
|
||||
haih->harea->queue_draw ();
|
||||
|
||||
haih->harea->setDirty (true);
|
||||
haih->harea->updateBackBuffer ();
|
||||
haih->harea->queue_draw ();
|
||||
haih->pending--;
|
||||
|
||||
haih->pending--;
|
||||
return false;
|
||||
};
|
||||
|
||||
return FALSE;
|
||||
};
|
||||
|
||||
idle_register.add(func, haih);
|
||||
idle_register.add<HistogramAreaIdleHelper>(func, haih, false);
|
||||
}
|
||||
|
||||
void HistogramArea::updateBackBuffer ()
|
||||
@@ -889,7 +889,7 @@ void HistogramArea::updateBackBuffer ()
|
||||
|
||||
// Compute the highest point of the histogram for scaling
|
||||
// Values at far left and right end (0 and 255) are handled differently
|
||||
|
||||
|
||||
unsigned int histheight = 0;
|
||||
|
||||
for (int i = 1; i < 255; i++) {
|
||||
@@ -915,7 +915,7 @@ void HistogramArea::updateBackBuffer ()
|
||||
}
|
||||
|
||||
int realhistheight = histheight;
|
||||
|
||||
|
||||
if (realhistheight < winh - 2) {
|
||||
realhistheight = winh - 2;
|
||||
}
|
||||
@@ -960,7 +960,7 @@ void HistogramArea::updateBackBuffer ()
|
||||
cr->stroke ();
|
||||
drawMarks(cr, bhchanged, realhistheight, w, ui, oi);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Draw the frame's border
|
||||
@@ -1044,16 +1044,16 @@ bool HistogramArea::on_button_press_event (GdkEventButton* event)
|
||||
{
|
||||
isPressed = true;
|
||||
movingPosition = event->x;
|
||||
|
||||
|
||||
if (event->type == GDK_2BUTTON_PRESS && event->button == 1) {
|
||||
|
||||
|
||||
drawMode = (drawMode + 1) % 3;
|
||||
options.histogramDrawMode = (options.histogramDrawMode + 1) % 3;
|
||||
|
||||
|
||||
if (myDrawModeListener) {
|
||||
myDrawModeListener->toggleButtonMode ();
|
||||
}
|
||||
|
||||
|
||||
updateBackBuffer ();
|
||||
queue_draw ();
|
||||
}
|
||||
@@ -1072,19 +1072,19 @@ bool HistogramArea::on_motion_notify_event (GdkEventMotion* event)
|
||||
if (isPressed)
|
||||
{
|
||||
double mod = 1 + (event->x - movingPosition) / get_width();
|
||||
|
||||
|
||||
factor /= mod;
|
||||
if (factor < 1.0)
|
||||
factor = 1.0;
|
||||
if (factor > 100.0)
|
||||
factor = 100.0;
|
||||
|
||||
|
||||
sigFactorChanged.emit(factor);
|
||||
|
||||
|
||||
setDirty(true);
|
||||
queue_draw ();
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user