xiaoxiang781216 commented on code in PR #3624: URL: https://github.com/apache/nuttx-apps/pull/3624#discussion_r3652942294
########## graphics/microwindows/Makefile: ########## @@ -0,0 +1,89 @@ +############################################################################ +# apps/graphics/microwindows/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +# LVGL graphic library Review Comment: fix the comment ########## graphics/microwindows/Make.defs: ########## @@ -20,6 +20,21 @@ # ############################################################################ -ifneq ($(CONFIG_EXAMPLES_RNG90),) -CONFIGURED_APPS += $(APPDIR)/examples/rng90 +ifneq ($(CONFIG_GRAPHICS_MICROWINDOWS),) +CONFIGURED_APPS += $(APPDIR)/graphics/microwindows + +# It allows `microwindows/src/include` import. + +CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/include +CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/include + +CFLAGS += -DHAVE_FNT_SUPPORT=1 +CFLAGS += -DUNIX=1 + +CFLAGS += -DSCREEN_PIXTYPE=MWPF_TRUECOLORARGB +CFLAGS += -DSCREEN_DEPTH=8 + +CFLAGS += -DKEYBOARD=NOKBD +CFLAGS += -DMOUSE=NOMOUSE Review Comment: should we move the config to Makefile ########## graphics/microwindows/Makefile: ########## @@ -0,0 +1,89 @@ +############################################################################ +# apps/graphics/microwindows/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +# LVGL graphic library + +MICROWINDOWS_DIR = . +MICROWINDOWS_DIR_NAME = microwindows + +#-include ./lvgl/lvgl.mk + +# Set up build configuration and environment + +WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} + +MICROWINDOWS_COMMIT_HASH := 8809effdd0dfe6c2ac8fd0f455a31407e8495a93 + +#CONFIG_GRAPH_MICROWINDOWS_URL ?= "https://codeload.github.com/ghaerr/microwindows/zip/refs/heads/master" Review Comment: remove ########## examples/microwindows/mwexample.c: ########## @@ -0,0 +1,21 @@ +#include <stdio.h> Review Comment: add copyright ########## graphics/microwindows/Makefile: ########## @@ -0,0 +1,89 @@ +############################################################################ +# apps/graphics/microwindows/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +# LVGL graphic library + +MICROWINDOWS_DIR = . +MICROWINDOWS_DIR_NAME = microwindows + +#-include ./lvgl/lvgl.mk + +# Set up build configuration and environment + +WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} + +MICROWINDOWS_COMMIT_HASH := 8809effdd0dfe6c2ac8fd0f455a31407e8495a93 + +#CONFIG_GRAPH_MICROWINDOWS_URL ?= "https://codeload.github.com/ghaerr/microwindows/zip/refs/heads/master" +CONFIG_GRAPH_MICROWINDOWS_URL ?= https://codeload.github.com/ghaerr/microwindows/zip/$(MICROWINDOWS_COMMIT_HASH) + +MICROWINDOWS_TARBALL := microwindows-$(MICROWINDOWS_COMMIT_HASH).zip + +MICROWINDOWS_UNPACKNAME = microwindows +UNPACK ?= unzip -o $(if $(V),,-q) +CURL ?= curl -L $(if $(V),,-Ss) + +MICROWINDOWS_UNPACKDIR = $(WD)/$(MICROWINDOWS_UNPACKNAME) + +$(MICROWINDOWS_TARBALL): + $(ECHO_BEGIN)"Downloading: $(MICROWINDOWS_TARBALL)" + $(Q) $(CURL) -o $(MICROWINDOWS_TARBALL) $(CONFIG_GRAPH_MICROWINDOWS_URL) + $(ECHO_END) + +$(MICROWINDOWS_UNPACKNAME): $(MICROWINDOWS_TARBALL) + $(ECHO_BEGIN)"Unpacking: $(MICROWINDOWS_TARBALL) -> $(MICROWINDOWS_UNPACKNAME)" + $(Q) $(UNPACK) $(MICROWINDOWS_TARBALL) + $(Q) mv microwindows-$(MICROWINDOWS_COMMIT_HASH) $(MICROWINDOWS_UNPACKNAME) + $(Q) touch $(MICROWINDOWS_UNPACKNAME) + $(ECHO_END) + +# Download and unpack tarball if no git repo found +ifeq ($(wildcard $(MICROWINDOWS_UNPACKNAME)/.git),) +context:: $(MICROWINDOWS_UNPACKNAME) +endif + +CFLAGS += -DRTEMS=0 -DPSP=0 -D__ECOS=0 -D__MINGW32__=0 +CFLAGS += -DELKS=0 -D_MINIX=0 -DMSDOS=0 -DLINUX=0 +CFLAGS += -DMACOSX=0 -DTRIMEDIA=0 + +CFLAGS += -Wno-undef +CFLAGS += -Wno-shadow + +MW_DIR_OBJ = $(WD)/$(MICROWINDOWS_DIR_NAME)/src + +-include microwindows/src/engine/Objects.rules +-include microwindows/src/drivers/Objects.rules +-include microwindows/src/fonts/Objects.rules + +CSRCS += $(MW_CORE_OBJS:%.o=%.c) + +#$(error EXTOBJS=$(EXTOBJS)) + +include $(APPDIR)/Application.mk + +ifeq ($(wildcard $(MICROWINDOWS_UNPACKNAME)/.git),) +distclean:: Review Comment: move after line 63 ########## examples/microwindows/Makefile: ########## @@ -0,0 +1,34 @@ +############################################################################ +# apps/examples/microwindows/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +PROGNAME = $(CONFIG_EXAMPLES_MICROWINDOWS_PROGNAME) +PRIORITY = $(CONFIG_EXAMPLES_MICROWINDOWS_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_MICROWINDOWS_STACKSIZE) +MODULE = y + +MAINSRC = mwexample.c + +CFLAGS += -Wno-undef Review Comment: fix the code ########## graphics/microwindows/Makefile: ########## @@ -0,0 +1,89 @@ +############################################################################ +# apps/graphics/microwindows/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +# LVGL graphic library + +MICROWINDOWS_DIR = . +MICROWINDOWS_DIR_NAME = microwindows + +#-include ./lvgl/lvgl.mk + +# Set up build configuration and environment + +WD := ${shell echo $(CURDIR) | sed -e 's/ /\\ /g'} + +MICROWINDOWS_COMMIT_HASH := 8809effdd0dfe6c2ac8fd0f455a31407e8495a93 + +#CONFIG_GRAPH_MICROWINDOWS_URL ?= "https://codeload.github.com/ghaerr/microwindows/zip/refs/heads/master" +CONFIG_GRAPH_MICROWINDOWS_URL ?= https://codeload.github.com/ghaerr/microwindows/zip/$(MICROWINDOWS_COMMIT_HASH) + +MICROWINDOWS_TARBALL := microwindows-$(MICROWINDOWS_COMMIT_HASH).zip + +MICROWINDOWS_UNPACKNAME = microwindows +UNPACK ?= unzip -o $(if $(V),,-q) +CURL ?= curl -L $(if $(V),,-Ss) + +MICROWINDOWS_UNPACKDIR = $(WD)/$(MICROWINDOWS_UNPACKNAME) + +$(MICROWINDOWS_TARBALL): + $(ECHO_BEGIN)"Downloading: $(MICROWINDOWS_TARBALL)" + $(Q) $(CURL) -o $(MICROWINDOWS_TARBALL) $(CONFIG_GRAPH_MICROWINDOWS_URL) + $(ECHO_END) + +$(MICROWINDOWS_UNPACKNAME): $(MICROWINDOWS_TARBALL) + $(ECHO_BEGIN)"Unpacking: $(MICROWINDOWS_TARBALL) -> $(MICROWINDOWS_UNPACKNAME)" + $(Q) $(UNPACK) $(MICROWINDOWS_TARBALL) + $(Q) mv microwindows-$(MICROWINDOWS_COMMIT_HASH) $(MICROWINDOWS_UNPACKNAME) + $(Q) touch $(MICROWINDOWS_UNPACKNAME) + $(ECHO_END) + +# Download and unpack tarball if no git repo found +ifeq ($(wildcard $(MICROWINDOWS_UNPACKNAME)/.git),) +context:: $(MICROWINDOWS_UNPACKNAME) +endif + +CFLAGS += -DRTEMS=0 -DPSP=0 -D__ECOS=0 -D__MINGW32__=0 +CFLAGS += -DELKS=0 -D_MINIX=0 -DMSDOS=0 -DLINUX=0 +CFLAGS += -DMACOSX=0 -DTRIMEDIA=0 + +CFLAGS += -Wno-undef +CFLAGS += -Wno-shadow + +MW_DIR_OBJ = $(WD)/$(MICROWINDOWS_DIR_NAME)/src + +-include microwindows/src/engine/Objects.rules +-include microwindows/src/drivers/Objects.rules +-include microwindows/src/fonts/Objects.rules + +CSRCS += $(MW_CORE_OBJS:%.o=%.c) + +#$(error EXTOBJS=$(EXTOBJS)) Review Comment: remove ########## examples/microwindows/Makefile: ########## @@ -0,0 +1,34 @@ +############################################################################ +# apps/examples/microwindows/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +PROGNAME = $(CONFIG_EXAMPLES_MICROWINDOWS_PROGNAME) +PRIORITY = $(CONFIG_EXAMPLES_MICROWINDOWS_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_MICROWINDOWS_STACKSIZE) +MODULE = y Review Comment: y->$(CONFIG_EXAMPLES_MICROWINDOWS) ########## graphics/microwindows/Makefile: ########## @@ -0,0 +1,89 @@ +############################################################################ +# apps/graphics/microwindows/Makefile +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(APPDIR)/Make.defs + +# LVGL graphic library + +MICROWINDOWS_DIR = . +MICROWINDOWS_DIR_NAME = microwindows + +#-include ./lvgl/lvgl.mk Review Comment: ditto ########## graphics/microwindows/Make.defs: ########## @@ -27,13 +27,21 @@ CONFIGURED_APPS += $(APPDIR)/graphics/microwindows CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/include CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/include +CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/drivers + +ifeq ($(CONFIG_VIDEO_FB),) +$(error Microwindows requires CONFIG_VIDEO_FB=y) +endif CFLAGS += -DHAVE_FNT_SUPPORT=1 CFLAGS += -DUNIX=1 CFLAGS += -DSCREEN_PIXTYPE=MWPF_TRUECOLORARGB CFLAGS += -DSCREEN_DEPTH=8 +KEYBOARD = NOKBD Review Comment: merge to the first patch ########## graphics/microwindows/mwin-local/scr_nuttx.c: ########## @@ -0,0 +1,104 @@ +#include <fcntl.h> Review Comment: remove, use upstream version instead ########## examples/microwindows/mwexample.c: ########## @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <unistd.h> +#include <nuttx/compiler.h> Review Comment: add blank line ########## examples/microwindows/Make.defs: ########## @@ -0,0 +1,25 @@ +############################################################################ +# apps/examples/hello/Make.defs Review Comment: fix the comment ########## examples/microwindows/mwexample.c: ########## @@ -1,21 +1,148 @@ #include <stdio.h> #include <unistd.h> +#include <sys/select.h> #include <nuttx/compiler.h> #include "device.h" +#include "genfont.h" + +#define TEXTBOX_H 60 +#define RECT_SIZE 20 +#define MAX_TEXT 256 + +static PSD psd; +static MWCOORD screen_w, screen_h; +static MWCOORD textbox_y; +static PMWCOREFONT cfont; +static char textbuf[MAX_TEXT]; +static int textlen = 0; + +static void draw_textbox(void) +{ + GdSetForegroundColor(psd, MWRGB(255, 255, 255)); + GdFillRect(psd, 0, textbox_y, screen_w, TEXTBOX_H); + GdSetForegroundColor(psd, MWRGB(0, 0, 0)); + GdFillRect(psd, 0, textbox_y, screen_w, 2); + GdFillRect(psd, 0, textbox_y + TEXTBOX_H - 2, screen_w, 2); + + if (textlen > 0) { + GdSetForegroundColor(psd, MWRGB(0, 0, 0)); + GdSetBackgroundColor(psd, MWRGB(255, 255, 255)); + GdText(psd, (PMWFONT)cfont, 8, textbox_y + 8, textbuf, textlen, MWTF_ASCII | MWTF_TOP); + } + + MWCOORD tw = 0, th = 0, tb = 0; + GdGetTextSize((PMWFONT)cfont, textbuf, textlen, &tw, &th, &tb, MWTF_ASCII); + GdSetForegroundColor(psd, MWRGB(0, 0, 0)); + GdFillRect(psd, 8 + tw, textbox_y + 8, 2, th > 0 ? th : 16); +} + +static void draw_mouse_rect(MWCOORD x, MWCOORD y) +{ + int rx = x - RECT_SIZE / 2; + int ry = y - RECT_SIZE / 2; + if (rx < 0) rx = 0; + if (ry < 0) ry = 0; + if (rx + RECT_SIZE > screen_w) rx = screen_w - RECT_SIZE; + if (ry + RECT_SIZE > textbox_y) ry = textbox_y - RECT_SIZE; + GdSetForegroundColor(psd, MWRGB(255, 0, 0)); + GdFillRect(psd, rx, ry, RECT_SIZE, RECT_SIZE); +} int main(int argc, FAR char *argv[]) { - PSD psd = GdOpenScreen(); + psd = GdOpenScreen(); if (!psd) { printf("GdOpenScreen failed\n"); return 1; } - GdSetForegroundColor(psd, MWRGB(255, 0, 0)); - GdFillRect(psd, 20, 20, 20, 20); + screen_w = psd->xres; + screen_h = psd->yres; + textbox_y = screen_h - TEXTBOX_H; + + cfont = psd->builtin_fonts; - sleep(5); + int mousefd = GdOpenMouse(); + if (mousefd < 0) { + printf("GdOpenMouse failed, continuing without mouse\n"); + mousefd = -1; + } + int kbd_fd = GdOpenKeyboard(); + if (kbd_fd < 0) { + printf("GdOpenKeyboard failed, continuing without keyboard\n"); + kbd_fd = -1; + } + + GdSetForegroundColor(psd, MWRGB(0, 0, 0)); + GdFillRect(psd, 0, 0, screen_w, screen_h); + + draw_textbox(); + + printf("Mouse+keyboard test. Click to draw, type to input, ESC to quit.\n"); + + fd_set fds; + struct timeval timeout; + MWCOORD mx, my; + int buttons, last_buttons = 0; + int maxfd = 0; Review Comment: move to beginning ########## graphics/microwindows/Make.defs: ########## @@ -27,13 +27,21 @@ CONFIGURED_APPS += $(APPDIR)/graphics/microwindows CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/include CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/include +CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/graphics/microwindows/microwindows/src/drivers + +ifeq ($(CONFIG_VIDEO_FB),) Review Comment: add the dependence to Kconfig -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
