void OnlineHandwritingPicture::draw(int spatialSize) {
  std::vector<char> grid(spatialSize * spatialSize, ' ');
  for (int i = 0; i < ops.size(); i++) {
    arma::mat csp = constantSpeed(ops[i], 0.1);
    for (int j = 0; j < csp.n_rows; ++j) {
      int a0 = csp(j, 0) + spatialSize / 2.0,
          a1 = csp(j, 1) + spatialSize / 2.0;
      if (a0 >= 0 and a1 >= 0 and a0 < spatialSize and a1 < spatialSize) {
        int n = a0 * spatialSize + a1;
        grid[n] = 'x';
      }
    }
  }
  for (int x = 0; x < spatialSize; x++)
    std::cout << "--";
  std::cout << "|\n";
  for (int y = 0; y < spatialSize; y++) {
    for (int x = 0; x < spatialSize; x++)
      std::cout << grid[x * spatialSize + y] << grid[x * spatialSize + y];
    std::cout << "|\n";
  }
  for (int x = 0; x < spatialSize; x++)
    std::cout << "--";
  std::cout << "|\n";
}
Beispiel #2
0
void do_sign(short town_num, short which_sign, short sign_type)
//town_num; // Will be 0 - 200 for town, 200 - 290 for outdoors
//short sign_type; // terrain type
{
	char sign_text[256];
	location view_loc;

	view_loc = (is_out()) ? party.p_loc : c_town.p_loc;
	SetCursor(sword_curs);

	cd_create_dialog(1014,mainPtr);

	store_sign_mode = sign_type;
	if (terrain_pic[sign_type] < 1000)
		csp(1014,3,terrain_pic[sign_type]);
		else csp(1014,3,94);

	if (town_num >= 200) {
		town_num -= 200;
		load_outdoors(town_num % scenario.out_width, town_num / scenario.out_width,party.i_w_c.x,party.i_w_c.y,
			1,which_sign + 100,(char *) sign_text);
		}
		else {
			sprintf((char *) sign_text,"%s",data_store->town_strs[120 + which_sign]);
			}
	csit(1014,2,(char *) sign_text);

	while (dialog_not_toast)
		ModalDialog();
	cd_kill_dialog(1014,0);
}
HeapWord*
G1BlockOffsetArray::forward_to_block_containing_addr_slow(HeapWord* q,
                                                          HeapWord* n,
                                                          const void* addr) {
  // We're not in the normal case.  We need to handle an important subcase
  // here: LAB allocation.  An allocation previously recorded in the
  // offset table was actually a lab allocation, and was divided into
  // several objects subsequently.  Fix this situation as we answer the
  // query, by updating entries as we cross them.

  // If the fist object's end q is at the card boundary. Start refining
  // with the corresponding card (the value of the entry will be basically
  // set to 0). If the object crosses the boundary -- start from the next card.
  size_t n_index = _array->index_for(n);
  size_t next_index = _array->index_for(n) + !_array->is_card_boundary(n);
  // Calculate a consistent next boundary.  If "n" is not at the boundary
  // already, step to the boundary.
  HeapWord* next_boundary = _array->address_for_index(n_index) +
                            (n_index == next_index ? 0 : N_words);
  assert(next_boundary <= _array->_end,
         err_msg("next_boundary is beyond the end of the covered region "
                 " next_boundary " PTR_FORMAT " _array->_end " PTR_FORMAT,
                 next_boundary, _array->_end));
  if (csp() != NULL) {
    if (addr >= csp()->top()) return csp()->top();
    while (next_boundary < addr) {
      while (n <= next_boundary) {
        q = n;
        oop obj = oop(q);
        if (obj->klass_or_null() == NULL) return q;
        n += obj->size();
      }
      assert(q <= next_boundary && n > next_boundary, "Consequence of loop");
      // [q, n) is the block that crosses the boundary.
      alloc_block_work2(&next_boundary, &next_index, q, n);
    }
  } else {
    while (next_boundary < addr) {
      while (n <= next_boundary) {
        q = n;
        oop obj = oop(q);
        if (obj->klass_or_null() == NULL) return q;
        n += _sp->block_size(q);
      }
      assert(q <= next_boundary && n > next_boundary, "Consequence of loop");
      // [q, n) is the block that crosses the boundary.
      alloc_block_work2(&next_boundary, &next_index, q, n);
    }
  }
  return forward_to_block_containing_addr_const(q, n, addr);
}
Beispiel #4
0
void put_party_stats()
{
	short i;

	for (i = 0; i < 6; i++) {
		if (adven[i].main_status > MAIN_STATUS_ABSENT) {
			cd_set_item_text(989,5 + 5 * i,adven[i].name);
			cd_activate_item(989,7 + 5 * i,1);
			cd_activate_item(989,8 + 5 * i,1);
			cd_set_flag(989,6 + 5 * i,96);
			cd_activate_item(989,35 + i,1);
			cd_activate_item(989,42 + i,1);
			csp(989,42 + i,800 + adven[i].which_graphic);
			}
			else {
				cd_set_item_text(989,5 + 5 * i,"Empty.");
				cd_activate_item(989,7 + 5 * i,0);
				cd_activate_item(989,8 + 5 * i,0);
				cd_set_flag(989,6 + 5 * i,98);
				cd_activate_item(989,35 + i,0);
				cd_activate_item(989,42 + i,0);
				}

	}
}
Beispiel #5
0
	void model::move_creature
		(const std::weak_ptr<creature>& c, int x, int y)
	{
		std::shared_ptr<creature> csp(c.lock());

		if (!csp)
		{
			std::cerr << "Invalid creature for movement." << std::endl;
			throw invalid_parameter();
		}

		map_.move_creature(csp, x, y);
	}
