Batch Index du Forum
S’enregistrerRechercherFAQMembresGroupesConnexion
Répondre au sujet Page 1 sur 2
Aller à la page: 1, 2  >
bg 3.0 rc1 sprite demo
Auteur Message
Répondre en citant
Message bg 3.0 rc1 sprite demo 
Hello.
I finally finished the new sprite function for bg. And coming soon I will publish the final version 3.0. The next is a candidate for release version.
Is nice: it use a binary file, but this is not slow, because the programming method.
The editor is very primitive, currently.

The first column is the color of background, the second column is the color of foreground.
Then you need select a background color, a foreground color and a symbol from the palette and clic in the paint zone.
X means transparent.
In the paint zone, do a secondary mouse clic and the cell will be transparent.
For save and quit, do a secondary mouse clic outside the paint zone.


For execute the editor run this command:
Editor.exe width eight filename

for example:
editor 11 8 invader.spr

That will create a paint zone of 11x8 and when you save it the data would be on invader.spr

And after paint on it:



and the syntax of bg for draw it is:
bg sprite row column filename ...
where row and column are the coords of the console screen.
you can repeat the list of arguments, and using this you will get speedy.
Note: I forget write on the documentation that here the row and column can be negative numbers, like -1 or -5

For example. I print 55 invaders of 11x8 in 00:00:00.080 seconds (tested on win8 8gb and win xp 64mb memory and take the same time) using this code:

Code:

@Echo off
SetLocal EnableDelayedExpansion

Set "bgcmd="
For /l %%C in (1, 12, 96) Do (
Set "bgcmd1=!bgcmd1!  0 %%C invader.spr"
Set "bgcmd2=!bgcmd2! 10 %%C invader.spr"
Set "bgcmd3=!bgcmd3! 20 %%C invader.spr"
Set "bgcmd4=!bgcmd4! 30 %%C invader.spr"
Set "bgcmd5=!bgcmd5! 40 %%C invader.spr"

)

bg sprite %bgcmd1% %bgcmd2% %bgcmd3% %bgcmd4% %bgcmd5%

Pause >Nul

Goto :Eof


And I get this screen:




Please, any suggestion. You think useful create a separate command only for the sprite?


With this I will write a speedy version of space invader for batch.
The old sprite function of bg was slow for it.

Also, source code and executables of bg 3.0 rc1, and documentation here:
http://consolesoft.com/p/bg/



Dernière édition par carlos le Sam 12 Juil 2014 - 23:35; édité 1 fois
Message Publicité 
PublicitéSupprimer les publicités ?


Répondre en citant
Message bg 3.0 rc1 sprite demo 
I did some tests.
And for more speedy I will left sprite as a separated program.



Répondre en citant
Message bg 3.0 rc1 sprite demo 
Great job !

Your tool has a good interface ! I love it Smile
but how to use the sprite files ? What external command is needed ?



Visiter le site web du posteur
Répondre en citant
Message bg 3.0 rc1 sprite demo 
Hello.
In the same url: http://consolesoft.com/p/bg/
Currently I left the rc13. I optimized the source code of sprite many times, and now the sprite is really speedy.
Check example1.cmd (press esc for quit and use arrows for move).
Now, sprite is a separated command (bg sprite not work anymore), use sprite.exe instead.
Inside, also the documentation.

I will continue the develop.
I will post the final release coming soon.



Répondre en citant
Message bg 3.0 rc1 sprite demo 
Very nice Very Happy

The editor is simple, and easy to use, and it works great Wink
However It is sad that the sprite format actually consists on a matrix of struct. AFAIK, It could be much more tiny if it used somewhat a palette to store symbols.

The code is sympathic too. I particularly like this line (sprite.c, line 236) Mr. Green
Code:
Hasta_La_Vista_Baby:
    ExitProcess(ret);


@+




______________________________________________________
--
> Que pensez vous de l'ajout du repertoire point dans $PATH ?
Ma version de troll 18.0.32 beta 3 vient de me faire un core dump.
-+- SE in Guide du Linuxien Pervers : Bien développer son troll -+-

[Dos9]
Visiter le site web du posteur Skype
Répondre en citant
Message bg 3.0 rc1 sprite demo 
Darkbatcher a écrit:
Very nice Very Happy

The editor is simple, and easy to use, and it works great Wink
However It is sad that the sprite format actually consists on a matrix of struct. AFAIK, It could be much more tiny if it used somewhat a palette to store symbols.

The code is sympathic too. I particularly like this line (sprite.c, line 236) Mr. Green
Code:
Hasta_La_Vista_Baby:
    ExitProcess(ret);


@+


Very Happy
The format is perfect. If it is more small it will require calculations for convert, and it decrese the speed.

The develop continue. But currently sprite in the release candidate 19 is ok.
I will continue develop the play function of bg and also I will some experiments with the keyboard input.
I hope publish the final release the 2 august 2014.



Répondre en citant
Message bg 3.0 rc1 sprite demo 
.


carlos a écrit:

I hope publish the final release the 2 august 2014.


oh, oh, you forget the time Laughing



Répondre en citant
Message bg 3.0 rc1 sprite demo 
Citation:
The format is perfect. If it is more small it will require calculations for convert, and it decrese the speed.

Don't get me wrong, Carlos Wink

I sugested that because I thought it was worth to decrease (a lot) the size of sprites, without adding much computation to decode it.
Well, to be honnest, I didn't see that sprites files were only about a Ko, so, there is no problem I think ...

Now, I'm quite interrested in trying to implement the decode algorithm within a batbox experiment (sadly, it is going to be 3ko, I think).
You won't be too annoyed by it Carlos, would you ? Mr. Green Okay

EDIT:
I was a little bit confused when i looked at the source, because your license is somewhat strange :
Code:
/*
 * Copyright (c) 2010-2014 Carlos Montiers Aguilera. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met: 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer. 2.
 * Neither the name of copyright holders nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 */

It strikes me because it is neither the 3-Clause BSD license nor the 2-Clause BSD license. I mean, the license does not talks of binary form redistribution. So I can redistribute
a binary copy, without giving the license ? without even saying that i've not written it ?
Maybe it is wanted ? I don't know.

@+




______________________________________________________
--
> Que pensez vous de l'ajout du repertoire point dans $PATH ?
Ma version de troll 18.0.32 beta 3 vient de me faire un core dump.
-+- SE in Guide du Linuxien Pervers : Bien développer son troll -+-

[Dos9]
Visiter le site web du posteur Skype
Répondre en citant
Message bg 3.0 rc1 sprite demo 
Oops. That license is wrong, because it not include the disclaimer. Anyways I changed it to the zlib license that represent better my idea of distribution.
Please see the rc20 that have the source codes with that licenses.
Also I will update all the software in my site for that license Very Happy
And see the new example1.cmd it moves very quickly.



