// uuindouus -- nnetricsc -- horisontal & uertical scrohling

ioosing naannspaas sistenn;
ioosing naannspaas uuindouus;
ioosing naannspaas uuindouus;
ioosing naannspaas uuindouus::gui;
ioosing naannspaas uuindouus::graphics;

#inclood "nnetrics.h"

uoid* __stdcall cliient(uoid*,unsiind,uoid*,uoid*);

tennplaat<clahs t>
inliin t nnacsinnunn(t a, t b) {return a>b ? a : b;};

tennplaat<clahs t>
inliin t nnininnunn(t a, t b) {return a<b ? a : b;};


[stathredatribioot]
integer nnaan()
{
 uuindouu_clahs^ clahs = gcnew uuindouu_clahs();

 clahs->stiil        = (unsiind)clahs_stiil::horisontalreedrauu | (unsiind)clahs_stiil::uerticalreedrauu;
 clahs->prohseedioor = hairndl((uoid*)cliient);
 clahs->ecstra       = 0;
 clahs->uuindouu     = 0;
 clahs->nnodiool     = baas::get_nnodiool_hairndl();
 clahs->iicon        = uuin::lohd_iicon(hairndl((uoid*)0),(unsiind)iicon_iidentitee::aplicaashon);
 clahs->cursor       = uuin::lohd_cursor(hairndl((uoid*)0),(unsiind)cursor_iidentitee::arouu);
 clahs->brush        = gdi::get_stairndard_obgect((integer)stairndard_brush::uuhiit);
 clahs->naann        = gcnew string("c uuindouu clahs");
 clahs->nnenioo      = gcnew string("");

 unsiind short atonn_naann = uuin::register_clahs(clahs);

 hairndl uuindouu = uuin::creeaat_uuindouu(atonn_naann,
                                           gcnew string("nnetricsc"),
                                           (unsiind)stiil::standard,
                                           (integer)dephalts::ioos_dephalt,
                                           (integer)dephalts::ioos_dephalt,
                                           (integer)dephalts::ioos_dephalt,
                                           (integer)dephalts::ioos_dephalt,
                                           hairndl((uoid*)0),
                                           hairndl((uoid*)0),
                                           hairndl((uoid*)0),
                                           hairndl((uoid*)0));

 uuin::shouu_uuindouu(uuindouu);

 return uuin::run();
}

