Example #1
0
gboolean prompt_mouse_event(ObPrompt *self, XEvent *e)
{
    gint i;
    ObPromptElement *but;

    if (e->type != ButtonPress && e->type != ButtonRelease &&
        e->type != MotionNotify) return FALSE;

    /* find the button */
    but = NULL;
    for (i = 0; i < self->n_buttons; ++i)
        if (self->button[i].window ==
            (e->type == MotionNotify ? e->xmotion.window : e->xbutton.window))
        {
            but = &self->button[i];
            break;
        }
    if (!but) return FALSE;

    if (e->type == ButtonPress) {
        ObPromptElement *oldfocus;

        oldfocus = self->focus;

        but->pressed = but->hover = TRUE;
        self->focus = but;

        if (oldfocus != but) render_button(self, oldfocus);
        render_button(self, but);
    }
    else if (e->type == ButtonRelease) {
        if (but->hover)
            prompt_run_callback(self, but->result);
        but->pressed = FALSE;
    }
    else if (e->type == MotionNotify) {
        if (but->pressed) {
            gboolean hover;

            hover = (e->xmotion.x >= 0 && e->xmotion.y >= 0 &&
                     e->xmotion.x < but->width && e->xmotion.y < but->height);

            if (hover != but->hover) {
                but->hover = hover;
                render_button(self, but);
            }
        }
    }
    return TRUE;
}
Example #2
0
File: tag.c Project: decasm/sxiv
void tag_render_palette(tag_t * tag) {
	palette_t * pal;
	win_t * win;
	int button_x = 10, button_y = 0;
	int button_w = 0, button_h = button_height;
	
	win = tag->win;
	imlib_context_set_drawable(win->pm);
	pal = tag->palette;

	button_y = tag_bar_y;

	while ( pal ) {
		if ( tag->current_palette != -1 && tag->current_palette == pal->index) {
			tag_render_palette_mapping(tag);
			set_label_highlight();
		}
		else {
			set_label_normal();
		}
		render_button(pal->index + 0x30, pal->label, button_x, button_y, &button_w, &button_h, true);
		button_x += button_w;

		pal = pal->next;
	}
}
Example #3
0
File: tag.c Project: decasm/sxiv
void tag_render_palette_mapping(tag_t *tag) {
	win_t * win;
	palette_t * pal;
	keytagmap_t * ktm;
	int button_x = tag_bar_left_offset, button_y = 0;
	int button_w = 0, button_h = button_height;

	win = tag->win;
	imlib_context_set_drawable(win->pm);

	pal = tag->palette;
	while ( pal->index != tag->current_palette) {
		pal = pal->next;
		if (pal == NULL ) return;
	}
	ktm = pal->tags;

	set_label_normal();
	button_y = tag_bar_y + button_height + 1;
	while ( ktm ) {
		render_button(ktm->key, ktm->tag, button_x, button_y, &button_w, &button_h, false);
		button_x += button_w;
		ktm = ktm->next;
	}
}
void render_controls( game* _pGame )
{
    // draw background first
    draw_image( ((controls_state*)_pGame->p_current_state)->p_background_img, GC_bg_img_x, GC_bg_img_y );

    // draw back button
    render_button( ((controls_state*)_pGame->p_current_state)->p_back );
}
Example #5
0
gboolean prompt_key_event(ObPrompt *self, XEvent *e)
{
    gboolean shift;
    guint shift_mask, mods;
    KeySym sym;

    if (e->type != KeyPress) return FALSE;

    shift_mask = obt_keyboard_modkey_to_modmask(OBT_KEYBOARD_MODKEY_SHIFT);
    mods = obt_keyboard_only_modmasks(e->xkey.state);
    shift = !!(mods & shift_mask);

    /* only accept shift */
    if (mods != 0 && mods != shift_mask)
        return FALSE;

    sym = obt_keyboard_keypress_to_keysym(e);

    if (sym == XK_Escape)
        prompt_cancel(self);
    else if (sym == XK_Return || sym == XK_KP_Enter || sym == XK_space)
        prompt_run_callback(self, self->focus->result);
    else if (sym == XK_Tab || sym == XK_Left || sym == XK_Right) {
        gint i;
        gboolean left;
        ObPromptElement *oldfocus;

        left = (sym == XK_Left) || ((sym == XK_Tab) && shift);
        oldfocus = self->focus;

        for (i = 0; i < self->n_buttons; ++i)
            if (self->focus == &self->button[i]) break;
        i += (left ? -1 : 1);
        if (i < 0) i = self->n_buttons - 1;
        else if (i >= self->n_buttons) i = 0;
        self->focus = &self->button[i];

        if (oldfocus != self->focus) render_button(self, oldfocus);
        render_button(self, self->focus);
    }
    return TRUE;
}
Example #6
0
static void render_all(ObPrompt *self)
{
    gint i;

    RrPaint(prompt_a_bg, self->super.window, self->width, self->height);

    prompt_a_msg->surface.parent = prompt_a_bg;
    prompt_a_msg->surface.parentx = self->msg.x;
    prompt_a_msg->surface.parenty = self->msg.y;

    prompt_a_msg->texture[0].data.text.string = self->msg.text;
    prompt_a_msg->texture[0].data.text.maxwidth = self->msg_wbound;
    RrPaint(prompt_a_msg, self->msg.window, self->msg.width, self->msg.height);

    for (i = 0; i < self->n_buttons; ++i)
        render_button(self, &self->button[i]);
}
Example #7
0
static uint32_t render_to_cairo(cairo_t *cairo, struct swaynag *swaynag) {
	uint32_t max_height = 0;

	cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
	cairo_set_source_u32(cairo, swaynag->type->background);
	cairo_paint(cairo);

	uint32_t h = render_message(cairo, swaynag);
	max_height = h > max_height ? h : max_height;

	int x = swaynag->width - swaynag->type->button_margin_right;
	x *= swaynag->scale;
	for (int i = 0; i < swaynag->buttons->length; i++) {
		h = render_button(cairo, swaynag, i, &x);
		max_height = h > max_height ? h : max_height;
		x -= swaynag->type->button_gap * swaynag->scale;
		if (i == 0) {
			x -= swaynag->type->button_gap_close * swaynag->scale;
		}
	}

	if (swaynag->details.visible) {
		h = render_detailed(cairo, swaynag, max_height);
		max_height = h > max_height ? h : max_height;
	}

	int border = swaynag->type->bar_border_thickness * swaynag->scale;
	if (max_height > swaynag->height) {
		max_height += border;
	}
	cairo_set_source_u32(cairo, swaynag->type->border_bottom);
	cairo_rectangle(cairo, 0,
			swaynag->height * swaynag->scale - border,
			swaynag->width * swaynag->scale,
			border);
	cairo_fill(cairo);

	return max_height;
}