示例#1
0
文件: gui.c 项目: Acknex/Ackmania
void gui_init() {
	panJetpackBorder = pan_create("", 2);
	panJetpackBorder.bmap = bmapJetpackColor;
	panJetpack = pan_create("", 3);
	panJetpack.bmap = bmapJetpackBorder;
	
	panHeart1 = pan_create("", 2);
	panHeart2 = pan_create("", 2);
	panHeart3 = pan_create("", 2);
	panHeart1.bmap = bmapZorroLife;
	panHeart2.bmap = bmapZorroLife;
	panHeart3.bmap = bmapZorroLife;
	txtLifes = txt_create(1, 2);
	set(txtLifes, OUTLINE);
	txtLifes.font = font_create("Arial#32b");
		
	panA4Cube = pan_create("", 2);
	panA4Cube.bmap = bmapA4Cube;
	txtA4Cube = txt_create(1, 3);
	set(txtA4Cube, OUTLINE);
	txtA4Cube.font = font_create("Arial#32b");
	
	txtGameOver = txt_create(1, 10);
	set(txtGameOver, OUTLINE | CENTER_X | CENTER_Y);
	txtGameOver.font = font_create("Arial#90b");
	vec_set(txtGameOver.blue, vector(0,0,255));
	str_cpy((txtGameOver.pstring)[0], "Game Over");
}
示例#2
0
void main ()
{
	video_mode = 8;
	fps_max = 60;
	wait(2);
	bmap_zbuffer ( bmap_createblack(2048,2048,32) );
	mouse_mode = 4;
	mouse_map = bmap_create ( "arrow_yellow.pcx" );
	vec_fill ( &screen_color, 128 );
	
	level_load ( "" );
	camera->pan = -40;
	camera->tilt = -30;
	evnCameraLocate ();
	vec_set ( &colCameraBG, vector(150,150,150) );
	camera->bg = pixel_for_vec ( &colCameraBG, 100, 8888 );
	
	ENTITY *ent = ent_create ( CUBE_MDL, nullvector, NULL );
	
	// Create style for the menues
	// CMMEMBER *myMenuStyle = cmstyle_create ( FONT *font, COLOR *colText, COLOR *colBack, COLOR *colOver )
	FONT *fntTTF = font_create("Arial#16");
	CMStyle *myMenuStyle01 = cmstyle_create ( fntTTF, vector(40,40,40), vector(250,250,250), vector(210,210,210) );
	FONT *fntBitmap = font_create("ackfont.pcx");
	CMStyle *myMenuStyle02 = cmstyle_create ( fntBitmap, vector(170,170,255), vector(30,20,0), vector(0,0,185) );
	
	// Create a compact menu panel
	// PANEL *cmenu_create ( char *chrMember, var pos_x, var pos_y, var size_x, var layer, var flags, CMStyle *style )
	PANEL *myMenu01 = cmenu_create ( "menu name.submenu=txtMain", 110, 20, 200, 1, SHOW, myMenuStyle01 );
	PANEL *myMenu02 = cmenu_create ( "debug & statics.submenu=txtCMDebug", 500, 20, 200, 1, SHOW, myMenuStyle01 );
	
	cmenu_modify ( myMenu02, 120, myMenuStyle02 );
	
	bmpSky = bmap_create ( "sky_fu_256+6.tga" );
	
	while ( !key_esc && !nExit )
	{
		str_setchr ( strString, 1, random(32)+32 );
		wait(1);
	}
	
	bmap_remove ( bmpSky );
	bmpSky = NULL;
	bmap_remove ( mouse_map );
	mouse_map = NULL;
	
	cmenu_remove ( myMenu01 );
	sys_free ( myMenuStyle01 ); 
	font_remove ( fntTTF );
	
	cmenu_remove ( myMenu02 );
	sys_free ( myMenuStyle02 );
	font_remove ( fntBitmap ); 
	
	sys_exit ( NULL );

}
示例#3
0
文件: label.c 项目: Tomy1use/ejoy2d
static const struct dfont_rect *
gen_char(int unicode, const char * utf8, int size) {
	// todo : use large size when size is large
	struct font_context ctx;
	font_create(FONT_SIZE, &ctx);
	if (ctx.font == NULL) {
		return NULL;
	}

	font_size(utf8, unicode, &ctx);
	const struct dfont_rect * rect = dfont_insert(Dfont, unicode, FONT_SIZE, ctx.w+1, ctx.h+1);
	if (rect == NULL) {
		font_release(&ctx);
		return NULL;
	}
	ctx.w = rect->w ;
	ctx.h = rect->h ;
	int buffer_sz = ctx.w * ctx.h;

	ARRAY(uint8_t, buffer, buffer_sz);
	ARRAY(uint8_t, tmp, buffer_sz);

	memset(tmp,0,buffer_sz);
	font_glyph(utf8, unicode, tmp, &ctx);
	gen_outline(ctx.w, ctx.h, tmp, buffer);
//	write_pgm(unicode, ctx.w, ctx.h, buffer);
	font_release(&ctx);

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexSubImage2D(GL_TEXTURE_2D, 0, rect->x, rect->y, rect->w, rect->h, TEX_FMT, GL_UNSIGNED_BYTE, buffer);

	return rect;
}
示例#4
0
文件: label.c 项目: 1414648814/ejoy2d
static struct font_context
char_size(int unicode, const char *utf8, int size, int edge) {
	const struct dfont_rect * rect = dfont_lookup(Dfont,unicode,FONT_SIZE,edge);
	struct font_context ctx;
	font_create(FONT_SIZE, &ctx);
	if (ctx.font == NULL) {
		ctx.w = 0;
		ctx.h = 0;
		return ctx;
	}

	if (rect == NULL) {
		font_size(utf8, unicode, &ctx);
		//see gen_char
		ctx.w += 1;
		ctx.h += 1;
		ctx.w = (ctx.w -1) * size / FONT_SIZE;
		ctx.h = ctx.h * size / FONT_SIZE;
	} else {
		ctx.w = (rect->w -1) * size / FONT_SIZE;
		ctx.h = rect->h * size / FONT_SIZE;
	}
	// font_release should not reset ctx.w/ctx.h
	font_release(&ctx);
	return ctx;
}
示例#5
0
void level_load_ext(STRING* _lvl) {
	if (_lvl != NULL) {
		if (panLoad == NULL) {
			on_level = on_level_event;
			on_level_load = on_level_loaded_event;
			panLoad = pan_create("", 100);
			vec_set(panLoad.blue, vector(8,8,8));
			pan_setdigits(panLoad, 0, 10, 10, "Loading...", font_create("Arial#30b"), 1, vDummy2);
			pan_setcolor(panLoad, 1, 1, vector(255,255,255));
			
			panLoadBar = pan_create("", 101);
			vec_set(panLoadBar.blue, vector(0,0,255));
		}
		
		panLoad.size_x = screen_size.x;
		panLoad.size_y = screen_size.y;
		panLoadBar.size_x = 0;
		panLoadBar.size_y = 40;
		panLoadBar.pos_x = 0;
		panLoadBar.pos_y = screen_size.y - 100;		
		set(panLoad, LIGHT | SHOW);
		set(panLoadBar, LIGHT | SHOW);
		
		wait(1);
		level_load(_lvl);
	}
}
示例#6
0
int bitmap_font_create(bitmap_font_decoder_t *decoder, void *decoder_data,
    uint32_t glyph_count, font_metrics_t font_metrics, uint16_t points,
    font_t **out_font)
{
	if (glyph_count == 0)
		return EINVAL;
	
	bitmap_backend_data_t *data = malloc(sizeof(bitmap_backend_data_t));
	if (data == NULL)
		return ENOMEM;

	data->glyph_count = glyph_count;
	data->points = points;
	data->decoder = decoder;
	data->decoder_data = decoder_data;
	data->font_metrics = font_metrics;
	metric_t line_height = (font_metrics.ascender + font_metrics.descender);
	if (points == line_height) {
		data->scale = false;
		data->scale_ratio = 1.0;
	}
	else {
		data->scale = true;
		data->scale_ratio = ((double) points) / ((double) line_height);
		line_height = (data->scale_ratio * ((double) line_height));
		data->font_metrics.ascender = (metric_t)
		    (data->scale_ratio * data->font_metrics.ascender + 0.5);
		data->font_metrics.descender =
		    line_height - data->font_metrics.ascender;
		data->font_metrics.leading = (metric_t)
		    (data->scale_ratio * data->font_metrics.leading + 0.5);
	}

	data->glyph_cache = calloc(data->glyph_count,
	    sizeof(glyph_cache_item_t));
	if (data->glyph_cache == NULL) {
		free(data);
		return ENOMEM;
	}

	for (size_t i = 0; i < data->glyph_count; ++i) {
		data->glyph_cache[i].surface = NULL;
		data->glyph_cache[i].metrics_loaded = false;
	}

	font_t *font = font_create(&bitmap_backend, data);
	if (font == NULL) {
		free(data->glyph_cache);
		free(data);
		return ENOMEM;
	}
	
	*out_font = font;
	return EOK;
}
示例#7
0
VGFont vegaCreateFont(VGint glyphCapacityHint)
{
   struct vg_context *ctx = vg_current_context();

   if (glyphCapacityHint < 0) {
      vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR);
      return VG_INVALID_HANDLE;
   }

   return (VGFont) font_create(glyphCapacityHint);
}
示例#8
0
文件: label.c 项目: 1414648814/ejoy2d
static const struct dfont_rect *
gen_char(int unicode, const char * utf8, int size, int edge) {
	// todo : use large size when size is large
	struct font_context ctx;
	font_create(FONT_SIZE, &ctx);
	if (ctx.font == NULL) {
		return NULL;
	}

	font_size(utf8, unicode, &ctx);
	const struct dfont_rect * rect = dfont_insert(Dfont, unicode, FONT_SIZE, ctx.w+1, ctx.h+1, edge);
	if (rect == NULL) {
		dfont_flush(Dfont);
		rect = dfont_insert(Dfont, unicode, FONT_SIZE, ctx.w+1, ctx.h+1, edge);
		if (rect == NULL) {
			font_release(&ctx);
			return NULL;
		}
	}
	ctx.w = rect->w ;
	ctx.h = rect->h ;
	int buffer_sz = ctx.w * ctx.h;

	ARRAY(uint8_t, buffer, buffer_sz);
	
#ifdef FONT_EDGE_HASH
  if (edge) {
    ARRAY(uint8_t, tmp, buffer_sz);
    memset(tmp,0,buffer_sz);
    font_glyph(utf8, unicode, tmp, &ctx);
    gen_outline(ctx.w, ctx.h, tmp, buffer);
  } else {
    memset(buffer,0,buffer_sz);
    font_glyph(utf8, unicode, buffer, &ctx);
  }
#else
	ARRAY(uint8_t, tmp, buffer_sz);
	memset(tmp,0,buffer_sz);
	font_glyph(utf8, unicode, tmp, &ctx);
	gen_outline(ctx.w, ctx.h, tmp, buffer);
#endif
	
//	write_pgm(unicode, ctx.w, ctx.h, buffer);
	font_release(&ctx);

	render_texture_subupdate(R, Tex, buffer, rect->x, rect->y, rect->w, rect->h);

	return rect;
}
示例#9
0
文件: text.c 项目: akheron/openomf
int fonts_init() {
    font_create(&font_small);
    font_create(&font_large);
    char filename[64];

    // Load small font
    get_filename_by_id(DAT_CHARSMAL, filename);
    if(font_load(&font_small, filename, FONT_SMALL)) {
        PERROR("Unable to load font file '%s'!", filename);
        return 1;
    }
    INFO("Loaded font file '%s'", filename);

    // Load big font
    get_filename_by_id(DAT_GRAPHCHR, filename);
    if(font_load(&font_large, filename, FONT_BIG)) {
        PERROR("Unable to load font file '%s'!", filename);
        return 1;
    }
    INFO("Loaded font file '%s'", filename);

    // All done.
    return 0;
}
示例#10
0
文件: Menu.c 项目: tobynet/clcl
/*
 * menu_create_font - メニュー用フォントの作成
 */