Répondre en citant
Message bg 3.0 rc1 sprite demo 
carlos a écrit:
Oops. That license is wrong, because it not include the disclaimer. Anyways I changed it to the zlib license that represent better my idea of distribution.
Please see the rc20 that have the source codes with that licenses.


You're welcome Carlos Wink (BTW, I'm auto-thanking me because it arguably was worth some thank Mr. Green )
Whatever, you're better off with zlib licence than with your strange modified BSD license.

Citation:
And see the new example1.cmd it moves very quickly.

Yeah ! It is really quick Carlos, great job Wink
I tried to implement the decode algorithm within BatBox (at beginning I had some troubles because I did not use the WriteConsoleOutput API), and I succeded, i'm able with my developement version to display sprites (through brand new the '/x' switch).

I seek to produce my own sprite, and I realised that there is a huge problem with editor.exe, that does not display the right characters for the full block (U+2588), and variety of other non-ascii characters. I'm working on fixing it, it must be not too tough for me Wink

++

EDIT:
I fixed it, the following code do the trick, it looks the same both in Unicode and ANSI. I also changed name of function _start on main and main on sprite_main (my compiler would not compile it otherwise). I also removed the codepage change because it has no influence on Unicode version.

Code:
/*
  Copyright (C) 2010-2014 Carlos Montiers Aguilera
  Copyright (C) 2014 Romain GARBI

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

  Carlos Montiers Aguilera
  cmontiers@gmail.com
*/

/*
 * BG Sprite Editor Version 0.5
 */

#define UNICODE

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

#ifdef UNICODE

#define      atoi            _wtoi

#endif

int sprite_main(int argc, TCHAR ** argv);

typedef struct {
    int newmode;
} _startupinfo;

int __wgetmainargs(int *_Argc, wchar_t *** _Argv, wchar_t *** _Env,
         int _DoWildCard, _startupinfo * _StartInfo);
int __getmainargs(int *_Argc, char ***_Argv, char ***_Env,
        int _DoWildCard, _startupinfo * _StartInfo);

int main(void)
{
    int argc;
    TCHAR **argv;
    TCHAR **env;
    int ret;

    _startupinfo start_info = { 0 };

#ifdef UNICODE
    ret = __wgetmainargs(&argc, &argv, &env, 0, &start_info);
#else
    ret = __getmainargs(&argc, &argv, &env, 0, &start_info);
#endif

    if (!ret) {
   ret = sprite_main(argc, argv);
    }
    ExitProcess(ret);
}

struct MOUSE_CLIC {
    COORD clicCoords;
    UINT buttonClic;
};

void spSizeErrorMessage();
void help();
void paintBlack();
void modeCon(int rows, int cols);
void mouse(struct MOUSE_CLIC *mouseClic);
BOOL coordHaveValues(COORD * coord, SHORT X, SHORT Y);

void showCursor(BOOL show);

#define S(color, character) ( (CHAR_INFO){(wchar_t)character, (WORD)color} )
#define SPACE S(0x0F, '-')

#ifndef UNICODE

#define FULL_BLOCK       0xDB
#define LIGHT_SHADE       0xB0
#define MEDIUM_SHADE   0xB1
#define DARK_SHADE       0xB2
#define WHITE_FACE      0x01
#define BLACK_FACE      0x02
#define HEART_SUIT      0x03
#define DIAMOND_SUIT   0x04
#define SPADE_SUIT      0x06
#define CLUB_SUIT      0x05
#define BEAMED_EIGHTH   0x07
#define SUN_RAYS      0x0F
#define BLACK_SQUARE   0xFE

#else

#define FULL_BLOCK      0x2588
#define LIGHT_SHADE      0x2591
#define MEDIUM_SHADE    0x2592
#define DARK_SHADE     0x2593
#define WHITE_FACE      0x263A
#define BLACK_FACE      0x263B
#define HEART_SUIT      0x2665
#define DIAMOND_SUIT   0x2666
#define SPADE_SUIT      0x2660
#define CLUB_SUIT      0x2663
#define BEAMED_EIGHTH   0x266B
#define SUN_RAYS      0x263C
#define BLACK_SQUARE   0x25A0

#endif

#define WBlock S(0x0F, MEDIUM_SHADE)
#define BBlock S(0x07, FULL_BLOCK)

#define CBlock S(0x00, 0x20)
#define PBlock S(0x07, 'X')

#define PAINTZONE_MAX_WIDTH (60)
#define PAINTZONE_MAX_EIGHT (20)

void spSizeErrorMessage()
{
    fwprintf(stderr,
        L"Size width must be from 1 to 60 and eight must be from 1 to 20\n");
}

void help()
{
    fwprintf(stdout,
        L"Bg Sprite Editor 0.5\n"
        "Arguments: width eight fileNameToSave\n\n");
}

