Esempio n. 1
0
bool
sc_rotate(girara_session_t* session, girara_argument_t* argument,
          girara_event_t* UNUSED(event), unsigned int t)
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  g_return_val_if_fail(zathura->document != NULL, false);

  const unsigned int page_number = zathura_document_get_current_page_number(zathura->document);

  int angle = 90;
  if (argument != NULL && argument->n == ROTATE_CCW) {
    angle = 270;
  }

  /* update rotate value */
  t = (t == 0) ? 1 : t;
  unsigned int rotation = zathura_document_get_rotation(zathura->document);
  zathura_document_set_rotation(zathura->document, (rotation + angle * t) % 360);

  /* update scale */
  girara_argument_t new_argument = { zathura_document_get_adjust_mode(zathura->document), NULL };
  sc_adjust_window(zathura->ui.session, &new_argument, NULL, 0);

  /* render all pages again */
  render_all(zathura);

  page_set(zathura, page_number);

  return false;
}
Esempio n. 2
0
static void
cb_color_change(girara_session_t* session, const char* name,
                girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{
  g_return_if_fail(value != NULL);
  g_return_if_fail(session != NULL);
  g_return_if_fail(session->global.data != NULL);
  g_return_if_fail(name != NULL);
  zathura_t* zathura = session->global.data;

  const char* string_value = (const char*) value;
  if (g_strcmp0(name, "highlight-color") == 0) {
    gdk_rgba_parse(&(zathura->ui.colors.highlight_color), string_value);
  } else if (g_strcmp0(name, "highlight-active-color") == 0) {
    gdk_rgba_parse(&(zathura->ui.colors.highlight_color_active), string_value);
  } else if (g_strcmp0(name, "recolor-darkcolor") == 0) {
    if (zathura->sync.render_thread != NULL) {
      zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, NULL, string_value);
    }
  } else if (g_strcmp0(name, "recolor-lightcolor") == 0) {
    if (zathura->sync.render_thread != NULL) {
      zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, string_value, NULL);
    }
  } else if (g_strcmp0(name, "render-loading-bg") == 0) {
    gdk_rgba_parse(&(zathura->ui.colors.render_loading_bg), string_value);
  } else if (g_strcmp0(name, "render-loading-fg") == 0) {
    gdk_rgba_parse(&(zathura->ui.colors.render_loading_fg), string_value);
  }

  render_all(zathura);
}
Esempio n. 3
0
bool
sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t*
        event, unsigned int t)
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  g_return_val_if_fail(argument != NULL, false);
  g_return_val_if_fail(zathura->document != NULL, false);

  zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_NONE);

  /* retrieve zoom step value */
  int value = 1;
  girara_setting_get(zathura->ui.session, "zoom-step", &value);

  const int nt = (t == 0) ? 1 : t;
  const double zoom_step = 1.0 + value / 100.0 * nt;
  const double old_zoom = zathura_document_get_scale(zathura->document);

  /* specify new zoom value */
  if (argument->n == ZOOM_IN) {
    girara_debug("Increasing zoom by %f.", zoom_step - 1.0);
    zathura_document_set_scale(zathura->document, old_zoom * zoom_step);
  } else if (argument->n == ZOOM_OUT) {
    girara_debug("Decreasing zoom by %f.", zoom_step - 1.0);
    zathura_document_set_scale(zathura->document, old_zoom / zoom_step);
  } else if (argument->n == ZOOM_SPECIFIC) {
    if (t == 0) {
      girara_debug("Setting zoom to 1.");
      zathura_document_set_scale(zathura->document, 1.0);
    } else {
      girara_debug("Setting zoom to %f.", t / 100.0);
      zathura_document_set_scale(zathura->document, t / 100.0);
    }
  } else if (argument->n == ZOOM_SMOOTH) {
    const double dy = (event != NULL) ? event->y : 1.0;
    girara_debug("Increasing zoom by %f.", zoom_step * dy - 1.0);
    zathura_document_set_scale(zathura->document, old_zoom + zoom_step * dy);
  } else {
    girara_debug("Setting zoom to 1.");
    zathura_document_set_scale(zathura->document, 1.0);
  }

  /* zoom limitations */
  const double scale = zathura_document_get_scale(zathura->document);
  zathura_document_set_scale(zathura->document, zathura_correct_scale_value(session, scale));

  const double new_zoom = zathura_document_get_scale(zathura->document);
  if (fabs(new_zoom - old_zoom) <= DBL_EPSILON) {
    girara_debug("New and old zoom level are too close: %f vs. %f, diff = %f", new_zoom, old_zoom, fabs(new_zoom - old_zoom));
    return false;
  }

  girara_debug("Re-rendering with new zoom level %f.", new_zoom);
  render_all(zathura);
  refresh_view(zathura);

  return false;
}
Esempio n. 4
0
bool
sc_toggle_page_mode(girara_session_t* session, girara_argument_t*
                    UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

  if (zathura->document == NULL) {
    girara_notify(session, GIRARA_WARNING, _("No document opened."));
    return false;
  }

  unsigned int page_id = zathura_document_get_current_page_number(zathura->document);

  int pages_per_row = 1;
  girara_setting_get(zathura->ui.session, "pages-per-row", &pages_per_row);

  int value = 1;
  if (pages_per_row == 1) {
    value = zathura->shortcut.toggle_page_mode.pages;
  } else {
    zathura->shortcut.toggle_page_mode.pages = pages_per_row;
  }

  girara_setting_set(zathura->ui.session, "pages-per-row", &value);
  adjust_view(zathura);

  page_set(zathura, page_id);
  render_all(zathura);
  refresh_view(zathura);

  return true;
}
Esempio n. 5
0
	void menu::init() {
		using lifetime = support::action::lifetime;
		namespace a = support::action::menu;
		namespace mse = support::action::mouse;

		auto assetM = engine->get<asset>().lock();
		auto act    = engine->get<action>().lock();
		auto tw     = engine->get<tweener<float>>().lock();

		assetM->request<polar::asset::audio>("menu1");

		font = assetM->get<polar::asset::font>("nasalization-rg");

		keep(act->bind<a::down   >(lifetime::on, [this] { navigate( 1);    }));
		keep(act->bind<a::up     >(lifetime::on, [this] { navigate(-1);    }));
		keep(act->bind<a::right  >(lifetime::on, [this] { navigate(0,  1); }));
		keep(act->bind<a::left   >(lifetime::on, [this] { navigate(0, -1); }));
		keep(act->bind<a::forward>(lifetime::on, [this] { activate();      }));
		keep(act->bind<a::back   >(lifetime::on, [this] {
			navigate(0, -1, true);
		}));

		keep(act->bind<mse::position_y>([this](Decimal y) {
			if(int(y) != 0) { on_cursor(int(y)); }
		}));

		keep(tw->tween(0.0f, 1.0f, 0.25, true, [this](auto, const float &x) {
			selectionAlpha = x;
		}));

		render_all();
	}