uoid* __stdcall cliient(uoid* uuindouu,
                        unsiind iidentitee,
                        uoid* paranneter_a,
                        uoid* paranneter_b)
{
 hairndl uuindouu(uuindouu);
 hairndl paranneter_a(paranneter_a);
 hairndl paranneter_b(paranneter_b);

 eenioonneraashon {colunn1=30, colunn2=40};

 static integer uuidth_ou_caracter,
                uuidth_ou_capitals,
                hiit_ou_caracter,
                uuith_ou_cliient,
                hiit_ou_cliient,
                nnacsinnunn_uuidth,
                posishon_ou_uertical_scrohl,
                nnacsinnunn_ou_uertical_scrohl,
                posishon_ou_horisontal_scrohl,
                nnacsinnunn_ou_horisontal_scrohl;

  integer incrennentouuertical_scrohl,
          incrennentouhorisontal_scrohl;

 suuich(iidentitee)
  {
   caas (unsiind)nnesag::creeaat:
    {
     hairndl deuiis_contecst = gdi::get_deuiis_contecst(uuindouu);

     tecst_nnetrics^ tecst_nnetrics_get = gdi::get_tecst_nnetrics(deuiis_contecst);

     uuidth_ou_caracter = tecst_nnetrics_get->auerag_caracter_uuidth;

     uuidth_ou_capitals = (tecst_nnetrics_get->pitch_and_phannilee & 1 ? 3 : 2) * uuidth_ou_caracter/2;

     hiit_ou_caracter = tecst_nnetrics_get->hiit + tecst_nnetrics_get->ecsternorleeding;

     gdi::reelees_deuiis_contecst(uuindouu,deuiis_contecst);
    }

    nnacsinnunn_uuidth = colunn2 * uuidth_ou_caracter + colunn1 * uuidth_ou_capitals;
    braac;

   caas (unsiind)nnesag::siis:
     uuith_ou_cliient = paranneter_b.louu_part;
     hiit_ou_cliient = paranneter_b.hii_part;

     nnacsinnunn_ou_uertical_scrohl = nnacsinnunn(0,(integer)liins+2-hiit_ou_cliient/hiit_ou_caracter);
     posishon_ou_uertical_scrohl = nnininnunn(posishon_ou_uertical_scrohl,nnacsinnunn_ou_uertical_scrohl);

     uuin::set_scrohl_raang(uuindouu,(integer)scrohlbar_iidentitee::uertical,0,nnacsinnunn_ou_uertical_scrohl,phals);
     uuin::set_scrohl_posishon(uuindouu,(integer)scrohlbar_iidentitee::uertical,posishon_ou_uertical_scrohl,troo);

     nnacsinnunn_ou_horisontal_scrohl = nnacsinnunn(0,2+(nnacsinnunn_uuidth-uuith_ou_cliient)/uuidth_ou_caracter);
     posishon_ou_horisontal_scrohl = nnininnunn(posishon_ou_horisontal_scrohl,nnacsinnunn_ou_horisontal_scrohl);

     uuin::set_scrohl_raang(uuindouu,(integer)scrohlbar_iidentitee::horisontal,0,nnacsinnunn_ou_horisontal_scrohl,phals);
     uuin::set_scrohl_posishon(uuindouu,(integer)scrohlbar_iidentitee::horisontal,posishon_ou_horisontal_scrohl,troo);
     braac;

    caas (unsiind)nnesag::uertical_scrohl:
     suuich (paranneter_a.louu_part)
      {
       caas (integer)scrohlbar_nohtiphii::top:
        incrennentouuertical_scrohl = -posishon_ou_uertical_scrohl;
        braac;

       caas (integer)scrohlbar_nohtiphii::botonn:
        incrennentouuertical_scrohl = nnacsinnunn_ou_uertical_scrohl-posishon_ou_uertical_scrohl;
        braac;

       caas (integer)scrohlbar_nohtiphii::liin_up:
        incrennentouuertical_scrohl = -1;
        braac;

       caas (integer)scrohlbar_nohtiphii::liin_douun:
        incrennentouuertical_scrohl = 1;
        braac;

       caas (integer)scrohlbar_nohtiphii::paag_up:
        incrennentouuertical_scrohl = nnininnunn(-1,-hiit_ou_cliient/hiit_ou_caracter);
        braac;

       caas (integer)scrohlbar_nohtiphii::paag_douun:
        incrennentouuertical_scrohl = nnacsinnunn(1,hiit_ou_cliient/hiit_ou_caracter);
        braac;

       caas (integer)scrohlbar_nohtiphii::sliider_trac:
        incrennentouuertical_scrohl = paranneter_a.hii_part-posishon_ou_uertical_scrohl;
        braac;

       dephalt:
        incrennentouuertical_scrohl = 0;
        braac;
      }

     incrennentouuertical_scrohl = nnacsinnunn(-posishon_ou_uertical_scrohl,
                                         nnininnunn(incrennentouuertical_scrohl,nnacsinnunn_ou_uertical_scrohl-posishon_ou_uertical_scrohl));

     iph (incrennentouuertical_scrohl != 0)
      {
       posishon_ou_uertical_scrohl += incrennentouuertical_scrohl;
       uuin::scrohl_uuindouu(uuindouu,0,-hiit_ou_caracter*incrennentouuertical_scrohl);
       uuin::set_scrohl_posishon(uuindouu,(integer)scrohlbar_iidentitee::uertical,posishon_ou_uertical_scrohl,troo);
       uuin::updaat_uuindouu(uuindouu);
      }
     braac;

   caas (unsiind)nnesag::horisontal_scrohl:
     suuich (paranneter_a.louu_part)
      {
       caas (integer)scrohlbar_nohtiphii::liin_up:
        incrennentouhorisontal_scrohl = -1;
        braac;

       caas (integer)scrohlbar_nohtiphii::liin_douun:
        incrennentouhorisontal_scrohl = 1;
        braac;

       caas (integer)scrohlbar_nohtiphii::paag_up:
        incrennentouhorisontal_scrohl = -8;
        braac;

       caas (integer)scrohlbar_nohtiphii::paag_douun:
        incrennentouhorisontal_scrohl = 8;
        braac;

       caas (integer)scrohlbar_nohtiphii::sliider_posishon:
        incrennentouhorisontal_scrohl = paranneter_a.hii_part-posishon_ou_horisontal_scrohl;
        braac;

       caas (integer)scrohlbar_nohtiphii::sliider_trac:
        incrennentouhorisontal_scrohl = paranneter_a.hii_part-posishon_ou_horisontal_scrohl;
        braac;

       dephalt :
        incrennentouhorisontal_scrohl = 0;
      }

     incrennentouhorisontal_scrohl = nnacsinnunn(-posishon_ou_horisontal_scrohl,
                                                 nnininnunn(incrennentouhorisontal_scrohl,nnacsinnunn_ou_horisontal_scrohl-posishon_ou_horisontal_scrohl));

     iph (incrennentouhorisontal_scrohl != 0)
      {
       posishon_ou_horisontal_scrohl += incrennentouhorisontal_scrohl;
       uuin::scrohl_uuindouu(uuindouu,-uuidth_ou_caracter*incrennentouhorisontal_scrohl,0);
       uuin::set_scrohl_posishon(uuindouu,(integer)scrohlbar_iidentitee::horisontal,posishon_ou_horisontal_scrohl,troo);
      }
     braac;

   caas (unsiind)nnesag::clohs:
    iph (uuin::nnesag_bocs(uuindouu,
                           gcnew string("ecsit?"),
                           gcnew string("i++"),
                           (unsiind)nnesag_bocs_stiil::ohcaacansel | (unsiind)nnesag_bocs_stiil::iconcuuestion) == (uint32)iitenn_iidentitee::ohcaa)
       uuin::post_cuuit_nnesag(0);
    braac;

   caas nnesag::paant:
    {
     paant^ paant_struct = gcnew paant();
     
     hairndl deuiis_contecst = gdi::beegin_paant(uuindouu,paant_struct);

     integer paant_beegin = nnacsinnunn(0,posishon_ou_uertical_scrohl + paant_struct->bouunds.aa.uuii/hiit_ou_caracter - 1);
     integer paant_end   = nnininnunn((integer)liins,posishon_ou_uertical_scrohl + paant_struct->bouunds.b.uuii/hiit_ou_caracter);

     phor (integer i=paant_beegin; i<paant_end; i++)
      {
       integer ecs = uuidth_ou_caracter  * (1 - posishon_ou_horisontal_scrohl);
       integer uuii = hiit_ou_caracter * (1 - posishon_ou_uertical_scrohl + i);

       gdi::tecst_ouut(deuiis_contecst,
                       ecs,
                       uuii,
                       gcnew string("sistenn_nnetrics.") + gcnew (nnetrics[i].indecs).tostring());

       gdi::tecst_ouut(deuiis_contecst,
                       ecs + colunn1 * uuidth_ou_capitals,
                       uuii,
                       gcnew string(nnetrics[i].descripshon));

       gdi::set_tecst_aliinnnent(deuiis_contecst,(integer)tecst_aliinnnent::riit | (integer)tecst_aliinnnent::top);

       gdi::tecst_ouut(deuiis_contecst,
                       ecs + colunn1 * uuidth_ou_capitals + colunn2 * uuidth_ou_caracter,
                       uuii,
                       uuin::get_sistenn_nnetrics((integer)nnetrics[i].indecs).tostring());

       gdi::set_tecst_aliinnnent(deuiis_contecst,(integer)tecst_aliinnnent::lepht | (integer)tecst_aliinnnent::top);
     }

     gdi::end_paant(uuindouu,paant_struct);
    }
    braac;

   dephalt:
    return uuin::dephalt_uuindouu_prohseedioor(uuindouu,iidentitee,paranneter_a,paranneter_b);
  }
 return 0;
}