int sprite_main(int argc, TCHAR ** argv)
{
#define BF(b,f) ((b<<4)+f)
#define TBF(c) ((c<<4)+c)

#define PALETTE_WIDTH (5)
#define PALETTE_EIGHT (14)
#define CARTOONS_WIDTH (2)
#define CARTOONS_EIGHT (7)

    struct MOUSE_CLIC mouseClic;
    HANDLE saveFile;

    //Init values
    UINT BColor = 0x0;
    UINT FColor = 0xE;
    UINT Cartoon = BLACK_SQUARE;

    UINT sp_Width;
    UINT sp_Eight;

    COORD dwSize;

    COORD dwCoord;
    HANDLE hOut;
    SMALL_RECT screenRegion;
    SMALL_RECT paintZoneRegion;

    UINT paintZone_Length;
    UINT paintZone_Width;
    UINT paintZone_Eight;

    CHAR_INFO palette[PALETTE_EIGHT][PALETTE_WIDTH] = {
   {BBlock, BBlock, BBlock, BBlock, BBlock},
   {WBlock, WBlock, WBlock, WBlock, WBlock},
   {WBlock, S(0x00, ' '), WBlock, S(0x80, ' '), WBlock},
   {WBlock, S(0x10, ' '), WBlock, S(0x90, ' '), WBlock},
   {WBlock, S(0x20, ' '), WBlock, S(0xA0, ' '), WBlock},
   {WBlock, S(0x30, ' '), WBlock, S(0xB0, ' '), WBlock},
   {WBlock, S(0x40, ' '), WBlock, S(0xC0, ' '), WBlock},
   {WBlock, S(0x50, ' '), WBlock, S(0xD0, ' '), WBlock},
   {WBlock, S(0x60, ' '), WBlock, S(0xE0, ' '), WBlock},
   {WBlock, S(0x70, ' '), WBlock, S(0xF0, ' '), WBlock},
   {WBlock, WBlock, WBlock, WBlock, WBlock},
   {WBlock, WBlock, WBlock, WBlock, WBlock},
   {WBlock, WBlock, CBlock, WBlock, WBlock},
   {WBlock, WBlock, WBlock, WBlock, WBlock}

    };

    CHAR_INFO cartoons[CARTOONS_EIGHT][CARTOONS_WIDTH] = {
   {S(0x07, WHITE_FACE), S(0x07, BLACK_FACE)},
   {S(0x07, HEART_SUIT), S(0x07, DIAMOND_SUIT)},
   {S(0x07, CLUB_SUIT), S(0x07, SPADE_SUIT)},
   {S(0x07, BEAMED_EIGHTH), S(0x07, SUN_RAYS)},
   {S(0x07, LIGHT_SHADE), S(0x07, FULL_BLOCK)},
   {S(0x07, MEDIUM_SHADE), S(0x07, BLACK_SQUARE)},
   {S(0x07, DARK_SHADE), CBlock}
    };

    CHAR_INFO paintCell = PBlock;

    COORD BCoord = { 3, 14 };
    COORD FCoord = { 9, 14 };
    COORD CCoord = { 14, 14 };
    DWORD numberOfCharsWritten;
    DWORD numberOfBytesWritten;

    UINT i;
    UINT limit;
    UINT writeErrors;

    CodePage = GetConsoleOutputCP();
    //SetConsoleOutputCP(1252u);

    modeCon(80, 25);
    paintBlack();

    if (argc != 4) {
   help();
   fwprintf(stderr, L"Few arguments.\n");
   return 1;
    }

    sp_Width = atoi(argv[1]);
    sp_Eight = atoi(argv[2]);



    if (sp_Width < 1 || sp_Width > PAINTZONE_MAX_WIDTH) {
   help();
   spSizeErrorMessage();
   return 1;
    }

    if (sp_Eight < 1 || sp_Eight > PAINTZONE_MAX_EIGHT) {
   help();
   spSizeErrorMessage();
   return 1;
    }

    saveFile = CreateFile(argv[3],
           GENERIC_WRITE,
           0,
           NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);

    if (INVALID_HANDLE_VALUE == saveFile) {
   help();
   fwprintf(stderr, L"The file cannot be open for write.\n");
   if (ERROR_FILE_EXISTS == GetLastError()) {
       fwprintf(stderr, L"The file already exists.\n");
   }
   return 1;
    }

    showCursor(FALSE);

    paintZone_Width = sp_Width;
    paintZone_Eight = sp_Eight;

    dwCoord.X = 0;
    dwCoord.Y = 0;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    dwSize.X = PALETTE_WIDTH;
    dwSize.Y = PALETTE_EIGHT;
    screenRegion.Left = 1;
    screenRegion.Top = 2;
    screenRegion.Right = screenRegion.Left + dwSize.X - 1;
    screenRegion.Bottom = screenRegion.Top + dwSize.Y - 1;
    WriteConsoleOutput(hOut,
             (const CHAR_INFO *) palette,
             dwSize, dwCoord, &screenRegion);

    screenRegion.Left = 7;
    screenRegion.Top = 2;
    screenRegion.Right = screenRegion.Left + dwSize.X - 1;
    screenRegion.Bottom = screenRegion.Top + dwSize.Y - 1;
    WriteConsoleOutput(hOut,
             (const CHAR_INFO *) palette,
             dwSize, dwCoord, &screenRegion);

    dwSize.X = CARTOONS_WIDTH;
    dwSize.Y = CARTOONS_EIGHT;
    screenRegion.Left = 14;
    screenRegion.Top = 2;
    screenRegion.Right = screenRegion.Left + dwSize.X - 1;
    screenRegion.Bottom = screenRegion.Top + dwSize.Y - 1;
    WriteConsoleOutput(hOut,
             (const CHAR_INFO *) cartoons,
             dwSize, dwCoord, &screenRegion);

    paintZone_Length = (UINT) (paintZone_Width * paintZone_Eight);

    CHAR_INFO *paintZone =
   (CHAR_INFO *) malloc(paintZone_Length * sizeof(CHAR_INFO));
    if (!paintZone) {
   abort();
    }

    for (i = 0; i < paintZone_Length; ++i) {
   paintZone[i] = paintCell;
    }

    dwSize.X = paintZone_Width;
    dwSize.Y = paintZone_Eight;

    paintZoneRegion.Left = 18;
    paintZoneRegion.Top = 2;
    paintZoneRegion.Right = paintZoneRegion.Left + dwSize.X - 1;
    paintZoneRegion.Bottom = paintZoneRegion.Top + dwSize.Y - 1;

    WriteConsoleOutput(hOut,
             (const CHAR_INFO *) paintZone,
             dwSize, dwCoord, &paintZoneRegion);

    FillConsoleOutputAttribute(hOut,
                TBF(BColor), 1, BCoord,
                &numberOfCharsWritten);

    FillConsoleOutputAttribute(hOut,
                TBF(FColor), 1, FCoord,
                &numberOfCharsWritten);

    FillConsoleOutputAttribute(hOut,
                BF(BColor, FColor), 1, CCoord,
                &numberOfCharsWritten);

    FillConsoleOutputCharacter(hOut,
                Cartoon, 1, CCoord, &numberOfCharsWritten);


  Inputs:
    mouse(&mouseClic);

    if (coordHaveValues(&mouseClic.clicCoords, 2, 4))
   BColor = 0x0;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 5))
   BColor = 0x1;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 6))
   BColor = 0x2;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 7))
   BColor = 0x3;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 8))
   BColor = 0x4;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 9))
   BColor = 0x5;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 10))
   BColor = 0x6;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 11))
   BColor = 0x7;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 4))
   BColor = 0x8;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 5))
   BColor = 0x9;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 6))
   BColor = 0xA;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 7))
   BColor = 0xB;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 8))
   BColor = 0xC;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 9))
   BColor = 0xD;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 10))
   BColor = 0xE;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 11))
   BColor = 0xF;

    if (coordHaveValues(&mouseClic.clicCoords, 8, 4))
   FColor = 0x0;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 5))
   FColor = 0x1;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 6))
   FColor = 0x2;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 7))
   FColor = 0x3;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 8))
   FColor = 0x4;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 9))
   FColor = 0x5;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 10))
   FColor = 0x6;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 11))
   FColor = 0x7;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 4))
   FColor = 0x8;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 5))
   FColor = 0x9;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 6))
   FColor = 0xA;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 7))
   FColor = 0xB;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 8))
   FColor = 0xC;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 9))
   FColor = 0xD;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 10))
   FColor = 0xE;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 11))
   FColor = 0xF;

    if (coordHaveValues(&mouseClic.clicCoords, 14, 2))
   Cartoon = WHITE_FACE;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 3))
   Cartoon = HEART_SUIT;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 4))
   Cartoon = CLUB_SUIT;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 5))
   Cartoon = BEAMED_EIGHTH;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 6))
   Cartoon = LIGHT_SHADE;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 7))
   Cartoon = MEDIUM_SHADE;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 8))
   Cartoon = DARK_SHADE;

    if (coordHaveValues(&mouseClic.clicCoords, 15, 2))
   Cartoon = BLACK_FACE;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 3))
   Cartoon = DIAMOND_SUIT;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 4))
   Cartoon = SPADE_SUIT;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 5))
   Cartoon = SUN_RAYS;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 6))
   Cartoon = FULL_BLOCK;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 7))
   Cartoon = BLACK_SQUARE;

    FillConsoleOutputAttribute(hOut,
                TBF(BColor), 1, BCoord,
                &numberOfCharsWritten);

    FillConsoleOutputAttribute(hOut,
                TBF(FColor), 1, FCoord,
                &numberOfCharsWritten);

    FillConsoleOutputAttribute(hOut,
                BF(BColor, FColor), 1, CCoord,
                &numberOfCharsWritten);

    FillConsoleOutputCharacter(hOut,
                Cartoon, 1, CCoord, &numberOfCharsWritten);

    //Inside paint zone
    if (mouseClic.clicCoords.X >= paintZoneRegion.Left
   && mouseClic.clicCoords.X <= paintZoneRegion.Right
   && mouseClic.clicCoords.Y >= paintZoneRegion.Top
   && mouseClic.clicCoords.Y <= paintZoneRegion.Bottom) {


   //secondary click: erase
   if (2 == mouseClic.buttonClic) {
       FillConsoleOutputAttribute(hOut,
                   0x07, 1, mouseClic.clicCoords,
                   &numberOfCharsWritten);

       FillConsoleOutputCharacter(hOut,
                   'X', 1, mouseClic.clicCoords,
                   &numberOfCharsWritten);

   } else {
       FillConsoleOutputAttribute(hOut,
                   BF(BColor, FColor), 1,
                   mouseClic.clicCoords,
                   &numberOfCharsWritten);

       if (BColor == FColor) {
      FillConsoleOutputCharacter(hOut,
                  0xDB, 1, mouseClic.clicCoords,
                  &numberOfCharsWritten);
       } else {
      FillConsoleOutputCharacter(hOut,
                  Cartoon, 1,
                  mouseClic.clicCoords,
                  &numberOfCharsWritten);
       }
   }
    } else {
   //secondary outside paintzone for quit
   if (mouseClic.buttonClic == 2)
       goto bye;
    }

    goto Inputs;

    return 0;

  bye:
    if (0 == ReadConsoleOutput(hOut,
                (CHAR_INFO *) paintZone,
                dwSize, dwCoord, &paintZoneRegion)
   ) {
   wprintf(L"Read failed. Error:%ld\n", GetLastError());
   goto quit;
    }
    //Set transparency
    limit = (dwSize.X * dwSize.Y);
    for (i = 0; i < limit; i++) {
   if (L'X' == paintZone[i].Char.UnicodeChar) {
       paintZone[i].Char.UnicodeChar = 0;
       paintZone[i].Attributes = 0;
   }
    }

    //Begin the save of the file
    writeErrors = 0;

    //save size
    if (0 == WriteFile(saveFile, &dwSize,
             (sizeof(COORD)), &numberOfBytesWritten, NULL)
   ) {
   ++writeErrors;
    }
    //save data
    if (0 == WriteFile(saveFile, paintZone,
             (paintZone_Length * sizeof(CHAR_INFO)),
             &numberOfBytesWritten, NULL)
   ) {
   ++writeErrors;
    }

    if (writeErrors) {
   wprintf(L"Write failed. Error:%ld\n", GetLastError());

    } else {
   paintBlack();
   wprintf(L"Saved correctly to: %ls\n", argv[3]);

    }


  quit:
    CloseHandle(saveFile);

    free(paintZone);

    showCursor(TRUE);

    return 0;

}