Esempio n. 6
0
void draw_loop(GLFWwindow *window) {
  while (!glfwWindowShouldClose(window)) {
    // Timing needs to be maintained if using single buffered context.
    /*timespec curr_time;
    clock_gettime(CLOCK_REALTIME, &curr_time);

    auto get_time_us = [] (const timespec &curr_time) {
      return 1000000 * curr_time.tv_sec + curr_time.tv_nsec / 1000;
    };

    long elapsed = get_time_us(curr_time) - get_time_us(last_time);
    float fps = 1000000. / elapsed;

    last_time = curr_time;*/

    shm_getg(kalman, kalman_g);
    update_transformations();
    handle_input(window);
    render_all(cam);

    glfwSwapBuffers(window);
    glfwPollEvents();

    /*clock_gettime(CLOCK_REALTIME, &curr_time);
    elapsed = get_time_us(curr_time) - get_time_us(last_time);

    float sleep_time_ms = (1000 / TARGET_FPS) - elapsed / 1000.;
    printf("%f FPS, time taken is %lu us\n", fps, elapsed);
    if (sleep_time_ms < 0) {
      sleep_time_ms = 0;
    }*/
  }
}
Esempio n. 7
0
File: naev.c Progetto: ekrumme/naev
/**
 * @brief Split main loop from main() for secondary loop hack in toolkit.c.
 */
