fbwhiptail_menu.h 4.22 KB
Newer Older
Youness Alaoui's avatar
Youness Alaoui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * fbwhiptail_menu.h : Menu utility functions
 *
 * Copyright (C) Youness Alaoui (KaKaRoTo)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 */

#ifndef __FBWHIPTAIL_MENU_H__
#define __FBWHIPTAIL_MENU_H__

#include <cairo/cairo.h>
#include "cairo_menu.h"
#include "cairo_utils.h"

typedef struct Menu_s Menu;

30 31 32 33 34 35 36
typedef struct {
  int nlines;
  char **lines;
  int start_line;
  cairo_surface_t *surface;
} MenuText;

Youness Alaoui's avatar
Youness Alaoui committed
37 38 39 40 41 42
struct Menu_s {
  cairo_surface_t *background;
  CairoMenu *menu;
  int width;
  int height;
  const char *title;
43
  MenuText text;
Youness Alaoui's avatar
Youness Alaoui committed
44 45 46 47 48
  cairo_surface_t *frame;
  void (*callback) (Menu *menu, int accepted);
  void (*draw) (Menu *menu, cairo_t *cr);
};

49 50 51 52 53
typedef struct {
  char *tag;
  char *item;
} whiptail_menu_item;

54 55 56 57
typedef enum {
  MODE_NONE = 0,
  MODE_MENU,
  MODE_YESNO,
Youness Alaoui's avatar
Youness Alaoui committed
58
  MODE_MSGBOX,
59 60
} whiptail_mode;

61 62 63 64 65 66
typedef struct {
  // Whiptail arguments
  char *title;
  char *backtitle;
  char *text;
  char *default_item;
67 68
  char *yes_button;
  char *no_button;
Youness Alaoui's avatar
Youness Alaoui committed
69 70
  char *ok_button;
  char *cancel_button;
71
  int clear;
72 73 74 75 76 77 78
  int noitem;
  int notags;
  int topleft;
  int output_fd;
  int width;
  int height;
  int menu_height;
79
  whiptail_mode mode;
80 81
  whiptail_menu_item *items;
  int num_items;
82 83 84
  // FBwhiptail arguments
  char *background_png;
  float background_grad_rgb[6];
85 86 87
} whiptail_args;


Youness Alaoui's avatar
Youness Alaoui committed
88
#define STANDARD_MENU_ITEM_WIDTH (800)
Youness Alaoui's avatar
Youness Alaoui committed
89 90 91
#define STANDARD_MENU_ITEM_HEIGHT 60
#define STANDARD_MENU_PAD_X 10
#define STANDARD_MENU_PAD_Y 3
92 93
#define STANDARD_MENU_BOX_X 5
#define STANDARD_MENU_BOX_Y 5
Youness Alaoui's avatar
Youness Alaoui committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#define STANDARD_MENU_ITEM_BOX_WIDTH (STANDARD_MENU_ITEM_WIDTH + \
      (2 * STANDARD_MENU_BOX_X))
#define STANDARD_MENU_ITEM_BOX_HEIGHT (STANDARD_MENU_ITEM_HEIGHT + \
      (2 * STANDARD_MENU_BOX_Y))
#define STANDARD_MENU_ITEM_TOTAL_WIDTH (STANDARD_MENU_ITEM_BOX_WIDTH + \
      (2 * STANDARD_MENU_PAD_X))
#define STANDARD_MENU_ITEM_TOTAL_HEIGHT (STANDARD_MENU_ITEM_BOX_HEIGHT + \
      (2 * STANDARD_MENU_PAD_Y))
#define STANDARD_MENU_ITEM_IPAD_X (STANDARD_MENU_BOX_X + CAIRO_MENU_DEFAULT_IPAD_X)
#define STANDARD_MENU_ITEM_IPAD_Y (STANDARD_MENU_BOX_Y + CAIRO_MENU_DEFAULT_IPAD_Y)
#define STANDARD_MENU_FRAME_SIDE 25
#define STANDARD_MENU_FRAME_TOP 60
#define STANDARD_MENU_FRAME_BOTTOM 40
#define STANDARD_MENU_FRAME_HEIGHT (STANDARD_MENU_FRAME_TOP + \
      STANDARD_MENU_FRAME_BOTTOM) // + nitems * STANDARD_MENU_ITEM_TOTAL_HEIGHT
#define STANDARD_MENU_FRAME_WIDTH (STANDARD_MENU_ITEM_TOTAL_WIDTH + \
      (2 * STANDARD_MENU_FRAME_SIDE))

#define STANDARD_MENU_WIDTH (STANDARD_MENU_ITEM_TOTAL_WIDTH)
#define STANDARD_MENU_HEIGHT (menu->height * 0.7)

#define STANDARD_MENU_BOX_CORNER_RADIUS 11
#define STANDARD_MENU_BOX_BORDER_WIDTH 1
#define STANDARD_MENU_FRAME_CORNER_RADIUS 32
#define STANDARD_MENU_FRAME_BORDER_WIDTH 2
#define STANDARD_MENU_TITLE_FONT_SIZE 25
#define MAIN_MENU_FONT_SIZE 15

122
#define FRAME_DROPSHADOW_DISTANCE 8
123

124 125 126 127 128 129 130 131 132 133
#define BACKGROUND_GRADIENT_START_R 0
#define BACKGROUND_GRADIENT_START_G 0.3
#define BACKGROUND_GRADIENT_START_B 0.8
#define BACKGROUND_GRADIENT_END_R 0
#define BACKGROUND_GRADIENT_END_G 0.8
#define BACKGROUND_GRADIENT_END_B 0.3

cairo_surface_t *create_gradient_background (int width, int height,
    float start_r, float start_g, float start_b,
    float end_r, float end_g, float end_b);
134
cairo_surface_t *load_image_and_scale (char *path, int width, int height);
Youness Alaoui's avatar
Youness Alaoui committed
135
void draw_background (Menu *menu, cairo_t *cr);
136 137
Menu *standard_menu_create (const char *title, char * text,
    int width, int height, int rows, int columns);
Youness Alaoui's avatar
Youness Alaoui committed
138
int standard_menu_add_item (Menu *menu, const char *title, int fontsize);
Youness Alaoui's avatar
Youness Alaoui committed
139
int standard_menu_add_tag (Menu *menu, const char *title, int fontsize);
Youness Alaoui's avatar
Youness Alaoui committed
140 141

#endif