BOOL coordHaveValues(COORD * coord, SHORT X, SHORT Y)
{
    if ((coord->X == X) && (coord->Y == Y)) {
   return TRUE;
    }

    return FALSE;
}


void paintBlack()
{
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbInfo;
    DWORD nLength;
    COORD coord;
    DWORD numberOfCharsWritten;

    GetConsoleScreenBufferInfo(hOut, &csbInfo);

    nLength = csbInfo.dwSize.X * csbInfo.dwSize.Y;
    coord.X = 0;
    coord.Y = 0;

    SetConsoleCursorPosition(hOut, coord);

    FillConsoleOutputAttribute(hOut,
                0x00, nLength, coord,
                &numberOfCharsWritten);

    FillConsoleOutputCharacter(hOut,
                0x20, nLength, coord,
                &numberOfCharsWritten);
}

void modeCon(int cols, int rows)
{

    HANDLE hOut;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    SMALL_RECT windowSize;
    COORD dwSize;

    dwSize.X = cols;
    dwSize.Y = rows;

    windowSize.Left = 0;
    windowSize.Top = 0;
    windowSize.Right = dwSize.X - 1;
    windowSize.Bottom = dwSize.Y - 1;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hOut, &csbi);
    SetConsoleScreenBufferSize(hOut, csbi.dwMaximumWindowSize);
    SetConsoleWindowInfo(hOut, TRUE, &windowSize);
    SetConsoleScreenBufferSize(hOut, dwSize);
    SetConsoleWindowInfo(hOut, TRUE, &windowSize);


}

void mouse(struct MOUSE_CLIC *mouseClic)
{
#ifndef ENABLE_QUICK_EDIT_MODE
#define ENABLE_QUICK_EDIT_MODE 0x0040
#endif

#ifndef ENABLE_EXTENDED_FLAGS
#define ENABLE_EXTENDED_FLAGS 0x0080
#endif
    HANDLE hIn;
    DWORD old_mode;
    DWORD new_mode;
    DWORD readed;
    INPUT_RECORD ir[1];
    int clic;

    hIn = GetStdHandle(STD_INPUT_HANDLE);
    GetConsoleMode(hIn, &old_mode);

    //
    // keep current configuration,
    // but enable mouse input,
    // disable quick edit mode,
    // disable ctrl+c
    //
    new_mode =
   (DWORD) ((old_mode | ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS) &
       ~(ENABLE_QUICK_EDIT_MODE | ENABLE_PROCESSED_INPUT));
    SetConsoleMode(hIn, new_mode);

  mouse_in:
    ReadConsoleInput(hIn, ir, 1, &readed);
    if (MOUSE_EVENT == ir[0].EventType) {
   clic = (int) (ir[0].Event.MouseEvent.dwButtonState);

   // allow only primary button and secondary button
   switch (clic) {
   case FROM_LEFT_1ST_BUTTON_PRESSED:
   case RIGHTMOST_BUTTON_PRESSED:
       mouseClic->clicCoords.X =
      ir[0].Event.MouseEvent.dwMousePosition.X;
       mouseClic->clicCoords.Y =
      ir[0].Event.MouseEvent.dwMousePosition.Y;
       mouseClic->buttonClic = clic;
       goto mouse_end;
   }
    }
    goto mouse_in;

  mouse_end:
    // restore mouse configuration
    SetConsoleMode(hIn, old_mode);

}

