Skip to content

Commit

Permalink
tying to add a red rectangle
Browse files Browse the repository at this point in the history
  • Loading branch information
atosh502 committed Mar 12, 2017
1 parent 85a0ee2 commit 7183bef
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
44 changes: 27 additions & 17 deletions src/manager/mainWindow.hh
Expand Up @@ -45,13 +45,17 @@ public:
MainWindow();
virtual ~MainWindow();
void load_scrolled_window();
void load_single_image(Glib::ustring image);
void load_single_image(Glib::ustring image, Glib::ustring format, std::vector<FaceDetail> faces);

Gtk::ApplicationWindow *appWindow = nullptr;

// signal handlers
void on_my_custom_item_activated(const Glib::ustring& item_name);
bool on_eventbox_button_press(GdkEventButton* button, Glib::ustring file/*Glib::RefPtr<Gdk::Pixbuf>& pimage*/);
bool on_eventbox_button_press( GdkEventButton* button,
Glib::ustring file,
Glib::ustring formatted_string,
std::vector<FaceDetail> faces);

void on_back_button_clicked();
void on_rotate_button_clicked();
};
Expand Down Expand Up @@ -125,10 +129,6 @@ void MainWindow::load_scrolled_window()
ServerProxy sp;
auto listOfFiles = sp.getPhotos();

Glib::ustring file_name;
std::vector<Glib::ustring> tags;
std::vector<FaceDetail> faces;

grid.set_column_spacing(10);
grid.set_row_spacing(10);

Expand All @@ -149,6 +149,10 @@ void MainWindow::load_scrolled_window()
{
Glib::RefPtr<Gdk::Pixbuf> ptr_image;
Glib::ustring formatted;
Glib::ustring file_name;
std::vector<Glib::ustring> tags;
std::vector<FaceDetail> faces;

try
{

Expand Down Expand Up @@ -219,7 +223,7 @@ void MainWindow::load_scrolled_window()

// make formatted string here;

formatted = "File: (" + file_name + ")";
formatted = "File: " + file_name + " ";

formatted += "Tags: ";
for (auto tag : tags)
Expand Down Expand Up @@ -250,9 +254,10 @@ void MainWindow::load_scrolled_window()

eventBox->set_events(Gdk::BUTTON_PRESS_MASK);
eventBox->signal_button_press_event().connect(
sigc::bind<Glib::ustring>(
sigc::bind<Glib::ustring, Glib::ustring>(
sigc::mem_fun(*this,
&MainWindow::on_eventbox_button_press), formatted));
&MainWindow::on_eventbox_button_press),
file_name, formatted, faces));

eventBox->set_margin_top(10);
eventBox->set_margin_bottom(10);
Expand All @@ -272,16 +277,21 @@ void MainWindow::load_scrolled_window()
appWindow->show_all();
}

void MainWindow::load_single_image(Glib::ustring image)
void MainWindow::load_single_image(Glib::ustring image, Glib::ustring format, std::vector<FaceDetail> faces)
{
std::size_t front = image.find('(');
std::size_t back = image.find(')');
std::cout << image.substr(front + 1, back - front - 1) << std::endl;
this->area.set_image(image.substr(front + 1, back - front - 1));
//std::size_t front = image.find('(');
//std::size_t back = image.find(')');
//std::cout << image.substr(front + 1, back - front - 1) << std::endl;
//this->area.set_image(image.substr(front + 1, back - front - 1));
//std::vector<int> points;
//this->area.set_coords();

this->area.set_image(image);
this->area.set_coords(faces);
box->pack_start(area);
box->pack_start(statusBar);
statusBar.remove_all_messages();
statusBar.push(image);
statusBar.push(format);
appWindow->show_all();
}

Expand Down Expand Up @@ -341,7 +351,7 @@ void MainWindow::on_my_custom_item_activated(const Glib::ustring& item_name)
}
}

bool MainWindow::on_eventbox_button_press(GdkEventButton* button, Glib::ustring image)
bool MainWindow::on_eventbox_button_press(GdkEventButton* button, Glib::ustring image, Glib::ustring format, std::vector<FaceDetail> faces)
{
if (button->type == GDK_DOUBLE_BUTTON_PRESS)
{
Expand All @@ -357,7 +367,7 @@ bool MainWindow::on_eventbox_button_press(GdkEventButton* button, Glib::ustring
box->remove(*child);

std::cout << "removed scrolled window " << std::endl;
this->load_single_image(image);
this->load_single_image(image, format, faces);
return true;
}
else if (button->type == GDK_BUTTON_PRESS)
Expand Down
29 changes: 27 additions & 2 deletions src/manager/myarea.hh
Expand Up @@ -5,6 +5,7 @@
#include <iostream>
#include <glibmm.h>
#include <giomm.h>
#include "../daemon/ImageDetails.hh"

class MyArea : public Gtk::DrawingArea{
public:
Expand All @@ -13,9 +14,11 @@ class MyArea : public Gtk::DrawingArea{
virtual ~MyArea();

Glib::RefPtr<Gdk::Pixbuf> pimage;
void set_coords(std::vector<FaceDetail>& coords);

protected:
double scale;
std::vector<FaceDetail> face_coords;

//override default signal handler
bool on_draw(const Cairo::RefPtr<Cairo::Context>& cr) override;
Expand All @@ -31,6 +34,11 @@ void MyArea::set_image(Glib::ustring image){
set_size_request(pimage->get_width()/2, pimage->get_height()/2);
}

void MyArea::set_coords(std::vector<FaceDetail>& coords)
{
face_coords = coords;
}

MyArea::MyArea()
{
std::cout << "In default constructor of MyArea " << std::endl;
Expand All @@ -57,8 +65,25 @@ bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr){
cr->scale(scale, scale);
Gdk::Cairo::set_source_pixbuf(cr, pimage, (width/2)/scale - pimage->get_width()/2, (height/2)/scale - pimage->get_height()/2);
cr->rectangle(0, 0, get_allocation().get_width() / scale, get_allocation().get_width()/scale);

cr->paint();

cr->fill();
cr->restore();

cr->save();
cr->set_source_rgb(0.8, 0.0, 0.0); //red
for (auto face : face_coords)
{
cr->move_to(face.bounds.x / 2 / scale, face.bounds.y / 2 / scale);
cr->line_to(face.bounds.x / 2 / scale + face.bounds.width / 2 / scale, face.bounds.y / 2 / scale);
cr->line_to(face.bounds.x / 2 / scale + face.bounds.width / 2 / scale, face.bounds.y / 2 / scale + face.bounds.height / 2 / scale);
cr->line_to(face.bounds.x / 2 / scale, face.bounds.y / 2 / scale + face.bounds.height / 2 / scale);
cr->line_to(face.bounds.x / 2 / scale, face.bounds.y / 2 / scale);
cr->stroke();
cr->save();
}

cr->restore();
//cr->paint();
return true;
}

Expand Down

0 comments on commit 7183bef

Please sign in to comment.