1 /* Copyright Krzysztof Kowalczyk 2006-2007
3 #include "DisplayState.h"
11 void normalizeRotation(int *rotation
)
14 if (!rotation
) return;
17 while (*rotation
>= 360)
21 BOOL
validRotation(int rotation
)
23 normalizeRotation(&rotation
);
24 if ((0 == rotation
) || (90 == rotation
) ||
25 (180 == rotation
) || (270 == rotation
))
30 BOOL
ValidZoomVirtual(double zoomVirtual
)
32 if ((ZOOM_FIT_PAGE
== zoomVirtual
) || (ZOOM_FIT_WIDTH
== zoomVirtual
))
34 if ((zoomVirtual
< ZOOM_MIN
) || (zoomVirtual
> ZOOM_MAX
)) {
35 DBG_OUT("ValidZoomVirtual() invalid zoom: %.4f\n", zoomVirtual
);
41 #define STR_FROM_ENUM(val) \
45 const char *DisplayModeNameFromEnum(DisplayMode var
)
47 STR_FROM_ENUM(DM_SINGLE_PAGE
)
48 STR_FROM_ENUM(DM_FACING
)
49 STR_FROM_ENUM(DM_CONTINUOUS
)
50 STR_FROM_ENUM(DM_CONTINUOUS_FACING
)
54 #define IS_STR_ENUM(enumName) \
55 if (str_eq(txt, enumName##_STR)) { \
60 BOOL
DisplayModeEnumFromName(const char *txt
, DisplayMode
*resOut
)
62 IS_STR_ENUM(DM_SINGLE_PAGE
)
63 IS_STR_ENUM(DM_FACING
)
64 IS_STR_ENUM(DM_CONTINUOUS
)
65 IS_STR_ENUM(DM_CONTINUOUS_FACING
)
70 void DisplayState_Init(DisplayState
*ds
)
72 memzero(ds
, sizeof(DisplayState
));
73 ds
->displayMode
= DM_SINGLE_PAGE
;
75 ds
->fullScreen
= FALSE
;
77 ds
->zoomVirtual
= 100.0;
81 void DisplayState_Free(DisplayState
*ds
)
83 free((void*)ds
->filePath
);
84 DisplayState_Init(ds
);
87 BOOL
DisplayState_Serialize(DisplayState
*ds
, DString
*strOut
)
89 const char * displayModeName
= NULL
;
91 DStringSprintf(strOut
, " %s: %s\n", FILE_STR
, ds
->filePath
);
93 displayModeName
= DisplayModeNameFromEnum(ds
->displayMode
);
95 DStringSprintf(strOut
, " %s: %s\n", DISPLAY_MODE_STR
, displayModeName
);
97 DStringSprintf(strOut
, " %s: %s\n", DISPLAY_MODE_STR
, DisplayModeNameFromEnum(DM_SINGLE_PAGE
));
99 DStringSprintf(strOut
, " %s: %d\n", VISIBLE_STR
, ds
->visible
);
100 DStringSprintf(strOut
, " %s: %d\n", PAGE_NO_STR
, ds
->pageNo
);
101 DStringSprintf(strOut
, " %s: %.4f\n", ZOOM_VIRTUAL_STR
, ds
->zoomVirtual
);
102 DStringSprintf(strOut
, " %s: %d\n", ROTATION_STR
, ds
->rotation
);
103 DStringSprintf(strOut
, " %s: %d\n", FULLSCREEN_STR
, (int)ds
->fullScreen
);
105 DStringSprintf(strOut
, " %s: %d\n", SCROLL_X_STR
, ds
->scrollX
);
106 DStringSprintf(strOut
, " %s: %d\n", SCROLL_Y_STR
, ds
->scrollY
);
108 DStringSprintf(strOut
, " %s: %d\n", WINDOW_X_STR
, ds
->windowX
);
109 DStringSprintf(strOut
, " %s: %d\n", WINDOW_Y_STR
, ds
->windowY
);
110 DStringSprintf(strOut
, " %s: %d\n", WINDOW_DX_STR
, ds
->windowDx
);
111 DStringSprintf(strOut
, " %s: %d\n", WINDOW_DY_STR
, ds
->windowDy
);