void showCursor(BOOL show)
{
    HANDLE hOut;
    CONSOLE_CURSOR_INFO cci;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleCursorInfo(hOut, &cci);

    if (show) {
   cci.bVisible = TRUE;
    } else {
   cci.bVisible = FALSE;
    }

    SetConsoleCursorInfo(hOut, &cci);
}


To end with, please Carlos, its Height and not Eight (Eight is the number 8 Wink )




______________________________________________________
--
> Que pensez vous de l'ajout du repertoire point dans $PATH ?
Ma version de troll 18.0.32 beta 3 vient de me faire un core dump.
-+- SE in Guide du Linuxien Pervers : Bien développer son troll -+-

[Dos9]
Visiter le site web du posteur Skype
Répondre en citant
Message bg 3.0 rc1 sprite demo 
Very thanks Romain.
I not know that exist that symbols have other unicode values.
Maybe there are other symbols availables in the terminal font.
I will test your code at night, and merge with the next rc.
Also, I'm developing a new optimization for sprite
With your contribution change the code page will be unnecessary, and it will be a new optimization also.



Répondre en citant
Message bg 3.0 rc1 sprite demo 
Thanks Romain again. I tested and is ok. Also using unicode characters solve a problem in japanase windows. Now it run very good on windows japanase.

Also, in your source I fixed this:
Code:
0xDB, 1, mouseClic.clicCoords,

by
Code:
BLACK_SQUARE, 1, mouseClic.clicCoords,


Thanks also for the correction about the word eight vs height Smile

With this update also i modify the binary files of the sprites, replacing: DB00 by 8825

I added new symbols.

rc21 is uploaded.
Is amazing how the example_1.cmd perfomance is very good also on windows xp 64 mb.

Now, I will work in the new sound function of bg.

Thanks again Romain, for your contribution. I keep your copyright notice on the editor source.



Répondre en citant
Message bg 3.0 rc1 sprite demo 
carlos a écrit:
Thanks Romain again. I tested and is ok. Also using unicode characters solve a problem in japanase windows. Now it run very good on windows japanase.

You're welcome. However, There's still one compatibility problem. Unicode characters would not display unless you set a TrueType font in the console. And microsoft's guy set a raster font by default in the console (in western editions). The only thing you can write portably is displaying full blocks by setting the same background and foreground and displaying something.

Citation:
Also, in your source I fixed this:
Code:
0xDB, 1, mouseClic.clicCoords,

by
Code:
BLACK_SQUARE, 1, mouseClic.clicCoords,

Hum, if I remember well, the define associated with 0xDB is FULL_BLOCK Wink

@+




______________________________________________________
--
> Que pensez vous de l'ajout du repertoire point dans $PATH ?
Ma version de troll 18.0.32 beta 3 vient de me faire un core dump.
-+- SE in Guide du Linuxien Pervers : Bien développer son troll -+-

[Dos9]
Visiter le site web du posteur Skype
Répondre en citant
Message bg 3.0 rc1 sprite demo 
In my tests, it uses the raster fonts and shows ok.
Also i will delay the publish of this new bg to the 10 of august.
I will develop new commands.



Répondre en citant
Message bg 3.0 rc1 sprite demo 
carlos a écrit:
Also i will delay the publish of this new bg to the 10 of august.

Okay ! No problem Wink

By the way, I found so sad that sprites could not be reloaded on editor.exe, that i added this functionnality Mr. Green
The command line is still :
Code:
editor X Y file

But X and Y have no influence if file already exist (and is valid, of course).

Code:
/*
  Copyright (C) 2010-2014 Carlos Montiers Aguilera
  Copyright (C) 2014 Romain GARBI

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not
     claim that you wrote the original software. If you use this software
     in a product, an acknowledgment in the product documentation would be
     appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be
     misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

  Carlos Montiers Aguilera
  cmontiers@gmail.com
*/

/*
 * BG Sprite Editor Version 0.5
 */

#define UNICODE

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

#ifdef UNICODE

#define      atoi            _wtoi

#endif

int sprite_main(int argc, TCHAR ** argv);

typedef struct {
    int newmode;
} _startupinfo;

int __wgetmainargs(int *_Argc, wchar_t *** _Argv, wchar_t *** _Env,
         int _DoWildCard, _startupinfo * _StartInfo);
int __getmainargs(int *_Argc, char ***_Argv, char ***_Env,
        int _DoWildCard, _startupinfo * _StartInfo);

int main(void)
{
    int argc;
    TCHAR **argv;
    TCHAR **env;
    int ret;

    _startupinfo start_info = { 0 };

#ifdef UNICODE
    ret = __wgetmainargs(&argc, &argv, &env, 0, &start_info);
#else
    ret = __getmainargs(&argc, &argv, &env, 0, &start_info);
#endif

    if (!ret) {
   ret = sprite_main(argc, argv);
    }
    ExitProcess(ret);
}

struct MOUSE_CLIC {
    COORD clicCoords;
    UINT buttonClic;
};

void spSizeErrorMessage();
void help();
void paintBlack();
void modeCon(int rows, int cols);
void mouse(struct MOUSE_CLIC *mouseClic);
BOOL coordHaveValues(COORD * coord, SHORT X, SHORT Y);
void loadFromFile(HANDLE hFile, CHAR_INFO** paintZone, UINT* paintZone_Height, UINT* paintZone_Width);

void showCursor(BOOL show);

#define S(color, character) ( (CHAR_INFO){(wchar_t)character, (WORD)color} )
#define SPACE S(0x0F, '-')

#ifndef UNICODE

#define FULL_BLOCK       0xDB
#define LIGHT_SHADE       0xB0
#define MEDIUM_SHADE   0xB1
#define DARK_SHADE       0xB2
#define WHITE_FACE      0x01
#define BLACK_FACE      0x02
#define HEART_SUIT      0x03
#define DIAMOND_SUIT   0x04
#define SPADE_SUIT      0x06
#define CLUB_SUIT      0x05
#define BEAMED_EIGHTH   0x07
#define SUN_RAYS      0x0F
#define BLACK_SQUARE   0xFE

#else

#define FULL_BLOCK      0x2588
#define LIGHT_SHADE      0x2591
#define MEDIUM_SHADE    0x2592
#define DARK_SHADE     0x2593
#define WHITE_FACE      0x263A
#define BLACK_FACE      0x263B
#define HEART_SUIT      0x2665
#define DIAMOND_SUIT   0x2666
#define SPADE_SUIT      0x2660
#define CLUB_SUIT      0x2663
#define BEAMED_EIGHTH   0x266B
#define SUN_RAYS      0x263C
#define BLACK_SQUARE   0x25A0

#endif

#define WBlock S(0x0F, MEDIUM_SHADE)
#define BBlock S(0x07, FULL_BLOCK)

#define CBlock S(0x00, 0x20)
#define PBlock S(0x07, 'X')

