aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez>2005-03-26 14:12:32 +0000
committerantirez <antirez>2005-03-26 14:12:32 +0000
commit3552074b2c1972f72e91cf7fbdc8d63545088142 (patch)
tree50c22a2c8869cee8c2fc8766f125f5f6c6a0486e
parentfe1d16ba54e519c5d71b5e25eb2c07f4ba39de7a (diff)
downloadjimtcl-3552074b2c1972f72e91cf7fbdc8d63545088142.zip
jimtcl-3552074b2c1972f72e91cf7fbdc8d63545088142.tar.gz
jimtcl-3552074b2c1972f72e91cf7fbdc8d63545088142.tar.bz2
some GFX primitive to SDL extension. Minor changes to jim.c
-rw-r--r--ChangeLog5
-rw-r--r--Makefile2
-rw-r--r--jim-sdl.c166
-rw-r--r--jim.c58
4 files changed, 96 insertions, 135 deletions
diff --git a/ChangeLog b/ChangeLog
index 9b37875..6d042bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-03-25 10:34 antirez
+
+ * ChangeLog, bench.tcl, jim.c: SetReturnCodeFromAny() modified to
+ accept numerical codes.
+
2005-03-24 14:58 antirez
* ChangeLog, jim.c, test.tcl: [range] command + tests
diff --git a/Makefile b/Makefile
index 6519f91..5de2688 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,7 @@ jim-sdl.xo: jim-sdl.c
jim-sdl.so: jim-sdl.xo
rm -f $@
- $(LD) -G -z text -o $@ $< -ldl -lc -L/usr/local/lib -lSDL -lpthread
+ $(LD) -G -z text -o $@ $< -ldl -lc -L/usr/local/lib -lSDL -lSDL_gfx -lpthread
jim: $(JIM_OBJECTS)
$(CC) $(LDFLAGS) -o jim $(JIM_OBJECTS) $(LIBS)
diff --git a/jim-sdl.c b/jim-sdl.c
index d8f2e0b..50240e0 100644
--- a/jim-sdl.c
+++ b/jim-sdl.c
@@ -1,7 +1,7 @@
/* Jim - SDL extension
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
*
- * $Id: jim-sdl.c,v 1.1 2005/03/24 11:00:44 antirez Exp $
+ * $Id: jim-sdl.c,v 1.2 2005/03/26 14:12:32 antirez Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
#include <string.h>
#include <errno.h>
#include <SDL.h>
+#include <SDL_gfxPrimitives.h>
#define JIM_EXTENSION
#include "jim.h"
@@ -48,77 +49,6 @@ static void JimSdlDelProc(Jim_Interp *interp, void *privData)
Jim_Free(jss);
}
-static void JimSdlSetPixel(SDL_Surface *screen, int x, int y,
- Uint8 r, Uint8 g, Uint8 b)
-{
- Uint8 *ubuff8;
- Uint16 *ubuff16;
- Uint32 *ubuff32;
- Uint32 color;
- char c1, c2, c3;
-
- /* Lock the screen, if needed */
- if(SDL_MUSTLOCK(screen)) {
- if(SDL_LockSurface(screen) < 0)
- return;
- }
-
- /* Get the color */
- color = SDL_MapRGB( screen->format, r, g, b );
-
- /* How we draw the pixel depends on the bitdepth */
- switch(screen->format->BytesPerPixel)
- {
- case 1:
- ubuff8 = (Uint8*) screen->pixels;
- ubuff8 += (y * screen->pitch) + x;
- *ubuff8 = (Uint8) color;
- break;
-
- case 2:
- ubuff8 = (Uint8*) screen->pixels;
- ubuff8 += (y * screen->pitch) + (x*2);
- ubuff16 = (Uint16*) ubuff8;
- *ubuff16 = (Uint16) color;
- break;
-
- case 3:
- ubuff8 = (Uint8*) screen->pixels;
- ubuff8 += (y * screen->pitch) + (x*3);
-
-
- if(SDL_BYTEORDER == SDL_LIL_ENDIAN) {
- c1 = (color & 0xFF0000) >> 16;
- c2 = (color & 0x00FF00) >> 8;
- c3 = (color & 0x0000FF);
- } else {
- c3 = (color & 0xFF0000) >> 16;
- c2 = (color & 0x00FF00) >> 8;
- c1 = (color & 0x0000FF);
- }
-
- ubuff8[0] = c3;
- ubuff8[1] = c2;
- ubuff8[2] = c1;
- break;
-
- case 4:
- ubuff8 = (Uint8*) screen->pixels;
- ubuff8 += (y*screen->pitch) + (x*4);
- ubuff32 = (Uint32*)ubuff8;
- *ubuff32 = color;
- break;
-
- default:
- fprintf(stderr, "Error: Unknown bitdepth!\n");
- }
-
- /* Unlock the screen if needed */
- if(SDL_MUSTLOCK(screen)) {
- SDL_UnlockSurface(screen);
- }
-}
-
/* Calls to commands created via [sdl.surface] are implemented by this
* C command. */
static int JimSdlHandlerCommand(Jim_Interp *interp, int argc,
@@ -127,9 +57,11 @@ static int JimSdlHandlerCommand(Jim_Interp *interp, int argc,
JimSdlSurface *jss = Jim_CmdPrivData(interp);
int option;
const char *options[] = {
- "free", "setpixel", "flip", NULL
+ "free", "flip", "pixel", "rectangle", "box", "line", "aaline",
+ "circle", "aacircle", "fcircle", NULL
};
- enum {OPT_FREE, OPT_SETPIXEL, OPT_FLIP};
+ enum {OPT_FREE, OPT_FLIP, OPT_PIXEL, OPT_RECTANGLE, OPT_BOX, OPT_LINE,
+ OPT_AALINE, OPT_CIRCLE, OPT_AACIRCLE, OPT_FCIRCLE};
if (argc < 2) {
Jim_WrongNumArgs(interp, 1, argv, "method ?args ...?");
@@ -138,12 +70,12 @@ static int JimSdlHandlerCommand(Jim_Interp *interp, int argc,
if (Jim_GetEnum(interp, argv[1], options, &option, "SDL surface method",
JIM_ERRMSG) != JIM_OK)
return JIM_ERR;
- /* SETPIXEL */
- if (option == OPT_SETPIXEL) {
- long x, y, red, green, blue;
+ if (option == OPT_PIXEL) {
+ /* PIXEL */
+ long x, y, red, green, blue, alpha = 255;
- if (argc != 7) {
- Jim_WrongNumArgs(interp, 2, argv, "x y red green blue");
+ if (argc != 7 && argc != 8) {
+ Jim_WrongNumArgs(interp, 2, argv, "x y red green blue ?alpha?");
return JIM_ERR;
}
if (Jim_GetLong(interp, argv[2], &x) != JIM_OK ||
@@ -154,7 +86,81 @@ static int JimSdlHandlerCommand(Jim_Interp *interp, int argc,
{
return JIM_ERR;
}
- JimSdlSetPixel(jss->screen, x, y, red, green, blue);
+ if (argc == 8 && Jim_GetLong(interp, argv[7], &alpha) != JIM_OK)
+ return JIM_ERR;
+ pixelRGBA(jss->screen, x, y, red, green, blue, alpha);
+ return JIM_OK;
+ } else if (option == OPT_RECTANGLE || option == OPT_BOX ||
+ option == OPT_LINE || option == OPT_AALINE)
+ {
+ /* RECTANGLE, BOX, LINE, AALINE */
+ long x1, y1, x2, y2, red, green, blue, alpha = 255;
+
+ if (argc != 9 && argc != 10) {
+ Jim_WrongNumArgs(interp, 2, argv, "x y red green blue ?alpha?");
+ return JIM_ERR;
+ }
+ if (Jim_GetLong(interp, argv[2], &x1) != JIM_OK ||
+ Jim_GetLong(interp, argv[3], &y1) != JIM_OK ||
+ Jim_GetLong(interp, argv[4], &x2) != JIM_OK ||
+ Jim_GetLong(interp, argv[5], &y2) != JIM_OK ||
+ Jim_GetLong(interp, argv[6], &red) != JIM_OK ||
+ Jim_GetLong(interp, argv[7], &green) != JIM_OK ||
+ Jim_GetLong(interp, argv[8], &blue) != JIM_OK)
+ {
+ return JIM_ERR;
+ }
+ if (argc == 10 && Jim_GetLong(interp, argv[9], &alpha) != JIM_OK)
+ return JIM_ERR;
+ switch(option) {
+ case OPT_RECTANGLE:
+ rectangleRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
+ break;
+ case OPT_BOX:
+ boxRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
+ break;
+ case OPT_LINE:
+ lineRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
+ break;
+ case OPT_AALINE:
+ aalineRGBA(jss->screen, x1, y1, x2, y2, red, green, blue, alpha);
+ break;
+ }
+ return JIM_OK;
+ } else if (option == OPT_CIRCLE || option == OPT_AACIRCLE ||
+ option == OPT_FCIRCLE)
+ {
+ /* CIRCLE, AACIRCLE, FCIRCLE */
+ long x, y, radius, red, green, blue, alpha = 255;
+
+ if (argc != 8 && argc != 9) {
+ Jim_WrongNumArgs(interp, 2, argv,
+ "x y radius red green blue ?alpha?");
+ return JIM_ERR;
+ }
+ if (Jim_GetLong(interp, argv[2], &x) != JIM_OK ||
+ Jim_GetLong(interp, argv[3], &y) != JIM_OK ||
+ Jim_GetLong(interp, argv[4], &radius) != JIM_OK ||
+ Jim_GetLong(interp, argv[5], &red) != JIM_OK ||
+ Jim_GetLong(interp, argv[6], &green) != JIM_OK ||
+ Jim_GetLong(interp, argv[7], &blue) != JIM_OK)
+ {
+ return JIM_ERR;
+ }
+ if (argc == 9 && Jim_GetLong(interp, argv[8], &alpha) != JIM_OK)
+ return JIM_ERR;
+ switch(option) {
+ case OPT_CIRCLE:
+ circleRGBA(jss->screen, x, y, radius, red, green, blue, alpha);
+ break;
+ case OPT_AACIRCLE:
+ aacircleRGBA(jss->screen, x, y, radius, red, green, blue, alpha);
+ break;
+ case OPT_FCIRCLE:
+ filledCircleRGBA(jss->screen, x, y, radius, red, green, blue,
+ alpha);
+ break;
+ }
return JIM_OK;
} else if (option == OPT_FREE) {
/* FREE */
diff --git a/jim.c b/jim.c
index bc2b273..3211c15 100644
--- a/jim.c
+++ b/jim.c
@@ -2,7 +2,7 @@
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
* Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
*
- * $Id: jim.c,v 1.129 2005/03/25 09:34:51 antirez Exp $
+ * $Id: jim.c,v 1.130 2005/03/26 14:12:32 antirez Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -7237,7 +7237,7 @@ int Jim_LoadLibrary(Jim_Interp *interp, const char *pathName)
static int JimCallProcedure(Jim_Interp *interp, Jim_Cmd *cmd, int argc,
Jim_Obj *const *argv);
-/* Hanlde class to the [unknown] command */
+/* Handle calls to the [unknown] command */
static int JimUnknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
Jim_Obj **v, *sv[JIM_EVAL_SARGV_LEN];
@@ -10849,58 +10849,8 @@ void Jim_RegisterCoreCommands(Jim_Interp *interp)
}
/* -----------------------------------------------------------------------------
- * Test
+ * Interactive prompt
* ---------------------------------------------------------------------------*/
-int test_parser(char *filename, int parsetype)
-{
- struct JimParserCtx parser;
- char prg[1024];
- FILE *fp;
- int nread;
-
- if ((fp = fopen(filename, "r")) == NULL) {
- perror("fopen");
- exit(1);
- }
- nread = fread(prg, 1, 1024, fp);
- prg[nread] = '\0';
- fclose(fp);
-
- JimParserInit(&parser, prg, nread, 1);
- while(!JimParserEof(&parser)) {
- const char *type = "", *tok;
- int len, retval = 0;
- if (parsetype == 0)
- retval = JimParseScript(&parser);
- else if (parsetype == 1)
- retval = JimParseExpression(&parser);
- else if (parsetype == 2)
- retval = JimParseSubst(&parser, 0);
- if (retval != JIM_OK) {
- printf("PARSE ERROR\n");
- exit(1);
- }
- switch(JimParserTtype(&parser)) {
- case JIM_TT_STR: type = "STR"; break;
- case JIM_TT_ESC: type = "ESC"; break;
- case JIM_TT_VAR: type = "VAR"; break;
- case JIM_TT_DICTSUGAR: type = "DICTSUGAR"; break;
- case JIM_TT_CMD: type = "CMD"; break;
- case JIM_TT_SEP: type = "SEP"; break;
- case JIM_TT_EOL: type = "EOL"; break;
- case JIM_TT_NONE: type = "NONE"; break;
- case JIM_TT_SUBEXPR_START: type = "SUBEXPR_START"; break;
- case JIM_TT_SUBEXPR_END : type = "SUBEXPR_END"; break;
- case JIM_TT_EXPR_NUMBER : type = "EXPR_NUMBER"; break;
- case JIM_TT_EXPR_OPERATOR: type = "EXPR_OPERATOR"; break;
- }
- printf("%d %s: ", JimParserTline(&parser), type);
- tok = JimParserGetToken(&parser, &len, NULL, NULL);
- printf("'%s' (%d)\n", tok, len);
- }
- return 0;
-}
-
void Jim_PrintErrorMessage(Jim_Interp *interp)
{
int len, i;
@@ -10934,7 +10884,7 @@ int Jim_InteractivePrompt(Jim_Interp *interp)
printf("Welcome to Jim version %d.%d, "
"Copyright (c) 2005 Salvatore Sanfilippo\n",
JIM_VERSION / 100, JIM_VERSION % 100);
- printf("CVS ID: $Id: jim.c,v 1.129 2005/03/25 09:34:51 antirez Exp $\n");
+ printf("CVS ID: $Id: jim.c,v 1.130 2005/03/26 14:12:32 antirez Exp $\n");
Jim_SetVariableStrWithStr(interp, "jim_interactive", "1");
while (1) {
char buf[1024];