static HFONT menu_create_font(void)
{
	NONCLIENTMETRICS ncMetrics;

	if (*option.menu_font_name != TEXT('\0')) {
		return font_create(option.menu_font_name, option.menu_font_size, option.menu_font_charset,
			option.menu_font_weight, (option.menu_font_italic == 0) ? FALSE : TRUE, FALSE);
	}

	ncMetrics.cbSize = sizeof(NONCLIENTMETRICS);
	if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
		sizeof(NONCLIENTMETRICS), &ncMetrics, 0) == FALSE) {
		return NULL;
	}
	return CreateFontIndirect(&ncMetrics.lfMenuFont);
}
示例#11
0
/* creates the background */
image_t* create_background()
{
    image_t* img = image_create(VIDEO_SCREEN_W, VIDEO_SCREEN_H);
    font_t *fnt = font_create("disclaimer");
    v2d_t camera = v2d_new(VIDEO_SCREEN_W/2, VIDEO_SCREEN_H/2);

    image_clear(video_get_backbuffer(), image_rgb(0,0,0));
    font_set_width(fnt, VIDEO_SCREEN_W - 6);
    font_set_text(fnt, "%s", text);
    font_set_position(fnt, v2d_new(3,3));
    font_render(fnt, camera);
    image_blit(video_get_backbuffer(), img, 0, 0, 0, 0, image_width(img), image_height(img));

    font_destroy(fnt);
    return img;
}
示例#12
0
objectmachine_t* make_decorator(objectmachine_t *decorated_machine, textoutstyle_t style, const char *font_name, expression_t *xpos, expression_t *ypos, const char *text, expression_t *max_width, expression_t *index_of_first_char, expression_t *length)
{
    objectdecorator_textout_t *me = mallocx(sizeof *me);
    objectdecorator_t *dec = (objectdecorator_t*)me;
    objectmachine_t *obj = (objectmachine_t*)dec;

    obj->init = init;
    obj->release = release;
    obj->update = update;
    obj->render = render;
    obj->get_object_instance = objectdecorator_get_object_instance; /* inherits from superclass */
    dec->decorated_machine = decorated_machine;

    me->style = style;
    me->fnt = font_create(font_name);
    me->xpos = xpos;
    me->ypos = ypos;
    me->text = str_dup(text);
    me->max_width = max_width;
    me->index_of_first_char = index_of_first_char;
    me->length = length;

    return obj;
}
示例#13
0
void game_start()
{
	#ifndef SKIP_INTRO
	
		
		resetPpSwirl ();
		level_load("menu2.wmb");
		wait(3);
		
		setHdr(LVL_INTRO_HDR_STRENGTH, LVL_INTRO_HDR_THRESHOLD, LVL_INTRO_HDR_EXPOSURE);
		
		camera->arc = 60;
		camera->ambient = 0;
		fog_color = 0;
		
		camera_path("path1");
		PANEL* panBlack = pan_create(" ", 100);
		vec_set(panBlack.blue, vector(8,8,8));
		pan_setdigits(panBlack, 0, 5, 5, "Press [Space] to skip", font_create("Arial#24b"), 1, vDummy);
		pan_setcolor(panBlack, 1, 1, vector(255,255,255));
		set(panBlack, SHOW | LIGHT | OVERLAY);
		
		var vMediaHandle = snd_play(g_musicIntro, 100, 0);
		
		while (key_esc || key_space || key_enter)
			wait(1);
		
		while (snd_playing(vMediaHandle) && !key_esc && !key_space && !key_enter)
			wait(1);
		
		proc_kill((void*)camera_path);
		ptr_remove(panBlack);
		
		snd_stop(vMediaHandle);
		vMediaHandle = 0;
	
	#endif
	
	nPlayerLifes = 3;
	flying_man = 0;
	gui_start();
	
	// standard start level = temple
	#ifndef SKIP_TO
		lvlTempleInit();
	#else
		
		#ifdef SKIP_TO_LOTTIFANTLEVEL
			lvlLfInit();
		#endif
	
		#ifdef SKIP_TO_BOSSLEVEL
			lvlBossInit();
		#endif
		
		#ifdef SKIP_TO_LAVASTAGE
			lvlLavastageInit();
		#endif
		
		#ifdef SKIP_TO_CREDITS
			creditsInit();
		#endif
		
	#endif
}
示例#14
0
文件: eg_lp_printer.c 项目: vaplv/lp
int
main(int argc, char** argv)
{
  /* Check command arguments */
  if(argc != 3) {
    printf("usage: %s RB_DRIVER FONT\n", argv[0]);
    return -1;
  }
  const char* driver_name = argv[1];
  const char* font_name = argv[2];

  FILE* file = fopen(driver_name, "r");
  if(!file) {
    fprintf(stderr, "Invalid driver %s\n", driver_name);
    return -1;
  }
  fclose(file);

  file = fopen(font_name, "r");
  if(!file) {
    fprintf(stderr, "Invalid font name %s\n", font_name);
    return -1;
  }
  fclose(file);

  /* Spawn a drawable windows */
  struct wm_device* device = NULL;
  struct wm_window* window = NULL;
  const struct wm_window_desc win_desc =
    { .width = 640, .height = 480, .fullscreen = false };
  WM(create_device(NULL, &device));
  WM(create_window(device, &win_desc, &window));

  /* Create a render backend */
  struct rbi rbi;
  struct rb_context* rb_ctxt = NULL;
  CHECK(rbi_init(driver_name, &rbi), 0);
  RBI(&rbi, create_context(NULL, &rb_ctxt));

  /* Load font resource */
  struct font_system* font_sys = NULL;
  struct font_rsrc* font_rsrc = NULL;
  bool is_font_scalable = false;
  int line_space = 0;
  FONT(system_create(NULL, &font_sys));
  FONT(rsrc_create(font_sys, font_name, &font_rsrc));
  FONT(rsrc_get_line_space(font_rsrc, &line_space));
  FONT(rsrc_is_scalable(font_rsrc, &is_font_scalable));
  if(is_font_scalable) {
    FONT(rsrc_set_size(font_rsrc, 24, 24));
  }

  /* Build x charset description */
  int glyph_min_width = INT_MAX;
  const wchar_t* charset =
    L"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    L" &~\"#'{([-|`_\\^@)]=}+$%*,?;.:/!<>";
  const size_t charset_len = wcslen(charset);
  size_t i = 0;
  struct lp_font_glyph_desc lp_font_glyph_desc_list[512];
  unsigned char* glyph_bitmap_list[512];
  ASSERT(charset_len <= 512);

  for(i = 0; i < charset_len; ++i) {
    struct font_glyph_desc font_glyph_desc;
    struct font_glyph* font_glyph = NULL;
    int width = 0;
    int height = 0;
    int Bpp = 0;

    FONT(rsrc_get_glyph(font_rsrc, charset[i], &font_glyph));

    FONT(glyph_get_desc(font_glyph, &font_glyph_desc));
    glyph_min_width = MIN(font_glyph_desc.width, glyph_min_width);
    lp_font_glyph_desc_list[i].width = font_glyph_desc.width;
    lp_font_glyph_desc_list[i].character = font_glyph_desc.character;
    lp_font_glyph_desc_list[i].bitmap_left = font_glyph_desc.bbox.x_min;
    lp_font_glyph_desc_list[i].bitmap_top = font_glyph_desc.bbox.y_min;

    FONT(glyph_get_bitmap(font_glyph, true, &width, &height, &Bpp, NULL));
    if(width && height ) {
      glyph_bitmap_list[i] = MEM_CALLOC
        (&mem_default_allocator, (size_t)(width*height), (size_t)Bpp);
      NCHECK(glyph_bitmap_list[i], NULL);
      FONT(glyph_get_bitmap
        (font_glyph, true, &width, &height, &Bpp, glyph_bitmap_list[i]));
    }

    lp_font_glyph_desc_list[i].bitmap.width = width;
    lp_font_glyph_desc_list[i].bitmap.height = height;
    lp_font_glyph_desc_list[i].bitmap.bytes_per_pixel = Bpp;
    lp_font_glyph_desc_list[i].bitmap.buffer = glyph_bitmap_list[i];

    FONT(glyph_ref_put(font_glyph));
  }

  /* Create the lp system and font  */
  struct lp* lp = NULL;
  struct lp_font* lp_font = NULL;
  LP(create(&rbi, rb_ctxt, NULL, &lp));
  LP(font_create(lp, &lp_font));
  LP(font_set_data
    (lp_font, line_space, (int)charset_len, lp_font_glyph_desc_list));

  /* Create the printer */
  struct lp_printer* lp_printer = NULL;
  LP(printer_create(lp, &lp_printer));
  LP(printer_set_font(lp_printer, lp_font));
  LP(printer_set_viewport(lp_printer, 0, 0, win_desc.width, win_desc.height));
  enum wm_state esc = WM_STATE_UNKNOWN;
  do {
    int cur[2] = { 0, 0 };

    RBI(&rbi, clear
      (rb_ctxt, RB_CLEAR_COLOR_BIT, (float[]){0.05f, 0.05f, 0.05f}, 0.f, 0));
    LP(printer_print_wstring
      (lp_printer, 50, 70, L">$ ",
       (float[]){0.f, 1.f, 0.f}, cur+0, cur+1));
    LP(printer_print_wstring
      (lp_printer, cur[0], cur[1], L"Hello",
       (float[]){1.f, 1.f, 1.f}, cur+0, cur+1));
示例#15
0
bool
font_resize_capacity(Font_data *data, const size_t size_hint)
{
  assert(data);
  assert(size_hint > data->size); // Will slice data

  // Create new data.
  Font_data new_data;
  const bool created_new = font_create(&new_data, size_hint);

  // Failed to resize.
  if(!created_new)
  {
    font_destroy(&new_data);
    return false;
  }

  // Copy over data
  {
    memcpy(new_data.keys, data->keys, sizeof(uint32_t) * data->size);
    memcpy(new_data.field_name, data->field_name, sizeof(char) * data->size * 32);
    memcpy(new_data.field_font_face, data->field_font_face, sizeof(stbtt_fontinfo) * data->size * 1);
    memcpy(new_data.field_font_bitmap, data->field_font_bitmap, sizeof(Text::Font_bitmap) * data->size * 1);
    memcpy(new_data.field_glyph_texture_id, data->field_glyph_texture_id, sizeof(uint32_t) * data->size * 1);
    memcpy(new_data.field_metric_texture_id, data->field_metric_texture_id, sizeof(uint32_t) * data->size * 1);
  }

  // Swap ptrs
  {
    uint32_t *old_keys = data->keys;
    data->keys = new_data.keys;
    new_data.keys = old_keys;

    char *old_name = data->field_name;
    data->field_name = new_data.field_name;
    new_data.field_name = old_name;

    stbtt_fontinfo *old_font_face = data->field_font_face;
    data->field_font_face = new_data.field_font_face;
    new_data.field_font_face = old_font_face;

    Text::Font_bitmap *old_font_bitmap = data->field_font_bitmap;
    data->field_font_bitmap = new_data.field_font_bitmap;
    new_data.field_font_bitmap = old_font_bitmap;

    uint32_t *old_glyph_texture_id = data->field_glyph_texture_id;
    data->field_glyph_texture_id = new_data.field_glyph_texture_id;
    new_data.field_glyph_texture_id = old_glyph_texture_id;

    uint32_t *old_metric_texture_id = data->field_metric_texture_id;
    data->field_metric_texture_id = new_data.field_metric_texture_id;
    new_data.field_metric_texture_id = old_metric_texture_id;
  }

  // Set the Capacity
  {
    size_t *capacity = const_cast<size_t*>(&data->capacity);
    *capacity = new_data.capacity;
  }

  // Destroy new data
  font_destroy(&new_data);

  return true;
}
示例#16
0
文件: ToolTip.c 项目: tobynet/clcl
/*
 * tooltip_proc - ツールチップ
 */
static LRESULT CALLBACK tooltip_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	NONCLIENTMETRICS ncMetrics;
	PAINTSTRUCT ps;
	DRAWTEXTPARAMS dtp;
	RECT rect;
	POINT pt;
	HDC hdc;
	HFONT hRetFont;
	TOOLTIP_INFO *ti;

	switch (msg) {
	case WM_CREATE:
		if ((ti = mem_calloc(sizeof(TOOLTIP_INFO))) == NULL) {
			return -1;
		}
		if (*option.tooltip_font_name != TEXT('\0')) {
			// フォント作成
			ti->hfont = font_create(option.tooltip_font_name,
				option.tooltip_font_size, option.tooltip_font_charset, option.tooltip_font_weight,
				(option.tooltip_font_italic == 0) ? FALSE : TRUE, FALSE);
		} else {
			ncMetrics.cbSize = sizeof(NONCLIENTMETRICS);
			if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
				sizeof(NONCLIENTMETRICS), &ncMetrics, 0) == TRUE) {
				// デフォルトのフォント作成
				ti->hfont = CreateFontIndirect(&ncMetrics.lfStatusFont);
			}
		}
		// tooltip info to window long
		SetWindowLong(hWnd, GWL_USERDATA, (LPARAM)ti);
		break;

	case WM_CLOSE:
		DestroyWindow(hWnd);
		break;

	case WM_DESTROY:
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) != NULL) {
			if (ti->hfont != NULL) {
				DeleteObject(ti->hfont);
				ti->hfont = NULL;
			}
			if (ti->buf != NULL) {
				mem_free(&ti->buf);
			}
			mem_free(&ti);
		}
		return DefWindowProc(hWnd, msg, wParam, lParam);

	case WM_SETTINGCHANGE:
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL ||
			*option.tooltip_font_name != TEXT('\0') ||
			wParam != SPI_SETNONCLIENTMETRICS) {
			break;
		}
		if (ti->hfont != NULL) {
			DeleteObject(ti->hfont);
			ti->hfont = NULL;
		}
		ncMetrics.cbSize = sizeof(NONCLIENTMETRICS);
		if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
			sizeof(NONCLIENTMETRICS), &ncMetrics, 0) == TRUE) {
			// デフォルトのフォント作成
			ti->hfont = CreateFontIndirect(&ncMetrics.lfStatusFont);
		}
		break;