#define PAINTZONE_MAX_WIDTH (60)
#define PAINTZONE_MAX_EIGHT (20)

void spSizeErrorMessage()
{
    fwprintf(stderr,
        L"Size width must be from 1 to 60 and eight must be from 1 to 20\n");
}

void help()
{
    fwprintf(stdout,
        L"Bg Sprite Editor 0.5\n"
        "Arguments: width eight fileNameToSave\n\n");
}

int sprite_main(int argc, TCHAR ** argv)
{
#define BF(b,f) ((b<<4)+f)
#define TBF(c) ((c<<4)+c)

#define PALETTE_WIDTH (5)
#define PALETTE_EIGHT (14)
#define CARTOONS_WIDTH (2)
#define CARTOONS_EIGHT (7)

    struct MOUSE_CLIC mouseClic;
    HANDLE saveFile;

    //Init values
    UINT BColor = 0x0;
    UINT FColor = 0xE;
    UINT Cartoon = BLACK_SQUARE;

    UINT sp_Width;
    UINT sp_Eight;

    COORD dwSize;

    COORD dwCoord;
    HANDLE hOut;
    SMALL_RECT screenRegion;
    SMALL_RECT paintZoneRegion;

    UINT paintZone_Length;
    UINT paintZone_Width;
    UINT paintZone_Eight;

    CHAR_INFO palette[PALETTE_EIGHT][PALETTE_WIDTH] = {
   {BBlock, BBlock, BBlock, BBlock, BBlock},
   {WBlock, WBlock, WBlock, WBlock, WBlock},
   {WBlock, S(0x00, ' '), WBlock, S(0x80, ' '), WBlock},
   {WBlock, S(0x10, ' '), WBlock, S(0x90, ' '), WBlock},
   {WBlock, S(0x20, ' '), WBlock, S(0xA0, ' '), WBlock},
   {WBlock, S(0x30, ' '), WBlock, S(0xB0, ' '), WBlock},
   {WBlock, S(0x40, ' '), WBlock, S(0xC0, ' '), WBlock},
   {WBlock, S(0x50, ' '), WBlock, S(0xD0, ' '), WBlock},
   {WBlock, S(0x60, ' '), WBlock, S(0xE0, ' '), WBlock},
   {WBlock, S(0x70, ' '), WBlock, S(0xF0, ' '), WBlock},
   {WBlock, WBlock, WBlock, WBlock, WBlock},
   {WBlock, WBlock, WBlock, WBlock, WBlock},
   {WBlock, WBlock, CBlock, WBlock, WBlock},
   {WBlock, WBlock, WBlock, WBlock, WBlock}

    };

    CHAR_INFO cartoons[CARTOONS_EIGHT][CARTOONS_WIDTH] = {
   {S(0x07, WHITE_FACE), S(0x07, BLACK_FACE)},
   {S(0x07, HEART_SUIT), S(0x07, DIAMOND_SUIT)},
   {S(0x07, CLUB_SUIT), S(0x07, SPADE_SUIT)},
   {S(0x07, BEAMED_EIGHTH), S(0x07, SUN_RAYS)},
   {S(0x07, LIGHT_SHADE), S(0x07, FULL_BLOCK)},
   {S(0x07, MEDIUM_SHADE), S(0x07, BLACK_SQUARE)},
   {S(0x07, DARK_SHADE), CBlock}
    };

    CHAR_INFO paintCell = PBlock;

    COORD BCoord = { 3, 14 };
    COORD FCoord = { 9, 14 };
    COORD CCoord = { 14, 14 };
    DWORD numberOfCharsWritten;
    DWORD numberOfBytesWritten;

    UINT i;
    UINT limit;
    UINT writeErrors;

   BOOL bLoadFromFile=FALSE;

   CHAR_INFO* paintZone;

    //SetConsoleOutputCP(1252u);

    modeCon(80, 25);
    paintBlack();

    if (argc != 4) {
   help();
   fwprintf(stderr, L"Few arguments.\n");
   return 1;
    }

   saveFile = CreateFile(argv[3],
           GENERIC_WRITE,
           0,
           NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);

    if (INVALID_HANDLE_VALUE == saveFile) {

   if (ERROR_FILE_EXISTS == GetLastError()) {
       /* Mark data to be loaded from the file */
       bLoadFromFile=TRUE;

   } else {
      help();
      fwprintf(stderr, L"The file cannot be open for write.\n");
      return 1;
   }
    }

    sp_Width = atoi(argv[1]);
    sp_Eight = atoi(argv[2]);

    if (sp_Width < 1 || sp_Width > PAINTZONE_MAX_WIDTH) {
   help();
   spSizeErrorMessage();
   return 1;
    }

    if (sp_Eight < 1 || sp_Eight > PAINTZONE_MAX_EIGHT) {
   help();
   spSizeErrorMessage();
   return 1;
    }

    showCursor(FALSE);

    paintZone_Width = sp_Width;
    paintZone_Eight = sp_Eight;

    dwCoord.X = 0;
    dwCoord.Y = 0;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);

    dwSize.X = PALETTE_WIDTH;
    dwSize.Y = PALETTE_EIGHT;
    screenRegion.Left = 1;
    screenRegion.Top = 2;
    screenRegion.Right = screenRegion.Left + dwSize.X - 1;
    screenRegion.Bottom = screenRegion.Top + dwSize.Y - 1;
    WriteConsoleOutput(hOut,
             (const CHAR_INFO *) palette,
             dwSize, dwCoord, &screenRegion);

    screenRegion.Left = 7;
    screenRegion.Top = 2;
    screenRegion.Right = screenRegion.Left + dwSize.X - 1;
    screenRegion.Bottom = screenRegion.Top + dwSize.Y - 1;
    WriteConsoleOutput(hOut,
             (const CHAR_INFO *) palette,
             dwSize, dwCoord, &screenRegion);

    dwSize.X = CARTOONS_WIDTH;
    dwSize.Y = CARTOONS_EIGHT;
    screenRegion.Left = 14;
    screenRegion.Top = 2;
    screenRegion.Right = screenRegion.Left + dwSize.X - 1;
    screenRegion.Bottom = screenRegion.Top + dwSize.Y - 1;
    WriteConsoleOutput(hOut,
             (const CHAR_INFO *) cartoons,
             dwSize, dwCoord, &screenRegion);

    if (!bLoadFromFile) {

      /* Allocate a new CHAR_INFO struct */

      paintZone_Length = (UINT) (paintZone_Width * paintZone_Eight);

      paintZone =(CHAR_INFO *) malloc(paintZone_Length * sizeof(CHAR_INFO));
      if (!paintZone) {
      abort();
      }

      /* generate the cells */
      for (i = 0; i < paintZone_Length; ++i) {
      paintZone[i] = paintCell;
       }

    } else {

      /* Load the file in read mode */

      saveFile = CreateFile(argv[3],
           GENERIC_WRITE | GENERIC_READ,
           0,
           NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

      if (saveFile == INVALID_HANDLE_VALUE) {
         fwprintf(stderr, L"Unabe to open the file !\n");
         abort();
      }

      loadFromFile(saveFile,
               &paintZone,
               &paintZone_Eight,
               &paintZone_Width
               );

      paintZone_Length = (UINT) (paintZone_Width * paintZone_Eight);

      /* put the pointer at the beginning of the file */
      SetFilePointer(saveFile,
                  0,
                  NULL,
                  FILE_BEGIN);

      /* truncate the file */
      SetEndOfFile(saveFile);

    }

    dwSize.X = paintZone_Width;
    dwSize.Y = paintZone_Eight;

    paintZoneRegion.Left = 18;
    paintZoneRegion.Top = 2;
    paintZoneRegion.Right = paintZoneRegion.Left + dwSize.X - 1;
    paintZoneRegion.Bottom = paintZoneRegion.Top + dwSize.Y - 1;

    WriteConsoleOutput(hOut,
             (const CHAR_INFO *) paintZone,
             dwSize, dwCoord, &paintZoneRegion);

    FillConsoleOutputAttribute(hOut,
                TBF(BColor), 1, BCoord,
                &numberOfCharsWritten);

    FillConsoleOutputAttribute(hOut,
                TBF(FColor), 1, FCoord,
                &numberOfCharsWritten);

    FillConsoleOutputAttribute(hOut,
                BF(BColor, FColor), 1, CCoord,
                &numberOfCharsWritten);

    FillConsoleOutputCharacter(hOut,
                Cartoon, 1, CCoord, &numberOfCharsWritten);


  Inputs:
    mouse(&mouseClic);

    if (coordHaveValues(&mouseClic.clicCoords, 2, 4))
   BColor = 0x0;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 5))
   BColor = 0x1;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 6))
   BColor = 0x2;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 7))
   BColor = 0x3;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 8))
   BColor = 0x4;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 9))
   BColor = 0x5;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 10))
   BColor = 0x6;
    else if (coordHaveValues(&mouseClic.clicCoords, 2, 11))
   BColor = 0x7;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 4))
   BColor = 0x8;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 5))
   BColor = 0x9;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 6))
   BColor = 0xA;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 7))
   BColor = 0xB;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 8))
   BColor = 0xC;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 9))
   BColor = 0xD;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 10))
   BColor = 0xE;
    else if (coordHaveValues(&mouseClic.clicCoords, 4, 11))
   BColor = 0xF;

    if (coordHaveValues(&mouseClic.clicCoords, 8, 4))
   FColor = 0x0;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 5))
   FColor = 0x1;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 6))
   FColor = 0x2;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 7))
   FColor = 0x3;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 8))
   FColor = 0x4;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 9))
   FColor = 0x5;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 10))
   FColor = 0x6;
    else if (coordHaveValues(&mouseClic.clicCoords, 8, 11))
   FColor = 0x7;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 4))
   FColor = 0x8;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 5))
   FColor = 0x9;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 6))
   FColor = 0xA;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 7))
   FColor = 0xB;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 8))
   FColor = 0xC;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 9))
   FColor = 0xD;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 10))
   FColor = 0xE;
    else if (coordHaveValues(&mouseClic.clicCoords, 10, 11))
   FColor = 0xF;

    if (coordHaveValues(&mouseClic.clicCoords, 14, 2))
   Cartoon = WHITE_FACE;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 3))
   Cartoon = HEART_SUIT;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 4))
   Cartoon = CLUB_SUIT;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 5))
   Cartoon = BEAMED_EIGHTH;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 6))
   Cartoon = LIGHT_SHADE;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 7))
   Cartoon = MEDIUM_SHADE;
    else if (coordHaveValues(&mouseClic.clicCoords, 14, 8))
   Cartoon = DARK_SHADE;

    if (coordHaveValues(&mouseClic.clicCoords, 15, 2))
   Cartoon = BLACK_FACE;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 3))
   Cartoon = DIAMOND_SUIT;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 4))
   Cartoon = SPADE_SUIT;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 5))
   Cartoon = SUN_RAYS;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 6))
   Cartoon = FULL_BLOCK;
    else if (coordHaveValues(&mouseClic.clicCoords, 15, 7))
   Cartoon = BLACK_SQUARE;

    FillConsoleOutputAttribute(hOut,
                TBF(BColor), 1, BCoord,
                &numberOfCharsWritten);

    FillConsoleOutputAttribute(hOut,
                TBF(FColor), 1, FCoord,
                &numberOfCharsWritten);

    FillConsoleOutputAttribute(hOut,
                BF(BColor, FColor), 1, CCoord,
                &numberOfCharsWritten);

    FillConsoleOutputCharacter(hOut,
                Cartoon, 1, CCoord, &numberOfCharsWritten);

    //Inside paint zone
    if (mouseClic.clicCoords.X >= paintZoneRegion.Left
   && mouseClic.clicCoords.X <= paintZoneRegion.Right
   && mouseClic.clicCoords.Y >= paintZoneRegion.Top
   && mouseClic.clicCoords.Y <= paintZoneRegion.Bottom) {


   //secondary click: erase
   if (2 == mouseClic.buttonClic) {
       FillConsoleOutputAttribute(hOut,
                   0x07, 1, mouseClic.clicCoords,
                   &numberOfCharsWritten);

       FillConsoleOutputCharacter(hOut,
                   'X', 1, mouseClic.clicCoords,
                   &numberOfCharsWritten);

   } else {
       FillConsoleOutputAttribute(hOut,
                   BF(BColor, FColor), 1,
                   mouseClic.clicCoords,
                   &numberOfCharsWritten);

       if (BColor == FColor) {
      FillConsoleOutputCharacter(hOut,
                  FULL_BLOCK, 1, mouseClic.clicCoords,
                  &numberOfCharsWritten);
       } else {
      FillConsoleOutputCharacter(hOut,
                  Cartoon, 1,
                  mouseClic.clicCoords,
                  &numberOfCharsWritten);
       }
   }
    } else {
   //secondary outside paintzone for quit
   if (mouseClic.buttonClic == 2)
       goto bye;
    }

    goto Inputs;

    return 0;

  bye:
    if (0 == ReadConsoleOutput(hOut,
                (CHAR_INFO *) paintZone,
                dwSize, dwCoord, &paintZoneRegion)
   ) {
   wprintf(L"Read failed. Error:%ld\n", GetLastError());
   goto quit;
    }
    //Set transparency
    limit = (dwSize.X * dwSize.Y);
    for (i = 0; i < limit; i++) {
   if (L'X' == paintZone[i].Char.UnicodeChar) {
       paintZone[i].Char.UnicodeChar = 0;
       paintZone[i].Attributes = 0;
   }
    }

    //Begin the save of the file
    writeErrors = 0;

    //save size
    if (0 == WriteFile(saveFile, &dwSize,
             (sizeof(COORD)), &numberOfBytesWritten, NULL)
   ) {
   ++writeErrors;
    }
    //save data
    if (0 == WriteFile(saveFile, paintZone,
             (paintZone_Length * sizeof(CHAR_INFO)),
             &numberOfBytesWritten, NULL)
   ) {
   ++writeErrors;
    }

    if (writeErrors) {
   wprintf(L"Write failed. Error:%ld\n", GetLastError());

    } else {
   paintBlack();
   wprintf(L"Saved correctly to: %ls\n", argv[3]);

    }


  quit:
    CloseHandle(saveFile);

    free(paintZone);

    showCursor(TRUE);

    return 0;

}

