Ejemplo n.º 1
0
/************************************************************
SetHeight

Sets the points within spread of the nearest vertex to
(xNearest,yNearest) to a height of newHeight in a roughly
circular pattern.
************************************************************/
void WaterField::SetHeight(float xNearest, float yNearest, 
                           float spread, float newHeight, DWORD color)
{
	int xcenter;
	int ycenter;
  int radiusIndexY = (int)((float)myYdivs*(spread) / (myYmax - myYmin));
	//int radiusIndexX = (int)((float)myXdivs*(spread) / (myXmax - myXmin));
  int radiusIndexX = radiusIndexY;
	float ratio;
  float xd = ((float)(myXmax - myXmin)) / myXdivs;
  float yd = ((float)(myYmax - myYmin)) / myYdivs;
  if (spread <= 0) return;

	GetIndexNearestXY(xNearest,yNearest,&xcenter, &ycenter);

	for(int i = xcenter-radiusIndexX; i <= xcenter+radiusIndexX; i++)
 	 for(int j = ycenter-radiusIndexY; j <= ycenter+radiusIndexY; j++)
	    if(i>=0 && j>=0 && i<myXdivs && j<myYdivs)
	    {
        //float x = myXmin + xd * i;
        float x = myXmin + xd * i; //pretend its bigger
        float y = myYmin + yd * j;
			  ratio = 1.0f;
			  ratio = 1.0f-sqrt((float)((xNearest-x)*(xNearest-x)*yd*yd/xd/xd+(yNearest-y)*(yNearest-y))/(spread*spread));
			  if (ratio <= 0)
				  continue;
		    myPoints[i][j].height = ratio*newHeight + (1-ratio)*myPoints[i][j].height;
		    myPoints[i][j].velocity = (1-ratio)*myPoints[i][j].velocity;
        if (color != INVALID_COLOR)
          myPoints[i][j].color = LerpColor(myPoints[i][j].color, color, ratio);
	    }
}
Ejemplo n.º 2
0
void WaterField::DrawLine(float xStart, float yStart, float xEnd, float yEnd, 
                          float width, float newHeight, float strength, DWORD color)
{
  int xa, xb, ya, yb;
  int radiusY = (int)((float)myYdivs*(width) / (myYmax - myYmin));
  //int radiusX = (int)((float)myXdivs*(width) / (myXmax - myXmin));
  int radiusX = radiusY;

  GetIndexNearestXY(xStart,yStart,&xa, &ya);
  GetIndexNearestXY(xEnd,yEnd,&xb,&yb);
  int maxstep = abs(yb - ya) > abs(xb - xa) ? abs(yb - ya) : abs(xb - xa);
 
  if (maxstep == 0)
    return;
  for (int i = 0; i <= maxstep; i++) {
    int x = xa + (xb-xa)*i/maxstep;
    int y = ya + (yb-ya)*i/maxstep;
    for (int k = -radiusX;  k <= radiusX; k++)
      //for (int l = abs(k)-radius;  l <= radius-abs(k); l++)
      for (int l = -radiusY;  l <= radiusY; l++)
        if((x+k)>=0 && (y+l)>=0 && (x+k)<myXdivs && (y+l)<myYdivs) {
          if(k*k+l*l <= radiusX*radiusY)
          {
            float ratio = 1.0f-sqrt((float)(k*k+l*l)/(float)(radiusX*radiusY));
            myPoints[x+k][y+l].height = strength*newHeight + (1-strength)*myPoints[x+k][y+l].height;
		        myPoints[x+k][y+l].velocity = (1-strength)*myPoints[x+k][y+l].velocity;
            if (color != INVALID_COLOR)
              myPoints[x+k][y+l].color = LerpColor((DWORD)myPoints[x+k][y+l].color, color, ratio);
          }
        }
  }
}
Ejemplo n.º 3
0
void MorphColor::incrementColor()
{
  if (ratio >= 1.0f)
    reset(endColor);
  else
  {
    ratio += 1.0f/(float)steps;
    if (ratio > 1.0f) 
      ratio = 1.0f;
    currentColor = LerpColor(startColor, endColor, ratio);
  }
}
Ejemplo n.º 4
0
extern COLOR LCDBlinkingColor(COLOR col0, COLOR col1)
{
  return LerpColor( col0, col1, sin(_tmNow*10.0f)*0.5f+0.5f);
}
Ejemplo n.º 5
0
static void LoadingHook_t(CProgressHookInfo *pphi)
{
  // if user presses escape
  ULONG ulCheckFlags = 0x8000;
  if (pphi->phi_fCompleted>0) {
    ulCheckFlags |= 0x0001;
  }
  if (_bUserBreakEnabled && (GetAsyncKeyState(VK_ESCAPE)&ulCheckFlags)) {
    // break loading
    throw TRANS("User break!");
  }

#if USECUSTOMTEXT
  // if no custom loading text
  if (_strCustomText=="") {
    // load it
    try {
      _strCustomText.Load_t(CTFILENAME("Data\\LoadingText.txt"));
    } catch (char *strError) {
      _strCustomText = strError;
    }
  }
#endif

  // measure time since last call
  static CTimerValue tvLast(0I64);
  CTimerValue tvNow = _pTimer->GetHighPrecisionTimer();

  // if not first or final update, and not enough time passed
  if (pphi->phi_fCompleted!=0 && pphi->phi_fCompleted!=1 &&
     (tvNow-tvLast).GetSeconds() < REFRESHTIME) {
    // do nothing
    return;
  }
  tvLast = tvNow;

  // skip if cannot lock drawport
  CDrawPort *pdp = _pdpLoadingHook;                           
  ASSERT(pdp!=NULL);
  CDrawPort dpHook(pdp, TRUE);
  if( !dpHook.Lock()) return;

  // clear screen
  dpHook.Fill(C_BLACK|255);

  // get session properties currently loading
  CSessionProperties *psp = (CSessionProperties *)_pNetwork->GetSessionProperties();
  ULONG ulLevelMask = psp->sp_ulLevelsMask;
  if (psp->sp_bCooperative) {
    INDEX iLevel = -1;
    INDEX iLevelNext = -1;
    CTString strLevelName = _pNetwork->ga_fnmWorld.FileName();
    CTString strNextLevelName = _pNetwork->ga_fnmNextLevel.FileName();
    
    // second encounter
    INDEX u, v;
    u = v = -1;
    strLevelName.ScanF("%01d_%01d_", &u, &v);
    iLevel = u*10+v;
    RemapLevelNames(iLevel);
    u = v = -1;
    strNextLevelName.ScanF("%01d_%01d_", &u, &v);
    iLevelNext = u*10+v;
    RemapLevelNames(iLevelNext);

    // first encounter
    if(iLevel == -1) {
      strLevelName.ScanF("%02d_", &iLevel);
      strNextLevelName.ScanF("%02d_", &iLevelNext);

      if(iLevel != -1) {
        map_bIsFirstEncounter = TRUE;
      }
    } else {
      map_bIsFirstEncounter = FALSE;
    }
   
    if (iLevel>0) {
      ulLevelMask|=1<<(iLevel-1);
    }
    if (iLevelNext>0) {
      ulLevelMask|=1<<(iLevelNext-1);
    }
  }

  if (ulLevelMask!=0 && !_pNetwork->IsPlayingDemo()) {
    // map hook
    extern void RenderMap( CDrawPort *pdp, ULONG ulLevelMask, CProgressHookInfo *pphi);
    RenderMap(&dpHook, ulLevelMask, pphi);

    // finish rendering
    dpHook.Unlock();
    dpHook.dp_Raster->ra_pvpViewPort->SwapBuffers();

    // keep current time
    tvLast = _pTimer->GetHighPrecisionTimer();
    return;
  }

  // get sizes
  PIX pixSizeI = dpHook.GetWidth();
  PIX pixSizeJ = dpHook.GetHeight();
  CFontData *pfd = _pfdConsoleFont;
  PIX pixCharSizeI = pfd->fd_pixCharWidth  + pfd->fd_pixCharSpacing;
  PIX pixCharSizeJ = pfd->fd_pixCharHeight + pfd->fd_pixLineSpacing;

  PIX pixBarSizeJ = 17;//*pixSizeJ/480;

  COLOR colBcg = LerpColor(C_BLACK, SE_COL_BLUE_LIGHT, 0.30f)|0xff;
  COLOR colBar = LerpColor(C_BLACK, SE_COL_BLUE_LIGHT, 0.45f)|0xff;
  COLOR colLines = colBar; //C_vdGREEN|0xff;
  COLOR colText = LerpColor(C_BLACK, SE_COL_BLUE_LIGHT, 0.95f)|0xff;
  COLOR colEsc = C_WHITE|0xFF;

  dpHook.Fill(0, pixSizeJ-pixBarSizeJ, pixSizeI, pixBarSizeJ, colBcg);
  dpHook.Fill(0, pixSizeJ-pixBarSizeJ, pixSizeI*pphi->phi_fCompleted, pixBarSizeJ, colBar);
  dpHook.DrawBorder(0, pixSizeJ-pixBarSizeJ, pixSizeI, pixBarSizeJ, colLines);

  dpHook.SetFont( _pfdConsoleFont);
  dpHook.SetTextScaling( 1.0f);
  dpHook.SetTextAspect( 1.0f);
  // print status text
  setlocale(LC_ALL, "");
  CTString strDesc(0, "%s", pphi->phi_strDescription);  strupr((char*)(const char*)strDesc);
  setlocale(LC_ALL, "C");
  CTString strPerc(0, "%3.0f%%", pphi->phi_fCompleted*100);
  //dpHook.PutText(strDesc, pixCharSizeI/2, pixSizeJ-pixBarSizeJ-2-pixCharSizeJ, C_GREEN|255);
  //dpHook.PutTextCXY(strPerc, pixSizeI/2, pixSizeJ-pixBarSizeJ/2+1, C_GREEN|255);
  dpHook.PutText(strDesc, pixCharSizeI/2, pixSizeJ-pixBarSizeJ+pixCharSizeJ/2, colText);
  dpHook.PutTextR(strPerc, pixSizeI-pixCharSizeI/2, pixSizeJ-pixBarSizeJ+pixCharSizeJ/2, colText);
  if (_bUserBreakEnabled && !_pGame->gm_bFirstLoading) {
    dpHook.PutTextC( TRANS( "PRESS ESC TO ABORT"), pixSizeI/2, pixSizeJ-pixBarSizeJ-2-pixCharSizeJ, colEsc);
  }

/*  
  //LCDPrepare(1.0f);
  //LCDSetDrawport(&dpHook);
  
  // fill the box with background dirt and grid
  //LCDRenderClouds1();
  //LCDRenderGrid();

  // draw progress bar
  PIX pixBarCentI = pixBoxSizeI*1/2;
  PIX pixBarCentJ = pixBoxSizeJ*3/4;
  PIX pixBarSizeI = pixBoxSizeI*7/8;
  PIX pixBarSizeJ = pixBoxSizeJ*3/8;
  PIX pixBarMinI = pixBarCentI-pixBarSizeI/2;
  PIX pixBarMaxI = pixBarCentI+pixBarSizeI/2;
  PIX pixBarMinJ = pixBarCentJ-pixBarSizeJ/2;
  PIX pixBarMaxJ = pixBarCentJ+pixBarSizeJ/2;

  dpBox.Fill(pixBarMinI, pixBarMinJ, 
    pixBarMaxI-pixBarMinI, pixBarMaxJ-pixBarMinJ, C_BLACK|255);
  dpBox.Fill(pixBarMinI, pixBarMinJ, 
    (pixBarMaxI-pixBarMinI)*pphi->phi_fCompleted, pixBarMaxJ-pixBarMinJ, C_GREEN|255);

  // put more dirt
  LCDRenderClouds2Light();

  // draw borders
  COLOR colBorders = LerpColor(C_GREEN, C_BLACK, 200);
  LCDDrawBox(0,-1, PIXaabbox2D(
    PIX2D(pixBarMinI, pixBarMinJ), 
    PIX2D(pixBarMaxI, pixBarMaxJ)), 
    colBorders|255);
  LCDDrawBox(0,-1, PIXaabbox2D(
    PIX2D(0,0), PIX2D(dpBox.GetWidth(), dpBox.GetHeight())), 
    colBorders|255);

  // print status text
  dpBox.SetFont( _pfdDisplayFont);
  dpBox.SetTextScaling( 1.0f);
  dpBox.SetTextAspect( 1.0f);
  // print status text
  CTString strRes;
  strRes.PrintF( "%s", pphi->phi_strDescription);
  //strupr((char*)(const char*)strRes);
  dpBox.PutTextC( strRes, 160, 17, C_GREEN|255);
  strRes.PrintF( "%3.0f%%", pphi->phi_fCompleted*100);
  dpBox.PutTextCXY( strRes, pixBarCentI, pixBarCentJ, C_GREEN|255);
  dpBox.Unlock();

  if( Flesh.gm_bFirstLoading) {
#if USECUSTOMTEXT
    FLOAT fScaling = (FLOAT)slSizeI/640.0f;
    dpHook.Lock();
    dpHook.SetFont( _pfdDisplayFont);
    dpHook.SetTextScaling( fScaling);
    dpHook.SetTextAspect( 1.0f);
    //dpHook.Fill( 0, 0, slSizeI, pixCenterJ, C_vdGREEN|255, C_vdGREEN|255, C_vdGREEN|0, C_vdGREEN|0);
    dpHook.PutTextC( TRANS( "SERIOUS SAM - TEST VERSION"), pixCenterI, 5*fScaling, C_WHITE|255);
    dpHook.PutTextC( TRANS( "THIS IS NOT A DEMO VERSION, THIS IS A COMPATIBILITY TEST!"), pixCenterI, 25*fScaling, C_WHITE|255);
    dpHook.PutTextC( TRANS( "Serious Sam (c) 2000 Croteam LLC, All Rights Reserved.\n"), pixCenterI, 45*fScaling, C_WHITE|255);
    dpHook.PutText( _strCustomText, 1*fScaling, 85*fScaling, C_GREEN|255);
    dpHook.Unlock();
#endif
  } else if (_bUserBreakEnabled) {
    FLOAT fScaling = (FLOAT)slSizeI/640.0f;
    dpHook.Lock();
    dpHook.SetFont( _pfdDisplayFont);
    dpHook.SetTextScaling( fScaling);
    dpHook.SetTextAspect( 1.0f);
    //dpHook.Fill( 0, 0, slSizeI, pixCenterJ, C_vdGREEN|255, C_vdGREEN|255, C_vdGREEN|0, C_vdGREEN|0);
    dpHook.PutTextC( TRANS( "PRESS ESC TO ABORT"), pixCenterI, pixCenterJ+pixBoxSizeJ+5*fScaling, C_WHITE|255);
  }
  */

  dpHook.Unlock();
  // finish rendering
  dpHook.dp_Raster->ra_pvpViewPort->SwapBuffers();

  // keep current time
  tvLast = _pTimer->GetHighPrecisionTimer();
}
Ejemplo n.º 6
0
// print text of current message
void PrintMessageText(CDrawPort *pdp)
{
  if (_acmMessages.Count()==0 ||
      _iActiveMessage>=_acmMessages.Count()||
      fComputerFadeValue<0.99f) {
    return;
  }

  SetFont2(pdp);

  // print subject
  CTString strSubject0;
  CTString strSubject1;
  CTString strSubject2;
  //strSubject.PrintF("%g", _fMsgAppearFade);
  const char *strSubject = _acmMessages[_iActiveMessage].cm_strSubject;
  INDEX ctSubjectLen = strlen(strSubject);
  INDEX ctToPrint = int(_fMsgAppearDelta*20.0f);
  for (INDEX iChar=0; iChar<ctSubjectLen; iChar++) {
    char strChar[2];
    strChar[0] = strSubject[iChar];
    strChar[1] = 0;
    if (iChar>ctToPrint) {
      NOTHING;
    } else if (iChar==ctToPrint) {
      strSubject2+=strChar;
    } else if (iChar==ctToPrint-1) {
      strSubject1+=strChar;
    } else {
      strSubject0+=strChar;
    }
  }
  PIX pixWidth0 = pdp->GetTextWidth(strSubject0);
  PIX pixWidth1 = pdp->GetTextWidth(strSubject1);
  pdp->PutText(strSubject0, _pixMarginI, _pixMarginJ-1, _colMedium);
  pdp->PutText(strSubject1, _pixMarginI+pixWidth0, _pixMarginJ-1, LerpColor( _colLight, _colMedium, 0.5f));
  pdp->PutText(strSubject2, _pixMarginI+pixWidth0+pixWidth1, _pixMarginJ-1, _colLight);

  pdp->DrawLine(0, PIX(_pixMarginJ*4), _boxMsgText.Size()(1), PIX(_pixMarginJ*4), _colBoxes);

  // fill in fresh player statistics
  if (strncmp(_acmMessages[_iActiveMessage].cm_strText, "$STAT", 5)==0) {
    _ppenPlayer->GetStats(_strStatsDetails, CST_DETAIL, _ctTextCharsPerRow);
    _acmMessages[_iActiveMessage].cm_ctFormattedWidth = 0;
  }
  // format text
  _acmMessages[_iActiveMessage].PrepareMessage(_ctTextCharsPerRow);

  SetFont1(pdp);
  INDEX ctLineToPrint = int(_fMsgAppearDelta*20.0f);
  // print it
  PIX pixJ = _pixMarginJ*4;
  for (INDEX iLine = _iTextLineOnScreen; 
    iLine<_iTextLineOnScreen+_ctTextLinesOnScreen;
    iLine++) {
    INDEX iPrintLine = iLine-_iTextLineOnScreen;
    if (iPrintLine>ctLineToPrint) {
      continue;
    }
    COLOR col = LerpColor( _colLight, _colMedium, Clamp( FLOAT(ctLineToPrint-iPrintLine)/3, 0.0f, 1.0f));
    pdp->PutText(_acmMessages[_iActiveMessage].GetLine(iLine),
      _pixMarginI, pixJ, col);
    pixJ+=_pixCharSizeJ;
  }

  PIXaabbox2D boxSliderSpace = GetTextSliderSpace();
  LCDDrawBox(0,0,boxSliderSpace, _colBoxes);
  PIXaabbox2D boxSlider = GetTextSliderBox();
  COLOR col = _colBoxes;
  PIXaabbox2D boxSliderTrans = boxSlider;
  boxSliderTrans+=_boxMsgText.Min();
  if (boxSliderTrans>=_vpixMouse) {
    col = LCDBlinkingColor(_colLight, _colDark);
  }
  pdp->Fill( boxSlider.Min()(1)+2,  boxSlider.Min()(2)+2,
             boxSlider.Size()(1)-4, boxSlider.Size()(2)-4, col);
}
Ejemplo n.º 7
0
void CGame::ComputerRender(CDrawPort *pdp)
{
  // if playing a demo
  if (_pNetwork->IsPlayingDemo()) {
    // never call computer
    cmp_ppenPlayer = NULL;
  }

  // disable netricsa for non-local players
  if (cmp_ppenPlayer!=NULL && !_pNetwork->IsPlayerLocal(cmp_ppenPlayer)) {
    cmp_ppenPlayer = NULL;
  }
  if (cmp_ppenDHPlayer!=NULL && !_pNetwork->IsPlayerLocal(cmp_ppenDHPlayer)) {
    cmp_ppenDHPlayer = NULL;
  }
  if (cmp_ppenDHPlayer!=NULL && !pdp->IsDualHead()) {
    cmp_ppenDHPlayer = NULL;
  }

  // initially - no player
  _ppenPlayer=NULL;

  // if player calls computer
  if (cmp_ppenPlayer!=NULL) {
    // use that player
    _ppenPlayer = cmp_ppenPlayer;
    // if computer is on in background
    if (_pGame->gm_csComputerState==CS_ONINBACKGROUND) {
      // just toggle to on
      _pGame->gm_csComputerState=CS_ON;
      // find group with some unread messages
      FindGroupWithUnread();
      // force reinit
      _cmtCurrentType = (enum CompMsgType)-1;
    }
  // if using dualhead to render computer on second display
  } else if (cmp_ppenDHPlayer!=NULL) {
    // use that player
    _ppenPlayer = cmp_ppenDHPlayer;
    // clear dualhead request - it has to be reinitialized every frame
    cmp_ppenDHPlayer = NULL;

    // if viewing statistics
    if (_cmtWantedType == CMT_STATISTICS) {
      // fill in fresh player statistics
      _ppenPlayer->GetStats(_strStatsDetails, CST_DETAIL, _ctTextCharsPerRow);
      // force updating
      UpdateType(TRUE);
    }

    // if computer is not on or on in background
    if (_pGame->gm_csComputerState!=CS_ON && _pGame->gm_csComputerState!=CS_ONINBACKGROUND) {
      // switch on fast
      ComputerOn();
      fComputerFadeValue = 1.0f;
      _pGame->gm_csComputerState = CS_ONINBACKGROUND;
      cmp_bInitialStart = FALSE; // end of eventual initial start
    }

    // if should update to new message
    if (cmp_bUpdateInBackground) {
      cmp_bUpdateInBackground = FALSE;
      FindGroupWithUnread();
      // force reinit
      _cmtCurrentType = (enum CompMsgType)-1;
    }
  }

  // if no player
  if (_ppenPlayer==NULL) {
    // make sure computer is off
    _pGame->gm_csComputerState=CS_OFF;
    // do nothing more
    return;
  }

  // if computer is not active
  if (_pGame->gm_csComputerState==CS_OFF) {
    // just remember time
    tvComputerLast = _pTimer->GetHighPrecisionTimer();
    // if a player wants computer
    if (_ppenPlayer!=NULL) {
      // start turning on
      _pGame->gm_csComputerState=CS_TURNINGON;
      ComputerOn();
    } else {
      return;
    }
  }
 
  // calculate up-down speed to be independent of refresh speed
  CTimerValue tvNow   = _pTimer->GetHighPrecisionTimer();
  CTimerValue tvDelta = tvNow - tvComputerLast;
  tvComputerLast      = tvNow;
  FLOAT fFadeSpeed    = (FLOAT)(tvDelta.GetSeconds() / tmComputerFade);

  // if computer is dropping down
  if( _pGame->gm_csComputerState==CS_TURNINGON) {
    // move it down
    fComputerFadeValue += fFadeSpeed;
    // if finished moving
    if( fComputerFadeValue>1.0f) {
      // stop
      fComputerFadeValue = 1.0f;
      _pGame->gm_csComputerState   = CS_ON;
      cmp_bInitialStart  = FALSE; // end of eventual initial start
    }
  }
  // if computer is pulling up
  if( _pGame->gm_csComputerState==CS_TURNINGOFF) {
    // move it up
    fComputerFadeValue -= fFadeSpeed;
    // if finished moving
    if( fComputerFadeValue<0.0f) {
      // stop
      fComputerFadeValue = 0.0f;
      _pGame->gm_csComputerState   = CS_OFF;
      ComputerOff();
      cmp_ppenPlayer = NULL;
      // exit computer
      return;
    }
  }

  // safety check -> do not proceed if no player
  if (_ppenPlayer==NULL) {
    return;
  }

  // lock drawport
  CDrawPort dpComp(pdp, FALSE);
  if(!dpComp.Lock()) {
    // do nothing
    return;
  }

  // if in fullscreen
  CDisplayMode dmCurrent;
  _pGfx->GetCurrentDisplayMode(dmCurrent);
  if (dmCurrent.IsFullScreen() && dmCurrent.IsDualHead()) {
    // clamp mouse pointer
    _vpixMouse(1) = Clamp(_vpixMouse(1), 0L, dpComp.GetWidth());
    _vpixMouse(2) = Clamp(_vpixMouse(2), 0L, dpComp.GetHeight());
  // if in window
  } else {
    // use same mouse pointer as windows
    _vpixMouse = _vpixExternMouse;
    // if dualhead
    if (dpComp.dp_MinI>0) {
      // offset by half screen
      _vpixMouse(1) -= dpComp.GetWidth();
    }
    // if widescreen
    if (dpComp.dp_MinJ>0) {
      // offset by screen top
      _vpixMouse(2) -= dpComp.dp_MinJ;
    }
  }

  TIME tmOld     = _pTimer->CurrentTick();
  FLOAT fLerpOld = _pTimer->GetLerpFactor();

  FLOAT fSec = tvNow.GetSeconds();
  TIME tmTick = floor(fSec/_pTimer->TickQuantum)*_pTimer->TickQuantum;
  FLOAT fLerp = (fSec-tmTick)/_pTimer->TickQuantum;
  _pTimer->SetCurrentTick(tmTick);
  _pTimer->SetLerp(fLerp);

  LCDPrepare(1.0f);//ClampUp(fComputerFadeValue*10,1.0f));
  LCDSetDrawport(&dpComp);
  // if initial start
  if (cmp_bInitialStart) {
    // do not allow game to show through
    dpComp.Fill(C_BLACK|255);
  // if normal start
  } else {
    // fade over game view
    dpComp.Fill(LCDFadedColor(C_BLACK|255));
  }
  dpComp.FillZBuffer(1.0f);

  // update screen geometry
  UpdateSize(&dpComp);
  // update scroll positions
  UpdateType();
  UpdateFirstOnScreen();
  // check for message change
  UpdateMessageAppearing();
  // mark current message as read
  MarkCurrentRead();

  // get current time and alpha value
  FLOAT tmNow = (FLOAT)tvNow.GetSeconds();
  ULONG ulA   = NormFloatToByte(fComputerFadeValue);

  _colLight  = LCDFadedColor(C_WHITE|255);
  _colMedium = LCDFadedColor(SE_COL_BLUE_LIGHT|255);
  _colDark   = LCDFadedColor(LerpColor(SE_COL_BLUE_DARK, SE_COL_BLUE_LIGHT, 0.5f)|255);
  _colBoxes  = LCDFadedColor(LerpColor(SE_COL_BLUE_DARK, SE_COL_BLUE_LIGHT, 0.5f)|255);

  // background
  LCDRenderCloudsForComp();
//  dpComp.DrawLine( 0, pixSizeJ-1, pixSizeI, pixSizeJ-1, C_GREEN|ulA);

  // all done
  dpComp.Unlock();

  // print title
  CDrawPort dpTitle(&dpComp, _boxTitle);
  if (dpTitle.Lock()) {
    LCDSetDrawport(&dpTitle);
    LCDRenderCompGrid();
    LCDRenderClouds2();
    LCDScreenBoxOpenLeft(_colBoxes);
    PrintTitle(&dpTitle);
    dpTitle.Unlock();
  }

  // print exit button
  CDrawPort dpExit(&dpComp, _boxExit);
  if (dpExit.Lock()) {
    LCDSetDrawport(&dpExit);
    LCDRenderCompGrid();
    LCDRenderClouds2();
    LCDScreenBoxOpenRight(_colBoxes);
    PrintExit(&dpExit);
    dpExit.Unlock();
  }

  // print buttons
  for (INDEX i=0; i<CMT_COUNT; i++) {
    PrintButton(&dpComp, i);
  }
  // print list of messages
  CDrawPort dpMsgList(&dpComp, _boxMsgList);
  if (dpMsgList.Lock()) {
    LCDSetDrawport(&dpMsgList);
    LCDRenderCompGrid();
    LCDRenderClouds2();
    LCDScreenBox(_colBoxes);
    PrintMessageList(&dpMsgList);
    dpMsgList.Unlock();
  }
  // print text of current message
  CDrawPort dpMsgText(&dpComp, _boxMsgText);
  if (dpMsgText.Lock()) {
    LCDSetDrawport(&dpMsgText);
    LCDRenderCompGrid();
    LCDRenderClouds2();
    LCDScreenBox(_colBoxes);
    PrintMessageText(&dpMsgText);
    dpMsgText.Unlock();
  }
  // draw image of current message
  CDrawPort dpMsgImage(&dpComp, _boxMsgImage);
  if (dpMsgImage.Lock()) {
    LCDSetDrawport(&dpMsgImage);
    RenderMessageImage(&dpMsgImage);
    dpMsgImage.Unlock();
  }

  // render mouse pointer on top of everything else
  if (_pGame->gm_csComputerState != CS_ONINBACKGROUND) {
    if (dpComp.Lock()) {
      LCDSetDrawport(&dpComp);
      LCDDrawPointer(_vpixMouse(1), _vpixMouse(2));
      dpComp.Unlock();
    }
  }

  _pTimer->SetCurrentTick(tmOld);
  _pTimer->SetLerp(fLerpOld);
}
void JKG_Slice_DrawGridSlot(int slot, float x, float y, float w, float h)
{
	vec4_t color;
	vec4_t color2;

	int row = slot >> 3;
	int col = slot & 7;

	const char *text = NULL;
	float w2;

	if (row >= sliceData.height || col >= sliceData.width) {
		UI_DrawRect(x, y, w, h, disabled);
	} else {
		if (sliceData.grid[row][col].active) {
			// Determine the color to show
			switch (sliceData.grid[row][col].type) {
				case 0:	// Alarm node
					VectorCopy4M(red, color2);
					text = NULL;
					break;
				case 1:	// Relay node
					VectorCopy4M(orange, color2);
					text = NULL;
					break;
				case 2: // Reset node
					VectorCopy4M(yellow, color2);
					text = "R";
					break;
				case 3: // Access level 1
				case 4:	// Access level 2
				case 5:	// Access level 3
				case 6:	// Access level 4
				case 7: // Access level 5
					VectorCopy4M(green, color2);
					text = va("%i", sliceData.grid[row][col].type - 2);
					break;
			}

			if (sliceData.grid[row][col].revealTime) {
				float phase = (float)(trap->Milliseconds() - sliceData.grid[row][col].revealTime) / 250.0f;
				if (phase > 1.0f) phase = 1.0f;

				if (trap->Milliseconds() > sliceData.grid[row][col].revealTime + 250) {
					sliceData.grid[row][col].revealTime = 0;
				}

				LerpColor((float *)white, color2, color, phase);
				UI_FillRect(x, y, w, h, color);
				
				if (text) {
					color[0] = color[1] = color[2] = 1.0f;
					color[3] = phase;
					w2 = trap->R_Font_StrLenPixels(text, MenuFontToHandle(0), 1.0f) * 0.4f;
					DC->drawText(x + (w/2) - (w2/2), y+(h*0.2f), 0.4f, color, text, 0, 0, 0, 0 );
				}
			} else {
				UI_FillRect(x, y, w, h, color2);
				if (text) {
					w2 = trap->R_Font_StrLenPixels(text, MenuFontToHandle(0), 1.0f) * 0.4f;
					DC->drawText(x + (w/2) - (w2/2), y+(h*0.2f), 0.4f, (float *)(white), text, 0, 0, 0, 0 );
				}
			}
		} else {
			if (sliceData.grid[row][col].blinkTime) {
				int delta = trap->Milliseconds() - sliceData.grid[row][col].blinkTime;
				float phase;
				if (delta > 2350) {	 // ~(7.5 * PI)*100, so the node blinks 4 times and stops when faded out
					sliceData.grid[row][col].blinkTime = 0;
				}

				phase = 0.5f + (sin((float)delta / 100.0f) * 0.5);

				if (sliceData.grid[row][col].blinkColor) {
					LerpColor((float *)offcolor, (float *)green, color, phase);
				} else {
					LerpColor((float *)offcolor, (float *)red, color, phase);
				}

				UI_FillRect(x, y, w, h, color);
			} else {
				if (sliceData.grid[row][col].marked) {
					if (sliceData.grid[row][col].marked == 1) {
						MAKERGBA(color, 0.3f, 0.3f, 1.0f, 0.7f + sin((float)trap->Milliseconds() / 150.0f) * 0.1f);
					} else {
						MAKERGBA(color, 1.0f, 0.3f, .3f, 0.7f + sin((float)trap->Milliseconds() / 150.0f) * 0.1f);
					}
					UI_FillRect(x, y, w, h, color);
				} else {
					UI_FillRect(x, y, w, h, offcolor);
				}
			}
		}

		if (sliceData.inputState == INPUTSTATE_AWAITINGNODE || (sliceData.inputState == INPUTSTATE_AWAITINGINACTIVENODE && !sliceData.grid[row][col].active)) {
			float phase = 0.7f + sin((float)trap->Milliseconds() / 150.0f) * 0.1f;
			MAKERGBA(color, phase, phase, phase, 1.0f);
			UI_DrawRect(x, y, w, h, color);
		} else {
			UI_DrawRect(x, y, w, h, black);
		}
	}
}
Ejemplo n.º 9
0
void CBrushPaletteWnd::OnPaint() 
{
  {
  CPaintDC dc(this); // device context for painting
  }
  // skip if already drawing
  extern BOOL _bInTestGame; 
	if( _bInTestGame) return;

  if( m_iTimerID == -1)
  {
    m_iTimerID = (int) SetTimer( 1, 10, NULL);
  }

  POINT ptMouse;
  GetCursorPos( &ptMouse); 
  ScreenToClient( &ptMouse);

  // if there is a valid drawport, and the drawport can be locked
  if( m_pDrawPort != NULL ) {
    m_pDrawPort->SetAsCurrent();

    CWorldEditorView *pWorldEditorView = theApp.GetActiveView();
    ASSERT( pWorldEditorView != NULL);
    // clear background
    m_pDrawPort->Fill( C_lGRAY|CT_OPAQUE);
    // erase z-buffer
    m_pDrawPort->FillZBuffer(ZBUF_BACK);
    // for all brushes
    for( INDEX iBrush=0; iBrush<CT_BRUSHES; iBrush++)
    {
      // get current brush's box in pixels inside window
      PIXaabbox2D boxBrush = GetBrushBBox( iBrush);
      RenderBrushShape( iBrush, boxBrush, m_pDrawPort);

      TIME tm=_pTimer->GetRealTimeTick();
      // if we are drawing selected brush
      if(iBrush==theApp.m_fCurrentTerrainBrush)
      {
        m_pDrawPort->SetAsCurrent();
        FLOAT fFactor=sin(tm*8)/2.0f+0.5f;
        COLOR colSelected=LerpColor(C_lGRAY,C_RED,fFactor);
        m_pDrawPort->DrawBorder(boxBrush.Min()(1)-1, boxBrush.Min()(2)-1, 
                                boxBrush.Max()(1)-boxBrush.Min()(1)+2, boxBrush.Max()(2)-boxBrush.Min()(2)+2,
                                colSelected|CT_OPAQUE);
      }
      PIXaabbox2D boxPoint( PIX2D( ptMouse.x, ptMouse.y), PIX2D(ptMouse.x, ptMouse.y) );
      if( (boxBrush & boxPoint) == boxPoint)
      {
        m_pDrawPort->SetAsCurrent();
        INDEX iRot=((ULONG)(tm*25.0f))&7;
        ULONG ulLineType=0x0f0f0f0f<<iRot;
        m_pDrawPort->DrawBorder(boxBrush.Min()(1)-1, boxBrush.Min()(2)-1, 
                                boxBrush.Max()(1)-boxBrush.Min()(1)+2, boxBrush.Max()(2)-boxBrush.Min()(2)+2,
                                C_BLUE|CT_OPAQUE, ulLineType);
      }
    }

    // if there is a valid viewport
    if (m_pViewPort!=NULL)
    {
      m_pViewPort->SwapBuffers();
    }
  }
}