Hi! I just coded a set of functions on the SDK. They are meant to cover the lack of TEXT* pointers in C-Script. (Similar functions can be done with panels in C-Script, but not with text objects).
The only function that would need an explanation is dllText_scale(txt,scalefactor). This was meant to scale proportionally both the size and position of the text object.
This allows you to reduce a text that was made for use in a 1024x768 screen in another resolution, say, 800x600 or 640x480 or 1152x864. This would need not only scaling the text but also repositioning it proportionally on the new sreen size. That's what this particular function does.
To calculate the scalefactor, just divide 800/1024 = 0,78125 or 1152/1024 = 1.125. How do you implement this 'video_set' and scale all needed panels and texts is up to you.
The other functions are very simple and easy to understand. There are still some functions to do if needed, par example, dllText_getTranslucent(txt) to get the translucent flag of a text.. but there are enough examples of this on the code, so it will be easy for you to add these functions.
Thanks to TripleX on all help for getting started with this!
Code:
// dllText.cpp
// Text functions
// Written by Emilio Le Roux
#include "stdafx.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
// engine specific header file
#define DLL_USE // always define before including adll.h
#include "adll.h"
#ifdef _MANAGED
#pragma managed(push, off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
engine_bind();
return TRUE;
}
#ifdef _MANAGED
#pragma managed(pop)
#endif
//TXT FLAG DEFINES (use these instead of the generic defines in atypes.h)
#define TXT_NARROW (1<<13) // draw text condensed
#define TXT_CONDENSED (1<<1) //draw text condensed
#define TXT_VISIBLE (1<<14) // visible
#define TXT_TRANSLUCENT (1<<10) //translucent for pcx or bmp only (tga w alpha always translucent)
#define TXT_CENTER_X (1<<8) // center text horizontally - bmp and ttf text
#define TXT_CENTER_Y (1<<9) // center text vertically -bmp text only
#define TXT_FILTER (1<<20) // filter pixels (good for big scaled fonts)
///////////////////////////////////////
// TEXT ACCESS FUNCTIONS
DLLFUNC void dllText_setAlpha(TEXT* txt, var alphavar)
{
if (!txt || !alphavar) return;
txt->alpha = alphavar;
}
DLLFUNC void dllText_setPos (TEXT* txt, var xvar, var yvar)
{
if (!txt || !xvar || !yvar) return;
txt->pos_x = xvar;
txt->pos_y = yvar;
}
DLLFUNC void dllText_setScaleX (TEXT* txt, var scalevar)
{
if (!txt || !scalevar) return;
txt->scale_x = scalevar;
}
DLLFUNC void dllText_setScaleY (TEXT* txt, var scalevar)
{
if (!txt || !scalevar) return;
txt->scale_y = scalevar;
}
//scale XY proportionally (does both of the above)
DLLFUNC void dllText_setScale (TEXT* txt, var scalevar)
{
if (!txt || !scalevar) return;
txt->scale_x = scalevar;
txt->scale_y = scalevar;
}
//Rescales both size and position. Doesn't use the above functions.
DLLFUNC void dllText_scale(TEXT* txt, var scalefactor)
{
if (!txt ) return;
float oldscale = max( float(txt->scale_x),0.0001f); //prevent div error if current scale is zero
float newscale = float(scalefactor)/oldscale; //revert old position rescaling
txt->scale_x = scalefactor;
txt->scale_y = scalefactor; //set scale
txt->pos_x = txt->pos_x * newscale; //adjust position x
txt->pos_y = txt->pos_y * newscale; //adjust position y
}
DLLFUNC var dllText_setString(TEXT* txt, var strindex, char* str)
{
//copy string to text.string[strindex]
if (!txt || !str) return (0);
if (strindex >= txt->strings ) return (0);
str_cpy(txt->pstrings[strindex],str);
return(_VAR(1));
}
DLLFUNC var dllText_setFont(TEXT* txt, FONT* fnt)
{
if (!txt || !fnt) return (0);
txt->font = fnt;
return (_VAR(1));
}
DLLFUNC void dllText_setVisible(TEXT* txt, var state)
{
if (!txt) return;
if (state)
{
txt->flags |= TXT_VISIBLE;
//for test only
txt->flags |= (1<<15);
}
else
{
txt->flags &= ~TXT_VISIBLE;
}
}
DLLFUNC void dllText_setCenter_X (TEXT* txt, var state)
{
if (!txt) return;
if (state)
{
txt->flags |= TXT_CENTER_X;
}
else
{
txt->flags &= ~TXT_CENTER_X;
}
}
DLLFUNC void dllText_setCenter_Y (TEXT* txt, var state)
{
if (!txt) return;
if (state)
{
txt->flags |= TXT_CENTER_Y;
}
else
{
txt->flags &= ~TXT_CENTER_Y;
}
}
DLLFUNC void dllText_setCondensed (TEXT* txt, var state)
{
if (!txt) return;
if (state)
{
txt->flags |= TXT_CONDENSED;//
}
else
{
txt->flags &= ~TXT_CONDENSED;
}
}
DLLFUNC void dllText_setNarrow (TEXT* txt, var state)
{
if (!txt) return;
if (state)
{
txt->flags |= NARROW;
}
else
{
txt->flags &= ~NARROW;
}
}
DLLFUNC void dllText_setFilter (TEXT* txt, var state)
{
if (!txt) return;
if (state)
{
txt->flags |= TXT_FILTER;//
}
else
{
txt->flags &= ~TXT_FILTER;
}
}
DLLFUNC void dllText_setTranslucent (TEXT* txt, var state)
{
if (!txt) return;
if (state)
{
txt->flags |= TXT_TRANSLUCENT;
}
else
{
txt->flags &= ~TXT_TRANSLUCENT;
}
}
DLLFUNC var dllText_getAlpha(TEXT* txt)
{
if (!txt) return (_VAR(-1));
return (txt->alpha);
}
//Is the flag on? (0) false (1) true;
DLLFUNC var dllText_getVisible(TEXT* txt)
{
if (!txt) return (_VAR(-1));
return ((txt->flags & TXT_VISIBLE) != 0); //I suppose you can test flags this way? (bitwise AND)
}
//copies the text at string[strindex] into the given wdl string.
DLLFUNC var dllText_getString(STRING* str,TEXT* txt, var strindex)
{
if (!txt || !str) return (0);
if (strindex >= txt->strings ) return (0);
str_cpy(str,(txt->pstrings[strindex])->chars);
return(_VAR(1));
}
Usage:
Build the DLL, put it on the proper folder.
Declare the functions in your WDL:
Code:
//dllTEXT functions
dllfunction dllText_setAlpha(txt,alphavar);
dllfunction dllText_setPos (txt,xvar,yvar);
dllfunction dllText_setScaleX (txt,scalevar);
dllfunction dllText_setScaleY (txt,scalevar);
dllfunction dllText_setScale (txt,scalevar);
dllfunction dllText_scale(txt,scalefactor);
dllfunction dllText_setString(txt,strindex,str);
dllfunction dllText_setFont(txt,fnt);
dllfunction dllText_setVisible(txt,state);
dllfunction dllText_setCenter_X(txt,state);
dllfunction dllText_setCenter_Y(txt,state);
dllfunction dllText_setNarrow(txt,state);
dllfunction dllText_setCondensed(txt,state);
dllfunction dllText_setTranslucent(txt,state);
dllfunction dllText_setFilter(txt,state);
dllfunction dllText_getAlpha(txt);
dllfunction dllText_getVisible(txt);
dllfunction dllText_getString(str,txt,strindex);
Examples:
Code:
//You can use these functions with normally declared texts or with handles for created texts:
TEXT normaltext
{
strings=1;
string="the text";
}
var textHandle;
function example()
{
textHandle = txt_create(1,1);
dllText_setVisible(normaltext,1); //set normaltext visible
dllText_setVisible(textHandle,0); //set textHandle invisible
if (dllText_getVisible())
{
dllText_setString(normaltext,0,"This text is visible");
}
//etc
}