Browse Source

vgui_support: remove it from the engine

pull/2/head
Alibek Omarov 3 years ago
parent
commit
b138a63502
  1. 3
      .gitmodules
  2. 1
      vgui-dev
  3. 23
      vgui_support/Android.mk
  4. 29
      vgui_support/Makefile.linux
  5. 5
      vgui_support/cl.bat
  6. 124
      vgui_support/vgui_clip.cpp
  7. 91
      vgui_support/vgui_input.cpp
  8. 123
      vgui_support/vgui_int.cpp
  9. 156
      vgui_support/vgui_main.h
  10. 440
      vgui_support/vgui_surf.cpp
  11. 125
      vgui_support/wscript

3
.gitmodules vendored

@ -7,9 +7,6 @@
[submodule "ref_gl/gl-wes-v2"] [submodule "ref_gl/gl-wes-v2"]
path = ref_gl/gl-wes-v2 path = ref_gl/gl-wes-v2
url = https://github.com/FWGS/gl-wes-v2 url = https://github.com/FWGS/gl-wes-v2
[submodule "vgui-dev"]
path = vgui-dev
url = https://github.com/FWGS/vgui-dev
[submodule "ref_gl/gl4es"] [submodule "ref_gl/gl4es"]
path = ref_gl/gl4es path = ref_gl/gl4es
url = https://github.com/ptitSeb/gl4es url = https://github.com/ptitSeb/gl4es

1
vgui-dev

@ -1 +0,0 @@
Subproject commit 93573075afe885618ea15831e72d44bdacd65bfb

23
vgui_support/Android.mk

@ -1,23 +0,0 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE = vgui_support
include $(XASH3D_CONFIG)
LOCAL_CFLAGS = -fsigned-char -DVGUI_TOUCH_SCROLL -DNO_STL -DXASH_GLES -DINTERNAL_VGUI_SUPPORT -Wall -Wextra -Wno-unused-parameter -Wno-unused-variable
LOCAL_CPPFLAGS = -frtti -fno-exceptions -Wno-write-strings -Wno-invalid-offsetof -std=gnu++98
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../common \
$(LOCAL_PATH)/../engine \
$(HLSDK_PATH)/utils/vgui/include \
$(VGUI_DIR)/include
LOCAL_SRC_FILES := vgui_clip.cpp vgui_font.cpp vgui_input.cpp vgui_int.cpp vgui_surf.cpp
LOCAL_STATIC_LIBRARIES := vgui
include $(BUILD_STATIC_LIBRARY)

29
vgui_support/Makefile.linux

@ -1,29 +0,0 @@
CC ?= gcc -m32
CXX ?= g++ -m32 -std=gnu++98
CFLAGS ?= -O2 -ggdb -fPIC
TOPDIR = $(PWD)/..
VGUI_DIR ?= ./vgui-dev
INCLUDES = -I../common -I../engine -I../engine/common -I../engine/client -I../engine/client/vgui -I../pm_shared
INCLUDES += -I$(VGUI_DIR)/include/
DEFINES = -DNO_STL
%.o : %.cpp
$(CXX) $(CFLAGS) $(INCLUDES) $(DEFINES) -c $< -o $@
SRCS = $(wildcard *.cpp)
OBJS = $(SRCS:.cpp=.o)
libvgui_support.so : $(OBJS)
$(CXX) $(LDFLAGS) -o libvgui_support.so -shared $(OBJS) vgui.so
.PHONY: depend clean
clean :
$(RM) $(OBJS) libvgui_support.so
depend: Makefile.dep
Makefile.dep: $(SRCS)
rm -f ./Makefile.dep
$(CC) $(CFLAGS) $(INCLUDES) $(DEFINES) -MM $^>>./Makefile.dep
include Makefile.dep

5
vgui_support/cl.bat

@ -1,5 +0,0 @@
set MSVCDir=Z:\path\to\msvc
set INCLUDE=%MSVCDir%\include
set LIB=%MSVCDir%\lib
set PATH=%MSVCDir%\bin;%PATH%
cl.exe %*

124
vgui_support/vgui_clip.cpp

