Пример #1
0
/*
 * layout_cipher() - Draws recover cipher
 *
 * INPUT
 *     - current_word: current word that is being typed in at this point in recovery
 *     - cipher: randomized cipher
 * OUTPUT
 *     none
 */
void layout_cipher(const char *current_word, const char *cipher)
{
    DrawableParams sp;
    const Font *title_font = get_body_font();
    Canvas *canvas = layout_get_canvas();

    call_leaving_handler();
    layout_clear();

    /* Draw prompt */
    sp.y = 11;
    sp.x = 4;
    sp.color = BODY_COLOR;
    draw_string(canvas, title_font, "Recovery Cipher:", &sp, 58, font_height(title_font) + 3);

    /* Draw current word */
    sp.y = 46;
    sp.x = 4;
    sp.color = BODY_COLOR;
    draw_string(canvas, title_font, current_word, &sp, 68, font_height(title_font));
    display_refresh();

    /* Animate cipher */
    layout_add_animation(&layout_animate_cipher, (void *)cipher,
                         CIPHER_ANIMATION_FREQUENCY_MS * 30);
}
Пример #2
0
static void _textbox_highlight(l_textbox *tb, uint8_t srci, uint8_t desti, \
				uint32_t lineno)
{
	uint32_t x, y;
	uint8_t *pixels;

	if (SDL_MUSTLOCK(tb->s))
		SDL_LockSurface(tb->s);
	
	pixels = (uint8_t *)tb->s->pixels + \
		 ((lineno * font_height(tb->font)) * tb->s->pitch);

	for (y = 0; y < font_height(tb->font); y++) {
		for (x = 0; x < tb->s->pitch; x++) {
			if (*pixels == srci)
				*pixels = desti;
			pixels++;
		}
	}	

	if (SDL_MUSTLOCK(tb->s))
		SDL_UnlockSurface(tb->s);

	_update_screen(tb);
}
Пример #3
0
/* Show some lines of text (during the game). */
struct widget * widget_new_game_window(char ** lines, int lines_count)
{
  int width, height;
  int x, y;

  width = 10;
  for(int i = 0; i < lines_count; i++)
    {
      int w;

      w = font_width(lines[i]);
      if(w > width)
        width = w;
    }
  width += 20;

  height = (2 + lines_count) * font_height();

  x = (SCREEN_WIDTH - width) / 2;
  y = (SCREEN_HEIGHT - height) / 2;

  struct widget * window;

  window = widget_new_frame(widget_root(), x, y, width, height);
  assert(window != NULL);

  widget_delete_flags(window, WF_DRAW_BORDERS | WF_CAST_SHADOW);
  widget_set_ulong(window, "alpha", 0xc0);

  for(int i = 0; i < lines_count; i++)
    widget_new_text(window, 10, (1 + i) * font_height(), lines[i]);

  return window;
}
Пример #4
0
Файл: menu.c Проект: S010/cwm
static void
menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
    struct menu_q *resultq)
{
	struct menu		*mi;
	XineramaScreenInfo	*xine;
	int			 xmin, xmax, ymin, ymax;
	int			 n, dy, xsave, ysave;
	int			 bwidth2;
	XftColor		*xftcolorp = &sc->xftcolor;

	if (mc->list) {
		if (TAILQ_EMPTY(resultq) && mc->list) {
			/* Copy them all over. */
			TAILQ_FOREACH(mi, menuq, entry)
				TAILQ_INSERT_TAIL(resultq, mi,
				    resultentry);

			mc->listing = 1;
		} else if (mc->changed)
			mc->listing = 0;
	}

	mc->num = 0;
	mc->width = 0;
	dy = 0;
	if (mc->hasprompt) {
		(void)snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%s",
		    mc->promptstr, mc->searchstr, PROMPT_ECHAR);
		mc->width = font_width(sc, mc->dispstr, strlen(mc->dispstr));
		dy = font_height(sc);
		mc->num = 1;
	}

	TAILQ_FOREACH(mi, resultq, resultentry) {
		char *text;

		if (mc->print != NULL) {
			(*mc->print)(mi, mc->listing);
			text = mi->print;
		} else {
			mi->print[0] = '\0';
			text = mi->text;
		}

		mc->width = MAX(mc->width, font_width(sc, text,
		    MIN(strlen(text), MENU_MAXENTRY)));
		dy += font_height(sc);
		mc->num++;
	}