void main_loop (void)
{
   int tk;

   /* Check to see if toolkit is open. */
   tk = toolkit_isOpen();

   /* Clear buffer. */
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   fps_control(); /* everyone loves fps control */

   sound_update( real_dt ); /* Update sounds. */
   if (tk) toolkit_update(); /* to simulate key repetition */
   if (!menu_isOpen(MENU_MAIN)) {
      if (!paused)
         update_all(); /* update game */
      render_all();
   }
   /* Toolkit is rendered on top. */
   if (tk) toolkit_render();

   gl_checkErr(); /* check error every loop */

   /* Draw buffer. */
   SDL_GL_SwapBuffers();
}
Esempio n. 8
0
void prompt_show(ObPrompt *self, ObClient *parent, gboolean modal)
{
    gint i;

    if (self->mapped) {
        /* activate the prompt */
        OBT_PROP_MSG(ob_screen, self->super.window, NET_ACTIVE_WINDOW,
                     1, /* from an application.. */
                     event_time(),
                     0,
                     0, 0);
        return;
    }

    /* set the focused button (if not found then the first button is used) */
    self->focus = &self->button[0];
    for (i = 0; i < self->n_buttons; ++i)
        if (self->button[i].result == self->default_result) {
            self->focus = &self->button[i];
            break;
        }

    if (parent) {
        Atom states[1];
        gint nstates;
        Window p;
        XWMHints h;

        if (parent->group) {
            /* make it transient for the window's group */
            h.flags = WindowGroupHint;
            h.window_group = parent->group->leader;
            p = obt_root(ob_screen);
        }
        else {
            /* make it transient for the window directly */
            h.flags = 0;
            p = parent->window;
        }

        XSetWMHints(obt_display, self->super.window, &h);
        OBT_PROP_SET32(self->super.window, WM_TRANSIENT_FOR, WINDOW, p);

        states[0] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
        nstates = (modal ? 1 : 0);
        OBT_PROP_SETA32(self->super.window, NET_WM_STATE, ATOM,
                        states, nstates);
    }
    else
        OBT_PROP_ERASE(self->super.window, WM_TRANSIENT_FOR);

    /* set up the dialog and render it */
    prompt_layout(self);
    render_all(self);

    client_manage(self->super.window, self);

    self->mapped = TRUE;
}
Esempio n. 9
0
bool
sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t*
        UNUSED(event), unsigned int t)
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  g_return_val_if_fail(argument != NULL, false);
  g_return_val_if_fail(zathura->document != NULL, false);

  zathura_document_set_adjust_mode(zathura->document, ZATHURA_ADJUST_NONE);

  /* retreive zoom step value */
  int value = 1;
  girara_setting_get(zathura->ui.session, "zoom-step", &value);

  int nt = (t == 0) ? 1 : t;
  float zoom_step = value / 100.0f * nt;
  float old_zoom = zathura_document_get_scale(zathura->document);

  /* specify new zoom value */
  if (argument->n == ZOOM_IN) {
    zathura_document_set_scale(zathura->document, old_zoom + zoom_step);
  } else if (argument->n == ZOOM_OUT) {
    zathura_document_set_scale(zathura->document, old_zoom - zoom_step);
  } else if (argument->n == ZOOM_SPECIFIC) {
    if (t == 0) {
      zathura_document_set_scale(zathura->document, 1.0f);
    } else {
      zathura_document_set_scale(zathura->document, t / 100.0f);
    }
  } else {
    zathura_document_set_scale(zathura->document, 1.0f);
  }

  /* zoom limitations */
  int zoom_min_int = 10;
  int zoom_max_int = 1000;
  girara_setting_get(session, "zoom-min", &zoom_min_int);
  girara_setting_get(session, "zoom-max", &zoom_max_int);

  float zoom_min = zoom_min_int * 0.01f;
  float zoom_max = zoom_max_int * 0.01f;

  float scale = zathura_document_get_scale(zathura->document);
  if (scale < zoom_min) {
    zathura_document_set_scale(zathura->document, zoom_min);
  } else if (scale > zoom_max) {
    zathura_document_set_scale(zathura->document, zoom_max);
  }

  /* keep position */
  readjust_view_after_zooming(zathura, old_zoom, true);

  render_all(zathura);

  return false;
}
Esempio n. 10
0
static void
cb_nohlsearch_changed(girara_session_t* session, const char* UNUSED(name),
                      girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{
  g_return_if_fail(value != NULL);
  g_return_if_fail(session != NULL);
  g_return_if_fail(session->global.data != NULL);
  zathura_t* zathura = session->global.data;

  document_draw_search_results(zathura, !(*(bool*) value));
  render_all(zathura);
}
Esempio n. 11
0
int main(int argc, char ** argv) {
	char * pwd = "."; /* TODO: Fetch the actual path */
	file_t * file = create_file(pwd, NEW_FILE);

	while(!file->term_status->quit_fl) {
		key_handle(file);
		render_all(file);
	}

	close_file(file);
	return 0;
}
Esempio n. 12
0
bool
cmd_nohlsearch(girara_session_t* session, girara_list_t* UNUSED(argument_list))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

  document_draw_search_results(zathura, false);
  render_all(zathura);

  return true;
}
Esempio n. 13
0
	void menu::navigate(int down, int right, bool force) {
		auto &item = current_at(current);

		bool playBeep = false;

		bool newForce = force;
		if(!force && right && item.control && item.control->navigate(right)) {
			item.fn(item.control->get());
			render(current, true);
			playBeep = true;
		} else {
			newForce = force;
		}

		if(newForce) {
			while(right > 0) {
				auto &i = current_at(current);
				if(!i.children.empty()) {
					stack.emplace_back(current);
					current = 0;
					--right;
					playBeep = true;
				} else {
					activate();
				}
			}
			while(right < 0) {
				if(stack.empty()) {
					if(force) {
						engine->transition = "back";
						return;
					}
				} else {
					current = (int)stack.back();
					stack.pop_back();
					++right;
					playBeep = true;
				}
			}
			render_all();
		}
		if(down != 0) {
			navigate_to(current + down);
		}

		if(playBeep) {
			beep();
		}
	}
