cyberslak
/lightsout
/amendments
/23
code cleanup
cyberslak made amendment 23 16 days ago
--- entity_ldef.c Sat Mar 15 17:08:02 2025
+++ entity_ldef.c Sun Mar 16 21:10:50 2025
@@ -5,7 +5,7 @@
#include "entity.h"
#include "util.h"
-pascal short
+pascal void
entity_ldef_proc(short message, Boolean selected, Rect *cellRect,
Cell theCell, short dataOffset, short dataLen,
ListHandle theList)
--- entity_ldef.h Sat Mar 15 17:08:39 2025
+++ entity_ldef.h Sun Mar 16 21:11:00 2025
@@ -2,7 +2,7 @@
#pragma once
-pascal short
+pascal void
entity_ldef_proc(short message, Boolean selected, Rect *cellRect,
Cell theCell, short dataOffset,
short dataLen, ListHandle theList);
--- main.c Sat Mar 15 17:10:46 2025
+++ main.c Tue Mar 18 00:37:54 2025
@@ -58,7 +58,7 @@ void entity_list_show(void);
void event_loop(void);
void event_update(WindowPtr win);
void event_activate(bool activate, EventRecord* evt, WindowPtr win);
-void event_mousedown(EventRecord*);
+void event_mousedown(EventRecord*, WindowPtr, short);
void menu_init(void);
void menu_click(long);
@@ -71,6 +71,7 @@ void resolve_entity_ldef();
pascal void dialog_list_update(WindowPtr theWin, short itemNo);
+void bar_draw(struct entity*);
void bars_draw();
void draw_background();
void bars_update();
@@ -78,7 +79,7 @@ void bars_update();
void scrollbar_create(WindowPtr win);
void scrollbar_remove(WindowPtr win);
-void update_entity_positions(WindowPtr win, short scrollValue);
+void update_entity_positions(short scrollValue);
void get_entity_bounds(struct entity *ent, Rect* out);
struct dialog_info
@@ -125,9 +126,7 @@ void ensure_valid_prefs(void)
}
int main()
-{
- Handle entHnd;
-
+{
toolbox_init();
memory_init();
net_init();
@@ -232,7 +231,6 @@ void bar_create(WindowPtr win, const char* id)
struct entity* ent = xmalloc(sizeof(struct entity));
Rect controlPos;
Rect updateBounds;
- ControlHandle ctrl;
short winHeight;
short barOffset = gNumBars * kBarWidth;
@@ -306,7 +304,7 @@ void bar_remove(WindowPtr win, struct entity *ent)
gNumBars--;
- update_entity_positions(win, scrollValue);
+ update_entity_positions(scrollValue);
handle_scrollbar(win);
}
@@ -390,7 +388,7 @@ void entity_list_activate(bool activate, WindowPtr win
/* Open the entity selection dialog. */
void entity_list_show()
{
- short type, itemHit;
+ short type;
Handle itemHnd;
Rect itemRect, contentRect;
Rect dataBounds;
@@ -431,7 +429,6 @@ void entity_list_show()
list_foreach(&dinfo->ents, node)
{
- size_t len;
ent = container_of(node, struct entity, node);
LSetCell(&ent, sizeof(Ptr), pt, lHnd);
pt.v++;
@@ -443,10 +440,8 @@ void entity_list_show()
void lightsout_init(Handle previousEnts)
{
WindowPtr win;
- Rect controlPos;
short controlWidth = 40;
short controlHeight = 80;
- short winWidth, winHeight;
struct window_info *wi = xmalloc(sizeof(struct window_info));
win = GetNewCWindow(128, nil, (WindowPtr)-1);
@@ -602,10 +597,9 @@ void get_entity_bounds(struct entity *ent, Rect* out)
win->portRect.bottom - scrollBarCompensation);
}
-static void bar_draw(struct entity *ent)
+void bar_draw(struct entity *ent)
{
ControlHandle ctrl = ent->ctrl;
- WindowPtr win = (*ctrl)->contrlOwner;
char buf[128];
unsigned char* pBuf;
Rect sliderBounds = (*ctrl)->contrlRect;
@@ -654,10 +648,8 @@ static void bar_draw(struct entity *ent)
}
}
-void bars_draw(WindowPtr w)
+void bars_draw()
{
- WindowPeek win = (WindowPeek)w;
- struct window_info *info = (void*)GetWRefCon(w);
list_t *node;
struct entity *ent;
@@ -741,14 +733,14 @@ void event_update(WindowPtr win)
with_port(win, {
if (win == gMainWindow)
{
- bars_draw(win);
+ bars_draw();
draw_background(win);
UpdateControls(win, win->visRgn);
}
})
}
-void update_entity_positions(WindowPtr win, short scrollValue)
+void update_entity_positions(short scrollValue)
{
struct entity *ent;
list_t *node;
@@ -810,7 +802,7 @@ control_mousedown(WindowPtr win, EventRecord* evt,
if (val != orig_val)
{
- update_entity_positions(win, val);
+ update_entity_positions(val);
InvalRect(&win->portRect);
}
break;
@@ -825,7 +817,7 @@ struct entity* find_entity_for_click(WindowPtr win, Po
list_t *node;
if (win != gMainWindow)
- return;
+ return NULL;
list_foreach(&gEntities, node)
{
@@ -837,12 +829,11 @@ struct entity* find_entity_for_click(WindowPtr win, Po
return NULL;
}
-void event_mousedown(EventRecord* evt)
+void
+event_mousedown(EventRecord* evt, WindowPtr win, short inPart)
{
- WindowPtr win;
WindowPtr frontWin = FrontWindow();
ControlHandle ctrl;
- short inPart = FindWindow(evt->where, &win);
short inCtrlPart;
long menuChoice;
@@ -910,11 +901,10 @@ void event_loop()
{
EventRecord event;
WindowPtr win;
- Boolean gotEvent;
- GrafPtr oldPort;
short theChar;
short junk;
+ short inPart;
while (gRunning)
{
@@ -923,8 +913,13 @@ void event_loop()
switch(event.what)
{
case mouseDown:
- event_mousedown(&event);
+ {
+ inPart = FindWindow(event.where, &win);
+ with_port(win, {
+ event_mousedown(&event, win, inPart);
+ })
break;
+ }
case updateEvt:
win = (WindowPtr)event.message;
if (win_is_dialog(win))
--- net.c Sat Mar 15 17:10:52 2025
+++ net.c Sun Mar 16 21:12:04 2025
@@ -280,6 +280,8 @@ short net_test_socks()
info("%s", respBuf.buf);
db_destroy(&respBuf);
OTCloseProvider(ep);
+
+ return 0;
}
/* Taken from the OT sample code here:
--- preferences.c Sat Mar 15 17:11:05 2025
+++ preferences.c Sun Mar 16 21:13:51 2025
@@ -91,6 +91,7 @@ short preferences_save(PrefHandle prefs)
short refNum = CurResFile();
ChangedResource((Handle)prefs);
UpdateResFile(refNum);
+ return ResError();
}
short preferences_dialog()
@@ -192,6 +193,8 @@ preferences_save_entities(list_t *entities)
AddResource(entHandle, 'ENTR', kEntsId, "\pSaved entries");
UpdateResFile(refNum);
+
+ return ResError();
}
Handle preferences_get_entities()
--- slider.c Sat Mar 15 17:11:17 2025
+++ slider.c Sun Mar 16 21:25:36 2025
@@ -20,7 +20,7 @@ RGBColor gLightGrey = {
* control.
*/
pascal long
-slider_proc(short varCode, ControlHandle ctl,
+slider_proc(short /* varCode */, ControlHandle ctl,
short message, long param)
{
Rect ctlRect, filledRect, dragRect, indicatorRect;
@@ -29,12 +29,8 @@ slider_proc(short varCode, ControlHandle ctl,
Point testPt;
IndicatorDragConstraint* dragConstraint;
RgnHandle cntlRgn;
- GrafPtr oldPort;
long retval = 0;
- GetPort(&oldPort);
- SetPort((**ctl).contrlOwner);
-
recalc:
ctlRect = (**ctl).contrlRect;
ctlValue = GetControlValue(ctl);
@@ -128,6 +124,5 @@ recalc:
break;
}
- SetPort(oldPort);
return retval;
}