@ -1,124 +0,0 @@
/*
vgui_clip.cpp - clip in 2D space
Copyright (C) 2011 Uncle Mike
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
In addition, as a special exception, the author gives permission
to link the code of this program with VGUI library developed by
Valve, L.L.C ("Valve"). You must obey the GNU General Public License
in all respects for all of the code used other than VGUI library.
If you modify this file, you may extend this exception to your
version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement
from your version.
*/
#include "vgui_main.h"
#include "wrect.h"
//-----------------------------------------------------------------------------
// For simulated scissor tests...
//-----------------------------------------------------------------------------
static wrect_t g_ScissorRect;
static qboolean g_bScissor = false;
namespace vgui_support {
//-----------------------------------------------------------------------------
// Enable/disable scissoring...
//-----------------------------------------------------------------------------
void EnableScissor( qboolean enable )
{
g_bScissor = enable;
}
void SetScissorRect( int left, int top, int right, int bottom )
{
// Check for a valid rectangle...
assert( left <= right );
assert( top <= bottom );
g_ScissorRect.left = left;
g_ScissorRect.top = top;
g_ScissorRect.right = right;
g_ScissorRect.bottom = bottom;
}
//-----------------------------------------------------------------------------
// Purpose: Used for clipping, produces an interpolated texture coordinate
//-----------------------------------------------------------------------------
inline float InterpTCoord( float val, float mins, float maxs, float tMin, float tMax )
{
float flPercent;
if( mins != maxs )
flPercent = (float)(val - mins) / (maxs - mins);
else flPercent = 0.5f;
return tMin + (tMax - tMin) * flPercent;
}
//-----------------------------------------------------------------------------
// Purpose: Does a scissor clip of the input rectangle.
// Returns false if it is completely clipped off.
//-----------------------------------------------------------------------------
qboolean ClipRect( const vpoint_t &inUL, const vpoint_t &inLR, vpoint_t *pOutUL, vpoint_t *pOutLR )
{
if( g_bScissor )
{
// pick whichever left side is larger
if( g_ScissorRect.left > inUL.point[0] )
pOutUL->point[0] = g_ScissorRect.left;
else
pOutUL->point[0] = inUL.point[0];
// pick whichever right side is smaller
if( g_ScissorRect.right <= inLR.point[0] )
pOutLR->point[0] = g_ScissorRect.right;
else
pOutLR->point[0] = inLR.point[0];
// pick whichever top side is larger
if( g_ScissorRect.top > inUL.point[1] )
pOutUL->point[1] = g_ScissorRect.top;
else
pOutUL->point[1] = inUL.point[1];
// pick whichever bottom side is smaller
if( g_ScissorRect.bottom <= inLR.point[1] )
pOutLR->point[1] = g_ScissorRect.bottom;
else
pOutLR->point[1] = inLR.point[1];
// Check for non-intersecting
if(( pOutUL->point[0] > pOutLR->point[0] ) || ( pOutUL->point[1] > pOutLR->point[1] ))
{
return false;
}
pOutUL->coord[0] = InterpTCoord(pOutUL->point[0],
inUL.point[0], inLR.point[0], inUL.coord[0], inLR.coord[0] );
pOutLR->coord[0] = InterpTCoord(pOutLR->point[0],
inUL.point[0], inLR.point[0], inUL.coord[0], inLR.coord[0] );
pOutUL->coord[1] = InterpTCoord(pOutUL->point[1],
inUL.point[1], inLR.point[1], inUL.coord[1], inLR.coord[1] );
pOutLR->coord[1] = InterpTCoord(pOutLR->point[1],
inUL.point[1], inLR.point[1], inUL.coord[1], inLR.coord[1] );
}
else
{
*pOutUL = inUL;
*pOutLR = inLR;
}
return true;
}
}

91
vgui_support/vgui_input.cpp

