Skip to content

Commit

Permalink
updated nxdraw.c from fbff
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Jun 13, 2019
1 parent e959bb8 commit f7781e8
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Original file line Diff line number Diff line change
@@ -1,2 +1,4 @@
13 Jun 2019
* updated nxdraw.c from fbff
8 Jun 2019 8 Jun 2019
* initial port to Nano-X, revised sources and fb_ api for simpler multiple platform support * initial port to Nano-X, revised sources and fb_ api for simpler multiple platform support
8 changes: 7 additions & 1 deletion draw.h
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
/* main functions */ /* main functions */
int fb_init(char *title, int w, int h); int fb_init(void);
int fb_open(char *title, int w, int h, int flags);
void fb_free(void); void fb_free(void);
unsigned fb_mode(void); unsigned fb_mode(void);
void *fb_mem(int r); void *fb_mem(int r);
Expand All @@ -10,6 +11,11 @@ void fb_update(void);


typedef unsigned int fbval_t; /* framebuffer depth */ typedef unsigned int fbval_t; /* framebuffer depth */


/* fb_open flags*/
#define NOFRAME 0
#define BORDER 1
#define APPFRAME 2

/* fb_mode() interpretation */ /* fb_mode() interpretation */
#define FBM_BPP(m) (((m) >> 16) & 0x0f) #define FBM_BPP(m) (((m) >> 16) & 0x0f)
#define FBM_COLORS(m) ((m) & 0x0fff) #define FBM_COLORS(m) ((m) & 0x0fff)
Expand Down
2 changes: 1 addition & 1 deletion fbpdf.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ int main(int argc, char *argv[])
break; break;
} }
} }
if (fb_init(PROGNAME, 800, 600)) if (fb_init() || fb_open(PROGNAME, 800, 600, APPFRAME))
return 1; return 1;
srows = fb_rows(); srows = fb_rows();
scols = fb_cols(); scols = fb_cols();
Expand Down
44 changes: 34 additions & 10 deletions nxdraw.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -55,27 +55,51 @@ static void init_colors(void)
bl = 0; bl = 0;
} }


int fb_init(char *title, int w, int h) int fb_init(void)
{ {
GR_SCREEN_INFO si;
if (GrOpen() < 0) if (GrOpen() < 0)
return 1; return 1;


bytespp = 4; bytespp = 4;
init_colors(); init_colors();


if (!w || !h) { /* get width/height for fb_cols/fb_rows before fb_open*/
GR_SCREEN_INFO si; GrGetScreenInfo(&si);
GrGetScreenInfo(&si); WIDTH = si.cols;
WIDTH = si.cols; HEIGHT = si.rows;
HEIGHT = si.rows; STRIDE = WIDTH * bytespp;
} else {
return 0;
}

int fb_open(char *title, int w, int h, int flags)
{
GR_WM_PROPS props;

/* reset window size from fullscreen if given*/
if (w && h) {
WIDTH = w; WIDTH = w;
HEIGHT = h; HEIGHT = h;
STRIDE = WIDTH * bytespp;
} }
STRIDE = WIDTH * bytespp;


wid = GrNewBufferedWindow(GR_WM_PROPS_BUFFER_MMAP|GR_WM_PROPS_BUFFER_BGRA, title, GR_ROOT_WINDOW_ID, switch (flags) {
0, 0, WIDTH, HEIGHT, 0); case NOFRAME:
props = GR_WM_PROPS_CLOSEBOX; /* will generate no frame, closebox, or border*/
break;
case BORDER:
props = GR_WM_PROPS_BORDER;
break;
case APPFRAME:
props = GR_WM_PROPS_APPWINDOW;
break;
default:
return 1;
}
props |= GR_WM_PROPS_BUFFER_MMAP | GR_WM_PROPS_BUFFER_BGRA | GR_WM_PROPS_NORESIZE;

wid = GrNewBufferedWindow(props, title, GR_ROOT_WINDOW_ID, 0, 0, WIDTH, HEIGHT, 0);
fb = GrOpenClientFramebuffer(wid); fb = GrOpenClientFramebuffer(wid);
if (!fb) { if (!fb) {
GrDestroyWindow(wid); GrDestroyWindow(wid);
Expand Down

0 comments on commit f7781e8

Please sign in to comment.