现在的位置: 首页 > 综合 > 正文

GTK-PIXBUF

2017年12月20日 ⁄ 综合 ⁄ 共 943字 ⁄ 字号 评论关闭

#include <gtk/gtk.h>
#include <stdlib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

#define DA_WIDTH 300
#define DA_HEIGHT 300
#define SCALE_FACTOR 1.2

#define PEN_MOVE  0
#define PEN_UP    1
#define PEN_DOWN  2

GdkPixmap *pixmap = NULL;
GtkWidget *window, *vbox, *tool_bar, *drawing_area;

gboolean status;
gboolean fdiscard = TRUE;

gint prev_x, prev_y;
GdkGC *my_gc_red;
GdkColor color;

struct ImageData {
  GtkWidget *drawing_area;
  int width, height;
  GdkPixbuf *pixbuf;
  float scale;
};

struct ImageData data;

static void expose_cb(GtkWidget *da, GdkEventExpose *event, struct ImageData *data)
{
    GdkPixbuf *pixbuf;
    gfloat ratio;
    gint s_width, s_height, w_width, w_height;
    s_width = gdk_pixbuf_get_width (data->pixbuf);
    s_height = gdk_pixbuf_get_height (data->pixbuf);
    w_width = data->width;
    w_height = data->height;

    if ((gfloat) w_width / s_width > (gfloat) w_height / s_height) {
        ratio = (gfloat) w_height / s_height;
      } else {
        ratio = (gfloat) w_width / s_width;
      }

    int width  = s_width  * ratio;
    int height = s_height * ratio;

【上篇】
【下篇】

抱歉!评论已关闭.