@ -1,91 +0,0 @@
/*
vgui_input.cpp - handle kb & mouse
Copyright (C) 2011 Uncle Mike
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
In addition, as a special exception, the author gives permission
to link the code of this program with VGUI library developed by
Valve, L.L.C ("Valve"). You must obey the GNU General Public License
in all respects for all of the code used other than VGUI library.
If you modify this file, you may extend this exception to your
version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement
from your version.
*/
#define OEMRESOURCE // for OCR_* cursor junk
#include "vgui_main.h"
namespace vgui_support {
void VGUI_Key(VGUI_KeyAction action, VGUI_KeyCode code)
{
App *pApp = App::getInstance();
if(!surface)
return;
switch( action )
{
case KA_PRESSED:
pApp->internalKeyPressed( (KeyCode) code, surface );
break;
case KA_RELEASED:
pApp->internalKeyReleased( (KeyCode) code, surface );
break;
case KA_TYPED:
pApp->internalKeyTyped( (KeyCode) code, surface );
break;
}
//fprintf(stdout,"vgui_support: VGUI key action %d %d\n", action, code);
//fflush(stdout);
}
void VGUI_Mouse(VGUI_MouseAction action, int code)
{
App *pApp = App::getInstance();
if(!surface)
return;
switch( action )
{
case MA_PRESSED:
pApp->internalMousePressed( (MouseCode) code, surface );
break;
case MA_RELEASED:
pApp->internalMouseReleased( (MouseCode) code, surface );
break;
case MA_DOUBLE:
pApp->internalMouseDoublePressed( (MouseCode) code, surface );
break;
case MA_WHEEL:
//fprintf(stdout, "vgui_support: VGUI mouse wheeled %d %d\n", action, code);
pApp->internalMouseWheeled( code, surface );
break;
}
//fprintf(stdout, "vgui_support: VGUI mouse action %d %d\n", action, code);
//fflush(stdout);
}
void VGUI_MouseMove(int x, int y)
{
App *pApp = App::getInstance();
//fprintf(stdout, "vgui_support: VGUI mouse move %d %d %p\n", x, y, surface);
//fflush(stdout);
if(!surface)
return;
pApp->internalCursorMoved( x, y, surface );
}
void VGUI_TextInput(const char *text)
{
// stub
}
}

123
vgui_support/vgui_int.cpp

@ -1,123 +0,0 @@
/*
vgui_int.c - vgui dll interaction
Copyright (C) 2011 Uncle Mike
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
In addition, as a special exception, the author gives permission
to link the code of this program with VGUI library developed by
Valve, L.L.C ("Valve"). You must obey the GNU General Public License
in all respects for all of the code used other than VGUI library.
If you modify this file, you may extend this exception to your
version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement
from your version.
*/
#include "vgui_main.h"
#include "xash3d_types.h"
namespace vgui_support {
vguiapi_t *g_api;
Panel *rootpanel = NULL;
CEngineSurface *surface = NULL;
CEngineApp staticApp;
void VGui_Startup( int width, int height )
{
if( rootpanel )
{
rootpanel->setSize( width, height );
return;
}
rootpanel = new Panel;
rootpanel->setSize( width, height );
rootpanel->setPaintBorderEnabled( false );
rootpanel->setPaintBackgroundEnabled( false );
rootpanel->setVisible( true );
rootpanel->setCursor( new Cursor( Cursor::dc_none ));
staticApp.start();
staticApp.setMinimumTickMillisInterval( 0 );
surface = new CEngineSurface( rootpanel );
rootpanel->setSurfaceBaseTraverse( surface );
//ASSERT( rootpanel->getApp() != NULL );
//ASSERT( rootpanel->getSurfaceBase() != NULL );
g_api->DrawInit ();
}
void VGui_Shutdown( void )
{
staticApp.stop();
delete rootpanel;
delete surface;
rootpanel = NULL;
surface = NULL;
}
void VGui_Paint( void )
{
int w, h;
//if( cls.state != ca_active || !rootpanel )
// return;
if( !g_api->IsInGame() || !rootpanel )
return;
// setup the base panel to cover the screen
Panel *pVPanel = surface->getEmbeddedPanel();
if( !pVPanel ) return;
//SDL_GetWindowSize(host.hWnd, &w, &h);
//host.input_enabled = rootpanel->isVisible();
rootpanel->getSize(w, h);
EnableScissor( true );
staticApp.externalTick ();
pVPanel->setBounds( 0, 0, w, h );
pVPanel->repaint();
// paint everything
pVPanel->paintTraverse();
EnableScissor( false );
}
void *VGui_GetPanel( void )
{
return (void *)rootpanel;
}
}
#ifdef INTERNAL_VGUI_SUPPORT
#define InitAPI InitVGUISupportAPI
#endif
extern "C" EXPORT void InitAPI(vguiapi_t * api)
{
g_api = api;
g_api->Startup = VGui_Startup;
g_api->Shutdown = VGui_Shutdown;
g_api->GetPanel = VGui_GetPanel;
g_api->Paint = VGui_Paint;
g_api->Mouse = VGUI_Mouse;
g_api->MouseMove = VGUI_MouseMove;
g_api->Key = VGUI_Key;
g_api->TextInput = VGUI_TextInput;
}

156
vgui_support/vgui_main.h

