<commit_before>#include "cssysdef.h"
#include "awscmdbt.h"
#include "ivideo/graph2d.h"
#include "ivideo/graph3d.h"
#include "ivideo/fontserv.h"

#include <stdio.h>

SCF_IMPLEMENT_IBASE(awsCmdButton)
  SCF_IMPLEMENTS_INTERFACE(awsComponent)
SCF_IMPLEMENT_IBASE_END

const unsigned int awsCmdButton::fsNormal =0x0;
const unsigned int awsCmdButton::fsToolbar=0x1;
const unsigned int awsCmdButton::fsBitmap =0x2;

awsCmdButton::awsCmdButton():is_down(false), mouse_is_over(false), 
                             frame_style(0), alpha_level(0),
                             caption(NULL)
{
  tex[0]=tex[1]=tex[2]=NULL;
}

awsCmdButton::~awsCmdButton()
{
}

bool
awsCmdButton::Setup(iAws *_wmgr, awsComponentNode *settings)
{
 if (!awsComponent::Setup(_wmgr, settings)) return false;

 iAwsPrefs *pm=WindowManager()->GetPrefMgr();
     
 pm->GetInt(settings, "Style", frame_style);
 pm->GetInt(settings, "Style", alpha_level);
 pm->GetString(settings, "Caption", caption);

 return true;
}