#ifdef TOOLTIP_ANIMATE
	case WM_PRINT:
		// テキスト描画
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL) {
			break;
		}
		// 非クライアントエリアの描画
		DefWindowProc(hWnd, msg, wParam, lParam);

		// ツールチップの描画
		GetClientRect(hWnd, (LPRECT)&rect);
		SetRect(&rect, rect.left + 1, rect.top + 1, rect.right + 1, rect.bottom + 1);
		tooltip_draw_text(ti, (HDC)wParam, &rect);
		break;
#endif

	case WM_PAINT:
		// テキスト描画
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL) {
			break;
		}
		hdc = BeginPaint(hWnd, &ps);

		// ツールチップの描画
		GetClientRect(hWnd, (LPRECT)&rect);
		tooltip_draw_text(ti, hdc, &rect);

		EndPaint(hWnd, &ps);
		break;

	case WM_MOUSEMOVE:
	case WM_LBUTTONDOWN:
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
	case WM_SETCURSOR:
	case WM_TOOLTIP_HIDE:
		// ツールチップ非表示
		KillTimer(hWnd, ID_SHOW_TIMER);
		KillTimer(hWnd, ID_MOUSE_TIMER);
		ShowWindow(hWnd, SW_HIDE);

		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) != NULL && ti->buf != NULL) {
			mem_free(&ti->buf);
		}
		break;

	case WM_TOOLTIP_SHOW:
		// ツールチップ表示
		KillTimer(hWnd, ID_SHOW_TIMER);
		KillTimer(hWnd, ID_MOUSE_TIMER);
		ShowWindow(hWnd, SW_HIDE);
		if (lParam == 0 ||
			((TOOLTIP_INFO *)lParam)->buf == NULL || *((TOOLTIP_INFO *)lParam)->buf == TEXT('\0')) {
			break;
		}
		if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL) {
			break;
		}

		// 座標設定
		ti->top = ((TOOLTIP_INFO *)lParam)->top;
		ti->pt.x = ((TOOLTIP_INFO *)lParam)->pt.x;
		ti->pt.y = ((TOOLTIP_INFO *)lParam)->pt.y;

		// ウィンドウ取得
		if (ti->pt.x == 0 && ti->pt.y == 0) {
			GetCursorPos(&pt);
			ti->hWnd = WindowFromPoint(pt);
		} else {
			ti->hWnd = NULL;
		}

		// テキスト設定
		if (ti->buf != NULL) {
			mem_free(&ti->buf);
		}
		ti->buf = alloc_copy(((TOOLTIP_INFO *)lParam)->buf);

		// ツールチップ表示
		SetTimer(hWnd, ID_SHOW_TIMER, wParam, NULL);
		break;

	case WM_TIMER:
		switch (wParam) {
		case ID_SHOW_TIMER:
			KillTimer(hWnd, wParam);
			if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL || ti->buf == NULL) {
				SendMessage(hWnd, WM_TOOLTIP_HIDE, 0, 0);
				break;
			}

			// 表示位置取得 (マウス位置)
			if (ti->pt.x == 0 && ti->pt.y == 0) {
				GetCursorPos(&ti->pt);
				ti->top = tooltip_get_cursor_height(GetCursor()) + 1;
				if (ti->hWnd != WindowFromPoint(ti->pt)) {
					SendMessage(hWnd, WM_TOOLTIP_HIDE, 0, 0);
					break;
				}
			}

			// サイズ取得
			hdc = GetDC(hWnd);
			hRetFont = SelectObject(hdc, (ti->hfont != NULL) ? ti->hfont : GetStockObject(DEFAULT_GUI_FONT));
			SetRectEmpty(&rect);

			ZeroMemory(&dtp, sizeof(DRAWTEXTPARAMS));
			dtp.cbSize = sizeof(DRAWTEXTPARAMS);
			dtp.iTabLength = option.tooltip_tab_length;
			DrawTextEx(hdc, ti->buf, lstrlen(ti->buf), &rect,
				DT_CALCRECT | DT_EDITCONTROL | DT_NOCLIP | DT_EXPANDTABS | DT_TABSTOP | DT_NOPREFIX, &dtp);

			SelectObject(hdc, hRetFont);
			ReleaseDC(hWnd, hdc);

			// ウィンドウサイズ設定
			SetRect(&rect,
				ti->pt.x,
				ti->pt.y + ti->top,
				rect.right + (option.tooltip_margin_x * 2) + 2,
				rect.bottom + (option.tooltip_margin_y * 2) + 2);

			// 横位置の補正
			if (rect.left + rect.right > GetSystemMetrics(SM_CXSCREEN)) {
				rect.left = GetSystemMetrics(SM_CXSCREEN) - rect.right;
			}
			if (rect.left < 0) {
				rect.left = 0;
			}

			// 縦位置の補正
			if (rect.top + rect.bottom > GetSystemMetrics(SM_CYSCREEN)) {
				rect.top = ti->pt.y - rect.bottom;
			}
			if (rect.top < 0) {
				rect.top = GetSystemMetrics(SM_CYSCREEN) - rect.bottom;
			}
			if (rect.top < 0) {
				rect.top = 0;
			}

			// ウィンドウの位置とサイズを設定
			SetWindowPos(hWnd, HWND_TOPMOST,
				rect.left, rect.top, rect.right, rect.bottom,
				SWP_NOACTIVATE);

