<commit_before>/*
    Copyright (C) 1998 by <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdarg.h>
#include "sysdef.h"
#include "cs2d/unxglide2/glidex2d.h"
#include "cscom/com.h"
#include "csinput/csevent.h"
#include "csinput/csinput.h"
#include "cssys/unix/iunix.h"
#include "csutil/inifile.h"
#include "csgeom/csrect.h"
#include "cs3d/glide2/glidelib.h"
#include "isystem.h"

BEGIN_INTERFACE_TABLE (csGraphics2DGlideX)
  IMPLEMENTS_COMPOSITE_INTERFACE_EX (IGraphics2D, XGraphics2D)
  IMPLEMENTS_COMPOSITE_INTERFACE_EX (IGraphicsInfo, XGraphicsInfo)
END_INTERFACE_TABLE ()

IMPLEMENT_UNKNOWN_NODELETE (csGraphics2DGlideX)

  // replace this with config stuff...
bool DoGlideInWindow=true; 

bool locked;

// csGraphics2DGLX functions
csGraphics2DGlideX::csGraphics2DGlideX(ISystem* piSystem) :
  csGraphics2D (piSystem), xim (NULL), cmap (0)
{
  System = piSystem;
  if (FAILED (System->QueryInterface (IID_IUnixSystemDriver, (void**)&UnixSystem)))
  {
    CsPrintf (MSG_FATAL_ERROR, "FATAL: The system driver does not support "
                               "the IUnixSystemDriver interface\n");
    exit (-1);
  }
}

void csGraphics2DGlideX::Initialize()
{
  csGraphics2D::Initialize ();
  Screen* screen_ptr;

  // see if we need to go fullscreen or not...
  csIniFile* config = new csIniFile("cryst.cfg");
  m_DoGlideInWindow = (!config->GetYesNo("VideoDriver","FULL_SCREEN",FALSE));
  CHK (delete config);

  // if we are going to do glide in an Xwindow, 
  // we need to set some environment vars first...
  if (m_DoGlideInWindow)
  {
    setenv("SST_NOSHUTDOWN","1",1);
    setenv("SSTV2_NOSHUTDOWN","1",1);
    setenv("SST_VGA_PASS","1",1);
    setenv("SSTV2_VGA_PASS","1",1);
  } 

  // Query system settings
  int sim_depth;
  bool do_shm;
  UnixSystem->GetSettings (sim_depth, do_shm, do_hwmouse);

  dpy = XOpenDisplay (NULL);

  screen_num = DefaultScreen (dpy);
  screen_ptr = DefaultScreenOfDisplay (dpy);
  display_width = DisplayWidth (dpy, screen_num);
  display_height = DisplayHeight (dpy, screen_num);

  // Determine visual information.
  //Visual* visual = DefaultVisual (dpy, screen_num);

  
  Depth=16;
	  
  DrawPixel = DrawPixelGlide;   WriteChar = WriteCharGlide;
  GetPixelAt = GetPixelAtGlide; DrawSprite = DrawSpriteGlide;
    
  // calculate CS's pixel format structure. 565
  pfmt.PixelBytes = 2;
  pfmt.PalEntries = 0;
  pfmt.RedMask = (1+2+4+8+16)<<11;
  pfmt.GreenMask = (1+2+4+8+16+32)<<5;
  pfmt.BlueMask = (1+2+4+8+16);
    
  complete_pixel_format();


	/* <commit_msg>Small bugfix from <NAME>.<commit_after>/*
    Copyright (C) 1998 by <NAME>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library 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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdarg.h>
#include "sysdef.h"
#include "cs2d/unxglide2/glidex2d.h"
#include "cscom/com.h"
#include "csinput/csevent.h"
#include "csinput/csinput.h"
#include "cssys/unix/iunix.h"
#include "csutil/inifile.h"
#include "csgeom/csrect.h"
#include "cs3d/glide2/glidelib.h"
#include "isystem.h"

BEGIN_INTERFACE_TABLE (csGraphics2DGlideX)
  IMPLEMENTS_COMPOSITE_INTERFACE_EX (IGraphics2D, XGraphics2D)
  IMPLEMENTS_COMPOSITE_INTERFACE_EX (IGraphicsInfo, XGraphicsInfo)
END_INTERFACE_TABLE ()

IMPLEMENT_UNKNOWN_NODELETE (csGraphics2DGlideX)

  // replace this with config stuff...
bool DoGlideInWindow=true; 

bool locked;

// csGraphics2DGLX functions
csGraphics2DGlideX::csGraphics2DGlideX(ISystem* piSystem) :
  csGraphics2D (piSystem), xim (NULL), cmap (0)
{
  System = piSystem;
  if (FAILED (System->QueryInterface (IID_IUnixSystemDriver, (void**)&UnixSystem)))
  {
    CsPrintf (MSG_FATAL_ERROR, "FATAL: The system driver does not support "
                               "the IUnixSystemDriver interface\n");
    exit (-1);
  }
}

void csGraphics2DGlideX::Initialize()
{
  csGraphics2D::Initialize ();
  Screen* screen_ptr;

  // see if we need to go fullscreen or not...
  csIniFile* config = new csIniFile("cryst.cfg");
  m_DoGlideInWindow = (!config->GetYesNo("VideoDriver","FULL_SCREEN",FALSE));
  CHK (delete config);

  // if we are going to do glide in an Xwindow, 
  // we need to set some environment vars first...
  if (m_DoGlideInWindow)
  {
    setenv("SST_NOSHUTDOWN","1",1);
    setenv("SSTV2_NOSHUTDOWN","1",1);
    setenv("SST_VGA_PASS","1",1);
    setenv("SSTV2_VGA_PASS","1",1);
  } 

  // Query system settings
  int sim_depth;
  bool do_shm;
  UnixSystem->GetSettings (sim_depth, do_shm, do_hwmouse);

  dpy = XOpenDisplay (NULL);
  if (!dpy)
  {
    CsPrintf (MSG_FATAL_ERROR, "FATAL: Cannot open X display\n");
    exit (-1);
  }

  screen_num = DefaultScreen (dpy);
  screen_ptr = DefaultScreenOfDisplay (dpy);
  display_width = DisplayWidth (dpy, screen_num);
  display_height = DisplayHeight (dpy, screen_num);

  // Determine visual information.
  //Visual* visual = DefaultVisual (dpy, screen_num);

  
  Depth=16;
	  
  DrawPixel = DrawPixelGlide;   WriteChar = WriteCharGlide;
  GetPixelAt = GetPixelAtGlide; DrawSprite = DrawSpriteGlide;
    
  // calculate CS's pixel format structure. 565
  pfmt.PixelBytes = 2;
  pfmt.PalEntries = 0;
  pfmt.RedMask = (1+2+4+8+16)<<11;
  pfmt.GreenMask = (1+2+4+8+16+32)<<5;
  pfmt.BlueMask = (1+2+4+8+16);
    
  complete_pixel_format();


	/* 
{'fraction_non_alphanumeric': 0.10936306705361235, 'fraction_numerical': 0.021536581640446004, 'mean_word_length': 3.998473282442748, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4616144', 'n_tokens_mistral': 2356, 'n_tokens_neox': 2280, 'n_words': 619}