Kaynağa Gözat

Stricter object encapsulation

master
Bert 13 yıl önce
ebeveyn
işleme
c7860b690b
5 değiştirilmiş dosya ile 25 ekleme ve 31 silme
  1. +13
    -11
      image.c
  2. +4
    -5
      image.h
  3. +2
    -8
      main.c
  4. +5
    -6
      window.c
  5. +1
    -1
      window.h

+ 13
- 11
image.c Dosyayı Görüntüle

@@ -28,20 +28,22 @@ int zl_cnt;
float zoom_min;
float zoom_max;

void imlib_init(win_t *win) {
if (!win)
return;

imlib_context_set_display(win->env.dpy);
imlib_context_set_visual(win->env.vis);
imlib_context_set_colormap(win->env.cmap);

void img_init(img_t *img, win_t *win) {
zl_cnt = sizeof(zoom_levels) / sizeof(zoom_levels[0]);
zoom_min = zoom_levels[0] / 100.0;
zoom_max = zoom_levels[zl_cnt - 1] / 100.0;

if (img)
img->zoom = 1.0;

if (win) {
imlib_context_set_display(win->env.dpy);
imlib_context_set_visual(win->env.vis);
imlib_context_set_colormap(win->env.cmap);
}
}

void imlib_destroy() {
void img_free(img_t* img) {
if (imlib_context_get_image())
imlib_free_image();
}
@@ -104,7 +106,7 @@ void img_render(img_t *img, win_t *win) {
img->re = 1;

/* set zoom level to fit image into window */
if (img->scalemode != SCALE_ZOOM) {
if (SCALE_MODE != SCALE_ZOOM) {
zw = (float) win->w / (float) img->w;
zh = (float) win->h / (float) img->h;
img->zoom = MIN(zw, zh);
@@ -114,7 +116,7 @@ void img_render(img_t *img, win_t *win) {
else if (img->zoom > zoom_max)
img->zoom = zoom_max;

if (img->scalemode == SCALE_DOWN && img->zoom > 1.0)
if (SCALE_MODE == SCALE_DOWN && img->zoom > 1.0)
img->zoom = 1.0;
}



+ 4
- 5
image.h Dosyayı Görüntüle

@@ -21,15 +21,14 @@

#include "window.h"

typedef enum scalemode_e {
enum scalemode {
SCALE_DOWN = 0,
SCALE_FIT,
SCALE_ZOOM
} scalemode_t;
};

typedef struct img_s {
float zoom;
scalemode_t scalemode;
unsigned char re;
int x;
int y;
@@ -37,8 +36,8 @@ typedef struct img_s {
int h;
} img_t;

void imlib_init(win_t*);
void imlib_destroy();
void img_init(img_t*, win_t*);
void img_free(img_t*);

int img_load(img_t*, const char*);
void img_render(img_t*, win_t*);


+ 2
- 8
main.c Dosyayı Görüntüle

@@ -83,14 +83,8 @@ int main(int argc, char **argv) {
exit(1);
}

img.zoom = 1.0;
img.scalemode = SCALE_MODE;

win.w = WIN_WIDTH;
win.h = WIN_HEIGHT;

win_open(&win);
imlib_init(&win);
img_init(&img, &win);

img_load(&img, filenames[fileidx]);
img_render(&img, &win);
@@ -107,7 +101,7 @@ void cleanup() {
static int in = 0;

if (!in++) {
imlib_destroy();
img_free(&img);
win_close(&win);
}
}


+ 5
- 6
window.c Dosyayı Görüntüle

@@ -32,16 +32,14 @@ void win_open(win_t *win) {

if (!win)
return;
e = &win->env;

e = &win->env;
if (!(e->dpy = XOpenDisplay(NULL)))
DIE("could not open display");
e->scr = DefaultScreen(e->dpy);
e->scrw = DisplayWidth(e->dpy, e->scr);
e->scrh = DisplayHeight(e->dpy, e->scr);

e->vis = DefaultVisual(e->dpy, e->scr);
e->cmap = DefaultColormap(e->dpy, e->scr);
e->depth = DefaultDepth(e->dpy, e->scr);
@@ -50,6 +48,8 @@ void win_open(win_t *win) {
&bgcol, &bgcol))
DIE("could not allocate color: %s", BG_COLOR);

win->w = WIN_WIDTH;
win->h = WIN_HEIGHT;
if (win->w > e->scrw)
win->w = e->scrw;
if (win->h > e->scrh)
@@ -66,10 +66,9 @@ void win_open(win_t *win) {
XSelectInput(e->dpy, win->xwin,
StructureNotifyMask | KeyPressMask);

win->pm = 0;

gcval.foreground = bgcol.pixel;
win->bgc = XCreateGC(e->dpy, win->xwin, GCForeground, &gcval);
win->pm = 0;

win_set_title(win, "sxiv");



+ 1
- 1
window.h Dosyayı Görüntüle

@@ -33,8 +33,8 @@ typedef struct win_env_s {
typedef struct win_s {
Window xwin;
win_env_t env;
Pixmap pm;
GC bgc;
Pixmap pm;

int w;
int h;


Yükleniyor…
İptal
Kaydet