mirror of
https://github.com/simtactics/niotso.git
synced 2025-07-04 05:37:02 -04:00
* License header formatting change
* New IFF chunk formats supported: CST, FBMP, CATS * Rebranded libfar to simply far * Started preliminary work on the hitutils package
This commit is contained in:
parent
55659f43b5
commit
bc51bb4aad
96 changed files with 2321 additions and 424 deletions
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
Niotso - The New Implementation of The Sims Online
|
||||
Graphics/Font.cpp
|
||||
Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -25,25 +28,25 @@ FT_Face FontFace;
|
|||
static void FindStringSize(const wchar_t * String, unsigned * width, unsigned * height, int * xoffset, int * yoffset, int font){
|
||||
int x = 0, y = 0;
|
||||
int lowestx = 0, lowesty = 0, highestx = 0, highesty = 0;
|
||||
|
||||
|
||||
for(wchar_t letter=*String; letter!='\0'; letter=*(++String)){
|
||||
int error = FT_Load_Char(FontFace, letter, FT_LOAD_RENDER);
|
||||
if(error) continue;
|
||||
|
||||
|
||||
int bottomx = x + FontFace->glyph->bitmap_left;
|
||||
int bottomy = y + FontFace->glyph->bitmap_top - FontFace->glyph->bitmap.rows;
|
||||
if(bottomx < lowestx) lowestx = bottomx;
|
||||
if(bottomy < lowesty) lowesty = bottomy;
|
||||
|
||||
|
||||
int topx = x + FontFace->glyph->bitmap_left + FontFace->glyph->bitmap.width;
|
||||
int topy = y + FontFace->glyph->bitmap_top;
|
||||
if(topx > highestx) highestx = topx;
|
||||
if(topy > highesty) highesty = topy;
|
||||
|
||||
|
||||
x += FontFace->glyph->advance.x >> 6;
|
||||
y += FontFace->glyph->advance.y >> 6;
|
||||
}
|
||||
|
||||
|
||||
*width = highestx-lowestx, *height = highesty-lowesty;
|
||||
*xoffset = -lowestx, *yoffset = -lowesty;
|
||||
}
|
||||
|
@ -53,14 +56,14 @@ void DrawText(Image_t * Image, const wchar_t * String, int x, int y, unsigned wi
|
|||
//x, y, width, height form the bounding rectangle into which the text should be drawn.
|
||||
//(x,y) defines the offset to the top-left of the rectangle from the top left of the background.
|
||||
//The destination image must be stored in bottom-up order.
|
||||
|
||||
|
||||
if(x >= (signed)Image->Width || y >= (signed)Image->Height) return;
|
||||
|
||||
//(stringx,stringy) will refer to the top-left of the string in bottom-up coordinates
|
||||
int stringx, stringy;
|
||||
unsigned StringWidth, StringHeight;
|
||||
FindStringSize(String, &StringWidth, &StringHeight, &stringx, &stringy, font);
|
||||
|
||||
|
||||
//Horizontal alignment
|
||||
if(Alignment < 2) stringx = x; //Left
|
||||
else if(Alignment < 4) stringx = x+(width-StringWidth+1)/2; //Middle
|
||||
|
@ -69,17 +72,17 @@ void DrawText(Image_t * Image, const wchar_t * String, int x, int y, unsigned wi
|
|||
if(!(Alignment&1)) stringy = y; //Top
|
||||
else stringy = y+(height-StringHeight+1)/2; //Middle
|
||||
stringy = Image->Height-stringy-StringHeight;
|
||||
|
||||
|
||||
//Now that we've done the alignment, we can crop the bounding box within the limits of the background image
|
||||
if(x < 0){ Image->Width += x; x = 0; }
|
||||
if(y < 0){ Image->Height += y; y = 0; }
|
||||
if(width > Image->Width) width = Image->Width;
|
||||
if(height > Image->Height) height = Image->Height;
|
||||
|
||||
|
||||
for(wchar_t letter=*String; letter!='\0'; letter=*(++String)){
|
||||
int error = FT_Load_Char(FontFace, letter, FT_LOAD_RENDER);
|
||||
if(error) continue;
|
||||
|
||||
|
||||
int cWidth = FontFace->glyph->bitmap.width, cHeight = FontFace->glyph->bitmap.rows;
|
||||
if(cWidth && cHeight){
|
||||
uint8_t * cRender; /* Convert to Bottom-up */
|
||||
|
@ -108,7 +111,7 @@ void DrawText(Image_t * Image, const wchar_t * String, int x, int y, unsigned wi
|
|||
}
|
||||
stringx -= FontFace->glyph->bitmap_left;
|
||||
stringy -= FontFace->glyph->bitmap_top-cHeight;
|
||||
|
||||
|
||||
if(FontFace->glyph->bitmap.pitch > 0) free(cRender);
|
||||
}
|
||||
stringx += FontFace->glyph->advance.x >> 6;
|
||||
|
@ -123,7 +126,7 @@ Image_t * StringImage(const wchar_t * String, int font, COLORREF Color){
|
|||
unsigned StringWidth, StringHeight;
|
||||
int stringx, stringy;
|
||||
FindStringSize(String, &StringWidth, &StringHeight, &stringx, &stringy, font);
|
||||
|
||||
|
||||
Image->Data = (uint8_t*) malloc(4 * StringWidth * StringHeight);
|
||||
if(Image->Data == NULL){
|
||||
free(Image);
|
||||
|
@ -135,11 +138,11 @@ Image_t * StringImage(const wchar_t * String, int font, COLORREF Color){
|
|||
Image->Data[i++] = GetRValue(Color);
|
||||
Image->Data[i++] = 0;
|
||||
}
|
||||
|
||||
|
||||
for(wchar_t letter=*String; letter!='\0'; letter=*(++String)){
|
||||
int error = FT_Load_Char(FontFace, letter, FT_LOAD_RENDER);
|
||||
if(error) continue;
|
||||
|
||||
|
||||
int cWidth = FontFace->glyph->bitmap.width, cHeight = FontFace->glyph->bitmap.rows;
|
||||
if(cWidth && cHeight){
|
||||
uint8_t * cRender; /* Convert to Bottom-up */
|
||||
|
@ -160,13 +163,13 @@ Image_t * StringImage(const wchar_t * String, int font, COLORREF Color){
|
|||
}
|
||||
stringx -= FontFace->glyph->bitmap_left;
|
||||
stringy -= FontFace->glyph->bitmap_top-cHeight;
|
||||
|
||||
|
||||
if(FontFace->glyph->bitmap.pitch > 0) free(cRender);
|
||||
}
|
||||
stringx += FontFace->glyph->advance.x >> 6;
|
||||
stringy += FontFace->glyph->advance.y >> 6;
|
||||
}
|
||||
|
||||
|
||||
Image->Width = StringWidth;
|
||||
Image->Height = StringHeight;
|
||||
Image->Format = FIMG_BGRA32;
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
Niotso - The New Implementation of The Sims Online
|
||||
Graphics/Graphics.hpp
|
||||
Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -24,10 +27,10 @@ namespace Graphics {
|
|||
void Shutdown();
|
||||
extern HDC hDC;
|
||||
extern HGLRC hRC;
|
||||
|
||||
|
||||
int InitGL();
|
||||
void ResizeViewport(unsigned width, unsigned height);
|
||||
|
||||
|
||||
enum TextAlignment {
|
||||
ALIGN_LEFT_TOP,
|
||||
ALIGN_LEFT_CENTER,
|
||||
|
@ -36,7 +39,7 @@ namespace Graphics {
|
|||
ALIGN_RIGHT_TOP,
|
||||
ALIGN_RIGHT_CENTER
|
||||
};
|
||||
|
||||
|
||||
//Font.cpp
|
||||
extern FT_Library FreeTypeLibrary;
|
||||
extern FT_Face FontFace;
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
Niotso - The New Implementation of The Sims Online
|
||||
Graphics/Startup.cpp
|
||||
Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -29,7 +32,7 @@ int Initialize(){
|
|||
Shutdown();
|
||||
return ERROR_GRAPHICS_OBTAIN_DC;
|
||||
}
|
||||
|
||||
|
||||
const PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof(PIXELFORMATDESCRIPTOR), 1, //Size and version
|
||||
PFD_DRAW_TO_WINDOW | //dwFlags
|
||||
|
@ -46,7 +49,7 @@ int Initialize(){
|
|||
0, //Reserved
|
||||
0, 0, 0 //Masks
|
||||
};
|
||||
|
||||
|
||||
unsigned PixelFormat = ChoosePixelFormat(hDC, &pfd);
|
||||
if(!PixelFormat){
|
||||
MessageBox(Window::hWnd, "Failed to find a suitable pixel format for the device context.", NULL, MB_OK | MB_ICONERROR);
|
||||
|
@ -59,31 +62,31 @@ int Initialize(){
|
|||
Shutdown();
|
||||
return ERROR_GRAPHICS_SET_PIXELFORMAT;
|
||||
}
|
||||
|
||||
|
||||
hRC = wglCreateContext(hDC);
|
||||
if(!hRC){
|
||||
MessageBox(Window::hWnd, "Failed to create an OpenGL rendering context.", NULL, MB_OK | MB_ICONERROR);
|
||||
Shutdown();
|
||||
return ERROR_GRAPHICS_CREATE_GLRC;
|
||||
}
|
||||
|
||||
|
||||
if(!wglMakeCurrent(hDC, hRC)){
|
||||
MessageBox(Window::hWnd, "Failed to activate the OpenGL device context.", NULL, MB_OK | MB_ICONERROR);
|
||||
Shutdown();
|
||||
return ERROR_GRAPHICS_ACTIVATE_GLRC;
|
||||
}
|
||||
|
||||
|
||||
BOOL (WINAPI *wglSwapIntervalEXT)(int) = (BOOL (WINAPI *)(int)) wglGetProcAddress("wglSwapIntervalEXT");
|
||||
if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
|
||||
int (WINAPI *wglGetSwapIntervalEXT)(void) = (int (WINAPI *)(void)) wglGetProcAddress("wglGetSwapIntervalEXT");
|
||||
if(wglGetSwapIntervalEXT) wglGetSwapIntervalEXT(); //Seems necessary on some cards
|
||||
|
||||
|
||||
int result = InitGL();
|
||||
if(result != 0){
|
||||
Shutdown();
|
||||
return ERROR_GRAPHICS_INIT_GLSCENE | result;
|
||||
}
|
||||
|
||||
|
||||
ResizeViewport(Window::Width, Window::Height);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/*
|
||||
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
|
||||
Niotso - The New Implementation of The Sims Online
|
||||
Graphics/Viewport.cpp
|
||||
Copyright (c) 2012 Niotso Project <http://niotso.org/>
|
||||
Author(s): Fatbag <X-Fi6@phppoll.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue