예제 #1
0
void FieldBookWidget::widget_refresh()
{
  if (!fieldbook_dirty) {
    return;
  }
  fieldbook_overlay->clear();

  switch (fieldbook_state) {
  case 1:
    fieldbook_overlay->paint(*fieldbook_closed, 0, 0);
    break;
  case 2:
    fieldbook_overlay->paint(*fieldbook_open, 0, 0);
    break;
  }
  if (fieldbook_state == 2) {
    if (page_num > 0) {
      char verso_num[10];
      snprintf(&verso_num[0], sizeof(verso_num), "%u", page_num);
      fieldbook_overlay->write(*ui->textFont, verso_num, 45, 385);
    }
    char recto_num[10];
    snprintf(&recto_num[0], sizeof(recto_num), "%u", page_num+1);
    fieldbook_overlay->write(*ui->textFont, recto_num, 490, 372);

    // draw the text of the page(s)
    draw_page(page_num);
    draw_page(page_num+1);
  }
  fieldbook_overlay->flush();
  fieldbook_dirty = false;
}
예제 #2
0
파일: editor.c 프로젝트: talkers/ew-too
void pager_fn(player *p,char *str)
{
  ed_info *e;
  e=p->edit_info;
  switch(tolower(*str)) {
  case 'b':
    back_page(p,e);
    break;
  case 'p':
    back_page(p,e);
    break;
  case 0:
    forward_page(p,e);
    break;
  case 'f':
    forward_page(p,e);
    break;
  case 'n':
    forward_page(p,e);
    break;
  case 't':
    e->current=e->buffer;
    e->size=0;
    draw_page(p,e->current);
    break;
  case 'q':
    quit_pager(p,e);
    return;
  }
  if (!draw_page(p,e->current)) quit_pager(p,e);
}
예제 #3
0
void            pager_fn(player * p, char *str)
{
   ed_info        *e;
   e = p->edit_info;
   if((int)strlen(str)<2) {
     switch (tolower(*str))
     {
       case 0:
    	 /* player hit return - next page */
    	 forward_page(p, e);
    	 break;
       case 'p':
    	 back_page(p, e);
    	 break;
       case 'n':
    	 forward_page(p, e);
    	 break;
       case 'l':
         last_page(p, e);
         break;
       case 'f':
    	 e->current = e->buffer;
    	 e->size = 0;
    	 break;
       case '?':
         help_page(p);
         p->input_to_fn = pager_help_pause;
         return;
       case 'q':
    	 quit_pager(p, e);
    	 return;
       case 'r':
         /* redraw the screen */
         break;
       default:
         /* this is what happens if it doesnt recognise the command */
         p->input_to_fn = 0;
         input_for_one(p);
         p->input_to_fn = pager_fn;
         draw_page(p, e->current, 0);
         return;
     }
     if (!draw_page(p, e->current, 1))
       quit_pager(p, e);
   }
   else {
     p->input_to_fn = 0;
     input_for_one(p);
     p->input_to_fn = pager_fn;
     draw_page(p, e->current, 0);
   }
}
예제 #4
0
파일: editor.c 프로젝트: talkers/ew-too
void pager(player *p,char *text,int page)
{
  ed_info *e;
  int length=0,lines=0;
  char *scan;

  if (p->saved_flags&NO_PAGER && !page) {
    tell_player(p,text);
    return;
  }

  if (p->edit_info) {
    tell_player(p,"Eeek, can't enter pager right now.\n");
    return;
  }
  for(scan=text;*scan;scan++,length++)
    if (*scan=='\n') lines++;
  length++;
  if (lines>(TERM_LINES-3)) {
    e=(ed_info *)MALLOC(sizeof(ed_info));
    memset(e,0,sizeof(ed_info));
    p->edit_info=e;
    e->buffer=(char *)MALLOC(length);
    memcpy(e->buffer,text,length);
    e->current=e->buffer;
    e->max_size=lines;
    e->size=0;
    e->input_copy=p->input_to_fn;
    e->flag_copy=p->flags;
    p->input_to_fn=pager_fn;
    p->flags &= ~PROMPT;
  }
  draw_page(p,text);
}
예제 #5
0
void		pager_help_pause(player *p, char *str)
{
  ed_info *e;
  e = p->edit_info;
  p->input_to_fn = pager_fn;
  if (!draw_page(p, e->current, 1))
    quit_pager(p, e);
}
예제 #6
0
파일: cat.c 프로젝트: shentino/simud
int main(string param) {
    string file_name, *opt;
    int size;

    WIZ_CHECK

    process_codes = FALSE;
    do_count = FALSE;
    list_count = FALSE;

    if( !param ) {
	notify_fail("==> [Format] cat [-p] [-n] [-l start end] filename\n");
	return 0;
    }

    /* Acius is so smart! :) */
    while( 1 ) {
        if( sscanf( param, "-l %d %d %s", start, end, param) == 3 ) { list_count = TRUE; continue; }
        if( sscanf( param, "-n %s", param) == 1 ) { do_count = TRUE; continue; }
        if( sscanf( param, "-p %s", param) == 1 ) { process_codes  = TRUE; continue; }
        break;
    }

    file_name = this_player()->make_path_absolute( param );
    if( !file_name ) {
	notify_fail("==> [Error] make_path_absolute failed.\n");
	return 0;
    }
    if( !legal_filename(file_name) ) {
	notify_fail("==> [Error] '"+file_name+"' is not a legal file name.\n");
	return 0;
    }
    size = file_size( file_name );
    if( size < 0 ) {
	notify_fail("==> [Error] Can't open the file "+file_name+" for reading.\n");
	return 0;
    }
    if( size > MAX_FILE_SIZE && list_count == FALSE) {
	notify_fail("==> [Error] Cannot list files over "+(MAX_FILE_SIZE/1024)+"K using cat. Use 'more' instead.\n");
	return 0;
    }
    if( size == 0 ) {
	notify_fail("==> File is empty.\n");
	return 0;
    }

    if( draw_page( file_name, 1, 0 ))
	msg("~[090<EOF>~CDEF");
    else
	msg("==> [Error] Access denied");
    return 1;
}
예제 #7
0
void            pager(player * p, char *text, int page)
{
   ed_info        *e;
   int             length = 0, lines = 0;
   char           *scan;

   if (p->saved_flags & NO_PAGER && !page)
   {
      tell_player(p, text);
      return;
   }
   if (p->edit_info)
   {
      tell_player(p, " You are currently already in the pager/editor!\n");
      return;
   }
   /* scan whole of string, if its a newline then increase lines, and inc
      length -again-?? 
      Of course - this routine below can't actually cope with overwrapping 
      lines */
   for (scan = text; *scan; scan++, length++)
   {
      if (*scan == '\n')
         lines++;
   }
   if (lines > (TERM_LINES + 1))
   {
      e = (ed_info *) MALLOC(sizeof(ed_info));
      if(e==NULL) {
         tell_player(p, " Eeek, can't enter pager right now.\n");
         return;
      }
      memset(e, 0, sizeof(ed_info));
      p->edit_info = e;
      e->buffer = (char *) MALLOC(length+1);
      if(e->buffer==NULL) {
         tell_player(p, " Eeek, can't enter pager right now.\n");
         free(e);
         return;
      }
      memset(e->buffer, 0, length+1);
      strncpy(e->buffer, text, length);
      e->current = e->buffer;
      e->max_size = lines;
      e->size = 0;
      e->input_copy = p->input_to_fn;
      e->flag_copy = p->flags;
      p->input_to_fn = pager_fn;
      p->flags &= ~PROMPT;
   }
   draw_page(p, text, 1);
}
예제 #8
0
static gboolean
preview_draw (GtkWidget         *widget,
	      cairo_t           *cr,
	      SoliPrintPreview *preview)
{
	GdkWindow *bin_window;
	gint tile_width;
	gint page_num;
	gint n_pages;
	gint col;

	bin_window = gtk_layout_get_bin_window (preview->layout);

	if (!gtk_cairo_should_draw_window (cr, bin_window))
	{
		return GDK_EVENT_STOP;
	}

	cairo_save (cr);

	gtk_cairo_transform_to_window (cr, widget, bin_window);

	get_tile_size (preview, &tile_width, NULL);
	n_pages = get_n_pages (preview);

	col = 0;
	page_num = get_first_page_displayed (preview);

	while (col < preview->n_columns && page_num < n_pages)
	{
		if (!gtk_print_operation_preview_is_selected (preview->gtk_preview, page_num))
		{
			page_num++;
			continue;
		}

		draw_page (cr,
			   col * tile_width,
			   0,
			   page_num,
			   preview);

		col++;
		page_num++;
	}

	cairo_restore (cr);

	return GDK_EVENT_STOP;
}
예제 #9
0
파일: ui.c 프로젝트: mtl/tmk_keyboard
static void draw_menu( ui_menu_t * menu ) {

    // Render title bar and background:
    draw_page( menu->title );

    // Draw list:
    u8g_SetFont( u8g, menu_list_font );
    int y = page_body_start + menu_list_vpad + menu_list_font_height + 1;
    int step = menu_list_font_vsize + ( menu_list_vpad << 1 ) + 1;
    int indent = menu_list_hpad + u8g_GetStrWidth( u8g, "2. " );
    ui_menu_item_t * items = menu->items;
    for ( int i = 0; i < menu->num_items; i++ ) {

        // Check if y descends beyond bottom of display:
        if ( y > 127 ) {
            break;
        }

        // Set item color:
        ui_menu_item_t * item = &items[ i ];
        switch ( item->type ) {

            case UI_DUMMY:
                display_set_draw_color( &menu_list_disabled_color_fg );
                break;

            case UI_FLAG:
                if ( ! get_flag_state( item->number, item->bit ) ) {
                    display_set_draw_color( &menu_list_disabled_color_fg );
                    break;
                }

            default:
                display_set_draw_color( &menu_list_color_fg );
        }

        // Draw item number:
        char number[] = "n. ";
        number[ 0 ] = 0x31 + i;
        u8g_DrawStr( u8g, menu_list_hpad, y, number );

        // Draw item label:
        u8g_DrawStr( u8g, indent, y, item->label );
        y += step;
    }
}
예제 #10
0
파일: ui.c 프로젝트: mtl/tmk_keyboard
static void draw_log() {

    // Render title bar and background:
    draw_page( "Log" );

    // Draw list:
    u8g_SetFont( u8g, menu_list_font );
    display_set_draw_color( &menu_list_color_fg );
    int y = page_body_start + menu_list_vpad + menu_list_font_height + 1;
    int step = menu_list_font_vsize + ( menu_list_vpad << 1 ) + 1;
    for ( int i = 0; i < UI_LOG_ROWS; i++ ) {

        // Draw item label:
        u8g_DrawStr( u8g, menu_list_hpad, y, (const char *) &log[ i ] );
        y += step;
    }
}
예제 #11
0
파일: ui.c 프로젝트: mtl/tmk_keyboard
static void draw_num_selector() {

    char number[ 6 ] = "     ";
    char * num;

    // Render title bar and background:
    draw_page( num_widget_title );

    // Compute first line y pos and line height:
    int y = page_body_start + num_font_height + num_vpad - 1;
    int step = ( menu_list_vpad << 1 ) + num_font_vsize - 1;

    // Create string from value:
    int val = num_widget_value;
    int num_digits = 0;
    num = &number[ 0 ] + 5;
    for ( int i = 0; i < 5; i++ ) {

        num--;
        *num = 0x30 + val % 10;
        num_digits++;
        val /= 10;

        if ( ! val ) break;
    }
    if ( ! num_digits ) {
        *num = '0';
    }

    // Draw current value:
    display_set_draw_color( &menu_list_color_fg );
    u8g_SetFont( u8g, num_selector_num_font );
    u8g_DrawStr(
        u8g,
        // Make sure this is positive if using a very wide font:
        ( 128 - u8g_GetStrWidth( u8g, num ) ) / 2,
        y,
        num
    );
}
예제 #12
0
파일: terrain.c 프로젝트: johnh530/electro
static void draw_areas(float V[6][4], const float M[16],
                       int i, float p, float t)
{
    float b[6], x, y, a;
    GLuint o;

    while (dequeue_area(&x, &y, &a, &o))
    {
        /*float kk =*/ get_bounds(i, b, x, y, a);

        if (test_frustum(V, b) >= 0)
        {
            float k = get_value(b, M, terrain[i].bias);

            if (k > 1.0f && a > 360.0f * terrain[i].n / terrain[i].w)
            {
                float xm = x + a / 2;
                float ym = y + a / 2;

                float x0 = (t > xm) ? x : xm;
                float x1 = (t > xm) ? xm : x;
                float y0 = (p > ym) ? y : ym;
                float y1 = (p > ym) ? ym : y;

                enqueue_area(x0, y0, a / 2, o);
                enqueue_area(x1, y0, a / 2, o);
                enqueue_area(x0, y1, a / 2, o);
                enqueue_area(x1, y1, a / 2, o);
            }
            else
            {
                glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
                glBindTexture(GL_TEXTURE_2D, o);

                draw_page(i, x, y, a);
            }
        }
    }
}
예제 #13
0
int main( int argc, char *argv[] )
{
    PLINT mode;
    PLINT i;

    // PLplot initialization

    // Parse and process command line arguments
    plparseopts( &argc, argv, PL_PARSE_FULL );

    // Initialize PLplot
    plinit();

    // Check for drawing mode support
    mode = plgdrawmode();

    if ( mode == PL_DRAWMODE_UNKNOWN )
    {
        printf( "WARNING: This driver does not support drawing mode getting/setting" );
    }
    else
    {
        // Setup colors
        initialize_colors();

        // Draw one page per drawing mode
        for ( i = 0; i < NUM_MODES; i++ )
        {
            draw_page( drawing_modes[i], drawing_mode_names[i] );
        }
    }

    // Clean up
    plend();

    exit( 0 );
}
예제 #14
0
int main(int argc, char **argv)
{
	SDL_Surface *screen;
	SDL_Event event;
	PopplerDocument *document;
	GError *error;
	const char *pdf_file;
	gchar *absolute, *uri;
	int page_num = 1, num_pages;
	cairo_t *cr;
	double width, height;
	float ofs;
	PopplerPage *page;
	SDL_TimerID t = 0;
	SDL_Surface *pg_sf;
	SDL_Surface *n1, *n2, *n1l, *n2l;
	SDL_Surface **preld_sf = NULL;
	SDL_Surface *src_sf = NULL;
	int prerender = 1;

	if (argc < 2) {
		printf("Usage: %s input_file.pdf (pagenum)\n",argv[0]);
		return 0;
	}

	pdf_file = argv[1];
	if (argc > 2)
		page_num = atoi(argv[2]);
	g_type_init();
	error = NULL;

	n1 = IMG_Load("1_32.png");
	n2 = IMG_Load("2_32.png");

	if (g_path_is_absolute(pdf_file)) {
		absolute = g_strdup(pdf_file);
	} else {
		gchar *dir = g_get_current_dir();
		absolute = g_build_filename(dir, pdf_file, (gchar *) 0);
		free(dir);
	}

	uri = g_filename_to_uri(absolute, NULL, &error);
	free(absolute);
	if (uri == NULL) {
		printf("%s\n", error->message);
		return 1;
	}

	document = poppler_document_new_from_file(uri, NULL, &error);
	if (document == NULL) {
		printf("%s\n", error->message);
		return 1;
	}

	num_pages = poppler_document_get_n_pages(document);
	if (page_num < 1 || page_num > num_pages) {
		printf("page must be between 1 and %d\n", num_pages);
		return 1;
	}

	page = poppler_document_get_page(document, 0);
	if (page == NULL) {
		printf("poppler fail: page not found\n");
		return 1;
	}

	/* Initialize SDL, open a screen */
	screen = init_screen(1024, 768, 32);

	n1l = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA,
				   screen->w,
				   32,
				   32,
				   0xff000000,
				   0x00ff0000, 0x0000ff00, 0x000000ff);

	n2l = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA,
				   screen->w,
				   32,
				   32,
				   0xff000000,
				   0x00ff0000, 0x0000ff00, 0x000000ff);

	make_nyans(n1l, n1);
	make_nyans(n2l, n2);

	pg_sf = SDL_CreateRGBSurface(SDL_HWSURFACE | 0,
				     screen->w,
				     screen->h,
				     32,
				     CAIROSDL_RMASK,
				     CAIROSDL_GMASK, CAIROSDL_BMASK, 0);

	cr = cairosdl_create(pg_sf);

	poppler_page_get_size(page, &width, &height);
	g_object_unref(page);

	cairo_scale(cr, screen->w / width, screen->h / height);
	draw_page(pg_sf, cr, document, page_num);
	SDL_BlitSurface(pg_sf, NULL, screen, NULL);
	SDL_Flip(screen);

	if (prerender) {
		int i;
		preld_sf = malloc(sizeof(SDL_Surface *) * num_pages);
		for (i = 0; i < num_pages; i++) {
			preld_sf[i] = SDL_CreateRGBSurface(SDL_HWSURFACE | 0,
							   screen->w,
							   screen->h,
							   32,
							   CAIROSDL_RMASK,
							   CAIROSDL_GMASK,
							   CAIROSDL_BMASK, 0);
			draw_page(pg_sf, cr, document, i + 1);
			SDL_BlitSurface(pg_sf, NULL, preld_sf[i], NULL);
		}
	}

	while (SDL_WaitEvent(&event)) {
		int new_page = 0;
		switch (event.type) {
		case SDL_KEYDOWN:
			if (event.key.keysym.sym == SDLK_ESCAPE) {
				goto done;
			} else if (event.key.keysym.sym == SDLK_SPACE) {
				new_page = 1;
				++page_num;
			} else if (event.key.keysym.sym == SDLK_RIGHT) {
				new_page = 1;
				++page_num;
			} else if (event.key.keysym.sym == SDLK_LEFT) {
				new_page = 1;
				--page_num;
			} else if (event.key.keysym.sym == SDLK_PAGEUP) {
				new_page = 1;
				--page_num;
			} else if (event.key.keysym.sym == SDLK_PAGEDOWN) {
				new_page = 1;
				++page_num;
			}

			if (new_page) {
				SDL_Rect sr, sd;
				float x;

				SDL_RemoveTimer(t);

				if (page_num > num_pages)
					page_num = num_pages;
				if (page_num < 1)
					page_num = 1;

				src_sf = pg_sf;
				if (!prerender)
					draw_page(pg_sf, cr, document,
						  page_num);
				else {
					src_sf = preld_sf[page_num - 1];
				}

				SDL_BlitSurface(src_sf, NULL, screen, NULL);
				
				ofs = num_pages - page_num;
				ofs /= num_pages;
				x = n1l->w;
				x *= ofs;
				sr.x = x;
				sr.w = n1l->w - x;
				sr.h = n1l->h;
				sr.y = 0;
#ifndef NYAN_TOP
				sd.y = screen->h - n1l->h;
#else
				sd.y = 0;
#endif
				sd.w = sr.w;
				sd.x = 0;
				sd.h = sr.h;
				SDL_BlitSurface(page_num & 1 ? n1l : n2l, &sr,
						screen, &sd);
				SDL_Flip(screen);
				t = SDL_AddTimer(1000, timer_cb, NULL);
			}
			break;

		case SDL_QUIT:
			goto done;

		case SDL_USEREVENT:
			SDL_BlitSurface(src_sf, NULL, screen, NULL);
			SDL_Flip(screen);
			break;

		default:
			break;
		}
	}

 done:
	SDL_FreeSurface(screen);
	SDL_Quit();
	return 0;
}
예제 #15
0
파일: ui.c 프로젝트: mtl/tmk_keyboard
static void draw_rgb_config() {

    int frame_width = 1;

    // Render title bar and background:
    draw_page( rgb_widget_title );

    // Compute first line y pos and line height:
    int y = (
        page_body_start + frame_width + widget_focus_frame_pad +
        menu_list_font_height + menu_list_hpad - 1
    );
    int step = ( frame_width << 1 ) + ( widget_focus_frame_pad << 1 ) + menu_list_font_vsize - 1;

    // Compute x pos for numbers:
    u8g_SetFont( u8g, menu_list_font );
    int char_width = u8g_GetStrWidth( u8g, "w" );
    int num_chars = 3;
    if ( rgb_max_value > 255 ) {
        num_chars = 4;
    }
    int num_x = 128 - menu_list_hpad - frame_width - num_chars * char_width;

    // Compute bar dimensions:
    int bar_frame_x = menu_list_hpad;
    int bar_x = bar_frame_x + frame_width + widget_focus_frame_pad;
    uint16_t max_bar_width = num_x - bar_x - ( widget_focus_frame_pad << 1 ) - 1;
    uint32_t bar_width = 0;

    // Draw bars:
    display_set_draw_color( &rgb_red );
    int y_red = y;
    bar_width = max_bar_width;
    bar_width *= rgb_widget_color[ 0 ];
    bar_width /= rgb_max_value;
    u8g_DrawBox(
        u8g,
        bar_x,
        y_red - menu_list_font_height,
        bar_width,
        menu_list_font_vsize
    );

    display_set_draw_color( &rgb_green );
    int y_green = y_red + step;
    bar_width = max_bar_width;
    bar_width *= rgb_widget_color[ 1 ];
    bar_width /= rgb_max_value;
    u8g_DrawBox(
        u8g,
        bar_x,
        y_green - menu_list_font_height,
        bar_width,
        menu_list_font_vsize
    );

    display_set_draw_color( &rgb_blue );
    int y_blue = y_green + step;
    bar_width = max_bar_width;
    bar_width *= rgb_widget_color[ 2 ];
    bar_width /= rgb_max_value;
    u8g_DrawBox(
        u8g,
        bar_x,
        y_blue - menu_list_font_height,
        bar_width,
        menu_list_font_vsize
    );

    // Draw numbers:
    display_set_draw_color( &menu_title_color_fg );
    char digits[] = "   ";
    if ( rgb_max_value < 256 ) {
        digits[ 2 ] = 0;
    }
    int d = 0;
    if ( rgb_max_value > 255 ) {
        digits[ d++ ] = nibchar( rgb_widget_color[ 0 ] >> 8 );
    }