Пример #5
0
struct widget * widget_new_text(struct widget * parent, int x, int y, char const * const text)
{
  struct widget * obj;
  int w, h;

  if(text != NULL)
    {
      w = 2 + font_width(text) + 2;
      h = 1 + font_height() + 1;
    }
  else
    {
      w = 4;
      h = 4;
    }
  obj = widget_new_child(parent, x, y, w, h);
  assert(obj != NULL);
  if(obj != NULL)
    {
      widget_set_on_draw(obj, widget_draw);
      widget_set_ulong(obj, "type", WT_TEXT);
      widget_set_flags(obj, 0);

      if(text != NULL)
        widget_set_string(obj, "text", "%s", text);
    }

  return obj;
}
Пример #6
0
void QuartzWindow::draw_text(const char* text, int x, int y)  { 
  int len = strlen(text);
  int h = font_height();
  
  clear_rectangle(x, y-h, len * font_width(), h);
  CGContextSetTextPosition(myContext, x, y);
  CGContextShowText(myContext, text, len);
} 
Пример #7
0
static void _textbox_scroll(l_textbox *tb)
{
	SDL_Rect	r;

	r.x = 0;	
	r.y = font_height(tb->font) / 2;
	r.w = tb->s->w;
	r.h = tb->s->h - font_height(tb->font) / 2;
	if (SDL_BlitSurface(tb->s, &r, tb->s, NULL))
		sdl_error(tb->errorState);

	r.y = r.h;
	r.h = font_height(tb->font) / 2;
	if (SDL_FillRect(tb->s, &r, BG_INDEX))
		sdl_error(tb->errorState);

	_update_screen(tb);
}
Пример #8
0
static int l_textbox_getcursor(lua_State *L)
{
	l_textbox *tb;

	tb = l_checkTextbox(L, 1);

	lua_pushnumber(L, tb->x);
	lua_pushnumber(L, tb->y / font_height(tb->font));

	return 2;
}
Пример #9
0
static void _textbox_newline(l_textbox *tb)
{
	SDL_Rect r;

	/* Update the cursor */
	tb->x = 0;
	tb->y += font_height(tb->font);

	/* Clear the number of caps and number of chars counters */
	tb->ncaps = 0;
	tb->nchars = 0;

	/* Scroll the text */
	if (tb->y >= tb->rect->h) {
		_textbox_scroll(tb);
		_textbox_scroll(tb);

		tb->y -= font_height(tb->font);
	}
}
Пример #10
0
static int l_textbox_setcursor(lua_State *L)
{
	l_textbox *tb;

	tb = l_checkTextbox(L, 1);
	tb->x = luaL_checkinteger(L, 2);
	tb->y = luaL_checkinteger(L, 3) * font_height(tb->font);

	tb->ncaps = 0;
	tb->nchars = 0;

	return 0;
}
Пример #11
0
/*
 * layout_address_notification() - Display address notification
 *
 * INPUT
 *     - desc: description of address being shown (normal or multisig)
 *     - address: address to display both as string and QR
 *     - type: notification type
 * OUTPUT
 *      none
 */
void layout_address_notification(const char *desc, const char *address,
                                 NotificationType type)
{
    call_leaving_handler();
    layout_clear();

    Canvas *canvas = layout_get_canvas();
    DrawableParams sp;
    const Font *address_font = get_title_font();

    /* Unbold fonts if address becomes too long */
    if(calc_str_width(address_font, address) > TRANSACTION_WIDTH)
    {
        address_font = get_body_font();
    }

    /* Determine vertical alignment and body width */
    sp.y =  TOP_MARGIN_FOR_ONE_LINE;

    /* Draw address */
    sp.y += font_height(address_font) + ADDRESS_TOP_MARGIN;
    sp.x = LEFT_MARGIN;
    sp.color = BODY_COLOR;
    draw_string(canvas, address_font, address, &sp, TRANSACTION_WIDTH,
                font_height(address_font) + BODY_FONT_LINE_PADDING);

    /* Draw description */
    if(strcmp(desc, "") != 0)
    {
        sp.y = TOP_MARGIN_FOR_ONE_LINE;
        sp.x = MULTISIG_LEFT_MARGIN;
        sp.color = BODY_COLOR;
        draw_string(canvas, address_font, desc, &sp, TRANSACTION_WIDTH,
                    font_height(address_font) + BODY_FONT_LINE_PADDING);
    }

    layout_address(address);
    layout_notification_icon(type, &sp);
}
Пример #12
0
/*
 * layout_transaction_notification() - Display transaction notification
 *
 * INPUT
 *     - amount: amount of transaction
 *     - address: destination address
 *     - type: notification type
 * OUTPUT
 *     none
 */