Esempio n. 14
0
void
cb_setting_recolor_keep_hue_change(girara_session_t* session, const char* name,
    girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{
  g_return_if_fail(value != NULL);
  g_return_if_fail(session != NULL);
  g_return_if_fail(session->global.data != NULL);
  g_return_if_fail(name != NULL);
  zathura_t* zathura = session->global.data;

  bool bool_value = *((bool*) value);

  if (zathura->global.recolor_keep_hue != bool_value) {
    zathura->global.recolor_keep_hue = bool_value;
    render_all(zathura);
  }
}
Esempio n. 15
0
void
cb_setting_recolor_keep_reverse_video_change(girara_session_t* session, const char* name,
                                   girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{
  g_return_if_fail(value != NULL);
  g_return_if_fail(session != NULL);
  g_return_if_fail(session->global.data != NULL);
  g_return_if_fail(name != NULL);
  zathura_t* zathura = session->global.data;

  const bool bool_value = *((bool*) value);

  if (zathura->sync.render_thread != NULL && zathura_renderer_recolor_reverse_video_enabled(zathura->sync.render_thread) != bool_value) {
     zathura_renderer_enable_recolor_reverse_video(zathura->sync.render_thread, bool_value);
     render_all(zathura);
  }
}
Esempio n. 16
0
void prompt_startup(gboolean reconfig)
{
    /* note: this is not a copy, don't free it */
    prompt_a_bg = ob_rr_theme->osd_bg;

    prompt_a_button = RrAppearanceCopy(ob_rr_theme->osd_unpressed_button);
    prompt_a_focus = RrAppearanceCopy(ob_rr_theme->osd_focused_button);
    prompt_a_press = RrAppearanceCopy(ob_rr_theme->osd_pressed_button);    

    prompt_a_msg = RrAppearanceCopy(ob_rr_theme->osd_hilite_label);
    prompt_a_msg->texture[0].data.text.flow = TRUE;

    if (reconfig) {
        GList *it;
        for (it = prompt_list; it; it = g_list_next(it)) {
            ObPrompt *p = it->data;
            prompt_layout(p);
            render_all(p);
        }
    }
}
Esempio n. 17
0
void
mark_evaluate(zathura_t* zathura, int key)
{
  if (zathura == NULL || zathura->global.marks == NULL) {
    return;
  }

  /* search for existing mark */
  GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark)
  if (mark != NULL && mark->key == key) {
    zathura_document_set_scale(zathura->document, mark->scale);
    render_all(zathura);

    position_set_delayed(zathura, mark->position_x, mark->position_y);

    cb_view_vadjustment_value_changed(NULL, zathura);

    zathura->global.update_page_number = true;
    return;
  }
  GIRARA_LIST_FOREACH_END(zathura->global.marks, zathura_mark_t*, iter, mark);
}
Esempio n. 18
0
void
cb_scale_factor(GObject* object, GParamSpec* UNUSED(pspec), gpointer data)
{
  zathura_t* zathura = data;
  if (zathura == NULL || zathura->document == NULL) {
    return;
  }

  int new_factor = gtk_widget_get_scale_factor(GTK_WIDGET(object));
  if (new_factor == 0) {
    girara_debug("Ignoring new device scale factor = 0");
    return;
  }

  zathura_device_factors_t current = zathura_document_get_device_factors(zathura->document);
  if (fabs(new_factor - current.x) >= DBL_EPSILON ||
      fabs(new_factor - current.y) >= DBL_EPSILON) {
    zathura_document_set_device_factors(zathura->document, new_factor, new_factor);
    girara_debug("New device scale factor: %d", new_factor);
    zathura_update_view_ppi(zathura);
    render_all(zathura);
  }
}
Esempio n. 19
0
void prompt_startup(gboolean reconfig)
{
    RrColor *c_button, *c_focus, *c_press, *c_pfocus;

    /* note: this is not a copy, don't free it */
    prompt_a_bg = ob_rr_theme->osd_bg;

    prompt_a_button = RrAppearanceCopy(ob_rr_theme->a_focused_unpressed_close);
    prompt_a_focus = RrAppearanceCopy(ob_rr_theme->a_hover_focused_close);
    prompt_a_press = RrAppearanceCopy(ob_rr_theme->a_focused_pressed_close);
    prompt_a_pfocus = RrAppearanceCopy(ob_rr_theme->a_focused_pressed_close);

    c_button = prompt_a_button->texture[0].data.mask.color;
    c_focus = prompt_a_focus->texture[0].data.mask.color;
    c_press = prompt_a_press->texture[0].data.mask.color;
    c_pfocus = prompt_a_press->texture[0].data.mask.color;

    RrAppearanceRemoveTextures(prompt_a_button);
    RrAppearanceRemoveTextures(prompt_a_focus);
    RrAppearanceRemoveTextures(prompt_a_press);
    RrAppearanceRemoveTextures(prompt_a_pfocus);

    /* texture[0] is the text and texture[1-4] (for prompt_a_focus and
       prompt_a_pfocus) is lineart to show where keyboard focus is */
    RrAppearanceAddTextures(prompt_a_button, 1);
    RrAppearanceAddTextures(prompt_a_focus, 5);
    RrAppearanceAddTextures(prompt_a_press, 1);
    RrAppearanceAddTextures(prompt_a_pfocus, 5);

    /* totally cheating here.. */
    prompt_a_button->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
    prompt_a_focus->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
    prompt_a_press->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
    prompt_a_pfocus->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];

    prompt_a_button->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
    prompt_a_focus->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
    prompt_a_press->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
    prompt_a_pfocus->texture[0].data.text.justify = RR_JUSTIFY_CENTER;

    prompt_a_button->texture[0].data.text.color = c_button;
    prompt_a_focus->texture[0].data.text.color = c_focus;
    prompt_a_press->texture[0].data.text.color = c_press;
    prompt_a_pfocus->texture[0].data.text.color = c_pfocus;

    prompt_a_focus->texture[1].data.lineart.color = c_focus;
    prompt_a_focus->texture[2].data.lineart.color = c_focus;
    prompt_a_focus->texture[3].data.lineart.color = c_focus;
    prompt_a_focus->texture[4].data.lineart.color = c_focus;

    prompt_a_pfocus->texture[1].data.lineart.color = c_press;
    prompt_a_pfocus->texture[2].data.lineart.color = c_press;
    prompt_a_pfocus->texture[3].data.lineart.color = c_press;
    prompt_a_pfocus->texture[4].data.lineart.color = c_press;

    prompt_a_msg = RrAppearanceCopy(ob_rr_theme->osd_hilite_label);
    prompt_a_msg->texture[0].data.text.flow = TRUE;

    if (reconfig) {
        GList *it;
        for (it = prompt_list; it; it = g_list_next(it)) {
            ObPrompt *p = it->data;
            prompt_layout(p);
            render_all(p);
        }
    }
}
Esempio n. 20
0
bool
sc_toggle_presentation(girara_session_t* session, girara_argument_t*
                     UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

  if (zathura->document == NULL) {
    girara_notify(session, GIRARA_WARNING, _("No document opened."));
    return false;
  }

  const girara_mode_t old_mode = girara_mode_get(session);
  if (old_mode == zathura->modes.presentation) {
    /* reset pages per row */
    girara_setting_set(session, "pages-per-row", &zathura->shortcut.toggle_presentation_mode.pages);

    /* reset first page column */
    if (zathura->shortcut.toggle_presentation_mode.first_page_column_list != NULL) {
      girara_setting_set(session, "first-page-column", zathura->shortcut.toggle_presentation_mode.first_page_column_list);
    }

    /* show status bar */
    gtk_widget_show(GTK_WIDGET(session->gtk.statusbar));

    /* set full screen */
    gtk_window_unfullscreen(GTK_WINDOW(session->gtk.window));

    /* reset scale */
    zathura_document_set_scale(zathura->document, zathura->shortcut.toggle_presentation_mode.zoom);
    render_all(zathura);
    refresh_view(zathura);

    /* set mode */
    girara_mode_set(session, zathura->modes.normal);
  } else if (old_mode == zathura->modes.normal) {
    /* backup pages per row */
    girara_setting_get(session, "pages-per-row", &zathura->shortcut.toggle_presentation_mode.pages);

    /* backup first page column */
    g_free(zathura->shortcut.toggle_presentation_mode.first_page_column_list);
    zathura->shortcut.toggle_presentation_mode.first_page_column_list = NULL;
    /* this will leak. we need to move the values somewhere else */
    girara_setting_get(session, "first-page-column", &zathura->shortcut.toggle_presentation_mode.first_page_column_list);

    /* set single view */
    int int_value = 1;
    girara_setting_set(session, "pages-per-row", &int_value);

    /* back up zoom */
    zathura->shortcut.toggle_presentation_mode.zoom = zathura_document_get_scale(zathura->document);

    /* adjust window */
    girara_argument_t argument = { ZATHURA_ADJUST_BESTFIT, NULL };
    sc_adjust_window(session, &argument, NULL, 0);

    /* hide status and inputbar */
    gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar));
    gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar));

    /* set full screen */
    gtk_window_fullscreen(GTK_WINDOW(session->gtk.window));
    refresh_view(zathura);

    /* set mode */
    girara_mode_set(session, zathura->modes.presentation);
  }

  return false;
}
Esempio n. 21
0
//run 1 NES frame with FF/REW control
void play() {
    static int framecount=0;
    static int fcount = 0;
    int forward = 0;
    int backward = 0;

    do_cheat();

    global_playcount++;
    if(global_playcount > 6)
        global_playcount = 0;

    if(nifi_stat)
        __emuflags &= ~(FASTFORWARD | REWIND);		//when nifi enabled, disable the fastforward & rewind.

    forward = __emuflags & FASTFORWARD;
    backward = __emuflags & REWIND;

    if(backward) { // for rolling back... a nice function?
        swiWaitForVBlank();
        framecount++;
        if(framecount>2) {
            framecount-=3;
            if(firstsave!=lastsave) {
                lastsave--;
                if(lastsave<0)
                    lastsave=maxsaves-1;
                loadstate(freemem_start+SAVESTATESIZE*lastsave);
                EMU_Run();
            }
        }
    } else {
        if(__emuflags & SOFTRENDER) {
            if(!(forward) && (fcount >= debuginfo[6] && fcount - debuginfo[6] < 10) ) // disable VBlank to speed up emulation.
                swiWaitForVBlank();
        } else {
            if(!(forward)) {
                if(__emuflags & PALSYNC) {
                    if(__emuflags & (SOFTRENDER | PALTIMING))
                        __emuflags ^= PALSYNC;
                    if(REG_VCOUNT < 190) {
                        swiWaitForVBlank();
                    }
                }
                else {
                    if((!(__emuflags & ALLPIXEL)) || (all_pix_start != 0))
                        swiWaitForVBlank();
                }
            }
        }

        if(!(__emuflags & PALTIMING && global_playcount == 6)) {
            EMU_Run(); //run a frame
            framecount++;
            if(framecount>8) {	//save state every 9th frame
                framecount-=9;
                savestate(freemem_start+SAVESTATESIZE*lastsave);
                lastsave++;
                if(lastsave>=maxsaves)
                    lastsave=0;
                if(lastsave==firstsave) {
                    firstsave++;
                    if(firstsave>=maxsaves)
                        firstsave=0;
                }
            }
        }
        else {
            if((__emuflags & PALTIMING) && (__emuflags & ALLPIXEL) && !(__emuflags & SOFTRENDER))
                swiWaitForVBlank();
        }
    }

    if(__emuflags & SOFTRENDER) {
        __emuflags &= ~AUTOSRAM;
        __rendercount++;
        if(SOFT_FRAMESKIP <= 1 ||__rendercount == 1) {
            if(__emuflags & ALLPIXEL)
                render_sub();
            render_all();
        }
        if(!(forward) && __rendercount >= SOFT_FRAMESKIP)
            __rendercount = 0;
        if((forward) && __rendercount > 16)
            __rendercount = 0;
    } else if(__emuflags & ALLPIXEL) {
        render_sub();
    }

    fcount++;
    if(fcount > 59)
        fcount = 0;

    __emuflags &= ~(FASTFORWARD | REWIND);
}
Esempio n. 22
0
int main(int argc, char* argv[]) {
  if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    printf("Can't initialize video \n");
    return 1;
  }

  if (TTF_Init() < 0) {
    printf("Can't initialize ttf \n");
    return 1;
  }

  lil_yuv_spec spec = lil_yuv420(3840, 2160);
  const size_t frame_size = lil_yuv_size(spec);
  const int frame_count = 500;
  int frame = 250;

  //yuv_video *video = yuv_video_alloc(argv[1], frame_size, frame_count);
  //yuv_video_read_frame(video, 0);

  //printf("Page size: %ld\n", );

  file_reader *reader = file_reader_alloc(argv[1]);
  if (!reader) {
    printf("Can't reader reader\n");
    return 1;
  }

  file_reader_map(reader, 0, frame_size);

  //TTF_Font *font = TTF_OpenFont("courier-new.ttf", 15);
  //This loads courier, but any font will do.
  //TTF_Font* font = loadfont("C:/windows/fonts/cour.ttf", 10);

  SDL_SetEventFilter(event_filter, NULL);

  atexit(SDL_Quit);
  int update_flag = 1;

  SDL_Window *window = SDL_CreateWindow(
        "An SDL2 window",
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        2 * spec.width,
        spec.height,
        SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

  const Uint32 windowID = SDL_GetWindowID(window);

  SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
  SDL_RendererInfo info;
  SDL_GetRendererInfo(renderer, &info);
  printf("Renderer: %s\n", info.name);
  //SDL_RenderSetLogicalSize(renderer, width, height);
  SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, spec.width, spec.height);
  SDL_UpdateTexture(texture, NULL, file_reader_get(reader), spec.width);

  SDL_Color color = { 255, 255, 255, 255 };
  SDL_Color color2 = { 0, 0, 0, 128 };

  while (1)  {
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
     // PrintEvent(&event);

      switch (event.type)  {
        case SDL_WINDOWEVENT:  {
          if (event.window.windowID == windowID)  {
            switch (event.window.event)  {
              case SDL_WINDOWEVENT_SIZE_CHANGED:  {
                const int width = event.window.data1;
                const int height = event.window.data2;
                update_flag = 1;
                break;
              }

              case SDL_WINDOWEVENT_CLOSE:  {
                event.type = SDL_QUIT;
                SDL_PushEvent(&event);
                break;
              }
            }
          }
          break;
        }

        case SDL_KEYDOWN: {
          switch (event.key.keysym.sym) {
          case SDLK_1:
            printf("1\n");
            SDL_SetWindowSize(window, 2 * spec.width, spec.height);
            break;
          case SDLK_2:
            printf("2\n");
            SDL_SetWindowSize(window, 2 * 2 * spec.width, 2 * spec.height);
            break;
          case SDLK_LEFT:
            if (frame > 0) {
              --frame;
              update_flag = 1;
            }
            break;
          case SDLK_RIGHT:
            if (frame < frame_count - 1) {
              ++frame;
              update_flag = 1;
            }
            break;
          }
          break;
        }

        case SDL_QUIT: {
          return 0;
        }
      }

      // after switch
      if (update_flag) {
        //yuv_video_read_frame(video, frame);
        if (!file_reader_map(reader, frame_size * frame, frame_size)) {
          perror("Can't map file\n");
        }
        SDL_UpdateTexture(texture, NULL, file_reader_get(reader), spec.width);

        char buf[100];
        sprintf(buf, "352 x 288\n%d/90\npsnr=43.4", frame);
        SDL_Texture *text = render_text(renderer, buf, "courier-new.ttf", color, 25);
        SDL_Texture *text2 = render_text(renderer, buf, "courier-new.ttf", color2, 25);

        SDL_Point size = {spec.width, spec.height};
        render_all(renderer, &size, texture, texture, text, text2);


        SDL_RenderPresent(renderer);
        SDL_DestroyTexture(text);
        SDL_DestroyTexture(text2);

        --update_flag;
      }
    }

    SDL_Delay(1);
  }

  SDL_DestroyWindow(window);

  SDL_Quit();


  //yuv_video_free(video);
  file_reader_free(reader);

  return 0;
}
Esempio n. 23
0
bool
sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
                 girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;
  g_return_val_if_fail(argument != NULL, false);

  unsigned int pages_per_row = 1;
  girara_setting_get(session, "pages-per-row", &pages_per_row);

  unsigned int first_page_column = 1;
  girara_setting_get(session, "first-page-column", &first_page_column);

  int padding = 1;
  girara_setting_get(zathura->ui.session, "page-padding", &padding);

  if (zathura->ui.page_widget == NULL || zathura->document == NULL) {
    goto error_ret;
  }

  float old_zoom = zathura_document_get_scale(zathura->document);
  zathura_document_set_adjust_mode(zathura->document, argument->n);
  if (argument->n == ZATHURA_ADJUST_NONE) {
    /* there is nothing todo */
    goto error_ret;
  }

  /* get window size */
  GtkAllocation allocation;
  gtk_widget_get_allocation(session->gtk.view, &allocation);
  unsigned int width  = allocation.width;
  unsigned int height = allocation.height;

  /* scrollbar spacing */
  gint spacing;
  gtk_widget_style_get(session->gtk.view, "scrollbar_spacing", &spacing, NULL);
  width -= spacing;

  /* correct view size */
  if (gtk_widget_get_visible(GTK_WIDGET(session->gtk.inputbar)) == true) {
    gtk_widget_get_allocation(session->gtk.inputbar, &allocation);
    height += allocation.height;
  }

  double scale = 1.0;
  unsigned int cell_height = 0, cell_width = 0;
  unsigned int document_height = 0, document_width = 0;

  zathura_document_set_scale(zathura->document, scale);
  zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width);
  zathura_get_document_size(zathura, cell_height, cell_width,
                            &document_height, &document_width);

  double page_ratio   = (double)cell_height / (double)document_width;
  double window_ratio = (double)height / (double)width;

  if (argument->n == ZATHURA_ADJUST_WIDTH ||
      (argument->n == ZATHURA_ADJUST_BESTFIT && page_ratio < window_ratio)) {
    scale = (double)(width - (pages_per_row - 1) * padding) /
            (double)(pages_per_row * cell_width);
    zathura_document_set_scale(zathura->document, scale);

    bool show_scrollbars = false;
    girara_setting_get(session, "show-scrollbars", &show_scrollbars);

    if (show_scrollbars) {
      /* If the document is taller than the view, there's a vertical
       * scrollbar; we need to substract its width from the view's width. */
      zathura_get_document_size(zathura, cell_height, cell_width,
                                &document_height, &document_width);
      if (height < document_height) {
        GtkWidget* vscrollbar = gtk_scrolled_window_get_vscrollbar(
            GTK_SCROLLED_WINDOW(session->gtk.view));

        if (vscrollbar != NULL) {
          GtkRequisition requisition;
          gtk_widget_get_requisition(vscrollbar, &requisition);
          if (0 < requisition.width && (unsigned)requisition.width < width) {
            width -= requisition.width;
            scale = (double)(width - (pages_per_row - 1) * padding) /
                    (double)(pages_per_row * cell_width);
            zathura_document_set_scale(zathura->document, scale);
          }
        }
      }
    }
  }
  else if (argument->n == ZATHURA_ADJUST_BESTFIT) {
    scale = (double)height / (double)cell_height;
    zathura_document_set_scale(zathura->document, scale);
  }
  else {
    goto error_ret;
  }

  /* keep position */
  readjust_view_after_zooming(zathura, old_zoom, false);

  /* re-render all pages */
  render_all(zathura);