#ifdef TOOLTIP_ANIMATE
			{
				HANDLE user32_lib;
				FARPROC AnimateWindow;
				BOOL effect_flag;

				// ウィンドウ表示
				SystemParametersInfo(SPI_GETTOOLTIPANIMATION, 0, &effect_flag, 0);
				if (effect_flag == TRUE) {
					SystemParametersInfo(SPI_GETTOOLTIPFADE, 0, &effect_flag, 0);
					user32_lib = LoadLibrary(TEXT("user32.dll"));
					if (user32_lib != NULL) {
						AnimateWindow = GetProcAddress(user32_lib, "AnimateWindow");
						if (AnimateWindow != NULL) {
							// アニメーション表示
							AnimateWindow(hWnd, 200, (effect_flag == TRUE) ? AW_BLEND : (AW_SLIDE | AW_VER_POSITIVE));
						}
						FreeLibrary(user32_lib);
					}
				}
			}
#endif
			ShowWindow(hWnd, SW_SHOWNOACTIVATE);
			SetTimer(hWnd, ID_MOUSE_TIMER, MOUSE_INTERVAL, NULL);
			break;

		case ID_MOUSE_TIMER:
			if ((ti = (TOOLTIP_INFO *)GetWindowLong(hWnd, GWL_USERDATA)) == NULL ||
				ti->hWnd == NULL || IsWindowVisible(hWnd) == FALSE) {
				KillTimer(hWnd, wParam);
				break;
			}
			// マウスの下のウィンドウをチェック
			GetCursorPos(&pt);
			if (ti->pt.x != pt.x && ti->pt.y != pt.y && ti->hWnd != WindowFromPoint(pt)) {
				SendMessage(hWnd, WM_TOOLTIP_HIDE, 0, 0);
				break;
			}
			break;
		}
		break;

	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
	}
	return 0;
}
示例#17
0
/*
 * int main(int argc, char **argl)
 *
 * GiN entry point. Initialize variables, structs, video devices, parsing
 * configuration files, setting up parameters, booting up subsystems,
 * and handling the main game loop, as well as cleaning up.
 */
