Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move SelectionRectangle to anonymous namespace #1659

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/command-line-handling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "filedata.h"
#include "filefilter.h"
#include "glua.h"
#include "image.h"
#include "img-view.h"
#include "intl.h"
#include "layout-image.h"
Expand Down
57 changes: 44 additions & 13 deletions src/image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,40 @@
struct ExifData;
struct FileCacheData;

static GList *image_list = nullptr;

static void image_read_ahead_start(ImageWindow *imd);
static void image_cache_set(ImageWindow *imd, FileData *fd);
namespace
{

// For draw rectangle function
static gint image_start_x;
static gint image_start_y;
static gint rect_x1, rect_x2, rect_y1, rect_y2;
static gint rect_id = 0;
static SelectionRectangle selection_rectangle;
constexpr gdouble aspect_ratios[5] {0.0, gdouble(1.0), gdouble(4.0) / 3, gdouble(3) / 2, gdouble(16) / 9};

/*
* SelectionRectangle
*/

void SelectionRectangle::setCursor(gint x, gint y) {
struct SelectionRectangle
{
gint origin_x;
gint origin_y;
gint cursor_x;
gint cursor_y;
gint height = 0;
gint width = 0;
gint x = 0;
gint y = 0;
gdouble aspect_ratio = 0.0;

SelectionRectangle(gint origin_x = 0, gint origin_y = 0, int rectangle_draw_aspect_ratio = RECTANGLE_DRAW_ASPECT_RATIO_NONE);
void set_cursor(gint x, gint y);
};

SelectionRectangle::SelectionRectangle(gint origin_x, gint origin_y, int rectangle_draw_aspect_ratio)
: origin_x(origin_x)
, origin_y(origin_y)
{
this->aspect_ratio = aspect_ratios[rectangle_draw_aspect_ratio];
}

void SelectionRectangle::set_cursor(gint x, gint y)
{
this->cursor_x = x;
this->cursor_y = y;
this->x = std::min(origin_x, cursor_x);
Expand All @@ -87,7 +104,21 @@ void SelectionRectangle::setCursor(gint x, gint y) {
if (cursor_y < origin_y)
this->y = origin_y - height;
}
}
}

// For draw rectangle function
gint image_start_x;
gint image_start_y;
gint rect_x1, rect_x2, rect_y1, rect_y2;
gint rect_id = 0;
SelectionRectangle selection_rectangle;

} // namespace

static GList *image_list = nullptr;

static void image_read_ahead_start(ImageWindow *imd);
static void image_cache_set(ImageWindow *imd, FileData *fd);

/*
*-------------------------------------------------------------------
Expand Down Expand Up @@ -232,7 +263,7 @@ static void image_drag_cb(PixbufRenderer *pr, GdkEventMotion *event, gpointer da
gint image_x_pixel;
gint image_y_pixel;

selection_rectangle.setCursor(event->x, event->y);
selection_rectangle.set_cursor(event->x, event->y);

if (options->draw_rectangle)
{
Expand Down
28 changes: 0 additions & 28 deletions src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ struct CollectionData;
class FileData;
struct ImageLoader;

enum RectangleDrawAspectRatio {
RECTANGLE_DRAW_ASPECT_RATIO_NONE = 0,
RECTANGLE_DRAW_ASPECT_RATIO_ONE_ONE,
RECTANGLE_DRAW_ASPECT_RATIO_FOUR_THREE,
RECTANGLE_DRAW_ASPECT_RATIO_THREE_TWO,
RECTANGLE_DRAW_ASPECT_RATIO_SIXTEEN_NINE
};

const gdouble AspectRatios[5] {0.0, gdouble(1.0), gdouble(4.0) / 3, gdouble(3) / 2, gdouble(16) / 9};

enum ImageState {
IMAGE_STATE_NONE = 0,
IMAGE_STATE_IMAGE = 1 << 0,
Expand All @@ -56,24 +46,6 @@ enum ImageState {
IMAGE_STATE_DELAY_FLIP = 1 << 6
};

struct SelectionRectangle {
gint origin_x;
gint origin_y;
gint cursor_x;
gint cursor_y;
gint height = 0;
gint width = 0;
gint x = 0;
gint y = 0;
gdouble aspect_ratio = 0.0;

SelectionRectangle(gint origin_x = 0, gint origin_y = 0, int rectangle_draw_aspect_ratio = RECTANGLE_DRAW_ASPECT_RATIO_NONE) : origin_x(origin_x), origin_y(origin_y)
{
this->aspect_ratio = AspectRatios[rectangle_draw_aspect_ratio];
}
void setCursor(gint x, gint y);
};

struct ImageWindow
{
GtkWidget *widget; /**< use this to add it and show it */
Expand Down
1 change: 1 addition & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
#include "glua.h"
#include "histogram.h"
#include "history-list.h"
#include "image.h"
#include "img-view.h"
#include "intl.h"
#include "layout-image.h"
Expand Down
9 changes: 8 additions & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <gdk/gdk.h>
#include <glib.h>

#include "image.h"
#include "typedefs.h"

enum TextPosition : gint;
Expand All @@ -44,6 +43,14 @@ enum DnDAction {
DND_ACTION_MOVE
};

enum RectangleDrawAspectRatio {
RECTANGLE_DRAW_ASPECT_RATIO_NONE = 0,
RECTANGLE_DRAW_ASPECT_RATIO_ONE_ONE,
RECTANGLE_DRAW_ASPECT_RATIO_FOUR_THREE,
RECTANGLE_DRAW_ASPECT_RATIO_THREE_TWO,
RECTANGLE_DRAW_ASPECT_RATIO_SIXTEEN_NINE
};

enum ZoomStyle {
ZOOM_GEOMETRIC = 0,
ZOOM_ARITHMETIC = 1
Expand Down