Skip to content

Commit

Permalink
Remove pointers from external APIs until a final decision in made on …
Browse files Browse the repository at this point in the history
…API types (#750)
  • Loading branch information
xelatihy authored Jan 20, 2020
1 parent 9d7ebcd commit 594aebf
Show file tree
Hide file tree
Showing 17 changed files with 1,796 additions and 1,752 deletions.
37 changes: 18 additions & 19 deletions apps/yimgview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ struct app_state {
bool colorgrade = false;

// viewing properties
unique_ptr<opengl_image> glimage = {};
draw_glimage_params glparams = {};
bool glupdated = true;
opengl_image glimage = {};
draw_glimage_params glparams = {};
bool glupdated = true;

// error
string error = "";
Expand Down Expand Up @@ -173,7 +173,7 @@ void load_image_async(shared_ptr<app_states> apps, const string& filename) {
}));
}

void draw_glwidgets(const opengl_window* win, shared_ptr<app_states> apps,
void draw_glwidgets(const opengl_window& win, shared_ptr<app_states> apps,
const opengl_input& input) {
static string load_path = "", save_path = "", error_message = "";
auto image_ok = !apps->states.empty() && apps->selected >= 0;
Expand Down Expand Up @@ -288,26 +288,24 @@ void draw_glwidgets(const opengl_window* win, shared_ptr<app_states> apps,
}
}

void draw(const opengl_window* win, shared_ptr<app_states> apps,
void draw(const opengl_window& win, shared_ptr<app_states> apps,
const opengl_input& input) {
if (!apps->states.empty() && apps->selected >= 0) {
auto app = apps->states[apps->selected];
app->glparams.window = input.window_size;
app->glparams.framebuffer = input.framebuffer_viewport;
if (!app->glimage) {
app->glimage = unique_ptr<opengl_image>{make_glimage()};
set_glimage(app->glimage.get(), app->display, false, false);
} else if (app->glupdated) {
set_glimage(app->glimage.get(), app->display, false, false);
if (!is_initialized(app->glimage)) init_glimage(app->glimage);
if (app->glupdated) {
set_glimage(app->glimage, app->display, false, false);
app->glupdated = false;
}
update_imview(app->glparams.center, app->glparams.scale,
app->display.size(), app->glparams.window, app->glparams.fit);
draw_glimage(app->glimage.get(), app->glparams);
draw_glimage(app->glimage, app->glparams);
}
}

void update(const opengl_window* win, shared_ptr<app_states> apps) {
void update(const opengl_window& win, shared_ptr<app_states> apps) {
auto is_ready = [](const future<load_state>& result) -> bool {
return result.valid() &&
result.wait_for(chrono::microseconds(0)) == future_status::ready;
Expand Down Expand Up @@ -342,23 +340,24 @@ int main(int argc, const char* argv[]) {
for (auto filename : filenames) load_image_async(apps, filename);

// window
auto win = make_glwindow({1280 + 320, 720}, "yimview", true);
auto win = opengl_window{};
init_glwindow(win, {1280 + 320, 720}, "yimview", true);

// callbacks
set_update_glcallback(
win, [apps](const opengl_window* win, const opengl_input& input) {
win, [apps](const opengl_window& win, const opengl_input& input) {
update(win, apps);
});
set_draw_glcallback(
win, [apps](const opengl_window* win, const opengl_input& input) {
win, [apps](const opengl_window& win, const opengl_input& input) {
draw(win, apps, input);
});
set_widgets_glcallback(
win, [apps](const opengl_window* win, const opengl_input& input) {
win, [apps](const opengl_window& win, const opengl_input& input) {
draw_glwidgets(win, apps, input);
});
set_uiupdate_glcallback(
win, [apps](const opengl_window* win, const opengl_input& input) {
win, [apps](const opengl_window& win, const opengl_input& input) {
// handle mouse
if (input.mouse_left && !input.widgets_active) {
auto app = apps->states[apps->selected];
Expand All @@ -371,7 +370,7 @@ int main(int argc, const char* argv[]) {
}
});
set_drop_glcallback(
win, [apps](const opengl_window* win, const vector<string>& paths,
win, [apps](const opengl_window& win, const vector<string>& paths,
const opengl_input& input) {
for (auto path : paths) load_image_async(apps, path);
});
Expand All @@ -380,7 +379,7 @@ int main(int argc, const char* argv[]) {
run_ui(win);

// cleanup
delete_glwindow(win);
clear_glwindow(win);

// done
return 0;
Expand Down
21 changes: 11 additions & 10 deletions apps/yimgviews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ struct app_state {
bool colorgrade = false;

// viewing properties
unique_ptr<opengl_image> glimage = {};
draw_glimage_params glparams = {};
opengl_image glimage = {};
draw_glimage_params glparams = {};
};

// Simple parallel for used since our target platforms do not yet support
Expand Down Expand Up @@ -103,23 +103,24 @@ int main(int argc, const char* argv[]) {
update_display(app);

// create window
auto win = make_glwindow({1280, 720}, "yimgviews", false);
auto win = opengl_window{};
init_glwindow(win, {1280, 720}, "yimgviews", false);

// set callbacks
set_draw_glcallback(
win, [app](const opengl_window* win, const opengl_input& input) {
win, [app](const opengl_window& win, const opengl_input& input) {
app->glparams.window = input.window_size;
app->glparams.framebuffer = input.framebuffer_viewport;
if (!app->glimage) {
app->glimage = unique_ptr<opengl_image>{make_glimage()};
set_glimage(app->glimage.get(), app->display, false, false);
if (!is_initialized(app->glimage)) {
init_glimage(app->glimage);
set_glimage(app->glimage, app->display, false, false);
}
update_imview(app->glparams.center, app->glparams.scale,
app->display.size(), app->glparams.window, app->glparams.fit);
draw_glimage(app->glimage.get(), app->glparams);
draw_glimage(app->glimage, app->glparams);
});
set_uiupdate_glcallback(
win, [app](const opengl_window* win, const opengl_input& input) {
win, [app](const opengl_window& win, const opengl_input& input) {
// handle mouse
if (input.mouse_left) {
app->glparams.center += input.mouse_pos - input.mouse_last;
Expand All @@ -134,7 +135,7 @@ int main(int argc, const char* argv[]) {
run_ui(win);

// cleanup
delete_glwindow(win);
clear_glwindow(win);

// done
return 0;
Expand Down
8 changes: 4 additions & 4 deletions apps/yimshproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void my_keycallback(
if (key == esc) {
printf("Esc pressed!\n");
init_camera(app);
set_camera(app->scene.get(), 0, app->camera.frame, app->camera.lens,
set_camera(app->scene, 0, app->camera.frame, app->camera.lens,
app->camera.aspect, app->camera.film, 0.001, 10000);
}

Expand All @@ -58,7 +58,7 @@ void my_click_callback(my_data& data, shared_ptr<app_state> app, int face,
}

void my_draw_glwidgets(
my_data& data, shared_ptr<app_state> app, const opengl_window* win) {
my_data& data, shared_ptr<app_state> app, const opengl_window& win) {
if (draw_glbutton(win, "Geodesic gradient field")) {
if (data.vertex_selection.size() > 1) {
data.scalar_field = compute_geodesic_distances(
Expand All @@ -82,7 +82,7 @@ void my_draw_glwidgets(
colors[i] = vec4f(data.scalar_field[i]);
colors[i].w = 1;
}
set_shape_colors(app->scene.get(), app->glshape_id, colors);
set_shape_colors(app->scene, app->glshape_id, colors);
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ int main(int num_args, const char* args[]) {
my_click_callback(data, a, f, uv, v, d);
};
auto draw_glwidgets = [&data](shared_ptr<app_state> app,
const opengl_window* win) {
const opengl_window& win) {
my_draw_glwidgets(data, app, win);
};

Expand Down
Loading

0 comments on commit 594aebf

Please sign in to comment.