@ -1,156 +0,0 @@
/*
vgui_main.h - vgui main header
Copyright (C) 2011 Uncle Mike
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
In addition, as a special exception, the author gives permission
to link the code of this program with VGUI library developed by
Valve, L.L.C ("Valve"). You must obey the GNU General Public License
in all respects for all of the code used other than VGUI library.
If you modify this file, you may extend this exception to your
version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement
from your version.
*/
#ifndef VGUI_MAIN_H
#define VGUI_MAIN_H
#ifdef _WIN32
#include <windows.h>
#else
#include <string.h>
#endif
#include <assert.h>
#include "vgui_api.h"
#include<VGUI.h>
#include<VGUI_App.h>
#include<VGUI_Font.h>
#include<VGUI_Panel.h>
#include<VGUI_Cursor.h>
#include<VGUI_SurfaceBase.h>
#include<VGUI_InputSignal.h>
#include<VGUI_MouseCode.h>
#include<VGUI_KeyCode.h>
namespace vgui_support
{
extern vguiapi_t *g_api;
using namespace vgui;
struct PaintStack
{
Panel *m_pPanel;
int iTranslateX;
int iTranslateY;
int iScissorLeft;
int iScissorRight;
int iScissorTop;
int iScissorBottom;
};
class CEngineSurface : public SurfaceBase
{
private:
// point translation for current panel
int _translateX;
int _translateY;
// the size of the window to draw into
int _surfaceExtents[4];
void SetupPaintState( const PaintStack *paintState );
void InitVertex( vpoint_t &vertex, int x, int y, float u, float v );
public:
CEngineSurface( Panel *embeddedPanel );
~CEngineSurface();
public:
virtual Panel *getEmbeddedPanel( void );
virtual bool setFullscreenMode( int wide, int tall, int bpp );
virtual void setWindowedMode( void );
virtual void setTitle( const char *title ) { }
virtual void createPopup( Panel* embeddedPanel ) { }
virtual bool isWithin( int x, int y ) { return true; }
virtual bool hasFocus( void );
// now it's not abstract class, yay
virtual void GetMousePos(int &x, int &y) {
g_api->GetCursorPos(&x, &y);
}
void drawPrintChar(int x, int y, int wide, int tall, float s0, float t0, float s1, float t1, int color[]);
protected:
virtual int createNewTextureID( void );
virtual void drawSetColor( int r, int g, int b, int a );
virtual void drawSetTextColor( int r, int g, int b, int a );
virtual void drawFilledRect( int x0, int y0, int x1, int y1 );
virtual void drawOutlinedRect( int x0,int y0,int x1,int y1 );
virtual void drawSetTextFont( Font *font );
virtual void drawSetTextPos( int x, int y );
virtual void drawPrintText( const char* text, int textLen );
virtual void drawSetTextureRGBA( int id, const char* rgba, int wide, int tall );
virtual void drawSetTexture( int id );
virtual void drawTexturedRect( int x0, int y0, int x1, int y1 );
virtual bool createPlat( void ) { return false; }
virtual bool recreateContext( void ) { return false; }
virtual void setCursor( Cursor* cursor );
virtual void pushMakeCurrent( Panel* panel, bool useInsets );
virtual void popMakeCurrent( Panel* panel );
// not used in engine instance
virtual void enableMouseCapture( bool state ) { }
virtual void invalidate( Panel *panel ) { }
virtual void setAsTopMost( bool state ) { }
virtual void applyChanges( void ) { }
virtual void swapBuffers( void ) { }
protected:
Cursor* _hCurrentCursor;
int _drawTextPos[2];
int _drawColor[4];
int _drawTextColor[4];
friend class App;
friend class Panel;
};
// initialize VGUI::App as external (part of engine)
class CEngineApp : public App
{
public:
CEngineApp( bool externalMain = true ) : App( externalMain ) { }
virtual void main( int argc, char* argv[] ) { } // stub
};
//
// vgui_input.cpp
//
void *VGui_GetPanel( void );
void VGui_Paint( void );
void VGUI_Mouse(VGUI_MouseAction action, int code);
void VGUI_Key(VGUI_KeyAction action, VGUI_KeyCode code);
void VGUI_MouseMove(int x, int y);
void VGUI_TextInput(const char *text);
//
// vgui_clip.cpp
//
void EnableScissor( qboolean enable );
void SetScissorRect( int left, int top, int right, int bottom );
qboolean ClipRect( const vpoint_t &inUL, const vpoint_t &inLR, vpoint_t *pOutUL, vpoint_t *pOutLR );
extern CEngineSurface *surface;
extern Panel *root;
}
using namespace vgui_support;
#endif//VGUI_MAIN_H

440
vgui_support/vgui_surf.cpp