error_ret:

  return false;
}
Esempio n. 24
0
bool
sc_toggle_fullscreen(girara_session_t* session, girara_argument_t*
                     UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t))
{
  g_return_val_if_fail(session != NULL, false);
  g_return_val_if_fail(session->global.data != NULL, false);
  zathura_t* zathura = session->global.data;

  if (zathura->document == NULL) {
    girara_notify(session, GIRARA_WARNING, _("No document opened."));
    return false;
  }

  static bool fullscreen = false;
  static int pages_per_row = 1;
  static int first_page_column = 1;
  static double zoom = 1.0;

  if (fullscreen == true) {
    /* reset pages per row */
    girara_setting_set(session, "pages-per-row", &pages_per_row);

    /* reset first page column */
    girara_setting_set(session, "first-page-column", &first_page_column);

    /* show status bar */
    gtk_widget_show(GTK_WIDGET(session->gtk.statusbar));

    /* set full screen */
    gtk_window_unfullscreen(GTK_WINDOW(session->gtk.window));

    /* reset scale */
    zathura_document_set_scale(zathura->document, zoom);
    render_all(zathura);
    page_set_delayed(zathura, zathura_document_get_current_page_number(zathura->document));

    /* setm ode */
    girara_mode_set(session, zathura->modes.normal);
  } else {
    /* backup pages per row */
    girara_setting_get(session, "pages-per-row", &pages_per_row);

    /* backup first page column */
    girara_setting_get(session, "first-page-column", &first_page_column);

    /* set single view */
    int int_value = 1;
    girara_setting_set(session, "pages-per-row", &int_value);

    /* back up zoom */
    zoom = zathura_document_get_scale(zathura->document);

    /* adjust window */
    girara_argument_t argument = { ZATHURA_ADJUST_BESTFIT, NULL };
    sc_adjust_window(session, &argument, NULL, 0);

    /* hide status and inputbar */
    gtk_widget_hide(GTK_WIDGET(session->gtk.inputbar));
    gtk_widget_hide(GTK_WIDGET(session->gtk.statusbar));

    /* set full screen */
    gtk_window_fullscreen(GTK_WINDOW(session->gtk.window));
    page_set_delayed(zathura, zathura_document_get_current_page_number(zathura->document));

    /* setm ode */
    girara_mode_set(session, zathura->modes.fullscreen);
  }

  fullscreen = fullscreen ? false : true;

  return false;
}
Esempio n. 25
0
int main() 
{
    SDL_Init(SDL_INIT_VIDEO);

    // SDL Initialization
    SDL_Window *window = SDL_CreateWindow("Roguelike", 
                                          SDL_WINDOWPOS_UNDEFINED, 
                                          SDL_WINDOWPOS_UNDEFINED,
                                          SCREEN_WIDTH, SCREEN_HEIGHT,
                                          0);//SDL_WINDOW_FULLSCREEN_DESKTOP);
    SDL_Renderer *renderer = SDL_CreateRenderer(window, 0, SDL_RENDERER_SOFTWARE);

    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
    SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);

    SDL_Texture *screen = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,
                                            SDL_TEXTUREACCESS_STREAMING,
                                            SCREEN_WIDTH, SCREEN_HEIGHT);

    // Set up our console
    PT_Console *console = PT_ConsoleInit(SCREEN_WIDTH, SCREEN_HEIGHT,
                                         GRID_ROW_COUNT, GRID_COL_COUNT);
    PT_ConsoleSetBitmapFont(console, "./terminal16x16.png", 0, 16, 16);

    game_init();

    // Main game loop
    u32 delayTime = 1000 / FPS_LIMIT;
    u32 frameStart, frameTime = 0;
    i32 spareTime = 0;
    bool done = false;
    while (!done) {
        frameStart = SDL_GetTicks();

        // Handle all events in the queue
        SDL_Event event;
        while (SDL_PollEvent(&event) != 0) {

            if (event.type == SDL_QUIT) {
                done = true;
                break;
            }

            if (event.type == SDL_KEYDOWN) {
                SDL_Keycode key = event.key.keysym.sym;

                switch (key) {
                    case SDLK_UP:
                        object_move(player, 0, -1);
                        break;
                    case SDLK_DOWN:
                        object_move(player, 0, 1);
                        break;
                    case SDLK_LEFT:
                        object_move(player, -1, 0);
                        break;
                    case SDLK_RIGHT:
                        object_move(player, 1, 0);
                        break;
                    default:
                        break;
                }
            }

        }

        // Render the current frame
        render_all(renderer, screen, console);

        // Avoid pegging the CPU at 100% by sleeping for a bit
        frameTime = SDL_GetTicks() - frameStart;
        spareTime = delayTime - frameTime;
        if (spareTime > 0) {
            SDL_Delay(spareTime);
        }
    }

    // Clean up
    SDL_DestroyRenderer(renderer);
    SDL_DestroyWindow(window);

    SDL_Quit();
    return 0;
}