void 
awsCmdButton::OnDraw(csRect clip)
{

  iGraphics2D *g2d = WindowManager()->G2D();
  iGraphics3D *g3d = WindowManager()->G3D();

  int hi    = WindowManager()->GetPrefMgr()->GetColor(AC_HIGHLIGHT);
  int hi2   = WindowManager()->GetPrefMgr()->GetColor(AC_HIGHLIGHT2);
  int lo    = WindowManager()->GetPrefMgr()->GetColor(AC_SHADOW);
  int lo2   = WindowManager()->GetPrefMgr()->GetColor(AC_SHADOW2);
  int fill  = WindowManager()->GetPrefMgr()->GetColor(AC_FILL);
  int black = WindowManager()->GetPrefMgr()->GetColor(AC_BLACK);
  
  switch(frame_style)
  {
  case fsNormal:
  case fsToolbar:

    if (is_down)
    {
      g2d->DrawLine(Frame().xmin+0, Frame().ymin+0, Frame().xmax-1, Frame().ymin+0, lo2);
      g2d->DrawLine(Frame().xmin+0, Frame().ymin+0, Frame().xmin+0, Frame().ymax-1, lo2);
      g2d->DrawLine(Frame().xmin+1, Frame().ymin+1, Frame().xmax-0, Frame().ymin+1, lo);
      g2d->DrawLine(Frame().xmin+1, Frame().ymin+1, Frame().xmin+1, Frame().ymax-0, lo);
      g2d->DrawLine(Frame().xmin+1, Frame().ymax-0, Frame().xmax-0, Frame().ymax-0, hi);
      g2d->DrawLine(Frame().xmax-0, Frame().ymin+1, Frame().xmax-0, Frame().ymax-0, hi);

      g2d->DrawLine(Frame().xmin+2, Frame().ymin+2, Frame().xmax-1, Frame().ymin+2, black);
      g2d->DrawLine(Frame().xmin+2, Frame().ymin+2, Frame().xmin+2, Frame().ymax-1, black);
      g2d->DrawLine(Frame().xmin+2, Frame().ymax-1, Frame().xmax-1, Frame().ymax-1, hi2);
      g2d->DrawLine(Frame().xmax-1, Frame().ymin+2, Frame().xmax-1, Frame().ymax-1, hi2);
    }
    else
    {
      g2d->DrawLine(Frame().xmin+0, Frame().ymin+0, Frame().xmax-1, Frame().ymin+0, hi);
      g2d->DrawLine(Frame().xmin+0, Frame().ymin+0, Frame().xmin+0, Frame().ymax-1, hi);
      g2d->DrawLine(Frame().xmin+0, Frame().ymax-1, Frame().xmax-1, Frame().ymax-1, lo);
      g2d->DrawLine(Frame().xmax-1, Frame().ymin+0, Frame().xmax-1, Frame().ymax-1, lo);
      g2d->DrawLine(Frame().xmin+1, Frame().ymax-0, Frame().xmax-0, Frame().ymax-0, black);
      g2d->DrawLine(Frame().xmax-0, Frame().ymin+1, Frame().xmax-0, Frame().ymax-0, black);

      g2d->DrawLine(Frame().xmin+1, Frame().ymin+1, Frame().xmax-2, Frame().ymin+1, hi2);
      g2d->DrawLine(Frame().xmin+1, Frame().ymin+1, Frame().xmin+1, Frame().ymax-2, hi2);
      g2d->DrawLine(Frame().xmin+1, Frame().ymax-2, Frame().xmax-2, Frame().ymax-2, lo2);
      g2d->DrawLine(Frame().xmax-2, Frame().ymin+1, Frame().xmax-2, Frame().ymax-2, lo2);
    }

    // Draw the caption, if there is one and the style permits it.
    if (caption && frame_style==fsNormal)
    {     
      int tw, th, tx, ty;

      // Get the size of the text
      WindowManager()->GetPrefMgr()->GetDefaultFont()->GetMaxSize(tw, th);

      // Calculate the center
      tx = (Frame().Width()>>1) - ((tw*caption->Length())>>1);
      ty = (Frame().Height()>>1) - (th>>1);

      // Draw the text
        g2d->Write(WindowManager()->GetPrefMgr()->GetDefaultFont(),
                   Frame().xmin+tx+is_down,
                   Frame().ymin+ty+is_down,
                   WindowManager()->GetPrefMgr()->GetColor(AC_TEXTFORE),
                   -1,
                   caption->GetData());
    }
    break;
<commit_msg>Christopher:<commit_after>#include "cssysdef.h"
#include "awscmdbt.h"
#include "ivideo/graph2d.h"
#include "ivideo/graph3d.h"
#include "ivideo/fontserv.h"

#include <stdio.h>

SCF_IMPLEMENT_IBASE(awsCmdButton)
  SCF_IMPLEMENTS_INTERFACE(awsComponent)
SCF_IMPLEMENT_IBASE_END

const unsigned int awsCmdButton::fsNormal =0x0;
const unsigned int awsCmdButton::fsToolbar=0x1;
const unsigned int awsCmdButton::fsBitmap =0x2;

awsCmdButton::awsCmdButton():is_down(false), mouse_is_over(false), 
                             frame_style(0), alpha_level(0),
                             caption(NULL)
{
  tex[0]=tex[1]=tex[2]=NULL;
}

awsCmdButton::~awsCmdButton()
{
}

bool
awsCmdButton::Setup(iAws *_wmgr, awsComponentNode *settings)
{
 if (!awsComponent::Setup(_wmgr, settings)) return false;

 iAwsPrefs *pm=WindowManager()->GetPrefMgr();
     
 pm->GetInt(settings, "Style", frame_style);
 pm->GetInt(settings, "Style", alpha_level);
 pm->GetString(settings, "Caption", caption);

 return true;
}

void 
awsCmdButton::OnDraw(csRect clip)
{

  iGraphics2D *g2d = WindowManager()->G2D();
  iGraphics3D *g3d = WindowManager()->G3D();

  int hi    = WindowManager()->GetPrefMgr()->GetColor(AC_HIGHLIGHT);
  int hi2   = WindowManager()->GetPrefMgr()->GetColor(AC_HIGHLIGHT2);
  int lo    = WindowManager()->GetPrefMgr()->GetColor(AC_SHADOW);
  int lo2   = WindowManager()->GetPrefMgr()->GetColor(AC_SHADOW2);
  int fill  = WindowManager()->GetPrefMgr()->GetColor(AC_FILL);
  int black = WindowManager()->GetPrefMgr()->GetColor(AC_BLACK);
  
  switch(frame_style)
  {
  case fsNormal:
  case fsToolbar:

    if (is_down)
    {
      g2d->DrawLine(Frame().xmin+0, Frame().ymin+0, Frame().xmax-1, Frame().ymin+0, lo2);
      g2d->DrawLine(Frame().xmin+0, Frame().ymin+0, Frame().xmin+0, Frame().ymax-1, lo2);
      g2d->DrawLine(Frame().xmin+1, Frame().ymin+1, Frame().xmax-0, Frame().ymin+1, lo);
      g2d->DrawLine(Frame().xmin+1, Frame().ymin+1, Frame().xmin+1, Frame().ymax-0, lo);
      g2d->DrawLine(Frame().xmin+1, Frame().ymax-0, Frame().xmax-0, Frame().ymax-0, hi);
      g2d->DrawLine(Frame().xmax-0, Frame().ymin+1, Frame().xmax-0, Frame().ymax-0, hi);

      g2d->DrawLine(Frame().xmin+2, Frame().ymin+2, Frame().xmax-1, Frame().ymin+2, black);
      g2d->DrawLine(Frame().xmin+2, Frame().ymin+2, Frame().xmin+2, Frame().ymax-1, black);
      g2d->DrawLine(Frame().xmin+2, Frame().ymax-1, Frame().xmax-1, Frame().ymax-1, hi2);
      g2d->DrawLine(Frame().xmax-1, Frame().ymin+2, Frame().xmax-1, Frame().ymax-1, hi2);
    }
    else
    {
      g2d->DrawLine(Frame().xmin+0, Frame().ymin+0, Frame().xmax-1, Frame().ymin+0, hi);
      g2d->DrawLine(Frame().xmin+0, Frame().ymin+0, Frame().xmin+0, Frame().ymax-1, hi);
      g2d->DrawLine(Frame().xmin+0, Frame().ymax-1, Frame().xmax-1, Frame().ymax-1, lo);
      g2d->DrawLine(Frame().xmax-1, Frame().ymin+0, Frame().xmax-1, Frame().ymax-1, lo);
      g2d->DrawLine(Frame().xmin+1, Frame().ymax-0, Frame().xmax-0, Frame().ymax-0, black);
      g2d->DrawLine(Frame().xmax-0, Frame().ymin+1, Frame().xmax-0, Frame().ymax-0, black);

      g2d->DrawLine(Frame().xmin+1, Frame().ymin+1, Frame().xmax-2, Frame().ymin+1, hi2);
      g2d->DrawLine(Frame().xmin+1, Frame().ymin+1, Frame().xmin+1, Frame().ymax-2, hi2);
      g2d->DrawLine(Frame().xmin+1, Frame().ymax-2, Frame().xmax-2, Frame().ymax-2, lo2);
      g2d->DrawLine(Frame().xmax-2, Frame().ymin+1, Frame().xmax-2, Frame().ymax-2, lo2);
    }

    // Draw the caption, if there is one and the style permits it.
    if (caption && frame_style==fsNormal)
    {     
      int tw, th, tx, ty;

      // Get the size of the text
      WindowManager()->GetPrefMgr()->GetDefaultFont()->GetDimensions(caption->GetData(), tw, th);

      // Calculate the center
      tx = (Frame().Width()>>1) -  (tw>>1);
      ty = (Frame().Height()>>1) - (th>>1);

      // Draw the text
        g2d->Write(WindowManager()->GetPrefMgr()->GetDefaultFont(),
                   Frame().xmin+tx+is_down,
                   Frame().ymin+ty+is_down,
                   WindowManager()->GetPrefMgr()->GetColor(AC_TEXTFORE),
                   -1,
                   caption->GetData());
    }
    break;

{'fraction_non_alphanumeric': 0.20766008378216635, 'fraction_numerical': 0.03279473369239976, 'mean_word_length': 3.5786301369863014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 117, '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': '4406404', 'n_tokens_mistral': 3228, 'n_tokens_neox': 3213, 'n_words': 483}