@ -1,440 +0,0 @@
/*
vgui_surf.cpp - main vgui layer
Copyright (C) 2011 Uncle Mike
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
In addition, as a special exception, the author gives permission
to link the code of this program with VGUI library developed by
Valve, L.L.C ("Valve"). You must obey the GNU General Public License
in all respects for all of the code used other than VGUI library.
If you modify this file, you may extend this exception to your
version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement
from your version.
*/
#include <ctype.h>
#include "vgui_main.h"
#define MAX_PAINT_STACK 16
#define FONT_SIZE 512
#define FONT_PAGES 8
struct FontInfo
{
int id;
int pageCount;
int pageForChar[256];
int bindIndex[FONT_PAGES];
float texCoord[256][FONT_PAGES];
int contextCount;
};
static int staticContextCount = 0;
static char staticRGBA[FONT_SIZE * FONT_SIZE * 4];
static Font* staticFont = NULL;
static FontInfo* staticFontInfo;
static Dar<FontInfo*> staticFontInfoDar;
static PaintStack paintStack[MAX_PAINT_STACK];
static int staticPaintStackPos = 0;
#define ColorIndex( c )((( c ) - '0' ) & 7 )
CEngineSurface :: CEngineSurface( Panel *embeddedPanel ):SurfaceBase( embeddedPanel )
{
_embeddedPanel = embeddedPanel;
_drawColor[0] = _drawColor[1] = _drawColor[2] = _drawColor[3] = 255;
_drawTextColor[0] = _drawTextColor[1] = _drawTextColor[2] = _drawTextColor[3] = 255;
_surfaceExtents[0] = _surfaceExtents[1] = 0;
//_surfaceExtents[2] = menu.globals->scrWidth;
//_surfaceExtents[3] = menu.globals->scrHeight;
embeddedPanel->getSize(_surfaceExtents[2], _surfaceExtents[3]);
_drawTextPos[0] = _drawTextPos[1] = 0;
_hCurrentCursor = null;
staticFont = NULL;
staticFontInfo = NULL;
staticFontInfoDar.setCount( 0 );
staticPaintStackPos = 0;
staticContextCount++;
_translateX = _translateY = 0;
}
CEngineSurface :: ~CEngineSurface( void )
{
g_api->DrawShutdown ();
}
Panel *CEngineSurface :: getEmbeddedPanel( void )
{
return _embeddedPanel;
}
bool CEngineSurface :: hasFocus( void )
{
// What differs when window does not has focus?
//return host.state != HOST_NOFOCUS;
return true;
}
void CEngineSurface :: setCursor( Cursor *cursor )
{
_currentCursor = cursor;
if( cursor )
{
g_api->CursorSelect( (VGUI_DefaultCursor)cursor->getDefaultCursor() );
}
}
void CEngineSurface :: SetupPaintState( const PaintStack *paintState )
{
_translateX = paintState->iTranslateX;
_translateY = paintState->iTranslateY;
SetScissorRect( paintState->iScissorLeft, paintState->iScissorTop,
paintState->iScissorRight, paintState->iScissorBottom );
}
void CEngineSurface :: InitVertex( vpoint_t &vertex, int x, int y, float u, float v )
{
vertex.point[0] = x + _translateX;
vertex.point[1] = y + _translateY;
vertex.coord[0] = u;
vertex.coord[1] = v;
}
int CEngineSurface :: createNewTextureID( void )
{
return g_api->GenerateTexture();
}
void CEngineSurface :: drawSetColor( int r, int g, int b, int a )
{
_drawColor[0] = r;
_drawColor[1] = g;
_drawColor[2] = b;
_drawColor[3] = a;
}
void CEngineSurface :: drawSetTextColor( int r, int g, int b, int a )
{
_drawTextColor[0] = r;
_drawTextColor[1] = g;
_drawTextColor[2] = b;
_drawTextColor[3] = a;
}
void CEngineSurface :: drawFilledRect( int x0, int y0, int x1, int y1 )
{
vpoint_t rect[2];
vpoint_t clippedRect[2];
if( _drawColor[3] >= 255 ) return;
InitVertex( rect[0], x0, y0, 0, 0 );
InitVertex( rect[1], x1, y1, 0, 0 );
// fully clipped?
if( !ClipRect( rect[0], rect[1], &clippedRect[0], &clippedRect[1] ))
return;
g_api->SetupDrawingRect( _drawColor );
g_api->EnableTexture( false );
g_api->DrawQuad( &clippedRect[0], &clippedRect[1] );
g_api->EnableTexture( true );
}
void CEngineSurface :: drawOutlinedRect( int x0, int y0, int x1, int y1 )
{
if( _drawColor[3] >= 255 ) return;
drawFilledRect( x0, y0, x1, y0 + 1 ); // top
drawFilledRect( x0, y1 - 1, x1, y1 ); // bottom
drawFilledRect( x0, y0 + 1, x0 + 1, y1 - 1 ); // left
drawFilledRect( x1 - 1, y0 + 1, x1, y1 - 1 ); // right
}
void CEngineSurface :: drawSetTextFont( Font *font )
{
staticFont = font;
if( font )
{
bool buildFont = false;
staticFontInfo = NULL;
for( int i = 0; i < staticFontInfoDar.getCount(); i++ )
{
if( staticFontInfoDar[i]->id == font->getId( ))
{
staticFontInfo = staticFontInfoDar[i];
if( staticFontInfo->contextCount != staticContextCount )
buildFont = true;
}
}
if( !staticFontInfo || buildFont )
{
staticFontInfo = new FontInfo;
staticFontInfo->id = 0;
staticFontInfo->pageCount = 0;
staticFontInfo->bindIndex[0] = 0;
staticFontInfo->bindIndex[1] = 0;
staticFontInfo->bindIndex[2] = 0;
staticFontInfo->bindIndex[3] = 0;
memset( staticFontInfo->pageForChar, 0, sizeof( staticFontInfo->pageForChar ));
staticFontInfo->contextCount = -1;
staticFontInfo->id = staticFont->getId();
staticFontInfoDar.putElement( staticFontInfo );
staticFontInfo->contextCount = staticContextCount;
int currentPage = 0;
int x = 0, y = 0;
memset( staticRGBA, 0, sizeof( staticRGBA ));
for( int i = 0; i < 256; i++ )
{
int abcA, abcB, abcC;
staticFont->getCharABCwide( i, abcA, abcB, abcC );
int wide = abcB;
if( isspace( i )) continue;
int tall = staticFont->getTall();
if( x + wide + 1 > FONT_SIZE )
{
x = 0;
y += tall + 1;
}
if( y + tall + 1 > FONT_SIZE )
{
if( !staticFontInfo->bindIndex[currentPage] )
staticFontInfo->bindIndex[currentPage] = createNewTextureID();
drawSetTextureRGBA( staticFontInfo->bindIndex[currentPage], staticRGBA, FONT_SIZE, FONT_SIZE );
currentPage++;
if( currentPage == FONT_PAGES )
break;
memset( staticRGBA, 0, sizeof( staticRGBA ));
x = y = 0;
}
staticFont->getCharRGBA( i, x, y, FONT_SIZE, FONT_SIZE, (byte *)staticRGBA );
staticFontInfo->pageForChar[i] = currentPage;
staticFontInfo->texCoord[i][0] = (float)((double)x / (double)FONT_SIZE );
staticFontInfo->texCoord[i][1] = (float)((double)y / (double)FONT_SIZE );
staticFontInfo->texCoord[i][2] = (float)((double)(x + wide)/(double)FONT_SIZE );
staticFontInfo->texCoord[i][3] = (float)((double)(y + tall)/(double)FONT_SIZE );
x += wide + 1;
}
if( currentPage != FONT_PAGES )
{
if( !staticFontInfo->bindIndex[currentPage] )
staticFontInfo->bindIndex[currentPage] = createNewTextureID();
drawSetTextureRGBA( staticFontInfo->bindIndex[currentPage], staticRGBA, FONT_SIZE, FONT_SIZE );
}
staticFontInfo->pageCount = currentPage + 1;
}
}
}
void CEngineSurface :: drawSetTextPos( int x, int y )
{
_drawTextPos[0] = x;
_drawTextPos[1] = y;
}
void CEngineSurface :: drawPrintChar( int x, int y, int wide, int tall, float s0, float t0, float s1, float t1, int color[4] )
{
vpoint_t ul, lr;
ul.point[0] = x;
ul.point[1] = y;
lr.point[0] = x + wide;
lr.point[1] = y + tall;
// gets at the texture coords for this character in its texture page
ul.coord[0] = s0;
ul.coord[1] = t0;
lr.coord[0] = s1;
lr.coord[1] = t1;
vpoint_t clippedRect[2];
if( !ClipRect( ul, lr, &clippedRect[0], &clippedRect[1] ))
return;
g_api->SetupDrawingImage( color );
g_api->DrawQuad( &clippedRect[0], &clippedRect[1] ); // draw the letter
}
void CEngineSurface :: drawPrintText( const char* text, int textLen )
{
//return;
static bool hasColor = 0;
static int numColor = 7;
if( !text || !staticFont || _drawTextColor[3] >= 255 )
return;
int x = _drawTextPos[0] + _translateX;
int y = _drawTextPos[1] + _translateY;
int tall = staticFont->getTall();
int j, iTotalWidth = 0;
int curTextColor[4];
// HACKHACK: allow color strings in VGUI
if( numColor != 7 )
{
for( j = 0; j < 3; j++ ) // grab predefined color
curTextColor[j] = g_api->GetColor(numColor,j);
}
else
{
for( j = 0; j < 3; j++ ) // revert default color
curTextColor[j] = _drawTextColor[j];
}
curTextColor[3] = _drawTextColor[3]; // copy alpha
if( textLen == 1 )
{
if( *text == '^' )
{
hasColor = true;
return; // skip '^'
}
else if( hasColor && isdigit( *text ))
{
numColor = ColorIndex( *text );
hasColor = false; // handled
return; // skip colornum
}
else hasColor = false;
}
for( int i = 0; i < textLen; i++ )
{
int curCh = g_api->ProcessUtfChar( (unsigned char)text[i] );
if( !curCh )
{
continue;
}
int abcA, abcB, abcC;
staticFont->getCharABCwide( curCh, abcA, abcB, abcC );
float s0 = staticFontInfo->texCoord[curCh][0];
float t0 = staticFontInfo->texCoord[curCh][1];
float s1 = staticFontInfo->texCoord[curCh][2];
float t1 = staticFontInfo->texCoord[curCh][3];
int wide = abcB;
iTotalWidth += abcA;
drawSetTexture( staticFontInfo->bindIndex[staticFontInfo->pageForChar[curCh]] );
drawPrintChar( x + iTotalWidth, y, wide, tall, s0, t0, s1, t1, curTextColor );
iTotalWidth += wide + abcC;
}
_drawTextPos[0] += iTotalWidth;
}
void CEngineSurface :: drawSetTextureRGBA( int id, const char* rgba, int wide, int tall )
{
g_api->UploadTexture( id, rgba, wide, tall );
}
void CEngineSurface :: drawSetTexture( int id )
{
g_api->BindTexture( id );
}
void CEngineSurface :: drawTexturedRect( int x0, int y0, int x1, int y1 )
{
vpoint_t rect[2];
vpoint_t clippedRect[2];
InitVertex( rect[0], x0, y0, 0, 0 );
InitVertex( rect[1], x1, y1, 1, 1 );
// fully clipped?
if( !ClipRect( rect[0], rect[1], &clippedRect[0], &clippedRect[1] ))
return;
g_api->SetupDrawingImage( _drawColor );
g_api->DrawQuad( &clippedRect[0], &clippedRect[1] );
}
void CEngineSurface :: pushMakeCurrent( Panel* panel, bool useInsets )
{
int insets[4] = { 0, 0, 0, 0 };
int absExtents[4];
int clipRect[4];
if( useInsets )
panel->getInset( insets[0], insets[1], insets[2], insets[3] );
panel->getAbsExtents( absExtents[0], absExtents[1], absExtents[2], absExtents[3] );
panel->getClipRect( clipRect[0], clipRect[1], clipRect[2], clipRect[3] );
PaintStack *paintState = &paintStack[staticPaintStackPos];
assert( staticPaintStackPos < MAX_PAINT_STACK );
paintState->m_pPanel = panel;
// determine corrected top left origin
paintState->iTranslateX = insets[0] + absExtents[0];
paintState->iTranslateY = insets[1] + absExtents[1];
// setup clipping rectangle for scissoring
paintState->iScissorLeft = clipRect[0];
paintState->iScissorTop = clipRect[1];
paintState->iScissorRight = clipRect[2];
paintState->iScissorBottom = clipRect[3];
SetupPaintState( paintState );
staticPaintStackPos++;
}
void CEngineSurface :: popMakeCurrent( Panel *panel )
{
int top = staticPaintStackPos - 1;
// more pops that pushes?
assert( top >= 0 );
// didn't pop in reverse order of push?
assert( paintStack[top].m_pPanel == panel );
staticPaintStackPos--;
if( top > 0 ) SetupPaintState( &paintStack[top-1] );
}
bool CEngineSurface :: setFullscreenMode( int wide, int tall, int bpp )
{
return false;
}
void CEngineSurface :: setWindowedMode( void )
{
}