Beispiel #6
0
/*
* Gather Entropy from Win32 CAPI
*/
void Win32_CAPI_EntropySource::poll(Entropy_Accumulator& accum)
   {
   secure_vector<byte>& buf = accum.get_io_buf(BOTAN_SYSTEM_RNG_POLL_REQUEST);

   for(size_t i = 0; i != m_prov_types.size(); ++i)
      {
      CSP_Handle csp(m_prov_types[i]);

      if(size_t got = csp.gen_random(buf.data(), buf.size()))
         {
         accum.add(buf.data(), got, BOTAN_ENTROPY_ESTIMATE_STRONG_RNG);
         break;
         }
      }
   }
Beispiel #7
0
/*
* Gather Entropy from Win32 CAPI
*/
void Win32_CAPI_EntropySource::poll(Entropy_Accumulator& accum)
   {
   m_buf.resize(32);

   for(size_t i = 0; i != prov_types.size(); ++i)
      {
      CSP_Handle csp(prov_types[i]);

      if(size_t got = csp.gen_random(m_buf.data(), m_buf.size()))
         {
         accum.add(m_buf.data(), got, 6);
         break;
         }
      }
   }
Beispiel #8
0
inline HeapWord*
G1BlockOffsetArray::
forward_to_block_containing_addr_const(HeapWord* q, HeapWord* n,
                                       const void* addr) const {
  if (csp() != NULL) {
    if (addr >= csp()->top()) return csp()->top();
    while (n <= addr) {
      q = n;
      oop obj = oop(q);
      if (obj->klass_or_null() == NULL) return q;
      n += obj->size();
    }
  } else {
    while (n <= addr) {
      q = n;
      oop obj = oop(q);
      if (obj->klass_or_null() == NULL) return q;
      n += _sp->block_size(q);
    }
  }
  assert(q <= n, "wrong order for q and addr");
  assert(addr < n, "wrong order for addr and n");
  return q;
}
/* Generate a floating key reference from a CSSM_KEY */
OSStatus
SecKeyCreateWithCSSMKey(const CSSM_KEY *cssmKey,
    SecKeyRef *keyRef)
{
	BEGIN_SECAPI

	Required(cssmKey);
	CssmClient::CSP csp(cssmKey->KeyHeader.CspId);
	CssmClient::Key key(csp, *cssmKey);
	KeyItem *item = new KeyItem(key);

	// Return the generated key.
	if (keyRef)
		*keyRef = item->handle();

	END_SECAPI
}
Beispiel #10
0
ChatDialog::ChatDialog(QUdpSocket* channel, QString objName, QWidget *parent) :
    QDialog(parent),
    mLabelRecv(0),
    mLabelSend(0),
    mBtnSend(0),
    mBtnClose(0),
    mTxtRecv(0),
    mTxtSend(0),
    mChannel(channel)
{
    this->setObjectName(objName);

    init();

    int pos = objName.indexOf('-');
    QString peer = objName.left(pos);

    ClientStringParser csp(peer);
    mPeerName = csp.getName();
    ClientStringParser csp1(objName.right(objName.length() - pos -1));
    mName = csp1.getName();

    this->setWindowTitle(TALK_WITH.arg(peer).arg(mName));
}
Beispiel #11
0
void ContentType::parse( const EString &s )
{
    EmailParser p( s );
    p.whitespace();
    while ( p.present( ":" ) )
        p.whitespace();

    bool mustGuess = false;

    if ( p.atEnd() ) {
        t = "text";
        st = "plain";
    }
    else {
        uint x = p.mark();
        if ( p.nextChar() == '/' )
            mustGuess = true;
        else
            t = p.mimeToken().lower();
        if ( p.atEnd() ) {
            if ( s == "text" ) {
                t = "text"; // elm? mailtool? someone does this, anyway.
                st = "plain";
            }
            // the remainder is from RFC 1049
            else if ( s == "postscript" ) {
                t = "application";
                st = "postscript";
            }
            else if ( s == "postscript" ) {
                t = "application";
                st = "postscript";
            }
            else if ( s == "sgml" ) {
                t = "text";
                st = "sgml";
            }
            else if ( s == "tex" ) {
                t = "application";
                st = "x-tex";
            }
            else if ( s == "troff" ) {
                t = "application";
                st = "x-troff";
            }
            else if ( s == "dvi" ) {
                t = "application";
                st = "x-dvi";
            }
            else if ( s.startsWith( "x-" ) ) {
                st = "x-rfc1049-" + s;
                t = "application";
            }
            else {
                // scribe and undefined types
                setError( "Invalid Content-Type: " + s.quoted() );
            }
        }
        else {
            if ( p.nextChar() == '/' ) {
                p.step();
                if ( !p.atEnd() || p.nextChar() != ';' )
                    st = p.mimeToken().lower();
                if ( st.isEmpty() )
                    mustGuess = true;
            }
            else if ( p.nextChar() == '=' ) {
                // oh no. someone skipped the content-type and
                // supplied only some parameters. we'll assume it's
                // text/plain and parse the parameters.
                t = "text";
                st = "plain";
                p.restore( x );
                mustGuess = true;
            }
            else {
                addParameter( "original-type", t + "/" + st );
                t = "application";
                st = "octet-stream";
                mustGuess = true;
            }
            parseParameters( &p );
        }
    }

    if ( mustGuess ) {
        EString fn = parameter( "name" );
        if ( fn.isEmpty() )
            fn = parameter( "filename" );
        while ( fn.endsWith( "." ) )
            fn.truncate( fn.length() - 1 );
        fn = fn.lower();
        if ( fn.endsWith( "jpg" ) || fn.endsWith( "jpeg" ) ) {
            t = "image";
            st = "jpeg";
        }
        else if ( fn.endsWith( "htm" ) || fn.endsWith( "html" ) ) {
            t = "text";
            st = "html";
        }
        else if ( fn.isEmpty() && st.isEmpty() && t == "text" ) {
            st = "plain";
        }
        else if ( t == "text" ) {
            addParameter( "original-type", t + "/" + st );
            st = "plain";
        }
        else {
            addParameter( "original-type", t + "/" + st );
            t = "application";
            st = "octet-stream";
        }
    }

    if ( t.isEmpty() || st.isEmpty() )
        setError( "Both type and subtype must be nonempty: " + s.quoted() );

    if ( valid() && t == "multipart" && st == "appledouble" &&
         parameter( "boundary" ).isEmpty() ) {
        // some people send appledouble without the header. what can
        // we do? let's just call it application/octet-stream. whoever
        // wants to decode can try, or reply.
        t = "application";
        st = "octet-steam";
    }

    if ( valid() && !p.atEnd() &&
         t == "multipart" && parameter( "boundary" ).isEmpty() &&
         s.lower().containsWord( "boundary" ) ) {
        EmailParser csp( s.mid( s.lower().find( "boundary" ) ) );
        csp.require( "boundary" );
        csp.whitespace();
        if ( csp.present( "=" ) )
            csp.whitespace();
        uint m = csp.mark();
        EString b = csp.string();
        if ( b.isEmpty() || !csp.ok() ) {
            csp.restore( m );
            b = csp.input().mid( csp.pos() ).section( ";", 1 ).simplified();
            if ( !b.isQuoted() )
                b.replace( "\\", "" );
            if ( b.isQuoted() )
                b = b.unquoted();
            else if ( b.isQuoted( '\'' ) )
                b = b.unquoted( '\'' );
        }
        if ( !b.isEmpty() )
            addParameter( "boundary", b );
    }

    if ( valid() && t == "multipart" && parameter( "boundary" ).isEmpty() )
        setError( "Multipart entities must have a boundary parameter." );

    if ( !parameter( "charset" ).isEmpty() ) {
        Codec * c = Codec::byName( parameter( "charset" ) );
        if ( c ) {
            EString cs = c->name().lower();
            if ( t == "text" && cs == "us-ascii" )
                removeParameter( "charset" );
            else if ( cs != parameter( "charset" ).lower() )
                addParameter( "charset", cs );
        }
    }

    if ( valid() && !p.atEnd() &&
         t == "text" && parameter( "charset" ).isEmpty() &&
         s.mid( p.pos() ).lower().containsWord( "charset" ) ) {
        EmailParser csp( s.mid( s.lower().find( "charset" ) ) );
        csp.require( "charset" );
        csp.whitespace();
        if ( csp.present( "=" ) )
            csp.whitespace();
        Codec * c = Codec::byName( csp.dotAtom() );
        if ( c )
            addParameter( "charset", c->name().lower() );
    }

    if ( !valid() )
        setUnparsedValue( s );
}
Beispiel #12
0
void display_pc_info()
{
	short i,store;
	Str255 str;
	short pc;
	char to_draw[60];
	
	short weap1 = 24,weap2 = 24,hit_adj = 0, dam_adj = 0,skill_item;

	pc = store_pc_num;
	
	store = pc_carry_weight(pc);
	i = amount_pc_can_carry(pc);
	sprintf ((char *) to_draw, "%s is carrying %d stones out of %d.",univ.party[pc].name.c_str(),store,i);
	csit(1019,69,(char *) to_draw);

	sprintf((char *) str,"%d out of %d.",
			univ.party[pc].cur_health,univ.party[pc].max_health);
	csit(1019,65,(char *) str);
	sprintf((char *) str,"%d out of %d.",
			univ.party[pc].cur_sp,univ.party[pc].max_sp);
	csit(1019,67,(char *) str);

	for (i = 0; i < 19; i++) {
		cdsin(1019,18 + i * 2,univ.party[pc].skills[i]);
		}
	store = total_encumberance(pc);
	cdsin(1019,62,store);
	csit(1019,9,univ.party[pc].name.c_str());
	cdsin(1019,11,univ.party[pc].level);
	cdsin(1019,13,univ.party[pc].experience);
	cdsin(1019,71,univ.party[pc].skill_pts);
	store = univ.party[pc].level * univ.party[pc].get_tnl();
	cdsin(1019,15,store);
	csp(1019,7,800 + univ.party[pc].which_graphic,PICT_PC);

	// Fight bonuses
	for (i = 0; i < 24; i++)
		if (((univ.party[pc].items[i].variety == 1) || (univ.party[pc].items[i].variety == 2)) &&
			(univ.party[pc].equip[i] == true)) {
					if (weap1 == 24)
						weap1 = i;
						else weap2 = i;
					}
				
	hit_adj = stat_adj(pc,1) * 5 - (total_encumberance(pc)) * 5 
		+ 5 * minmax(-8,8,univ.party[pc].status[1]);
	if ((univ.party[pc].traits[2] == false) && (weap2 < 24))
		hit_adj -= 25;

	dam_adj = stat_adj(pc,0) + minmax(-8,8,univ.party[pc].status[1]);
	if ((skill_item = text_pc_has_abil_equip(pc,37)) < 24) {
		hit_adj += 5 * (univ.party[pc].items[skill_item].item_level / 2 + 1);
		dam_adj += univ.party[pc].items[skill_item].item_level / 2;
		}
	if ((skill_item = text_pc_has_abil_equip(pc,43)) < 24) {
		dam_adj += univ.party[pc].items[skill_item].item_level;
		hit_adj += univ.party[pc].items[skill_item].item_level * 2;
		}

		
	csit(1019,56,"No weapon.");	
	csit(1019,57,"");	
	csit(1019,59,"No weapon.");	
	csit(1019,60,"");	
	if (weap1 < 24) {
		if (!univ.party[pc].items[weap1].ident)
			csit(1019,56,"Not identified.");
			else {
				if (hit_adj + 5 * univ.party[pc].items[weap1].bonus < 0)
					sprintf(to_draw,"Penalty to hit: %%%d",hit_adj + 5 * univ.party[pc].items[weap1].bonus);
					else sprintf(to_draw,"Bonus to hit: +%%%d",hit_adj + 5 * univ.party[pc].items[weap1].bonus);
				csit(1019,56,to_draw);
				sprintf(to_draw,"Damage: (1-%d) + %d",univ.party[pc].items[weap1].item_level
					,dam_adj + univ.party[pc].items[weap1].bonus);
				csit(1019,57,to_draw);

				}
			}
	if (weap2 < 24) {
		if (!univ.party[pc].items[weap2].ident)
			csit(1019,59,"Not identified.");
			else {
				if (hit_adj + 5 * univ.party[pc].items[weap2].bonus < 0)
					sprintf(to_draw,"Penalty to hit: %%%d",hit_adj + 5 * univ.party[pc].items[weap2].bonus);
					else sprintf(to_draw,"Bonus to hit: +%%%d",hit_adj + 5 * univ.party[pc].items[weap2].bonus);
				csit(1019,59,to_draw);
				sprintf(to_draw,"Damage: (1-%d) + %d",univ.party[pc].items[weap2].item_level
					,dam_adj + univ.party[pc].items[weap2].bonus);
				csit(1019,60,to_draw);

				}
			}

}
Beispiel #13
0
void put_item_info(short pc,short item)////
{
	char store_text[256];
	Str255 desc_str;
	short i;	
	cItemRec s_i;
	char *item_types[] = {"","1-Handed weapon","2-Handed weapon","","Bow","Arrows","Thrown missile",
			"Potion/Magic Item","Scroll/Magic Item","Wand","Tool","","Shield","Armor","Helm",
			"Gloves","Shield","Boots","Ring","Necklace",
			"Weapon Poison","Gem, Stone, Etc.","Pants","Crossbow","Bolts","Missile Weapon"};

		
	s_i = store_i;
	
	csp(998,1,0,PICT_BLANK);
	if (s_i.graphic_num >= 1000) // was 150
		csp(998,1,s_i.graphic_num - 1000,PICT_CUSTOM + PICT_ITEM);
		else csp(998,1,s_i.graphic_num,PICT_ITEM);
		
	// id? magic?
	if (store_i.magic && store_i.ident)
		cd_set_led(998,17,1);
	else cd_set_led(998,17,0);
	if (store_i.ident)
		cd_set_led(998,16,1);
	else cd_set_led(998,16,0);
	cd_set_item_text(998,4,	item_types[s_i.variety]);
	
	// Clear fields
	for (i = 5; i < 13; i++) {
		cd_set_item_text(998,i,	"");
		}
			

	if (!s_i.ident) {
			cd_set_item_text(998,3,	s_i.name.c_str());
			return;
		}	
			
	cd_set_item_text(998,3,	s_i.full_name.c_str());
	i = s_i.item_weight();
	cd_set_item_num(998,20,i);
	
	cd_set_item_num(998,5,(s_i.charges > 0) ? s_i.value * s_i.charges : s_i.value);

	if (s_i.ability > 0) {////
		if (s_i.concealed) {
			cd_set_item_text(998,12,"???");
		} else {
			get_str(desc_str,23,s_i.ability + 1);
			cd_set_item_text(998,12,(char *) desc_str);
		}
	}	
	if (s_i.charges > 0)
		cd_set_item_num(998,10,s_i.charges);
	if (s_i.protection > 0)	
		cd_set_item_num(998,8,s_i.protection);

	switch (s_i.variety) {
		case ITEM_TYPE_ONE_HANDED:
		case ITEM_TYPE_TWO_HANDED:
			cd_set_item_num(998,6,s_i.item_level);
			cd_set_item_num(998,7,s_i.bonus);
		
			switch (s_i.type) {
				case ITEM_EDGED:
					sprintf((char *) store_text, "Edged weapon");
					break;
				case ITEM_BASHING:
					sprintf((char *) store_text, "Bashing weapon");
					break;
				case ITEM_POLE:
					sprintf((char *) store_text, "Pole weapon");
					break;
				case ITEM_NOT_MELEE:
				default:
					sprintf((char*)store_text, "Error weapon"); // should never be reached
				}
			if (s_i.ability == 0)
				cd_set_item_text(998,12,store_text);
			break;
		case ITEM_TYPE_BOW:
		case ITEM_TYPE_CROSSBOW:
			cd_set_item_num(998,6,s_i.item_level);
			cd_set_item_num(998,7,s_i.bonus);
			break;
		case ITEM_TYPE_ARROW:
		case ITEM_TYPE_THROWN_MISSILE:
		case ITEM_TYPE_BOLTS:
		case ITEM_TYPE_MISSILE_NO_AMMO:
			cd_set_item_num(998,6,s_i.item_level);
			cd_set_item_num(998,7,s_i.bonus);	
			break;
		case ITEM_TYPE_POTION:
		case ITEM_TYPE_RING:
		case ITEM_TYPE_SCROLL: // TODO: Does this make sense for a scroll, though?
		case ITEM_TYPE_TOOL: // and what about for a tool?
		case ITEM_TYPE_WAND: // and a wand? Maybe showing ability strength would be better...
		case ITEM_TYPE_NECKLACE: // TODO: This doesn't seem right for a necklace...
			cd_set_item_num(998,11,s_i.item_level);
			break;
		case ITEM_TYPE_SHIELD:
		case ITEM_TYPE_ARMOR:
		case ITEM_TYPE_HELM:
		case ITEM_TYPE_GLOVES:
		case ITEM_TYPE_SHIELD_2:
		case ITEM_TYPE_BOOTS: // TODO: Should this also check ITEM_TYPE_PANTS?
			cd_set_item_num(998,7,s_i.bonus + s_i.protection);	
			cd_set_item_num(998,8,s_i.item_level);	
			cd_set_item_num(998,9,s_i.awkward);
			break;	
		case ITEM_TYPE_WEAPON_POISON:
			cd_set_item_num(998,11,s_i.item_level);
			break;
		default:
			// no item, gold, food, non-use, unused 1 and 2: do nothing
			break;
		}	

}
Beispiel #14
0
long CALLBACK WndProc (HWND hwnd, UINT message,WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
//RECT s_rect = {0,0,30,30},d_rect = {0,0,30,30},d2 = {0,0,420,216},s2 = {0,0,420,216};
POINT press;
short handled = 0,sbar_pos = 0,old_setting;
long which_sbar;
int min = 0, max = 0;
HMENU menu;
POINT p;
RECT r;

	switch (message) {
	case WM_KEYDOWN:
		 if (hwnd != mainPtr) {
			check_cd_event(hwnd,message,wParam,lParam);
			}
			else {
				All_Done = handle_syskeystroke(wParam,lParam,&handled);
				}
		return 0;
		break;

	case WM_CHAR:
		if (hwnd != mainPtr)
			check_cd_event(hwnd,message,wParam,lParam);
			else {
				All_Done = handle_keystroke(wParam,lParam);
				}
		return 0;
		break;

	case WM_LBUTTONDOWN:
		cursor_stay();
		if (hwnd != mainPtr)
			check_cd_event(hwnd,message,wParam,lParam);
			else {
				SetFocus(hwnd);
				press = MAKEPOINT(lParam);

				All_Done = handle_action(press, wParam,lParam);
				check_game_done();
				}
		return 0;
		break;

	case WM_LBUTTONUP:
		mouse_button_held = FALSE;
		break;

	case WM_RBUTTONDOWN:
		mouse_button_held = FALSE;
		cursor_stay();
		if (hwnd != mainPtr)
			check_cd_event(hwnd,message,wParam,lParam);
			else {
				SetFocus(hwnd);
				press = MAKEPOINT(lParam);

				All_Done = handle_action(press, wParam,-2);
				check_game_done();
				}
		return 0;
		break;

	case WM_TIMER:
		// first, mouse held?
		if ((wParam == 1) && (mouse_button_held == TRUE)) {
			GetCursorPos(&p);
			ScreenToClient(mainPtr,&p);
			All_Done = handle_action(p, 0,0);
			}
		// second, refresh cursor?
		if ((wParam == 1) && (overall_mode < 60) && (GetFocus() == mainPtr)) {
			GetCursorPos(&p);
			ScreenToClient(mainPtr,&p);
			GetClientRect(mainPtr,&r);
			if (PtInRect(&r,p))
				restore_cursor();
			}

        if(play_anim == TRUE){
            anim_ticks++;
		    if(overall_mode < 60){
        	    draw_terrain();
                }
            if(overall_mode == 62){
            if(store_ter.picture >= 2000)
                csp(813,14,store_ter.picture - 2000, 5);
       	    else if (store_ter.picture >= 400 && store_ter.picture < 1000)
			    csp(813,14,store_ter.picture - 100, 0);

            if(do_choose_anim == TRUE){
                put_choice_pics();
			    }
            }
        }
		break;

	case WM_PALETTECHANGED:
		 palette_suspect = TRUE;
		 return 0;

	case WM_ACTIVATE:
		if (hwnd == mainPtr) {
			if (((wParam == WA_ACTIVE) ||(wParam == WA_CLICKACTIVE)) &&
				(palette_suspect == TRUE)) {
				palette_suspect = FALSE;
				}
			if ((wParam == WA_ACTIVE) ||(wParam == WA_CLICKACTIVE)) {
				window_in_front = TRUE;
				 }
			if (wParam == WA_INACTIVE) {
				window_in_front = FALSE;
				}
			}
		return 0;


	case WM_MOUSEMOVE:
		if ((mouse_button_held == TRUE) && (hwnd == mainPtr)) {
			press = MAKEPOINT(lParam);
			All_Done = handle_action(press, wParam,lParam);
			}
      	restore_cursor();
		return 0;

	case WM_PAINT:
		hdc = BeginPaint(hwnd,&ps);
		EndPaint(hwnd,&ps);
		if (hwnd != mainPtr)
			check_cd_event(hwnd,message,wParam,lParam);
			else redraw_screen();
		return 0;

	case WM_VSCROLL:
		which_sbar = GetWindowLong((HWND) lParam, GWL_ID);
		switch (which_sbar) {
			case 1:
				sbar_pos = GetScrollPos(right_sbar,SB_CTL);
				old_setting = sbar_pos;
				GetScrollRange(right_sbar,SB_CTL,&min,&max);
				switch (LOWORD(wParam)) {
					case SB_PAGEDOWN: sbar_pos += NRSONPAGE - 1; break;
					case SB_LINEDOWN: sbar_pos++; break;
					case SB_PAGEUP: sbar_pos -= NRSONPAGE - 1; break;
					case SB_LINEUP: sbar_pos--; break;
					case SB_TOP: sbar_pos = 0; break;
					case SB_BOTTOM: sbar_pos = max; break;
					case SB_THUMBPOSITION:
					case SB_THUMBTRACK:
						sbar_pos = HIWORD(wParam);
						break;
					}
				if (sbar_pos < 0)
					sbar_pos = 0;
				if (sbar_pos > max)
					sbar_pos = max;

                lpsi.fMask = SIF_POS;
                lpsi.nPos = sbar_pos;
                SetScrollInfo(right_sbar,SB_CTL,&lpsi,TRUE);
//				SetScrollPos(right_sbar,SB_CTL,sbar_pos,TRUE);

				if (sbar_pos != old_setting)
					draw_rb();
				break;
			}
	    SetFocus(mainPtr);
		return 0;

	case WM_COMMAND:
		if (hwnd == mainPtr) {

			menu = GetMenu(mainPtr);
			handle_menu((short) wParam, menu);
			check_game_done();
			}
			else {
				check_cd_event(hwnd,message,wParam,lParam);
				}
		return 0;


	case WM_DESTROY:
	case WM_CLOSE:
		if (hwnd == mainPtr) {
		discard_graphics();
		PostQuitMessage(0);
			}
		return 0;
	case WM_QUIT:
      if (hwnd == mainPtr)
		discard_graphics();
		break;


	}

return DefWindowProc(hwnd,message,wParam,lParam);
}
void OnlineHandwritingPicture::codifyInputData(SparseGrid &grid, std::vector<float> &features, int &nSpatialSites, int spatialSize) {
  int nInputFeatures=OnlineHandwritingEncodingSize[enc];
  //Background feature
  grid.backgroundCol=nSpatialSites++;
  features.resize(nInputFeatures*nSpatialSites,0);
  //Render character
  switch(enc) {
  case Simple:
    for (int i=0; i<ops.size(); i++) {
      arma::mat csp=constantSpeed(ops[i],0.1);
      for (int j=0;j<csp.n_rows;++j) {
        int
          a0=csp(j,0)+spatialSize/2.0,
          a1=csp(j,1)+spatialSize/2.0;
        if (a0>=0 and a1>=0 and a0<spatialSize and a1<spatialSize) {
          int n= a0*spatialSize + a1;
          if (grid.mp.find(n)==grid.mp.end()) {
            grid.mp[n]=nSpatialSites++;
            features.resize(nInputFeatures*nSpatialSites,0);
          }
          ++features[grid.mp[n]];
          //          std::cout <<"."<<std::flush;
        } //else  std::cout <<"x"<<std::flush;
      }
    }
    break;
  case Octogram: {//todo: Test
    float piBy4=3.1415926536/4;
    for (int i=0; i<ops.size(); i++) {
      arma::mat csp=constantSpeed(ops[i],0.1);
      for (int j=0;j<csp.n_rows-1;++j) {
        int
          a0=csp(j,0)+spatialSize/2.0,
          a1=csp(j,1)+spatialSize/2.0;
        if (a0>=0 and a1>=0 and a0<spatialSize and a1<spatialSize) {
          int n= a0*spatialSize + a1;
          if (grid.mp.find(n)==grid.mp.end()) {
            grid.mp[n]=nSpatialSites++;
            features.resize(nInputFeatures*nSpatialSites,0);
          }
          int mpnnIF=nInputFeatures*grid.mp[n];
          features[mpnnIF]++;
          float dx=(csp(j+1,0)-csp(j,0));
          float dy=(csp(j+1,1)-csp(j,1));
          float m=powf(dx*dx+dy*dy,0.5);
          dx/=m;
          dy/=m;
          for (int k=0;k<8;k++) {
            float alpha=1-acosf(cosf(k*piBy4)*dx+sinf(k*piBy4)*dy)/piBy4;
            if (alpha>0)
              features[mpnnIF+k+1]+=alpha;
          }
        }
      }
    }
    break;
  }
  case LogSignature1:
    //Todo
    break;
  case LogSignature2:
    //Todo
    break;
  case LogSignature3:
    //Todo
    break;
  case LogSignature4:
    //Todo
    break;
  case SpaceTime3d: {
    std::vector<arma::mat> csp;
    int cspLengths=0;
    for (int i=0; i<ops.size(); i++) {
      csp.push_back(constantSpeed(ops[i],0.1));
      cspLengths+=csp[i].n_rows;
    }
    // if (cspLengths>maxLength) {
    //   std::cout <<cspLengths*penSpeed3d << " " << std::flush;
    //   maxLength=cspLengths;
    // }
    int z=0;
    for (int i=0; i<ops.size(); i++) {
      for (int j=0;j<csp[i].n_rows;++j) {
        int
          a0=csp[i](j,0)+spatialSize/2.0,
          a1=csp[i](j,1)+spatialSize/2.0,
          a2=renderSize*((z-cspLengths/2)*penSpeed3d+offset3d)+spatialSize/2;
        z++;
        if (a0>=0 and a1>=0 and a2>=0 and a0<spatialSize and a1<spatialSize and a2<spatialSize) {
          int n= a0*spatialSize*spatialSize + a1*spatialSize + a2;
          if (grid.mp.find(n)==grid.mp.end()) {
            grid.mp[n]=nSpatialSites++;
            features.resize(nInputFeatures*nSpatialSites,0);
          }
          ++features[grid.mp[n]];
        }
      }
    }
    break;
  }
  case VectorSpaceTime3d: {
    std::vector<arma::mat> csp;
    int cspLengths=0;
    for (int i=0; i<ops.size(); i++) {
      csp.push_back(constantSpeed(ops[i],0.1));
      cspLengths+=csp[i].n_rows;
    }
    // if (cspLengths>maxLength) {
    //   std::cout << cspLengths*penSpeed3d << " " << std::flush;
    //   maxLength=cspLengths;
    // }
    int z=0;
    for (int i=0; i<ops.size(); i++) {
      for (int j=0;j<csp[i].n_rows-1;++j) {
        int
          a0=csp[i](j,0)+spatialSize/2.0,
          a1=csp[i](j,1)+spatialSize/2.0,
          a2=renderSize*((z-cspLengths/2)*penSpeed3d+offset3d)+spatialSize/2;
        z++;
        if (a0>=0 and a1>=0 and a2>=0 and a0<spatialSize and a1<spatialSize and a2<spatialSize) {
          int n= a0*spatialSize*spatialSize + a1*spatialSize + a2;
          if (grid.mp.find(n)==grid.mp.end()) {
            grid.mp[n]=nSpatialSites++;
            features.resize(nInputFeatures*nSpatialSites,0);
          }
          int mpnnIF=nInputFeatures*grid.mp[n];
          features[mpnnIF]++;
          float dx=(csp[i](j+1,0)-csp[i](j,0));
          float dy=(csp[i](j+1,1)-csp[i](j,1));
          float m=powf(dx*dx+dy*dy,0.5);
          dx/=m;
          dy/=m;
          features[mpnnIF+1]+=dx;
          features[mpnnIF+2]+=dy;
        }
      }
    }
    break;
  }
  }
}