void layout_transaction_notification(const char *amount, const char *address,
                                     NotificationType type)
{
    call_leaving_handler();
    layout_clear();

    Canvas *canvas = layout_get_canvas();
    DrawableParams sp;
    const Font *amount_font = get_title_font();
    const Font *address_font = get_title_font();

    /* Unbold fonts if address becomes too long */
    if(calc_str_width(address_font, address) > TRANSACTION_WIDTH)
    {
        amount_font = get_body_font();
        address_font = get_body_font();
    }

    /* Determine vertical alignment and body width */
    sp.y =  TOP_MARGIN_FOR_ONE_LINE;

    /* Format amount line */
    char title[BODY_CHAR_MAX];
    snprintf(title, BODY_CHAR_MAX, "Send %s to", amount);

    /* Draw amount */
    sp.x = LEFT_MARGIN;
    sp.color = TITLE_COLOR;
    draw_string(canvas, amount_font, title, &sp, TRANSACTION_WIDTH, font_height(amount_font));

    /* Draw address */
    sp.y += font_height(address_font) + TRANSACTION_TOP_MARGIN;
    sp.x = LEFT_MARGIN;
    sp.color = BODY_COLOR;
    draw_string(canvas, address_font, address, &sp, TRANSACTION_WIDTH,
                font_height(address_font) + BODY_FONT_LINE_PADDING);

    layout_notification_icon(type, &sp);
}
Пример #13
0
static
void window_redraw(Window *w, Graphics *g)
{
  Rect r;
  Point p;
  int l, h;
  int length;
  char *buffer;

  assert(lines != NULL);
  /* Each wide char is encoded in at most 6 UTF8 characters. For the Base Plane,
   * 3 UTF8 characters per Unicode character is enough
   */
  buffer = malloc((6 * NUM_COLUMNS + 1) * sizeof(char));
  if (buffer != NULL) {
    r = get_window_area(w);

    set_rgb(g, rgb(240,240,240)); //??? attrib
    fill_rect(g, r);

    set_rgb(g, rgb(0,0,0));       //??? attrib
    set_font(g, font);
    set_text_direction(g, LR_TB);
    p = pt(0,0);
    h = font_height(font);
    for (l = 0; l < NUM_LINES; l++) {
      #if defined _UNICODE
        /* convert the line to UTF8 */
        int c;
        char *ptr;
        for (c = 0, ptr = buffer; c < NUM_COLUMNS; c++)
          amx_UTF8Put(ptr, &ptr, 6, lines + l * NUM_COLUMNS + c);
        *ptr = '\0';
        length = (int)(ptr - buffer);
      #else
        /* assume line is ASCII */
        memcpy(buffer, lines + l * NUM_COLUMNS, NUM_COLUMNS);
        buffer[NUM_COLUMNS] = '\0';
        length = NUM_COLUMNS;
      #endif

      /* draw the line */
      draw_utf8(g, p, buffer, length);
      p.y += h;
      if (p.y > r.height)
        break;
    } /* if */

    free(buffer);
  } /* if */
}
Пример #14
0
int createconsole(int argc, char *argv[])
{
  if (win != NULL)
    return 1;

  if (app != NULL)      /* delete existing partial data structures */
    deleteconsole();

  lines = malloc(NUM_LINES*NUM_COLUMNS*sizeof(TCHAR));
  if (lines == NULL)
    return 0;
  memset(lines, __T(' '), NUM_LINES * NUM_COLUMNS);

  app = new_app(argc, argv);
  if (app == NULL) {
    deleteconsole();
    return 0;
  } /* if */

  font = new_font(app, "unifont", PLAIN | PORTABLE_FONT, 16);
  if (font == NULL)
    font = new_font(app, "courier", PLAIN | NATIVE_FONT, 16);
  if (font == NULL)
    font = find_default_font(app);
  if (font == NULL) {
    deleteconsole();
    return 0;
  } /* if */

  win = new_window(app,
                   rect(0,0,
                        NUM_COLUMNS*font_width(font,"x",1),
                        NUM_LINES*font_height(font)),
                   "Pawn console",
                   TITLEBAR|CLOSEBOX|MAXIMIZE|MINIMIZE|CENTRED);
  on_window_redraw(win, window_redraw);
  on_window_close (win, window_close);
  on_window_key_down(win, window_key_action);     /* normal keys (including CR) */
  show_window(win);

  /* handle any pending events */
  while (do_event(app))
    /* nothing */;

  csrx = 0;
  csry = 0;
  autowrap = 0;
  attrib = 0x07;

  return 1;
}
Пример #15
0
static void refresh_screen(int top, int bottom)
{
  Rect r;
  int h;

  if (top != bottom) {
    assert(win != NULL);
    r = get_window_area(win);
    assert(font != NULL);
    h = font_height(font);
    redraw_rect(win, rect(0, top * h, r.width, (bottom - top) * h));
  } /* if */

  //??? set to draw a caret
}
Пример #16
0
void put_string_tkiz(ofstream& output,
		     const long double& x, const long double& y,
		     const string & comment, const string & str)
{
  if (str.size() == 0)
    return;

  output << endl
	 << "%    " << comment << endl
	 << "\\draw (" << x << "mm," 
            /* Se ajusta la posicion y del caracter segun si la
	       impresion es flip o no */   
	 << (flip_y ? YPIC(y) - font_height() : YPIC(y))
	 << "mm) node { " << str << " }" << endl << endl;
}
Пример #17
0
/* Create the messagebox */
static void intro_message (char *msg)
{
    intr_message.show = 1;
    /* Make the messagebox */
    if (intr_message.text)
        SDL_FreeSurface (intr_message.text);
    intr_message.text = renderstring (Bigfont, msg, font_color_white);
    intr_message.x = screen->w / 2 - intr_message.text->w / 2 - 25;
    intr_message.y = screen->h / 2 - intr_message.text->h / 2 - 10;
    intr_message.w = intr_message.text->w + 50;
    intr_message.h = intr_message.text->h + 20;
    intr_message.textrect.x =
        intr_message.x + intr_message.w / 2 - intr_message.text->w / 2;
    intr_message.textrect.y =
        intr_message.y + intr_message.h / 2 - font_height (Bigfont) / 2;
}
Пример #18
0
static int l_textbox_unhighlight(lua_State *L)
{
	int lineno;
	l_textbox *tb;

	tb = l_checkTextbox(L, 1);
	lineno = luaL_checkint(L, 2);

	/* Make sure the line number is in the window */
	if (lineno * font_height(tb->font) >= tb->s->h)
		return 0;

	_textbox_highlight(tb, HG_INDEX, BG_INDEX, lineno);
	
	return 0;
}
Пример #19
0
/* dx = in columns, dy = in lines */
void scroll_window(int dx, int dy)
{
  Graphics *g;
  Rect r;
  Point p;

  /* a negative value scrolls up */
  assert(lines != NULL);
  if (dy < 0) {
    assert(-dy < NUM_LINES);
    memmove(lines,lines-dy*NUM_COLUMNS,(NUM_LINES+dy)*NUM_COLUMNS*sizeof(TCHAR));
    memset(lines+(NUM_LINES+dy)*NUM_COLUMNS*sizeof(TCHAR), __T(' '), -dy*NUM_COLUMNS);
  } else if (dy > 0) {
    assert(dy < NUM_LINES);
    memmove(lines+dy*NUM_COLUMNS,lines,(NUM_LINES-dy)*NUM_COLUMNS*sizeof(TCHAR));
    memset(lines, __T(' '), dy*NUM_COLUMNS);
  } /* if */
  csry += dy;
  if (csry < 0)
    csry = 0;
  if (csry >= NUM_LINES)
    csry=NUM_LINES - 1;

  assert(font != NULL);
  dx *= font_width(font, "x", 1);
  dy *= font_height(font);

  g = get_window_graphics(win);
  r = get_window_area(win);
  p = pt(r.x + dx, r.y + dy);
  copy_rect(g, p, g, r);
  if (dy > 0) {
    /* moving window contents downwards */
    redraw_rect(win, rect(0,0,r.width,dy));
  } else if (dy < 0) {
    /* moving window contents upwards */
    redraw_rect(win, rect(0,r.height+dy,r.width,0-dy));
  } /* if */
  if (dx > 0) {
    /* moving window contents to the right */
    redraw_rect(win, rect(0,0,dx,r.height));
  } else if (dx < 0) {
    /* moving window contents to the left */
    redraw_rect(win, rect(r.width+dx,0,0-dx,r.height));
  } /* if */
  del_graphics(g);
}
Пример #20
0
/* Draw the header bar common to all selection screens */
static void draw_header(SDL_Surface *surface, const char *title) {
    SDL_Rect rect;
    rect.x = 0; rect.y = 0;
    rect.w = screen->w; rect.h = HEADER_HEIGHT;
    SDL_FillRect(surface,&rect,SDL_MapRGB(surface->format,220,220,220));

    putstring_direct(surface,Bigfont,10,
            HEADER_HEIGHT/2-font_height(Bigfont)/2,title, font_color_blue);

    if(game_status.lastwin > 0) {
        SDL_Rect trophy_rect;
        trophy_rect.x = screen->w - trophy_gfx[game_status.lastwin-1]->w - 20;
        trophy_rect.y = 16;
        SDL_BlitSurface (trophy_gfx[game_status.lastwin - 1], NULL, surface,
                         &trophy_rect);
    }
}
Пример #21
0
int dgreed_main(int argc, const char** argv) {
	params_init(argc, argv);
	rand_init(time(NULL));
	layouts_init();
	layouts_set("dvorak");

	bool fullscreen = true;
	if(params_find("-windowed") != ~0)
		fullscreen = false;

	video_init_ex(SCREEN_WIDTH, SCREEN_HEIGHT, 
		SCREEN_WIDTH, SCREEN_HEIGHT, "KeyMingler", fullscreen);
	font = font_load(FONT_FILE);	
	float text_width = font_width(font, LOADING_TEXT);
	float text_height = font_height(font);
	Vector2 pos = vec2((SCREEN_WIDTH - text_width) / 2.0f,
		(SCREEN_HEIGHT - text_height) / 2.0f);
	font_draw(font, LOADING_TEXT, 0, &pos, COLOR_WHITE);	
	video_present();
	system_update();

	game_init();
	sounds_init();
	music = sound_load_stream(MUSIC_FILE);
	sound_play(music);

	while(system_update()) {
		game_update();
		game_render();
		video_present();
		sound_update();

		if(key_up(KEY_QUIT))
			break;
	}
	
	font_free(font);
	sound_free(music);
	sounds_close();
	game_close();
	video_close();
	layouts_close();

	return 0;
}
Пример #22
0
/*
 * l_textbox_clearline()
 * Clear the line that the cursor is on
 */