125
vgui_support/wscript

@ -1,125 +0,0 @@
#! /usr/bin/env python
# encoding: utf-8
# mittorn, 2018
from waflib import Logs
import os
top = '.'
VGUI_SUPPORTED_OS = ['win32', 'darwin', 'linux']
def options(opt):
grp = opt.add_option_group('VGUI options')
grp.add_option('--vgui', action = 'store', dest = 'VGUI_DEV', default='vgui-dev',
help = 'path to vgui-dev repo [default: %default]')
grp.add_option('--disable-vgui', action = 'store_true', dest = 'NO_VGUI', default = False,
help = 'disable vgui_support [default: %default]')
grp.add_option('--skip-vgui-sanity-check', action = 'store_false', dest = 'VGUI_SANITY_CHECK', default=False,
help = 'skip checking VGUI sanity [default: %default]' )
return
def configure(conf):
conf.env.NO_VGUI = conf.options.NO_VGUI
if conf.options.NO_VGUI:
return
conf.start_msg('Does this architecture support VGUI?')
if conf.env.DEST_CPU != 'x86' and not (conf.env.DEST_CPU == 'x86_64' and not conf.options.ALLOW64):
conf.end_msg('no')
Logs.warn('vgui is not supported on this CPU: ' + str(conf.env.DEST_CPU))
conf.env.NO_VGUI = True
return
else:
conf.end_msg('yes')
conf.start_msg('Does this OS support VGUI?')
if conf.env.DEST_OS not in VGUI_SUPPORTED_OS:
conf.end_msg('no')
Logs.warn('vgui is not supported on this OS: ' + str(conf.env.DEST_OS))
conf.env.NO_VGUI = True
return
else:
conf.end_msg('yes')
conf.start_msg('Does this toolchain able to link VGUI?')
if conf.env.DEST_OS == 'win32' and conf.env.COMPILER_CXX == 'g++':
conf.end_msg('no')
# we have ABI incompatibility ONLY on MinGW
Logs.warn('vgui_support can\'t be built with MinGW')
conf.env.NO_VGUI = True
return
else:
conf.end_msg('yes')
if conf.env.NO_VGUI:
return
if conf.options.VGUI_DEV:
conf.start_msg('Configuring VGUI by provided path')
conf.env.VGUI_DEV = conf.options.VGUI_DEV
else:
conf.start_msg('Configuring VGUI by default path')
conf.env.VGUI_DEV = 'vgui-dev'
if conf.env.DEST_OS == 'win32':
conf.env.LIB_VGUI = ['vgui']
conf.env.LIBPATH_VGUI = [os.path.abspath(os.path.join(conf.env.VGUI_DEV, 'lib/win32_vc6/'))]
else:
libpath = os.path.abspath(os.path.join(conf.env.VGUI_DEV, 'lib'))
if conf.env.DEST_OS == 'linux':
conf.env.LIB_VGUI = [':vgui.so']
conf.env.LIBPATH_VGUI = [libpath]
elif conf.env.DEST_OS == 'darwin':
conf.env.LDFLAGS_VGUI = [os.path.join(libpath, 'vgui.dylib')]
else:
conf.fatal('vgui is not supported on this OS: ' + conf.env.DEST_OS)
conf.env.INCLUDES_VGUI = [os.path.abspath(os.path.join(conf.env.VGUI_DEV, 'include'))]
conf.env.HAVE_VGUI = 1
conf.end_msg('yes: {0}, {1}, {2}'.format(conf.env.LIB_VGUI, conf.env.LIBPATH_VGUI, conf.env.INCLUDES_VGUI))
if conf.env.HAVE_VGUI and conf.options.VGUI_SANITY_CHECK:
try:
conf.check_cxx(
fragment='''
#include <VGUI.h>
int main( int argc, char **argv )
{
return 0;
}''',
msg = 'Checking for library VGUI sanity',
use = 'VGUI',
execute = False)
except conf.errors.ConfigurationError:
conf.fatal("Can't compile simple program. Check your path to vgui-dev repository.")
def build(bld):
if bld.env.NO_VGUI:
return
libs = []
# basic build: dedicated only, no dependencies
if bld.env.DEST_OS != 'win32':
libs += ['DL','M']
libs.append('VGUI')
source = bld.path.ant_glob(['*.cpp'])
includes = [ '.', '../common', '../engine', '../public' ]
bld.shlib(
source = source,
target = 'vgui_support',
features = 'cxx',
includes = includes,
use = libs,
rpath = '.',
install_path = bld.env.LIBDIR,
subsystem = bld.env.MSVC_SUBSYSTEM
)
Loading…
Cancel
Save