BOOL coordHaveValues(COORD * coord, SHORT X, SHORT Y)
{
    if ((coord->X == X) && (coord->Y == Y)) {
   return TRUE;
    }

    return FALSE;
}


void paintBlack()
{
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbInfo;
    DWORD nLength;
    COORD coord;
    DWORD numberOfCharsWritten;

    GetConsoleScreenBufferInfo(hOut, &csbInfo);

    nLength = csbInfo.dwSize.X * csbInfo.dwSize.Y;
    coord.X = 0;
    coord.Y = 0;

    SetConsoleCursorPosition(hOut, coord);

    FillConsoleOutputAttribute(hOut,
                0x00, nLength, coord,
                &numberOfCharsWritten);

    FillConsoleOutputCharacter(hOut,
                0x20, nLength, coord,
                &numberOfCharsWritten);
}

void modeCon(int cols, int rows)
{

    HANDLE hOut;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    SMALL_RECT windowSize;
    COORD dwSize;

    dwSize.X = cols;
    dwSize.Y = rows;

    windowSize.Left = 0;
    windowSize.Top = 0;
    windowSize.Right = dwSize.X - 1;
    windowSize.Bottom = dwSize.Y - 1;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo(hOut, &csbi);
    SetConsoleScreenBufferSize(hOut, csbi.dwMaximumWindowSize);
    SetConsoleWindowInfo(hOut, TRUE, &windowSize);
    SetConsoleScreenBufferSize(hOut, dwSize);
    SetConsoleWindowInfo(hOut, TRUE, &windowSize);


}