static int l_textbox_clearline(lua_State *L)
{
	l_textbox *tb;
	SDL_Rect srect;

	tb = l_checkTextbox(L, 1);

	srect.x = 0;
	srect.y = tb->y;
	srect.w = tb->rect->w;
	srect.h = font_height(tb->font);
	if (SDL_FillRect(tb->s, &srect, BG_INDEX))
		sdl_error(L);

	_update_screen(tb);

	return 0;
}
Пример #23
0
/*
 * layout_pin() - Draws pin matrix
 *
 * INPUT
 *     - str: string prompt to display next to pin matrix
 *     - pin: randomized pin matric
 * OUTPUT
 *     none
 */
void layout_pin(const char *str, char pin[])
{
    DrawableParams sp;
    Canvas *canvas = layout_get_canvas();

    call_leaving_handler();
    layout_clear();

    /* Draw prompt */
    const Font *font = get_body_font();
    sp.y = 29;
    sp.x = (140 - calc_str_width(font, str)) / 2;
    sp.color = BODY_COLOR;
    draw_string(canvas, font, str, &sp, TITLE_WIDTH, font_height(font));
    display_refresh();

    /* Animate pin scrambling */
    layout_add_animation(&layout_animate_pin, (void *)pin, PIN_MAX_ANIMATION_MS);
}
Пример #24
0
/* Draw a single weapon selection bar */
static SDL_Rect draw_weapon_bar(SDL_Surface *surface,int plr) {
    SDL_Rect rect;
    Uint32 color;
    int i,plrs=0;
    switch(plr) {
        case 0: color = map_rgba(156,0,0,255); break;
        case 1: color = map_rgba(0,0,156,255); break;
        case 2: color = map_rgba(0,156,0,255); break;
        case 3: color = map_rgba(156,156,0,255); break;
        default: color = 0;
    }

    rect.x = 0; rect.w = screen->w/4-WEAPON_SEP;
    rect.h = font_height(Bigfont);

    rect.y = 0;
    for(i=0;i<4;i++) {
        if(players[i].state != INACTIVE) {
            plrs++;
            if(i<plr) rect.y += rect.h + WEAPON_SEP;
        }
    }

    rect.y += screen->h/2 - ((rect.h + WEAPON_SEP) * plrs)/2;

    fill_box(surface,rect.x,rect.y,rect.w,rect.h,color);

    putstring_direct(surface, Bigfont, rect.x + 10, rect.y,
            normal_weapon[players[plr].standardWeapon].name, font_color_white);

    rect.x = rect.w + WEAPON_SEP;
    rect.w = screen->w - rect.x;

    fill_box(surface,rect.x,rect.y,rect.w,rect.h,color);

    putstring_direct(surface, Bigfont, rect.x + 10, rect.y,
            special_weapon[players[plr].specialWeapon].name, font_color_white);

    rect.x = 0;
    rect.w = screen->w;

    return rect;
}
Пример #25
0
void put_string(ofstream& output,
		const long double& x, const long double& y,
		const string & comment, const string & str)
{
  if (str.size() == 0)
    return;

  output << endl
	 << "%    " << comment << endl
	 << "\\put(" << x << "," 
            /* Se ajusta la posicion y del caracter segun si la
	       impresion es flip o no */   
	 << (flip_y ? YPIC(y) - font_height() : YPIC(y))
	 << "){" ;
  if (tiny_keys)
    output << font_wrapper << "{\\tiny " << str << "}}}" << endl << endl;
  else
    output << font_wrapper << str << "}}" << endl << endl;
}
Пример #26
0
static void DrawScore(struct state *st, int xlim, int ylim)
{
  char buf[16];
  int width, height;
  sprintf(buf, "%ld", st->score);
  width = XTextWidth(st->scoreFont, buf, strlen(buf));
  height = font_height(st->scoreFont);
  XSetForeground (st->dpy, st->draw_gc, st->scoreColor.pixel);
  XFillRectangle(st->dpy, st->window, st->erase_gc,
				  xlim - width - 6, ylim - height - 2, width + 6, height + 2);
  XDrawString(st->dpy, st->window, st->draw_gc, xlim - width - 2, ylim - 2,
		    buf, strlen(buf));

  sprintf(buf, "%ld", st->highscore);
  width = XTextWidth(st->scoreFont, buf, strlen(buf));
  XFillRectangle(st->dpy, st->window, st->erase_gc,
				  4, ylim - height - 2, width + 4, height + 2);
  XDrawString(st->dpy, st->window, st->draw_gc, 4, ylim - 2,
		    buf, strlen(buf));
}
Пример #27
0
static void test_setitemheight(DWORD style)
{
    HWND hCombo = build_combo(style);
    RECT r;
    int i;

    trace("Style %x\n", style);
    GetClientRect(hCombo, &r);
    expect_rect(r, 0, 0, 100, font_height(GetStockObject(SYSTEM_FONT)) + 8);
    SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
    MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
    todo_wine expect_rect(r, 5, 5, 105, 105);

    for (i = 1; i < 30; i++)
    {
        SendMessage(hCombo, CB_SETITEMHEIGHT, -1, i);
        GetClientRect(hCombo, &r);
        expect_eq(r.bottom - r.top, i + 6, int, "%d");
    }

    DestroyWindow(hCombo);
}
Пример #28
0
static void NewLevel(struct state *st, int xlim, int ylim)
{
  char buf[32];
  int width, i, sumlive = 0;
  int liv[kNumCities];
  int freecity = 0;

  if (st->level == 0) {
	 st->level++;
	 goto END_LEVEL;
  }

  /* check for a free city */
  if (st->score >= st->nextBonus) {
	 st->numBonus++;
	 st->nextBonus += kFirstBonus * st->numBonus;
	 freecity = 1;
  }

  for (i=0;i<kNumCities;i++) {
	 if (st->bround)
		st->city[i].alive = st->blive[i];
	 liv[i] = st->city[i].alive;
	 sumlive += liv[i];
	 if (!st->bround)
		st->city[i].alive = 0;
  }

  /* print out screen */
  XFillRectangle(st->dpy, st->window, st->erase_gc,
				  0, 0, xlim, ylim);
  if (st->bround)
	 sprintf(buf, "Bonus Round Over");
  else {
	 if (sumlive || freecity)
		sprintf(buf, "Level %d Cleared", st->level);
	 else
		sprintf(buf, "GAME OVER");
  }
  if (st->level > 0) {
	 width = XTextWidth(st->font, buf, strlen(buf));
	 XDrawString(st->dpy, st->window, st->level_gc, xlim / 2 - width / 2, ylim / 2 - font_height(st->font) / 2,
					 buf, strlen(buf));
	 XSync(st->dpy, False);
	 usleep(1000000);
  }

  if (!st->bround) {
	 if (sumlive || freecity) {
		int sumwidth;
		/* draw live cities */
		XFillRectangle(st->dpy, st->window, st->erase_gc,
							0, ylim - 100, xlim, 100);

		sprintf(buf, "X %ld", st->level * 100L);
		/* how much they get */
		sumwidth = XTextWidth(st->font, buf, strlen(buf));
		/* add width of city */
		sumwidth += 60;
		/* add spacer */
		sumwidth += 40;
		DrawCity(st, xlim / 2 - sumwidth / 2 + 30, ylim * 0.70, st->city[0].color);
		XDrawString(st->dpy, st->window, st->level_gc, xlim / 2 - sumwidth / 2 + 40 + 60, ylim * 0.7, buf, strlen(buf));
		for (i=0;i<kNumCities;i++) {
		  if (liv[i]) {
			 st->city[i].alive = 1;
			 AddScore(st, xlim, ylim, 100 * st->level);
			 DrawCities(st, xlim, ylim);
			 XSync(st->dpy, False);
			 usleep(kCityPause);
		  }
		}
	 }
	 else {
		/* we're dead */
		usleep(3000000);

		/* start new */
		st->gamez++;
		Improve(st);
		for (i=0;i<kNumCities;i++)
		  st->city[i].alive = 1;
		st->level = 0;
		st->loop = 1;
		st->score = 0;
		st->nextBonus = kFirstBonus;
		st->numBonus = 0;
		DrawCities(st, xlim, ylim);
	 }
  }

  /* do free city part */
  if (freecity && sumlive < 5) {
	 int ncnt = random() % (5 - sumlive) + 1;
	 for (i=0;i<kNumCities;i++)
		if (!st->city[i].alive)
		  if (!--ncnt)
			 st->city[i].alive = 1;
	 strcpy(buf, "Bonus City");
	 width = XTextWidth(st->font, buf, strlen(buf));
	 XDrawString(st->dpy, st->window, st->level_gc, xlim / 2 - width / 2, ylim / 4, buf, strlen(buf));
	 DrawCities(st, xlim, ylim);
	 XSync(st->dpy, False);
	 usleep(1000000);
  }

  XFillRectangle(st->dpy, st->window, st->erase_gc,
					  0, 0, xlim, ylim - 100);
  
  if (!st->bround)
	 st->level++;
  if (st->level == 1) {
	 st->nextBonus = kFirstBonus;
  }

  if (st->level > 3 && (st->level % 5 == 1)) {
	 if (st->bround) {
		st->bround = 0;
		DrawCities(st, xlim, ylim);
	 }
	 else {
		/* bonus round */
		st->bround = 1;
		st->levMissiles = 20 + st->level * 10;
		st->levFreq = 10;
		for (i=0;i<kNumCities;i++)
		  st->blive[i] = st->city[i].alive;
		sprintf(buf, "Bonus Round");
		width = XTextWidth(st->font, buf, strlen(buf));
		XDrawString(st->dpy, st->window, st->level_gc, xlim / 2 - width / 2, ylim / 2 - font_height(st->font) / 2, buf, strlen(buf));
		XSync(st->dpy, False);
		usleep(1000000);
		XFillRectangle(st->dpy, st->window, st->erase_gc,
							0, 0, xlim, ylim - 100);
	 }
  }

 END_LEVEL: ;

  if (!st->bround) {
	 st->levMissiles = 5 + st->level * 3;
	 if (st->level > 5)
		st->levMissiles += st->level * 5;
	 /*  levMissiles = 2; */
	 st->levFreq = 120 - st->level * 5;
	 if (st->levFreq < 30)
		st->levFreq = 30;
  }

  /* ready to fire */
  st->lastLaser = 0;
}
Пример #29
0
static Bool
NumberScreen(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	puzzlestruct *pp = &puzzles[MI_SCREEN(mi)];

	if (mode_font == None)
		mode_font = getFont(display);
	if (!pp->done) {
		XGCValues   gcv;

		pp->done = 1;
		gcv.font = mode_font->fid;
		gcv.graphics_exposures = False;
		gcv.foreground = MI_WHITE_PIXEL(mi);
		gcv.background = MI_BLACK_PIXEL(mi);
		if ((pp->gc = XCreateGC(display, window,
				GCForeground | GCBackground | GCGraphicsExposures | GCFont,
				&gcv)) == None) {
			free_puzzle(display, pp);
			return False;
		}
		pp->ascent = mode_font->ascent;
		pp->fontHeight = font_height(mode_font);
		pp->fontWidth = font_width(mode_font, '5');
	}
	XSetForeground(display, pp->gc, MI_WHITE_PIXEL(mi));

	{
		XPoint      pos, letter;
		int         count = 1, digitOffset = 1, temp, letterOffset;
		int         i, j, mult = pp->count.x * pp->count.y;
		char        buf[16];

		letter.x = pp->boxsize.x / 2 - 3;
		letter.y = pp->boxsize.y / 2 + pp->ascent / 2 - 1;
		letterOffset = pp->fontWidth / 2;
		pos.y = 0;
		for (j = 0; j < pp->count.y; j++) {
			pos.x = 0;
			for (i = 0; i < pp->count.x; i++) {
				if (count < mult) {
					if (pp->boxsize.x > 2 * pp->fontWidth &&
					    pp->boxsize.y > pp->fontHeight) {
						(void) sprintf(buf, "%d", count);
						(void) XDrawString(display, window, pp->gc,
								   pos.x + letter.x - letterOffset * digitOffset +
							     pp->randompos.x,
								   pos.y + letter.y + pp->randompos.y, buf, digitOffset);
					}
					XDrawRectangle(display, window, pp->gc,
						       pos.x + 1 + pp->randompos.x, pos.y + 1 + pp->randompos.y,
					pp->boxsize.x - 3, pp->boxsize.y - 3);
					count++;
					digitOffset = 0;
					temp = count;
					while (temp >= 1) {
						temp /= 10;
						digitOffset++;
					}
				}
				pos.x += pp->boxsize.x;
			}
			pos.y += pp->boxsize.y;
		}
	}
	return True;
}
Пример #30
0
static void test_setfont(DWORD style)
{
    HWND hCombo;
    HFONT hFont1, hFont2;
    RECT r;
    int i;

    if (!is_font_installed("Marlett"))
    {
        skip("Marlett font not available\n");
        return;
    }

    trace("Style %x\n", style);

    hCombo = build_combo(style);
    hFont1 = CreateFont(10, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
    hFont2 = CreateFont(8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");

    GetClientRect(hCombo, &r);
    expect_rect(r, 0, 0, 100, font_height(GetStockObject(SYSTEM_FONT)) + 8);
    SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
    MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
    todo_wine expect_rect(r, 5, 5, 105, 105);

    /* The size of the dropped control is initially equal to the size
       of the window when it was created.  The size of the calculated
       dropped area changes only by how much the selection area
       changes, not by how much the list area changes.  */
    if (font_height(hFont1) == 10 && font_height(hFont2) == 8)
    {
        SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
        GetClientRect(hCombo, &r);
        expect_rect(r, 0, 0, 100, 18);
        SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
        MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
        todo_wine expect_rect(r, 5, 5, 105, 105 - (font_height(GetStockObject(SYSTEM_FONT)) - font_height(hFont1)));

        SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont2, FALSE);
        GetClientRect(hCombo, &r);
        expect_rect(r, 0, 0, 100, 16);
        SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
        MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
        todo_wine expect_rect(r, 5, 5, 105, 105 - (font_height(GetStockObject(SYSTEM_FONT)) - font_height(hFont2)));

        SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
        GetClientRect(hCombo, &r);
        expect_rect(r, 0, 0, 100, 18);
        SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
        MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
        todo_wine expect_rect(r, 5, 5, 105, 105 - (font_height(GetStockObject(SYSTEM_FONT)) - font_height(hFont1)));
    }
    else
    {
        ok(0, "Expected Marlett font heights 10/8, got %d/%d\n",
           font_height(hFont1), font_height(hFont2));
    }

    for (i = 1; i < 30; i++)
    {
        HFONT hFont = CreateFont(i, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
        int height = font_height(hFont);

        SendMessage(hCombo, WM_SETFONT, (WPARAM)hFont, FALSE);
        GetClientRect(hCombo, &r);
        expect_eq(r.bottom - r.top, height + 8, int, "%d");
        SendMessage(hCombo, WM_SETFONT, 0, FALSE);
        DeleteObject(hFont);
    }

    DestroyWindow(hCombo);
    DeleteObject(hFont1);
    DeleteObject(hFont2);
}