int main(int argc, char **argl)
{
	const char *__err_launcher = "Please run the game through the launcher!";
	const char *__err_language = "Language list cannot be found! Run generate_language_list.exe to let the language definition be generated once.";
	const char *__wrn_lowres   = "The game requires a monitor with a resolution of at least 1,024 x 768. The game will still run, but certain GUI elements won't be displayed correctly.";
	const char *__wrn_lowram   = "You need at least 3 GB RAM in order to play the game. If you're having less than 3 GB RAM, clicking \"OK\" will force the game to run, but it may causes unexpected issues. If you want to quit now, open Task Manager and close the game process.\n\nSorry for the inconvenience.";
	const char *__wrn_redist   = "One or more required DLLs for music playback cannot be found.\n\nOn Steam, try verifying game files and make sure you've installed the redistributable files before launching the game.\n\nitch.io users can launch the game through Launcher.bat.";

	// See if the game was launched through the Go-based launcher.
	#ifndef    DEBUG
		// ASSERT(game_locker_check() != 0, __err_launcher);
	#endif

	if( sys_metrics(0) < 1024.0 && sys_metrics(1) < 768.0 )
		printf(__wrn_lowres);

	if( os_get_ram(S_MB) < 3072 )
		printf(__wrn_lowram);

	String *temp = "";
	str_cat(temp, os_get_system_directory());
	str_cat(temp, "ogg.dll");

	if( !file_exists(temp) )
	{
		printf(__wrn_redist);
	}

	#ifndef    DEBUG
		ASSERT(file_exists("./translation/__language.pad") != 0, __err_language);
	#else
		if( !file_exists("./translation/__language.pad") )
		{
			printf(__err_language);

			sys_exit((void *) 0);
		}
	#endif

	// Overrides some of the global variables (their default values are way too low)
	game_globals_set();

	// mouse_lock(true);

	// Wait for the video device.
	while( !ready() )
		wait(1.0);

	// After the video device is initialized, parse the video configuration file
	// and apply video settings to the current video device, and set the new game title.
	game_video_cfg_parse();
	game_title_set();

	// Exports the game version to the game folder. This is used by the external launcher
	// which uses the file for updating purposes. The completed, released version should
	// have a versioning file ready already.
	__game_version_export();

	// Pops up the GUI to let the user chooses their desired language.
	// After that, a call to nov_region_init() will be invoked to pick the chosen language and perform string initialization.
	nov_region_init("en");

	// Initializes subsystems (game state, GUI, PhysX, ...)
	nov_modules_init();

	// Static initialization.
	nov_gui_static_init();

	// Initializes the scene list, the scenes, and push them into the list.
	nov_scene_list_init();

	game_gui_set_state(STATE_INTRO);
	game_gui_render();

	Vector3 tx;
	tx.x = screen_size.x - 150.0;
	tx.y = 15.0;
	tx.z = 0;

	Text *todo = txt_create(1, LAYER_DEBUG_1);
	todo->font = font_create("UVN remind#30b");

	gui_text_set_color(todo, COLOR_DARK_GREY);
	gui_text_set_pos(todo, __GUIState_singleton->todo_texture->pos_x + 10.0, __GUIState_singleton->todo_texture->pos_y + 10.0);
	gui_text_set_pos(txtSubtitleHandler, (screen_size.x / 2.0) - 156.0, __GUIState_singleton->todo_texture->pos_y + bmap_height(__GUIState_singleton->todo_texture->bmap) + 25.0);

	// Main game loop, which can be terminated with the "Alt + F4" key.
	while(!(__GameState_singleton->exit_switch))
	{
		__GameState_singleton->exit_switch = key_alt && key_f4;

		// Updates PhysX.
		game_physx_loop();

		// Updates the GUI state.
		game_gui_update();

		// Continuously update the area the player is currently in.
		#ifndef    UI_LESS
			if( STATE_NULL == game_gui_get_state() && game_intro_done ) // Because draw_*() functions don't take layers into account,
			                                                            // I have to rely a lot on GUI states in order to manage rendering orders of GUI objects.
			{
				draw_text(game_region_check(), tx.x, tx.y, COLOR_WHITE);
			}
		#endif

		// Updates FOV.
		if( NULL != camera )
		{
			if( !var_cmp(fov, camera->arc) )
				camera->arc = fov;
		}

		// Updates the global volume.
		if( !var_cmp(volume, game_volume) )
			game_volume = volume;

		// Updates the mouse sensivity.
		mickey.x *= sensivity_mul;
		mickey.y *= sensivity_mul;

		if( key_f1 )
		{
			while ( key_f1 ) wait(1.0);
				switch( __invert_y )
				{
					case    1: __invert_y = -1; break;
					case   -1: __invert_y = 1;
				}
		}

		if( key_tab && (STATE_NULL == game_gui_get_state()) )
		{
			switch ( game_day_get() )
			{
				case DAY_3:
				case DAY_4:
				case DAY_5:
				case DAY_6:
				{
					if( (todo->pstring)[0] != lstr_todo_c3 )
						(todo->pstring)[0] = lstr_todo_c3;
					break;
				}

				case DAY_1:
				{
					draw_obj( __GUIState_singleton->todo_texture );

					if( (todo->pstring)[0] != lstr_todo_c1 )
						(todo->pstring)[0] = lstr_todo_c1;
					break;
				}

				case DAY_2:
				{
					draw_obj( __GUIState_singleton->todo_texture );

					if( (todo->pstring)[0] != lstr_todo_c2 )
						(todo->pstring)[0] = lstr_todo_c2;
				}
			}

			draw_obj( todo );
		}

		if( key_esc && __can_press_esc && (game_gui_get_state() != STATE_ENDING) )
		{
			while(key_esc) wait(1.0);

			wait(1.0);

			__GameState_singleton->menu_switch = 1 - __GameState_singleton->menu_switch;

			switch(__GameState_singleton->menu_switch)
			{
				case    1:    game_gui_set_state(STATE_MAIN_MENU); game_gui_render(); break;
				case    0:    game_gui_set_state(STATE_NULL);      game_gui_render();
			}
		}

		wait(1.0);
	}

	RETURN(0);
}
示例#18
0
文件: xlib.c 项目: Tarek-Samy/zahnrad
int
main(int argc, char *argv[])
{
    long dt;
    long started;
    XWindow xw;
    struct demo_gui gui;

    /* Platform */
    UNUSED(argc); UNUSED(argv);
    memset(&xw, 0, sizeof xw);
    xw.dpy = XOpenDisplay(NULL);
    xw.root = DefaultRootWindow(xw.dpy);
    xw.screen = XDefaultScreen(xw.dpy);
    xw.vis = XDefaultVisual(xw.dpy, xw.screen);
    xw.cmap = XCreateColormap(xw.dpy,xw.root,xw.vis,AllocNone);
    xw.swa.colormap = xw.cmap;
    xw.swa.event_mask =
        ExposureMask | KeyPressMask | KeyReleaseMask |
        ButtonPress | ButtonReleaseMask| ButtonMotionMask |
        Button1MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask|
        PointerMotionMask;
    xw.win = XCreateWindow(xw.dpy, xw.root, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, 0,
        XDefaultDepth(xw.dpy, xw.screen), InputOutput,
        xw.vis, CWEventMask | CWColormap, &xw.swa);
    XStoreName(xw.dpy, xw.win, "X11");
    XMapWindow(xw.dpy, xw.win);
    XGetWindowAttributes(xw.dpy, xw.win, &xw.attr);
    xw.width = (unsigned int)xw.attr.width;
    xw.height = (unsigned int)xw.attr.height;
    xw.surf = surface_create(xw.dpy, xw.screen, xw.win, xw.width, xw.height);
    xw.font = font_create(xw.dpy, "fixed");

    /* GUI */
    memset(&gui, 0, sizeof gui);
    zr_command_queue_init_fixed(&gui.queue, calloc(MAX_MEMORY, 1), MAX_MEMORY);
    gui.font.userdata = zr_handle_ptr(xw.font);
    gui.font.height = (zr_float)xw.font->height;
    gui.font.width = font_get_text_width;
    init_demo(&gui);

    while (gui.running) {
        /* Input */
        XEvent evt;
        started = timestamp();
        zr_input_begin(&gui.input);
        while (XCheckWindowEvent(xw.dpy, xw.win, xw.swa.event_mask, &evt)) {
            if (evt.type == KeyPress)
                key(&xw, &gui.input, &evt, zr_true);
            else if (evt.type == KeyRelease) key(&xw, &gui.input, &evt, zr_false);
            else if (evt.type == ButtonPress) btn(&gui.input, &evt, zr_true);
            else if (evt.type == ButtonRelease) btn(&gui.input, &evt, zr_false);
            else if (evt.type == MotionNotify) motion(&gui.input, &evt);
            else if (evt.type == Expose || evt.type == ConfigureNotify)
                resize(&xw, xw.surf);
        }
        zr_input_end(&gui.input);

        /* GUI */
        run_demo(&gui);

        /* Draw */
        XClearWindow(xw.dpy, xw.win);
        surface_clear(xw.surf, 0x00646464);
        draw(xw.surf, &gui.queue);
        surface_blit(xw.win, xw.surf, xw.width, xw.height);
        XFlush(xw.dpy);

        /* Timing */
        dt = timestamp() - started;
        if (dt < DTIME)
            sleep_for(DTIME - dt);
    }

    free(zr_buffer_memory(&gui.queue.buffer));
    font_del(xw.dpy, xw.font);
    surface_del(xw.surf);
    XUnmapWindow(xw.dpy, xw.win);
    XFreeColormap(xw.dpy, xw.cmap);
    XDestroyWindow(xw.dpy, xw.win);
    XCloseDisplay(xw.dpy);
    return 0;
}