void mouse(struct MOUSE_CLIC *mouseClic)
{
#ifndef ENABLE_QUICK_EDIT_MODE
#define ENABLE_QUICK_EDIT_MODE 0x0040
#endif

#ifndef ENABLE_EXTENDED_FLAGS
#define ENABLE_EXTENDED_FLAGS 0x0080
#endif
    HANDLE hIn;
    DWORD old_mode;
    DWORD new_mode;
    DWORD readed;
    INPUT_RECORD ir[1];
    int clic;

    hIn = GetStdHandle(STD_INPUT_HANDLE);
    GetConsoleMode(hIn, &old_mode);

    //
    // keep current configuration,
    // but enable mouse input,
    // disable quick edit mode,
    // disable ctrl+c
    //
    new_mode =
   (DWORD) ((old_mode | ENABLE_MOUSE_INPUT | ENABLE_EXTENDED_FLAGS) &
       ~(ENABLE_QUICK_EDIT_MODE | ENABLE_PROCESSED_INPUT));
    SetConsoleMode(hIn, new_mode);

  mouse_in:
    ReadConsoleInput(hIn, ir, 1, &readed);
    if (MOUSE_EVENT == ir[0].EventType) {
   clic = (int) (ir[0].Event.MouseEvent.dwButtonState);

   // allow only primary button and secondary button
   switch (clic) {
   case FROM_LEFT_1ST_BUTTON_PRESSED:
   case RIGHTMOST_BUTTON_PRESSED:
       mouseClic->clicCoords.X =
      ir[0].Event.MouseEvent.dwMousePosition.X;
       mouseClic->clicCoords.Y =
      ir[0].Event.MouseEvent.dwMousePosition.Y;
       mouseClic->buttonClic = clic;
       goto mouse_end;
   }
    }
    goto mouse_in;

  mouse_end:
    // restore mouse configuration
    SetConsoleMode(hIn, old_mode);

}

void showCursor(BOOL show)
{
    HANDLE hOut;
    CONSOLE_CURSOR_INFO cci;

    hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    GetConsoleCursorInfo(hOut, &cci);

    if (show) {
   cci.bVisible = TRUE;
    } else {
   cci.bVisible = FALSE;
    }

    SetConsoleCursorInfo(hOut, &cci);
}

void loadFromFile(HANDLE hFile, CHAR_INFO** paintZone,
            UINT* paintZone_Height, UINT* paintZone_Width)
{
   DWORD read, count,i;
   BOOL  ret;
   COORD size;
   CHAR_INFO* zone;

   /* get the dword structure at the beginning of file */
   ret=ReadFile(hFile, &size, sizeof(COORD), &read, NULL);

   if ((read != sizeof(COORD)) || !ret) {

      /* the read failed */
      fwprintf(stderr, L"Invalid file format.\n");
      exit(1);

   }

   *paintZone_Height=size.Y;
   *paintZone_Width=size.X;

   /* Allocate memory for the paintzone */

   count = size.X * size.Y * sizeof(CHAR_INFO);

   *paintZone=(PCHAR_INFO)malloc(count);

   if (*paintZone == NULL) {

      /* Not enough memory */
      fwprintf(stderr, L"To few memory.\n");
      exit(1);

   }

   ret=ReadFile(hFile,
            *paintZone,
            count,
            &read,
            NULL);

   if ( !ret || (read != count)) {

      /* the read failed */
      fwprintf(stderr, L"Invalid file format.\n");
      exit(1);

   }

   /* try to read more, to check the file is conform */

   ReadFile(hFile,
          &i,
          sizeof(int),
          &read,
          NULL);

   if (read != 0) {

      fwprintf(stderr, L"Invalid file format.\n");
      exit(1);

   }

   /* convert '\0' characters to 'X' */

   zone = *paintZone;

   for (i=0;i<count;i++) {

      if (zone[i].Char.UnicodeChar == 0) {
         zone[i].Char.UnicodeChar = L'X';
         zone[i].Attributes = 0x07;
      }

   }
}


bye Razz




______________________________________________________
--
> Que pensez vous de l'ajout du repertoire point dans $PATH ?
Ma version de troll 18.0.32 beta 3 vient de me faire un core dump.
-+- SE in Guide du Linuxien Pervers : Bien développer son troll -+-

[Dos9]
Visiter le site web du posteur Skype
Message bg 3.0 rc1 sprite demo 


Montrer les messages depuis:
Répondre au sujet Page 1 sur 2
Aller à la page: 1, 2  >
  



Index | créer un forum | Forum gratuit d’entraide | Annuaire des forums gratuits | Signaler une violation | Conditions générales d'utilisation
Copyright 2008 - 2016 // Batch