static void PointSet2D_Draw(GF_Node *node, GF_TraverseState *tr_state) { GF_Path *path; Fixed alpha, w, h; u32 i; SFColor col; DrawableContext *ctx = tr_state->ctx; M_PointSet2D *ps2D = (M_PointSet2D *)node; M_Coordinate2D *coord = (M_Coordinate2D*) ps2D->coord; M_Color *color = (M_Color *) ps2D->color; /*never outline PS2D*/ ctx->flags |= CTX_PATH_STROKE; if (!color || color->color.count<coord->point.count) { /*no texturing*/ visual_2d_draw_path(tr_state->visual, ctx->drawable->path, ctx, NULL, NULL, tr_state); return; } get_point_size(&ctx->transform, &w, &h); path = gf_path_new(); alpha = INT2FIX(GF_COL_A(ctx->aspect.line_color)) / 255; for (i = 0; i < coord->point.count; i++) { col = color->color.vals[i]; ctx->aspect.line_color = GF_COL_ARGB_FIXED(alpha, col.red, col.green, col.blue); gf_path_add_rect_center(path, coord->point.vals[i].x, coord->point.vals[i].y, w, h); visual_2d_draw_path(tr_state->visual, path, ctx, NULL, NULL, tr_state); gf_path_reset(path); ctx->flags &= ~CTX_PATH_FILLED; } gf_path_del(path); }
static void PointSet2D_Draw(DrawableContext *ctx) { LPM4PATH path; Float alpha, w, h; u32 i; SFColor col; M_PointSet2D *ps2D = (M_PointSet2D *)ctx->node->owner; M_Coordinate2D *coord = (M_Coordinate2D*) ps2D->coord; M_Color *color = (M_Color *) ps2D->color; /*never outline PS2D*/ ctx->path_stroke = 1; if (!color || color->color.count<coord->point.count) { /*no texturing*/ VS2D_DrawPath(ctx->surface, ctx->node->path, ctx, NULL, NULL); return; } get_point_size(&ctx->transform, &w, &h); path = m4_new_path(); alpha = (Float) M4C_A(ctx->aspect.line_color) / 255; for (i = 0; i < coord->point.count; i++) { col = color->color.vals[i]; ctx->aspect.line_color = MAKE_ARGB_FLOAT(alpha, col.red, col.green, col.blue); m4_path_add_rectangle(path, coord->point.vals[i].x, coord->point.vals[i].y, w, h); VS2D_DrawPath(ctx->surface, path, ctx, NULL, NULL); m4_path_reset(path); ctx->path_filled = 0; } m4_path_delete(path); }
TextWriter& TextWriter::next_line() { y += std::max(last_line_height, get_point_size()); x = original_x; last_line_height = 0; return *this; }
static void build_graph(Drawable *cs, M4Matrix2D *mat, M_PointSet2D *ps2D) { u32 i; Float w, h; M_Coordinate2D *coord = (M_Coordinate2D *)ps2D->coord; get_point_size(mat, &w, &h); for (i=0; i < coord->point.count; i++) m4_path_add_rectangle(cs->path, coord->point.vals[i].x, coord->point.vals[i].y, w, h); }
static void pointset2d_check_changes(GF_Node *node, Drawable *stack, GF_TraverseState *tr_state) { u32 i; Fixed w, h; M_Coordinate2D *coord; if (!gf_node_dirty_get(node)) return; coord = (M_Coordinate2D *) ((M_PointSet2D *)node)->coord; drawable_reset_path(stack); get_point_size(&tr_state->transform, &w, &h); /*for PS2D don't add to avoid too much antialiasing, just try to fill the given pixel*/ for (i=0; i < coord->point.count; i++) gf_path_add_rect(stack->path, coord->point.vals[i].x, coord->point.vals[i].y, w, h); stack->path->flags |= GF_PATH_FILL_ZERO_NONZERO; gf_node_dirty_clear(node, 0); drawable_mark_modified(stack, tr_state); }
TextWriter::TextWriter(int in_x, int in_y, Renderer &in_renderer, bool in_centered, int in_size, std::wstring fontname) : x(in_x), y(in_y), size(in_size), original_x(0), last_line_height(0), centered(in_centered), renderer(in_renderer) { x += renderer.m_xoffset; original_x = x; y += renderer.m_yoffset; #ifdef WIN32 Context c = renderer.m_context; point_size = MulDiv(size, GetDeviceCaps(c, LOGPIXELSY), 72); HFONT font = 0; if (font_size_lookup[in_size] == 0) { // Set up the LOGFONT structure LOGFONT logical_font; logical_font.lfHeight = get_point_size(); logical_font.lfWidth = 0; logical_font.lfEscapement = 0; logical_font.lfOrientation = 0; logical_font.lfWeight = FW_NORMAL; logical_font.lfItalic = false; logical_font.lfUnderline = false; logical_font.lfStrikeOut = false; logical_font.lfCharSet = ANSI_CHARSET; logical_font.lfOutPrecision = OUT_DEFAULT_PRECIS; logical_font.lfClipPrecision = CLIP_DEFAULT_PRECIS; logical_font.lfQuality = PROOF_QUALITY; logical_font.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; lstrcpy(logical_font.lfFaceName, fontname.c_str()); font = CreateFontIndirect(&logical_font); HFONT previous_font = (HFONT)SelectObject(c, font); wglUseFontBitmaps(c, 0, 128, next_call_list_start); font_size_lookup[in_size] = next_call_list_start; font_handle_lookup[in_size] = font; next_call_list_start += 130; SelectObject(c, previous_font); } #else // TODO: is this sufficient? point_size = size; if (font_size_lookup[size] == 0) { int list_start = glGenLists(128); // MACNOTE: Force Trebuchet MS. It's what we mostly use anyway, but // I want to be sure they have it. const CFStringRef font_name = CFSTR("Trebuchet MS"); ATSFontFamilyRef font = ATSFontFamilyFindFromName(font_name, kATSOptionFlagsDefault); if (!font) throw PianoGameError(WSTRING(L"Couldn't get ATSFontFamilyRef for font '" << WideFromMacString(font_name) << L"'.")); AGLContext context = aglGetCurrentContext(); if (!context) throw PianoGameError(L"Couldn't retrieve OpenGL context while creating font."); GLboolean ret = aglUseFont(context, font, normal, size, 0, 128, list_start); if (ret == GL_FALSE) throw PianoGameError(WSTRING(L"aglUseFont() call failed with error code: " << aglGetError())); font_size_lookup[size] = list_start; // Create the ATSU style object that we'll use for calculating text extents and store it for later. ATSUStyle style; OSStatus status = ATSUCreateStyle(&style); if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't create ATSU style. Error code: " << static_cast<int>(status))); Fixed fixed_size = Long2Fix(size); ATSUAttributeTag tags[] = { kATSUSizeTag }; ByteCount sizes[] = { sizeof(Fixed) }; ATSUAttributeValuePtr values[] = { &fixed_size }; status = ATSUSetAttributes(style, sizeof(sizes) / sizeof(ByteCount), tags, sizes, values); if (status != noErr) throw PianoGameError(WSTRING(L"Couldn't set ATSU style attributes. Error code: " << static_cast<int>(status))); atsu_style_lookup[size] = style; } #endif }